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