Description:
Draw areas when clicked.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -0,0 +1,29 | |||
|
1 | using System; | |
|
2 | using Microsoft.Xna.Framework; | |
|
3 | using Microsoft.Xna.Framework.Graphics; | |
|
4 | using Microsoft.Xna.Framework.Input; | |
|
5 | ||
|
6 | using Encompass; | |
|
7 | ||
|
8 | using isometricparkfna.Messages; | |
|
9 | using isometricparkfna.Components; | |
|
10 | ||
|
11 | namespace isometricparkfna.Engines { | |
|
12 | ||
|
13 | [Receives(typeof(SpawnSelection), | |
|
14 | typeof(AdjustSelection))] | |
|
15 | [Writes(typeof(AreaComponent))] | |
|
16 | public class BuildToolEngine : Engine { | |
|
17 | public override void Update(double dt) { | |
|
18 | ||
|
19 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) | |
|
20 | { | |
|
21 | var entity = CreateEntity(); | |
|
22 | ||
|
23 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start} }); | |
|
24 | AddComponent(entity, new SelectedComponent { selected = false}); | |
|
25 | } | |
|
26 | } | |
|
27 | } | |
|
28 | } | |
|
29 |
@@ -0,0 +1,9 | |||
|
1 | using Microsoft.Xna.Framework; | |
|
2 | ||
|
3 | using Encompass; | |
|
4 | ||
|
5 | namespace isometricparkfna.Messages { | |
|
6 | public struct AdjustSelection : IMessage { | |
|
7 | public Vector2 End; | |
|
8 | } | |
|
9 | } |
@@ -0,0 +1,9 | |||
|
1 | using Microsoft.Xna.Framework; | |
|
2 | ||
|
3 | using Encompass; | |
|
4 | ||
|
5 | namespace isometricparkfna.Messages { | |
|
6 | public struct SpawnSelection : IMessage { | |
|
7 | public Vector2 Start; | |
|
8 | } | |
|
9 | } |
@@ -1,6 +1,8 | |||
|
1 | 1 | using System; |
|
2 | 2 | using System.Collections.Generic; |
|
3 | 3 | |
|
4 | using Microsoft.Xna.Framework; | |
|
5 | ||
|
4 | 6 | namespace isometricparkfna |
|
5 | 7 | { |
|
6 | 8 | |
@@ -186,6 +188,17 | |||
|
186 | 188 | return count; |
|
187 | 189 | } |
|
188 | 190 | |
|
191 | public static Vector2 calculateMousegrid(Vector2 normalizedMousePos) | |
|
192 | { | |
|
193 | Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); | |
|
194 | Vector2 adjustedMousePos = normalizedMousePos - adjust; | |
|
195 | ||
|
196 | float boardx = ((adjustedMousePos.X / Tile.TileSpriteWidth) + (adjustedMousePos.Y / Tile.TileSpriteHeight)); | |
|
197 | float boardy = ((adjustedMousePos.Y / Tile.TileSpriteHeight) - (adjustedMousePos.X / Tile.TileSpriteWidth)); | |
|
198 | ||
|
199 | return new Vector2((int)boardx, (int)boardy); | |
|
200 | } | |
|
201 | ||
|
189 | 202 | public System.Collections.Generic.IEnumerable<Cell> iterate_cells_with_neighbors(int neighbors) |
|
190 | 203 | { |
|
191 | 204 | for (int i = 0; i < MapHeight; i++) |
@@ -91,19 +91,23 | |||
|
91 | 91 | foreach (ref readonly var entity in ReadEntities<AreaComponent>()) |
|
92 | 92 | { |
|
93 | 93 | var areaComponent = GetComponent<AreaComponent>(entity); |
|
94 | var contractStatusComponent = GetComponent<ContractStatusComponent>(entity); | |
|
95 | foreach (var square in areaComponent.squares) | |
|
96 | { | |
|
97 | if (game.mouseGrid == square) | |
|
98 | { | |
|
99 | game.in_zone = true; | |
|
100 | if ((contractStatusComponent.status == ContractStatus.Active) | |
|
101 | || (contractStatusComponent.status == ContractStatus.Accepted)) | |
|
102 | { | |
|
103 | game.in_active_zone = true; | |
|
104 | } | |
|
105 | } | |
|
106 | } | |
|
94 | ||
|
95 | if (HasComponent<ContractStatusComponent>(entity)) | |
|
96 | { | |
|
97 | var contractStatusComponent = GetComponent<ContractStatusComponent>(entity); | |
|
98 | foreach (var square in areaComponent.squares) | |
|
99 | { | |
|
100 | if (game.mouseGrid == square) | |
|
101 | { | |
|
102 | game.in_zone = true; | |
|
103 | if ((contractStatusComponent.status == ContractStatus.Active) | |
|
104 | || (contractStatusComponent.status == ContractStatus.Accepted)) | |
|
105 | { | |
|
106 | game.in_active_zone = true; | |
|
107 | } | |
|
108 | } | |
|
109 | } | |
|
110 | } | |
|
107 | 111 | } |
|
108 | 112 | |
|
109 | 113 | foreach (ref readonly var message in ReadMessages<QuitGameMessage>()) |
@@ -20,7 +20,9 | |||
|
20 | 20 | typeof(TogglePauseMessage), |
|
21 | 21 | typeof(GameRateMessage), |
|
22 | 22 | typeof(GameStateMessage), |
|
23 |
typeof(QuitGameMessage) |
|
|
23 | typeof(QuitGameMessage), | |
|
24 | typeof(SpawnSelection), | |
|
25 | typeof(AdjustSelection))] | |
|
24 | 26 | [Reads(typeof(WindowTypeComponent), |
|
25 | 27 | typeof(GameStateComponent), |
|
26 | 28 | typeof(VisibilityComponent))] |
@@ -52,7 +54,6 | |||
|
52 | 54 | var mouseCur = Mouse.GetState(); |
|
53 | 55 | var original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y), |
|
54 | 56 | Matrix.Invert(this.camera.get_transformation(this.graphicsDevice))); |
|
55 | ||
|
56 | 57 | bool isPlaying = false; |
|
57 | 58 | |
|
58 | 59 | var viewWidth = gdm.PreferredBackBufferWidth; |
@@ -238,6 +239,13 | |||
|
238 | 239 | SendMessage(new JumpCameraMessage {Movement = original_point}); |
|
239 | 240 | } |
|
240 | 241 | |
|
242 | if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Released | |
|
243 | && keyboardCur.IsKeyDown(Keys.LeftShift) | |
|
244 | ) | |
|
245 | { | |
|
246 | SendMessage(new SpawnSelection {Start = CellMap.calculateMousegrid(original_point)}); | |
|
247 | } | |
|
248 | ||
|
241 | 249 | #endregion |
|
242 | 250 | this.keyboardPrev = keyboardCur; |
|
243 | 251 | this.mousePrev = mouseCur; |
@@ -288,7 +288,7 | |||
|
288 | 288 | WorldBuilder.AddEngine(new PolicyEngine()); |
|
289 | 289 | WorldBuilder.AddEngine(new TraceryBridgeEngine(this.grammar)); |
|
290 | 290 | WorldBuilder.AddEngine(new SimulationGameRateBridgeEngine(this.simulation)); |
|
291 | ||
|
291 | WorldBuilder.AddEngine(new BuildToolEngine()); | |
|
292 | 292 | |
|
293 | 293 | WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.tileBatch, this.monoFont), 1); |
|
294 | 294 | WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(this, this.simulation, this.imGuiWindowBridgeEngine, this.gdm), 2); |
@@ -32,6 +32,7 | |||
|
32 | 32 | { |
|
33 | 33 | var areaComponent = GetComponent<AreaComponent>(entity); |
|
34 | 34 | // var SelectedComponent = GetComponent<SelectedComponent>(entity); |
|
35 | var selected = GetComponent<SelectedComponent>(entity).selected; | |
|
35 | 36 | |
|
36 | 37 | if (!HasComponent<ContractStatusComponent>(entity) |
|
37 | 38 | || GetComponent<ContractStatusComponent>(entity).status == ContractStatus.Accepted |
@@ -41,9 +42,7 | |||
|
41 | 42 | Quad.FillSquares(batch, areaComponent.squares, Color.Teal, 0.5f, 0.79f); |
|
42 | 43 | } |
|
43 | 44 | |
|
44 | var selected = GetComponent<SelectedComponent>(entity).selected; | |
|
45 | ||
|
46 | if (HasComponent<ContractStatusComponent>(entity) | |
|
45 | else if (HasComponent<ContractStatusComponent>(entity) | |
|
47 | 46 | && selected |
|
48 | 47 | // && GetComponent<SelectedComponent>(entity).selected |
|
49 | 48 | ) |
@@ -51,6 +50,11 | |||
|
51 | 50 | Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color.Teal); |
|
52 | 51 | Quad.FillSquares(batch, areaComponent.squares, Color.Gray, 0.5f, 0.80f); |
|
53 | 52 | } |
|
53 | else if (!HasComponent<ContractStatusComponent>(entity) ) | |
|
54 | { | |
|
55 | Quad.FillSquares(batch, areaComponent.squares, Color.Red, 0.5f, 0.80f); | |
|
56 | Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color.Red); | |
|
57 | } | |
|
54 | 58 | } |
|
55 | 59 | } |
|
56 | 60 | } |
You need to be logged in to leave comments.
Login now