Description:
Add tool selection button.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r543:4bd5beb7a195 -

@@ -0,0 +1,17
1 using Encompass;
2
3 using isometricparkfna.Messages;
4
5 namespace isometricparkfna.Components {
6
7 public enum Tool
8 {
9 None,
10 Preserve
11
12 }
13
14 public struct ToolComponent : IComponent {
15 public Tool Tool;
16 }
17 }
@@ -0,0 +1,11
1 using isometricparkfna.Components;
2
3 using Encompass;
4
5 namespace isometricparkfna.Messages
6 {
7 public struct ToggleToolMessage : IMessage
8 {
9 public Tool Tool;
10 }
11 }
@@ -6,7 +6,8
6 6 public enum SelectionType {
7 7 None,
8 8 Window, //Selected in a window
9 ActiveTool
9 Area, //Selecting an area
10 Tool //Selecting a tool
10 11 }
11 12
12 13 public struct SelectedComponent : IComponent {
@@ -74,14 +74,14
74 74 var entity = CreateEntity();
75 75
76 76 AddComponent(entity, new AreaComponent { squares = new[] {message.Start} });
77 AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.ActiveTool});
77 AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area});
78 78 }
79 79 }
80 80
81 81 foreach (ref readonly var message in ReadMessages<AdjustSelection>()) {
82 82 foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) {
83 83 var selection = GetComponent<SelectedComponent>(entity);
84 if(selection.Type == SelectionType.ActiveTool
84 if(selection.Type == SelectionType.Area
85 85 && selection.selected) {
86 86 if(message.Type == AdjustmentType.Clear) {
87 87 Destroy(entity);
@@ -27,14 +27,17
27 27 typeof(SetDialogMessage),
28 28 typeof(DialogChoiceMessage),
29 29 typeof(SetOptionMessage),
30 typeof(QuitGameMessage))]
30 typeof(QuitGameMessage),
31 typeof(ToggleToolMessage))]
31 32 [Reads(typeof(VisibilityComponent),
32 33 typeof(WindowTypeComponent),
33 34 typeof(TrespassingPolicyComponent),
34 35 typeof(ContractStatusComponent),
35 36 typeof(RelatedOrganizationComponent),
36 37 typeof(NameAndDescriptionComponent),
37 typeof(OptionsComponent))]
38 typeof(OptionsComponent),
39 typeof(ToolComponent),
40 typeof(SelectedComponent))]
38 41 [Writes(typeof(OptionsComponent))]
39 42 public class ImGuiWindowBridgeEngine : Engine
40 43 {
@@ -54,6 +57,7
54 57 public List<SetOptionMessage> setOptionMessages;
55 58 public List<GameRateMessage> gameRateMessages;
56 59 public List<QuitGameMessage> quitGameMessages;
60 public List<ToggleToolMessage> toggleToolMessages;
57 61
58 62 bool showBudget { get; }
59 63 bool showForest { get; }
@@ -62,6 +66,7
62 66 bool showTrees { get; }
63 67
64 68 public Dictionary<Window, bool> windowStatuses { get; }
69 public Dictionary<Tool, bool> toolStatuses { get; }
65 70
66 71 public bool showContractIndicator;
67 72 public List<string> contracts;
@@ -103,8 +108,10
103 108 this.setOptionMessages = new List<SetOptionMessage>();
104 109 this.gameRateMessages = new List<GameRateMessage>();
105 110 this.quitGameMessages = new List<QuitGameMessage>();
111 this.toggleToolMessages = new List<ToggleToolMessage>();
106 112
107 113 this.windowStatuses = new Dictionary<Window, bool>();
114 this.toolStatuses = new Dictionary<Tool, bool>();
108 115
109 116 this.showContractIndicator = false;
110 117 this.showBudgetLow = false;
@@ -124,6 +131,11
124 131 {
125 132 windowStatuses.Add((Window)type, false);
126 133 }
134
135 foreach (var type in System.Enum.GetValues(typeof(Tool)))
136 {
137 toolStatuses.Add((Tool)type, false);
138 }
127 139 }
128 140
129 141 public override void Update(double dt)
@@ -209,6 +221,11
209 221 SendMessage(message);
210 222 }
211 223
224 foreach (var message in this.toggleToolMessages)
225 {
226 SendMessage(message);
227 }
228
212 229 foreach (var message in this.setOptionMessages)
213 230 {
214 231 foreach (var entity in ReadEntities<OptionsComponent>())
@@ -229,6 +246,12
229 246 windowStatuses[type] = visibility;
230 247 }
231 248
249 foreach (var entity in ReadEntities<ToolComponent>()) {
250 var tool = GetComponent<ToolComponent>(entity).Tool;
251 var selected = HasComponent<SelectedComponent>(entity) ? GetComponent<SelectedComponent>(entity).selected : false;
252 toolStatuses[tool] = selected;
253 }
254
232 255 //reset
233 256 this.showContractIndicator = false;
234 257 this.contracts.Clear();
@@ -277,6 +300,7
277 300 this.gameRateMessages.Clear();
278 301 this.setOptionMessages.Clear();
279 302 this.quitGameMessages.Clear();
303 this.toggleToolMessages.Clear();
280 304 }
281 305 }
282 306 }
@@ -21,11 +21,13
21 21 typeof(SelectMessage),
22 22 typeof(SetDialogMessage),
23 23 typeof(DialogChoiceMessage),
24 typeof(AdjustSelection))]
24 typeof(AdjustSelection),
25 typeof(ToggleToolMessage))]
25 26 [Reads(typeof(DialogComponent),
26 27 typeof(WindowTypeComponent),
27 28 typeof(VisibilityComponent),
28 typeof(SelectedComponent))]
29 typeof(SelectedComponent),
30 typeof(ToolComponent))]
29 31 [Writes(typeof(VisibilityComponent),
30 32 typeof(SelectedComponent))]
31 33 class UIEngine : Engine
@@ -96,6 +98,22
96 98 }
97 99 }
98 100
101 foreach (ref readonly var toolMessage in ReadMessages<ToggleToolMessage>())
102 {
103 foreach (ref readonly var entity in ReadEntities<ToolComponent>())
104 {
105
106 var tool_type = GetComponent<ToolComponent>(entity).Tool;
107 if (tool_type == toolMessage.Tool)
108 {
109 var selectedComponent = GetComponent<SelectedComponent>(entity);
110 selectedComponent.selected = !selectedComponent.selected;
111 SetComponent(entity, selectedComponent);
112 }
113
114 }
115 }
116
99 117 foreach (ref readonly var selectedMessage in ReadMessages<SelectMessage>())
100 118 {
101 119 SetComponent<SelectedComponent>(selectedMessage.Entity,
@@ -106,9 +124,9
106 124 if(message.Type == AdjustmentType.Complete) {
107 125 foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) {
108 126 var selection = GetComponent<SelectedComponent>(entity);
109 if(selection.Type == SelectionType.ActiveTool
127 if(selection.Type == SelectionType.Area
110 128 && selection.selected) {
111 SetComponent(entity, new SelectedComponent {Type = SelectionType.ActiveTool,
129 SetComponent(entity, new SelectedComponent {Type = SelectionType.Area,
112 130 selected = false
113 131 });
114 132 }
@@ -326,6 +326,10
326 326 WorldBuilder.SetComponent(graphWindow, new VisibilityComponent { visible = false });
327 327 WorldBuilder.SetComponent(graphWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Graph });
328 328
329 var preserveTool = WorldBuilder.CreateEntity();
330 WorldBuilder.SetComponent(preserveTool, new ToolComponent { Tool = Tool.Preserve });
331 WorldBuilder.SetComponent(preserveTool, new SelectedComponent {Type = SelectionType.Tool, selected = true});
332
329 333
330 334 var gameEntity = WorldBuilder.CreateEntity();
331 335
@@ -1,4 +1,3
1
2 1 using Encompass;
3 2
4 3 namespace isometricparkfna.Messages
@@ -6,6 +6,7
6 6
7 7 using isometricparkfna.Engines;
8 8 using isometricparkfna.Messages;
9 using isometricparkfna.Components;
9 10
10 11 namespace isometricparkfna.UI
11 12 {
@@ -98,11 +99,20
98 99 ImGui.Text(header);
99 100
100 101
101 var dimensions = ImGui.CalcTextSize("X Graph X Contracts $ Budget X Forest X News X | Pause 1 2 3 4 5") ;
102 var dimensions = ImGui.CalcTextSize("| X Graph X Contracts $ Budget X Forest X News X | Pause 1 2 3 4 5") ;
102 103
103 104 // ImGui.SetCursorPosX(width - 520);
104 105 // Add 12 pixels for each button, plus separator
105 106 ImGui.SetCursorPosX(width - (dimensions.X + 11*12));
107
108 if (Menu.activeButton("X Preserve", bridgeEngine.toolStatuses[Tool.Preserve], StyleSets.selected, StyleSets.white))
109 {
110 bridgeEngine.toggleToolMessages.Add(new ToggleToolMessage {Tool = Tool.Preserve});
111
112 }
113
114 ImGui.Text("|");
115
106 116 if (Menu.activeButton("\ue03e Graph", bridgeEngine.windowStatuses[Window.Graph], StyleSets.selected, StyleSets.white))
107 117 {
108 118 bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage {Window = Window.Graph});
You need to be logged in to leave comments. Login now