Description:
Limit to boundaries.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -188,16 +188,16 | |||
|
188 | 188 | return count; |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | public static Vector2 calculateMousegrid(Vector2 normalizedMousePos) | |
|
192 | { | |
|
193 | Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); | |
|
194 | Vector2 adjustedMousePos = normalizedMousePos - adjust; | |
|
191 | public static Vector2 calculateMousegrid(Vector2 normalizedMousePos) | |
|
192 | { | |
|
193 | Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); | |
|
194 | Vector2 adjustedMousePos = normalizedMousePos - adjust; | |
|
195 | 195 | |
|
196 | float boardx = ((adjustedMousePos.X / Tile.TileSpriteWidth) + (adjustedMousePos.Y / Tile.TileSpriteHeight)); | |
|
197 | float boardy = ((adjustedMousePos.Y / Tile.TileSpriteHeight) - (adjustedMousePos.X / Tile.TileSpriteWidth)); | |
|
196 | float boardx = ((adjustedMousePos.X / Tile.TileSpriteWidth) + (adjustedMousePos.Y / Tile.TileSpriteHeight)); | |
|
197 | float boardy = ((adjustedMousePos.Y / Tile.TileSpriteHeight) - (adjustedMousePos.X / Tile.TileSpriteWidth)); | |
|
198 | 198 | |
|
199 | return new Vector2((int)boardx, (int)boardy); | |
|
200 | } | |
|
199 | return new Vector2((int)boardx, (int)boardy); | |
|
200 | } | |
|
201 | 201 | |
|
202 | 202 | public System.Collections.Generic.IEnumerable<Cell> iterate_cells_with_neighbors(int neighbors) |
|
203 | 203 | { |
@@ -13,12 +13,18 | |||
|
13 | 13 | namespace isometricparkfna.Engines { |
|
14 | 14 | |
|
15 | 15 | [Receives(typeof(SpawnSelection), |
|
16 | typeof(AdjustSelection))] | |
|
16 | typeof(AdjustSelection))] | |
|
17 | 17 | [Writes(typeof(AreaComponent))] |
|
18 | 18 | [Reads(typeof(SelectedComponent), |
|
19 |
|
|
|
19 | typeof(AreaComponent))] | |
|
20 | 20 | public class BuildToolEngine : Engine { |
|
21 | 21 | |
|
22 | private CellMap Map; | |
|
23 | ||
|
24 | public BuildToolEngine(CellMap map) { | |
|
25 | this.Map = map; | |
|
26 | } | |
|
27 | ||
|
22 | 28 | private System.Collections.Generic.IEnumerable<float> step_until(float start, float stop) { |
|
23 | 29 | if (stop >= start) { |
|
24 | 30 | for(float i = start; i <= stop; i++) |
@@ -60,22 +66,11 | |||
|
60 | 66 | |
|
61 | 67 | newSquares.Add(area.squares[0]); |
|
62 | 68 | |
|
69 | var end_x = MathUtils.Clamp(message.End.X, 0.0f, this.Map.MapWidth); | |
|
70 | var end_y = MathUtils.Clamp(message.End.Y, 0.0f, this.Map.MapHeight); | |
|
63 | 71 | |
|
64 | // | |
|
65 |
|
|
|
66 | // for (float j = area.squares[0].Y; j >= message.End.Y; j--) { | |
|
67 | // newSquares.Add(new Vector2(i, j)); | |
|
68 | // } | |
|
69 | // } | |
|
70 | // | |
|
71 | // for (float i = area.squares[0].X; i <= message.End.X; i++) { | |
|
72 | // for (float j = area.squares[0].Y; j <= message.End.Y; j++) { | |
|
73 | // newSquares.Add(new Vector2(i, j)); | |
|
74 | // } | |
|
75 | // } | |
|
76 | ||
|
77 | foreach (var i in step_until(area.squares[0].X, message.End.X)) { | |
|
78 | foreach (var j in step_until(area.squares[0].Y, message.End.Y)) { | |
|
72 | foreach (var i in step_until(area.squares[0].X, end_x)) { | |
|
73 | foreach (var j in step_until(area.squares[0].Y, end_y)) { | |
|
79 | 74 | newSquares.Add(new Vector2(i, j)); |
|
80 | 75 | } |
|
81 | 76 | } |
@@ -83,12 +78,12 | |||
|
83 | 78 | newSquares.Add(message.End); |
|
84 | 79 | |
|
85 | 80 | SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*( new[]{ area.squares[0], message.End}*/}); |
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
81 | } | |
|
82 | } | |
|
83 | } | |
|
89 | 84 | |
|
90 | } | |
|
91 | } | |
|
92 | } | |
|
93 | } | |
|
85 | } | |
|
86 | } | |
|
87 | } | |
|
88 | } | |
|
94 | 89 |
@@ -92,22 +92,22 | |||
|
92 | 92 | { |
|
93 | 93 | var areaComponent = GetComponent<AreaComponent>(entity); |
|
94 | 94 | |
|
95 |
|
|
|
96 | { | |
|
97 |
|
|
|
98 |
|
|
|
99 | { | |
|
100 |
|
|
|
101 | { | |
|
102 | game.in_zone = true; | |
|
103 |
|
|
|
104 |
|
|
|
105 | { | |
|
106 | game.in_active_zone = true; | |
|
107 | } | |
|
108 | } | |
|
109 | } | |
|
110 | } | |
|
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 | } | |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | foreach (ref readonly var message in ReadMessages<QuitGameMessage>()) |
@@ -21,8 +21,8 | |||
|
21 | 21 | typeof(GameRateMessage), |
|
22 | 22 | typeof(GameStateMessage), |
|
23 | 23 | typeof(QuitGameMessage), |
|
24 |
|
|
|
25 |
|
|
|
24 | typeof(SpawnSelection), | |
|
25 | typeof(AdjustSelection))] | |
|
26 | 26 | [Reads(typeof(WindowTypeComponent), |
|
27 | 27 | typeof(GameStateComponent), |
|
28 | 28 | typeof(VisibilityComponent))] |
@@ -240,21 +240,21 | |||
|
240 | 240 | } |
|
241 | 241 | |
|
242 | 242 | if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Released |
|
243 |
|
|
|
244 | ) | |
|
243 | && keyboardCur.IsKeyDown(Keys.LeftShift) | |
|
244 | ) | |
|
245 | 245 | { |
|
246 | 246 | SendMessage(new SpawnSelection {Start = CellMap.calculateMousegrid(original_point)}); |
|
247 | 247 | } |
|
248 | 248 | |
|
249 |
|
|
|
250 | { | |
|
249 | if ( mouseCur.LeftButton == ButtonState.Released && mousePrev.LeftButton == ButtonState.Pressed ) | |
|
250 | { | |
|
251 | 251 | SendMessage(new AdjustSelection {Clear = true }); |
|
252 | } | |
|
252 | } | |
|
253 | 253 | |
|
254 | 254 | if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Pressed) |
|
255 | { | |
|
256 |
|
|
|
257 | } | |
|
255 | { | |
|
256 | SendMessage(new AdjustSelection { End = CellMap.calculateMousegrid(original_point)}); | |
|
257 | } | |
|
258 | 258 | |
|
259 | 259 | #endregion |
|
260 | 260 | this.keyboardPrev = keyboardCur; |
@@ -40,10 +40,10 | |||
|
40 | 40 | { |
|
41 | 41 | foreach (var entity in ReadEntities<SelectedComponent>()) |
|
42 | 42 | { |
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 | } | |
|
43 | var selected = GetComponent<SelectedComponent>(entity); | |
|
44 | if (selected.Type == SelectionType.Window) { | |
|
45 | SetComponent(entity, new SelectedComponent { selected = false }); | |
|
46 | } | |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | foreach (ref readonly var windowMessage in ReadMessages<SetWindowVisibilityMessage>()) |
@@ -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 | WorldBuilder.AddEngine(new BuildToolEngine()); | |
|
291 | WorldBuilder.AddEngine(new BuildToolEngine(this.simulation.map)); | |
|
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); |
@@ -36,25 +36,25 | |||
|
36 | 36 | |
|
37 | 37 | if ((!HasComponent<ContractStatusComponent>(entity) |
|
38 | 38 | || GetComponent<ContractStatusComponent>(entity).status == ContractStatus.Accepted) |
|
39 | && !selected) | |
|
39 | && !selected) | |
|
40 | 40 | { |
|
41 | 41 | Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color.Teal); |
|
42 | 42 | Quad.FillSquares(batch, areaComponent.squares, Color.Teal, 0.5f, 0.78f); |
|
43 | 43 | } |
|
44 | 44 | |
|
45 |
|
|
|
46 | && selected | |
|
47 | // && GetComponent<SelectedComponent>(entity).selected | |
|
48 | ) | |
|
45 | else if (HasComponent<ContractStatusComponent>(entity) | |
|
46 | && selected | |
|
47 | // && GetComponent<SelectedComponent>(entity).selected | |
|
48 | ) | |
|
49 | 49 | { |
|
50 | 50 | Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color.Teal); |
|
51 | 51 | Quad.FillSquares(batch, areaComponent.squares, Color.Gray, 0.5f, 0.78f); |
|
52 | 52 | } |
|
53 |
|
|
|
54 | { | |
|
53 | else if (!HasComponent<ContractStatusComponent>(entity) ) | |
|
54 | { | |
|
55 | 55 | Quad.FillSquares(batch, areaComponent.squares, Color.Red, 0.5f, 0.79f); |
|
56 | 56 | Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color.Red); |
|
57 | } | |
|
57 | } | |
|
58 | 58 | } |
|
59 | 59 | } |
|
60 | 60 | } |
@@ -116,9 +116,9 | |||
|
116 | 116 | |
|
117 | 117 | foreach (var e in contracts) |
|
118 | 118 | { |
|
119 |
|
|
|
120 |
|
|
|
121 | } | |
|
119 | if(HasComponent<ContractStatusComponent>(e)) { | |
|
120 | contract_data.Add(getContractDetails(e)); | |
|
121 | } | |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | ContractsWindow.Render(this.BridgeEngine.font, this.BridgeEngine, contract_data); |
@@ -68,6 +68,22 | |||
|
68 | 68 | } |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | public static float Clamp(float val, float min, float max) | |
|
72 | { | |
|
73 | if (val > max) | |
|
74 | { | |
|
75 | return max; | |
|
76 | } | |
|
77 | else if (val < min) | |
|
78 | { | |
|
79 | return min; | |
|
80 | } | |
|
81 | else | |
|
82 | { | |
|
83 | return val; | |
|
84 | } | |
|
85 | } | |
|
86 | ||
|
71 | 87 | protected float Decrement(float value, float delta) |
|
72 | 88 | { |
|
73 | 89 | float magnitude = Math.Abs(value); |
You need to be logged in to leave comments.
Login now