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