Description:
Allow finalizing preserve areas.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r539:99b285f3e6d3 -

@@ -0,0 +1,10
1
2 using Encompass;
3 using System;
4
5 namespace isometricparkfna.Components {
6
7 public struct PreserveComponent : IComponent {
8 public DateTime date;
9 }
10 }
@@ -14,7 +14,9
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 // typeof(SelectedComponent),
19 typeof(PreserveComponent))]
18 [Reads(typeof(SelectedComponent),
20 [Reads(typeof(SelectedComponent),
19 typeof(AreaComponent))]
21 typeof(AreaComponent))]
20 public class BuildToolEngine : Engine {
22 public class BuildToolEngine : Engine {
@@ -44,28 +46,32
44
46
45 foreach (ref readonly var message in ReadMessages<SpawnSelection>())
47 foreach (ref readonly var message in ReadMessages<SpawnSelection>())
46 {
48 {
49 if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth
50 && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) {
47 var entity = CreateEntity();
51 var entity = CreateEntity();
48
52
49 AddComponent(entity, new AreaComponent { squares = new[] {message.Start} });
53 AddComponent(entity, new AreaComponent { squares = new[] {message.Start} });
50 AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.ActiveTool});
54 AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.ActiveTool});
55 }
51 }
56 }
52
57
53 foreach (ref readonly var message in ReadMessages<AdjustSelection>())
58 foreach (ref readonly var message in ReadMessages<AdjustSelection>()) {
54 {
59 foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) {
55 foreach (ref readonly var entity in ReadEntities<SelectedComponent>())
56 {
57 var selection = GetComponent<SelectedComponent>(entity);
60 var selection = GetComponent<SelectedComponent>(entity);
58 if(selection.Type == SelectionType.ActiveTool) {
61 if(selection.Type == SelectionType.ActiveTool
59 if(message.Clear) {
62 && selection.selected) {
63 if(message.Type == AdjustmentType.Clear) {
60 Destroy(entity);
64 Destroy(entity);
61 }
65 }
66 else if(message.Type == AdjustmentType.Complete) {
67 SetComponent(entity, new PreserveComponent {});
68 // SetComponent(entity, new SelectedComponent {selected = false });
69 }
62 else {
70 else {
63 var area = GetComponent<AreaComponent>(entity);
71 var area = GetComponent<AreaComponent>(entity);
64
72
65 var newSquares = new List<Vector2>();
73 var newSquares = new List<Vector2>();
66
74
67 newSquares.Add(area.squares[0]);
68
69 var end_x = MathUtils.Clamp(message.End.X, 0.0f, this.Map.MapWidth);
75 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);
76 var end_y = MathUtils.Clamp(message.End.Y, 0.0f, this.Map.MapHeight);
71
77
@@ -75,8 +81,6
75 }
81 }
76 }
82 }
77
83
78 newSquares.Add(message.End);
79
80 SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*( new[]{ area.squares[0], message.End}*/});
84 SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*( new[]{ area.squares[0], message.End}*/});
81 }
85 }
82 }
86 }
@@ -188,6 +188,7
188 {
188 {
189 SendMessage(new ToggleWindowTypeMessage {Window = Window.InGameMenu});
189 SendMessage(new ToggleWindowTypeMessage {Window = Window.InGameMenu});
190 SendMessage(new GameRateMessage { paused = true, rate = null });
190 SendMessage(new GameRateMessage { paused = true, rate = null });
191 SendMessage(new AdjustSelection {Type = AdjustmentType.Complete });
191 }
192 }
192 }
193 }
193
194
@@ -248,7 +249,7
248
249
249 if ( mouseCur.LeftButton == ButtonState.Released && mousePrev.LeftButton == ButtonState.Pressed )
250 if ( mouseCur.LeftButton == ButtonState.Released && mousePrev.LeftButton == ButtonState.Pressed )
250 {
251 {
251 SendMessage(new AdjustSelection {Clear = true });
252 SendMessage(new AdjustSelection {Type = AdjustmentType.Complete });
252 }
253 }
253
254
254 if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Pressed)
255 if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Pressed)
@@ -20,7 +20,8
20 typeof(SetWindowVisibilityMessage),
20 typeof(SetWindowVisibilityMessage),
21 typeof(SelectMessage),
21 typeof(SelectMessage),
22 typeof(SetDialogMessage),
22 typeof(SetDialogMessage),
23 typeof(DialogChoiceMessage))]
23 typeof(DialogChoiceMessage),
24 typeof(AdjustSelection))]
24 [Reads(typeof(DialogComponent),
25 [Reads(typeof(DialogComponent),
25 typeof(WindowTypeComponent),
26 typeof(WindowTypeComponent),
26 typeof(VisibilityComponent),
27 typeof(VisibilityComponent),
@@ -101,7 +102,20
101 new SelectedComponent { selected = true });
102 new SelectedComponent { selected = true });
102 }
103 }
103
104
105 foreach (ref readonly var message in ReadMessages<AdjustSelection>()) {
106 if(message.Type == AdjustmentType.Complete) {
107 foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) {
108 var selection = GetComponent<SelectedComponent>(entity);
109 if(selection.Type == SelectionType.ActiveTool
110 && selection.selected) {
111 SetComponent(entity, new SelectedComponent {Type = SelectionType.ActiveTool,
112 selected = false });
113 }
114 }
115 }
116 }
104
117
105 }
118
106 }
119 }
120 }
107 }
121 }
@@ -3,8 +3,15
3 using Encompass;
3 using Encompass;
4
4
5 namespace isometricparkfna.Messages {
5 namespace isometricparkfna.Messages {
6
7 public enum AdjustmentType {
8 None,
9 Clear,
10 Complete
11 }
12
6 public struct AdjustSelection : IMessage {
13 public struct AdjustSelection : IMessage {
7 public Vector2 End;
14 public Vector2 End;
8 public bool Clear;
15 public AdjustmentType Type;
9 }
16 }
10 }
17 }
You need to be logged in to leave comments. Login now