Description:
Extend ranges properly.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -3,7 +3,14 | |||||
|
3 |
|
3 | ||
|
4 | namespace isometricparkfna.Components |
|
4 | namespace isometricparkfna.Components |
|
5 | { |
|
5 | { |
|
|
6 | public enum SelectionType { | ||
|
|
7 | None, | ||
|
|
8 | Window, //Selected in a window | ||
|
|
9 | ActiveTool | ||
|
|
10 | } | ||
|
|
11 | |||
|
6 | public struct SelectedComponent : IComponent { |
|
12 | public struct SelectedComponent : IComponent { |
|
7 | public bool selected; |
|
13 | public bool selected; |
|
|
14 | public SelectionType Type; | ||
|
8 | } |
|
15 | } |
|
9 | } No newline at end of file |
|
16 | } |
@@ -1,4 +1,6 | |||||
|
1 | using System; |
|
1 | using System; |
|
|
2 | using System.Linq; | ||
|
|
3 | using System.Collections.Generic; | ||
|
2 | using Microsoft.Xna.Framework; |
|
4 | using Microsoft.Xna.Framework; |
|
3 | using Microsoft.Xna.Framework.Graphics; |
|
5 | using Microsoft.Xna.Framework.Graphics; |
|
4 | using Microsoft.Xna.Framework.Input; |
|
6 | using Microsoft.Xna.Framework.Input; |
@@ -13,7 +15,25 | |||||
|
13 | [Receives(typeof(SpawnSelection), |
|
15 | [Receives(typeof(SpawnSelection), |
|
14 | typeof(AdjustSelection))] |
|
16 | typeof(AdjustSelection))] |
|
15 | [Writes(typeof(AreaComponent))] |
|
17 | [Writes(typeof(AreaComponent))] |
|
|
18 | [Reads(typeof(SelectedComponent), | ||
|
|
19 | typeof(AreaComponent))] | ||
|
16 | public class BuildToolEngine : Engine { |
|
20 | public class BuildToolEngine : Engine { |
|
|
21 | |||
|
|
22 | private System.Collections.Generic.IEnumerable<float> step_until(float start, float stop) { | ||
|
|
23 | if (stop >= start) { | ||
|
|
24 | for(float i = start; i <= stop; i++) | ||
|
|
25 | { | ||
|
|
26 | yield return i; | ||
|
|
27 | } | ||
|
|
28 | } | ||
|
|
29 | else { | ||
|
|
30 | for(float i = start; i >= stop; i--) | ||
|
|
31 | { | ||
|
|
32 | yield return i; | ||
|
|
33 | } | ||
|
|
34 | } | ||
|
|
35 | } | ||
|
|
36 | |||
|
17 | public override void Update(double dt) { |
|
37 | public override void Update(double dt) { |
|
18 |
|
38 | ||
|
19 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) |
|
39 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) |
@@ -21,9 +41,54 | |||||
|
21 | var entity = CreateEntity(); |
|
41 | var entity = CreateEntity(); |
|
22 |
|
42 | ||
|
23 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start} }); |
|
43 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start} }); |
|
24 |
AddComponent(entity, new SelectedComponent { selected = |
|
44 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.ActiveTool}); |
|
25 | } |
|
45 | } |
|
26 | } |
|
46 | |
|
27 | } |
|
47 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) |
|
28 | } |
|
48 | { |
|
|
49 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) | ||
|
|
50 | { | ||
|
|
51 | var selection = GetComponent<SelectedComponent>(entity); | ||
|
|
52 | if(selection.Type == SelectionType.ActiveTool) { | ||
|
|
53 | if(message.Clear) { | ||
|
|
54 | Destroy(entity); | ||
|
|
55 | } | ||
|
|
56 | else { | ||
|
|
57 | var area = GetComponent<AreaComponent>(entity); | ||
|
|
58 | |||
|
|
59 | var newSquares = new List<Vector2>(); | ||
|
|
60 | |||
|
|
61 | newSquares.Add(area.squares[0]); | ||
|
|
62 | |||
|
29 |
|
63 | ||
|
|
64 | // | ||
|
|
65 | // for (float i = area.squares[0].X; i >= message.End.X; i--) { | ||
|
|
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)); | ||
|
|
80 | } | ||
|
|
81 | } | ||
|
|
82 | |||
|
|
83 | newSquares.Add(message.End); | ||
|
|
84 | |||
|
|
85 | SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*( new[]{ area.squares[0], message.End}*/}); | ||
|
|
86 | } | ||
|
|
87 | } | ||
|
|
88 | } | ||
|
|
89 | |||
|
|
90 | } | ||
|
|
91 | } | ||
|
|
92 | } | ||
|
|
93 | } | ||
|
|
94 |
@@ -246,6 +246,16 | |||||
|
246 | SendMessage(new SpawnSelection {Start = CellMap.calculateMousegrid(original_point)}); |
|
246 | SendMessage(new SpawnSelection {Start = CellMap.calculateMousegrid(original_point)}); |
|
247 | } |
|
247 | } |
|
248 |
|
248 | ||
|
|
249 | if ( mouseCur.LeftButton == ButtonState.Released && mousePrev.LeftButton == ButtonState.Pressed ) | ||
|
|
250 | { | ||
|
|
251 | SendMessage(new AdjustSelection {Clear = true }); | ||
|
|
252 | } | ||
|
|
253 | |||
|
|
254 | if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Pressed) | ||
|
|
255 | { | ||
|
|
256 | SendMessage(new AdjustSelection { End = CellMap.calculateMousegrid(original_point)}); | ||
|
|
257 | } | ||
|
|
258 | |||
|
249 | #endregion |
|
259 | #endregion |
|
250 | this.keyboardPrev = keyboardCur; |
|
260 | this.keyboardPrev = keyboardCur; |
|
251 | this.mousePrev = mouseCur; |
|
261 | this.mousePrev = mouseCur; |
@@ -206,7 +206,7 | |||||
|
206 | AddComponent(contract, new AreaComponent { squares = squares }); |
|
206 | AddComponent(contract, new AreaComponent { squares = squares }); |
|
207 | var nameAndDescription = new NameAndDescriptionComponent { DisplayName = this.grammar.Flatten(message.name) }; |
|
207 | var nameAndDescription = new NameAndDescriptionComponent { DisplayName = this.grammar.Flatten(message.name) }; |
|
208 | AddComponent(contract, nameAndDescription); |
|
208 | AddComponent(contract, nameAndDescription); |
|
209 | AddComponent(contract, new SelectedComponent { selected = false }); |
|
209 | AddComponent(contract, new SelectedComponent { selected = false, Type = SelectionType.Window }); |
|
210 | AddComponent(contract, new ContractStatusComponent { status = ContractStatus.Proposed, date = this.simulation.DateTime }); |
|
210 | AddComponent(contract, new ContractStatusComponent { status = ContractStatus.Proposed, date = this.simulation.DateTime }); |
|
211 | AddComponent(contract, new TreeDeltaComponent { deltaTrees = new Fact<int>(deltaTrees) }); |
|
211 | AddComponent(contract, new TreeDeltaComponent { deltaTrees = new Fact<int>(deltaTrees) }); |
|
212 | AddComponent(contract, new BudgetLineComponent |
|
212 | AddComponent(contract, new BudgetLineComponent |
@@ -40,7 +40,10 | |||||
|
40 | { |
|
40 | { |
|
41 | foreach (var entity in ReadEntities<SelectedComponent>()) |
|
41 | foreach (var entity in ReadEntities<SelectedComponent>()) |
|
42 | { |
|
42 | { |
|
43 | SetComponent(entity, new SelectedComponent { selected = false }); |
|
43 | var selected = GetComponent<SelectedComponent>(entity); |
|
|
44 | if (selected.Type == SelectionType.Window) { | ||
|
|
45 | SetComponent(entity, new SelectedComponent { selected = false }); | ||
|
|
46 | } | ||
|
44 | } |
|
47 | } |
|
45 |
|
48 | ||
|
46 | foreach (ref readonly var windowMessage in ReadMessages<SetWindowVisibilityMessage>()) |
|
49 | foreach (ref readonly var windowMessage in ReadMessages<SetWindowVisibilityMessage>()) |
@@ -5,5 +5,6 | |||||
|
5 | namespace isometricparkfna.Messages { |
|
5 | namespace isometricparkfna.Messages { |
|
6 | public struct AdjustSelection : IMessage { |
|
6 | public struct AdjustSelection : IMessage { |
|
7 | public Vector2 End; |
|
7 | public Vector2 End; |
|
|
8 | public bool Clear; | ||
|
8 | } |
|
9 | } |
|
9 | } |
|
10 | } |
@@ -34,12 +34,12 | |||||
|
34 | // var SelectedComponent = GetComponent<SelectedComponent>(entity); |
|
34 | // var SelectedComponent = GetComponent<SelectedComponent>(entity); |
|
35 | var selected = GetComponent<SelectedComponent>(entity).selected; |
|
35 | var selected = GetComponent<SelectedComponent>(entity).selected; |
|
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 | ) |
|
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.7 |
|
42 | Quad.FillSquares(batch, areaComponent.squares, Color.Teal, 0.5f, 0.78f); |
|
43 | } |
|
43 | } |
|
44 |
|
44 | ||
|
45 | else if (HasComponent<ContractStatusComponent>(entity) |
|
45 | else if (HasComponent<ContractStatusComponent>(entity) |
@@ -48,11 +48,11 | |||||
|
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.8 |
|
51 | Quad.FillSquares(batch, areaComponent.squares, Color.Gray, 0.5f, 0.78f); |
|
52 | } |
|
52 | } |
|
53 | else if (!HasComponent<ContractStatusComponent>(entity) ) |
|
53 | else if (!HasComponent<ContractStatusComponent>(entity) ) |
|
54 | { |
|
54 | { |
|
55 |
Quad.FillSquares(batch, areaComponent.squares, Color.Red, 0.5f, 0. |
|
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 | } |
@@ -116,7 +116,9 | |||||
|
116 |
|
116 | ||
|
117 | foreach (var e in contracts) |
|
117 | foreach (var e in contracts) |
|
118 | { |
|
118 | { |
|
119 | contract_data.Add(getContractDetails(e)); |
|
119 | if(HasComponent<ContractStatusComponent>(e)) { |
|
|
120 | contract_data.Add(getContractDetails(e)); | ||
|
|
121 | } | ||
|
120 | } |
|
122 | } |
|
121 |
|
123 | ||
|
122 | ContractsWindow.Render(this.BridgeEngine.font, this.BridgeEngine, contract_data); |
|
124 | ContractsWindow.Render(this.BridgeEngine.font, this.BridgeEngine, contract_data); |
You need to be logged in to leave comments.
Login now