Description:
Add Tower placement.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -0,0 +1,11 | |||
|
1 | using Microsoft.Xna.Framework; | |
|
2 | ||
|
3 | using Encompass; | |
|
4 | ||
|
5 | namespace isometricparkfna.Components { | |
|
6 | ||
|
7 | public struct PointComponent : IComponent { | |
|
8 | public Vector2 Square; | |
|
9 | public Tool Tool; | |
|
10 | } | |
|
11 | } |
@@ -0,0 +1,17 | |||
|
1 | ||
|
2 | using Encompass; | |
|
3 | ||
|
4 | using isometricparkfna.Messages; | |
|
5 | ||
|
6 | namespace isometricparkfna.Components { | |
|
7 | public enum Structure | |
|
8 | { | |
|
9 | None, | |
|
10 | Tower | |
|
11 | } | |
|
12 | ||
|
13 | public struct StructureComponent : IComponent { | |
|
14 | public Structure Structure; | |
|
15 | // public DateTime Placed; | |
|
16 | } | |
|
17 | } |
@@ -0,0 +1,40 | |||
|
1 | using Microsoft.Xna.Framework; | |
|
2 | using Microsoft.Xna.Framework.Graphics; | |
|
3 | ||
|
4 | using isometricparkfna.UI; | |
|
5 | using isometricparkfna.Components; | |
|
6 | ||
|
7 | using Encompass; | |
|
8 | using SpriteFontPlus; | |
|
9 | ||
|
10 | namespace isometricparkfna.Renderers | |
|
11 | { | |
|
12 | public class StructureRenderer : GeneralRenderer | |
|
13 | { | |
|
14 | private SpriteBatch batch; | |
|
15 | private SpriteFont font; | |
|
16 | ||
|
17 | public StructureRenderer(SpriteBatch batch, SpriteFont font) | |
|
18 | { | |
|
19 | this.batch = batch; | |
|
20 | this.font = font; | |
|
21 | } | |
|
22 | ||
|
23 | public override void Render() | |
|
24 | { | |
|
25 | ||
|
26 | ||
|
27 | foreach (ref readonly var entity in ReadEntities<StructureComponent>()) | |
|
28 | { | |
|
29 | var point = GetComponent<PointComponent>(entity); | |
|
30 | Tile.drawTileAt(this.batch, (int)point.Square.X, (int)point.Square.Y, | |
|
31 | 300, 2, 0.79f, Color.White); | |
|
32 | } | |
|
33 | ||
|
34 | ||
|
35 | ||
|
36 | } | |
|
37 | } | |
|
38 | ||
|
39 | ||
|
40 | } |
@@ -17,13 +17,15 | |||
|
17 | 17 | typeof(AdjustSelection))] |
|
18 | 18 | [Writes(typeof(AreaComponent), |
|
19 | 19 | // typeof(SelectedComponent), |
|
20 | typeof(PointComponent), | |
|
20 | 21 | typeof(PreserveComponent))] |
|
21 | 22 | [Reads(typeof(SelectedComponent), |
|
22 | 23 | typeof(ContractStatusComponent), |
|
23 | 24 | typeof(AreaComponent), |
|
24 | 25 | typeof(PreserveComponent), |
|
25 | 26 | typeof(SelectedComponent), |
|
26 |
typeof(ToolComponent) |
|
|
27 | typeof(ToolComponent), | |
|
28 | typeof(PointComponent))] | |
|
27 | 29 | [Sends(typeof(ChangeContractStatusMessage))] |
|
28 | 30 | public class BuildToolEngine : Engine { |
|
29 | 31 | |
@@ -204,6 +206,52 | |||
|
204 | 206 | } |
|
205 | 207 | } |
|
206 | 208 | } |
|
209 | else if (statuses.ContainsKey(Tool.Tower) && statuses[Tool.Tower]) { | |
|
210 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) | |
|
211 | { | |
|
212 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth | |
|
213 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { | |
|
214 | var entity = CreateEntity(); | |
|
215 | ||
|
216 | AddComponent(entity, new PointComponent {Square = message.Start, | |
|
217 | Tool=Tool.Tower}); | |
|
218 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); | |
|
219 | } | |
|
220 | } | |
|
221 | ||
|
222 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { | |
|
223 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { | |
|
224 | var selection = GetComponent<SelectedComponent>(entity); | |
|
225 | ||
|
226 | if (selection.Type == SelectionType.Area | |
|
227 | && selection.selected) { | |
|
228 | if(message.Type == AdjustmentType.Clear) { | |
|
229 | Destroy(entity); | |
|
230 | } | |
|
231 | else if(message.Type == AdjustmentType.Complete) { | |
|
232 | var point = GetComponent<PointComponent>(entity); | |
|
233 | var structure_entity = CreateEntity(); | |
|
234 | ||
|
235 | AddComponent(structure_entity, new PointComponent {Square = point.Square, | |
|
236 | Tool = point.Tool} ); | |
|
237 | AddComponent(structure_entity, | |
|
238 | new StructureComponent { Structure = Structure.Tower}); | |
|
239 | Destroy(entity); | |
|
240 | Logging.Success("Placed Tower!"); | |
|
241 | ||
|
242 | } | |
|
243 | else { | |
|
244 | var point = GetComponent<PointComponent>(entity); | |
|
245 | SetComponent(entity, new PointComponent {Square = message.End, | |
|
246 | Tool = point.Tool}); | |
|
247 | } | |
|
248 | } | |
|
249 | ||
|
250 | } | |
|
251 | ||
|
252 | } | |
|
253 | ||
|
254 | } | |
|
207 | 255 | } |
|
208 | 256 | } |
|
209 | 257 | } |
@@ -318,6 +318,7 | |||
|
318 | 318 | WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.tileBatch, this.monoFont), 1); |
|
319 | 319 | WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(this, this.simulation, this.imGuiWindowBridgeEngine, this.gdm), 2); |
|
320 | 320 | WorldBuilder.AddGeneralRenderer(new CursorRenderer(this.tileBatch, this.monoFont), 3); |
|
321 | WorldBuilder.AddGeneralRenderer(new StructureRenderer(this.tileBatch, this.monoFont), 4); | |
|
321 | 322 | var contractWindow = WorldBuilder.CreateEntity(); |
|
322 | 323 | WorldBuilder.SetComponent(contractWindow, new VisibilityComponent { visible = false }); |
|
323 | 324 | WorldBuilder.SetComponent(contractWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Contracts }); |
@@ -34,8 +34,8 | |||
|
34 | 34 | {ImGuiCol.FrameBg, grey}, |
|
35 | 35 | {ImGuiCol.FrameBgHovered, grey}, |
|
36 | 36 | {ImGuiCol.Header, darkgrey}, |
|
37 | {ImGuiCol.HeaderHovered, grey}, | |
|
38 | {ImGuiCol.HeaderActive, grey}, | |
|
37 | {ImGuiCol.HeaderHovered, darkgrey}, | |
|
38 | {ImGuiCol.HeaderActive, darkgrey}, | |
|
39 | 39 | {ImGuiCol.ButtonHovered, grey}, |
|
40 | 40 | {ImGuiCol.ButtonActive, darkgrey}, |
|
41 | 41 | {ImGuiCol.SliderGrab, darkgrey}, |
You need to be logged in to leave comments.
Login now