Description:
Refactor dialog into Encompass.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r381:82c352fd371d -

@@ -0,0 +1,15
1
2
3 using Microsoft.Xna.Framework;
4
5 using Encompass;
6 using isometricparkfna.Utils;
7 using isometricparkfna.UI;
8 using isometricparkfna.Engines;
9
10 namespace isometricparkfna.Components {
11
12 public struct DialogComponent : IComponent {
13 public Node<DialogOption> Dialog;
14 }
15 }
@@ -0,0 +1,16
1 using Encompass;
2
3 using isometricparkfna.Utils;
4 using isometricparkfna.UI;
5
6 namespace isometricparkfna.Messages
7 {
8
9 //You must specify both or you get 0 for a window, which is the default window :(
10 public struct SetDialogMessage : IMessage, IHasEntity
11 {
12
13 public Entity Entity { set; get; }
14 public Node<DialogOption> newOption;
15 }
16 }
@@ -0,0 +1,14
1
2 using Encompass;
3
4 namespace isometricparkfna.Messages
5 {
6
7 //You must specify both or you get 0 for a window, which is the default window :(
8 public struct SetWindowVisibilityMessage : IMessage, IHasEntity
9 {
10
11 public Entity Entity { set; get; }
12 public bool Visibility;
13 }
14 }
@@ -21,7 +21,8
21 typeof(SetFontMessage),
21 typeof(SetFontMessage),
22 typeof(SetTrespassingPolicyMessage),
22 typeof(SetTrespassingPolicyMessage),
23 typeof(SpawnGameMessage),
23 typeof(SpawnGameMessage),
24 typeof(SetTextVariableMessage))]
24 typeof(SetTextVariableMessage),
25 typeof(SetDialogMessage))]
25 [Reads(typeof(VisibilityComponent),
26 [Reads(typeof(VisibilityComponent),
26 typeof(WindowTypeComponent),
27 typeof(WindowTypeComponent),
27 typeof(TrespassingPolicyComponent)
28 typeof(TrespassingPolicyComponent)
@@ -42,6 +43,7
42 public List<SetTrespassingPolicyMessage> trespassingPolicyMessages;
43 public List<SetTrespassingPolicyMessage> trespassingPolicyMessages;
43 public List<SpawnGameMessage> spawnGameMessages;
44 public List<SpawnGameMessage> spawnGameMessages;
44 public List<SetTextVariableMessage> setTextVariableMessages;
45 public List<SetTextVariableMessage> setTextVariableMessages;
46 public List<SetDialogMessage> setDialogMessages;
45
47
46 bool showBudget {get;}
48 bool showBudget {get;}
47 bool showForest {get;}
49 bool showForest {get;}
@@ -70,6 +72,7
70 this.trespassingPolicyMessages = new List<SetTrespassingPolicyMessage>();
72 this.trespassingPolicyMessages = new List<SetTrespassingPolicyMessage>();
71 this.spawnGameMessages = new List<SpawnGameMessage>();
73 this.spawnGameMessages = new List<SpawnGameMessage>();
72 this.setTextVariableMessages = new List<SetTextVariableMessage>();
74 this.setTextVariableMessages = new List<SetTextVariableMessage>();
75 this.setDialogMessages = new List<SetDialogMessage>();
73 this.windowStatuses = new Dictionary<Window, bool>();
76 this.windowStatuses = new Dictionary<Window, bool>();
74
77
75
78
@@ -109,6 +112,11
109 SendMessage(message);
112 SendMessage(message);
110 }
113 }
111
114
115 //
116 foreach (var message in this.setTextVariableMessages)
117 {
118 SendMessage(message);
119 }
112 foreach(var message in this.gameStateMessages)
120 foreach(var message in this.gameStateMessages)
113 {
121 {
114 SendMessage(message);
122 SendMessage(message);
@@ -144,8 +152,8
144 SendMessage(message);
152 SendMessage(message);
145 }
153 }
146
154
147 //This may need to be moved up.
155
148 foreach (var message in this.setTextVariableMessages)
156 foreach (var message in this.setDialogMessages)
149 {
157 {
150 SendMessage(message);
158 SendMessage(message);
151 }
159 }
@@ -157,11 +165,12
157 foreach(var entity in ReadEntities<WindowTypeComponent>())
165 foreach(var entity in ReadEntities<WindowTypeComponent>())
158 {
166 {
159 var type = GetComponent<WindowTypeComponent>(entity).type;
167 var type = GetComponent<WindowTypeComponent>(entity).type;
160 var visibility = GetComponent<VisibilityComponent>(entity).visible;
168 var visibility = HasComponent<VisibilityComponent>(entity) ? GetComponent<VisibilityComponent>(entity).visible : false;
161 windowStatuses[type] = visibility;
169 windowStatuses[type] = visibility;
162
170
163 }
171 }
164
172
173
165 this.messages.Clear();
174 this.messages.Clear();
166 this.typeMessages.Clear();
175 this.typeMessages.Clear();
167 this.contractStatusMessages.Clear();
176 this.contractStatusMessages.Clear();
@@ -173,6 +182,7
173 this.trespassingPolicyMessages.Clear();
182 this.trespassingPolicyMessages.Clear();
174 this.spawnGameMessages.Clear();
183 this.spawnGameMessages.Clear();
175 this.setTextVariableMessages.Clear();
184 this.setTextVariableMessages.Clear();
185 this.setDialogMessages.Clear();
176 }
186 }
177 }
187 }
178 }
188 }
@@ -5,6 +5,7
5 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework;
6
6
7 using isometricparkfna.Messages;
7 using isometricparkfna.Messages;
8 using isometricparkfna.Components;
8 using static isometricparkfna.CellMap;
9 using static isometricparkfna.CellMap;
9 using isometricparkfna.UI;
10 using isometricparkfna.UI;
10
11
@@ -15,7 +16,11
15
16
16 [Receives(typeof(SpawnGameMessage))]
17 [Receives(typeof(SpawnGameMessage))]
17 [Sends(typeof(SpawnContractMessage),
18 [Sends(typeof(SpawnContractMessage),
18 typeof(SpawnOrganizationtMessage))]
19 typeof(SpawnOrganizationtMessage),
20 typeof(ToggleWindowMessage))]
21 [Writes(typeof(WindowTypeComponent)
22 //, typeof(DialogComponent)
23 )]
19 class GameSpawner : Spawner<SpawnGameMessage>
24 class GameSpawner : Spawner<SpawnGameMessage>
20
25
21 {
26 {
@@ -106,7 +111,34
106 #endregion
111 #endregion
107 #region dialog
112 #region dialog
108
113
109 this.game.enqueueDialog(DialogTrees.flatten(DialogTrees.testTree, this.grammar));
114 // this.game.enqueueDialog(DialogTrees.flatten(DialogTrees.testTree, this.grammar));
115 //
116
117 var dialogInitial = CreateEntity();
118 // SetComponent(dialogInitial, new VisibilityComponent { visible = true });
119 AddComponent(dialogInitial, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Dialog });
120 AddComponent(dialogInitial,
121 new DialogComponent {Dialog = DialogTrees.introTree });
122 AddComponent(dialogInitial,
123 new VisibilityComponent{ visible = true});
124 // SendMessage(new SetWindowVisibilityMessage {
125 // Entity = dialogInitial,
126 // Visibility = true });
127
128
129 var dialogTest = CreateEntity();
130 // SetComponent(dialogTest, new VisibilityComponent { visible = true });
131 AddComponent(dialogTest, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Dialog });
132 AddComponent(dialogTest,
133 new DialogComponent {Dialog = DialogTrees.flatten(DialogTrees.testTree, this.grammar)});
134 // SendMessage(new SetWindowVisibilityMessage {
135 // Entity = dialogTest,
136 // Visibility = true
137 // });
138 AddComponent(dialogTest,
139 new VisibilityComponent{ visible = true});
140
141
110 #endregion
142 #endregion
111 this.simulation.Subsidy = message.Difficulty switch {
143 this.simulation.Subsidy = message.Difficulty switch {
112 DifficultyLevel.Hard => 0M,
144 DifficultyLevel.Hard => 0M,
@@ -8,11 +8,18
8 namespace isometricparkfna.Engines
8 namespace isometricparkfna.Engines
9 {
9 {
10
10
11 [Receives(typeof(ToggleWindowMessage), typeof(ToggleWindowTypeMessage), typeof(ToggleVisibilityMessage),
11 [Receives(typeof(ToggleWindowMessage),
12 typeof(SelectMessage))]
12 typeof(ToggleWindowTypeMessage),
13 [Reads(typeof(WindowTypeComponent), typeof(VisibilityComponent),
13 typeof(ToggleVisibilityMessage),
14 typeof(SelectedComponent))]
14 typeof(SetWindowVisibilityMessage),
15 [Writes(typeof(VisibilityComponent), typeof(SelectedComponent))]
15 typeof(SelectMessage),
16 typeof(SetDialogMessage))]
17 [Reads(typeof(WindowTypeComponent),
18 typeof(VisibilityComponent),
19 typeof(SelectedComponent))]
20 [Writes(typeof(VisibilityComponent),
21 typeof(SelectedComponent),
22 typeof(DialogComponent))]
16 class UIEngine : Engine
23 class UIEngine : Engine
17 {
24 {
18
25
@@ -23,6 +30,23
23 SetComponent(entity, new SelectedComponent { selected = false });
30 SetComponent(entity, new SelectedComponent { selected = false });
24 }
31 }
25
32
33 foreach (ref readonly var windowMessage in ReadMessages<SetWindowVisibilityMessage>())
34 {
35 Logging.Spy(windowMessage, "message");
36 Logging.Spy(windowMessage.Entity, "message.Entity");
37 Logging.Spy(windowMessage.Entity.ID, "message.Entity.ID");
38 Logging.Spy(windowMessage.Visibility, "message.Visibility");
39 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
40 {
41 Logging.Spy(entity.ID, "ID");
42 if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID)
43 {
44 AddComponent(entity, new VisibilityComponent { visible = windowMessage.Visibility });
45 Logging.Success("Set Visibility.");
46
47 }
48 }
49 }
26 foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowMessage>())
50 foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowMessage>())
27 {
51 {
28 Logging.Spy(windowMessage, "message");
52 Logging.Spy(windowMessage, "message");
@@ -33,7 +57,7
33 if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID)
57 if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID)
34 {
58 {
35 var visibilityComponent = GetComponent<VisibilityComponent>(entity);
59 var visibilityComponent = GetComponent<VisibilityComponent>(entity);
36 SetComponent(entity, new VisibilityComponent { visible = !visibilityComponent.visible });
60 AddComponent(entity, new VisibilityComponent { visible = !visibilityComponent.visible });
37
61
38 }
62 }
39 }
63 }
@@ -60,6 +84,21
60 SetComponent<SelectedComponent>(selectedMessage.Entity,
84 SetComponent<SelectedComponent>(selectedMessage.Entity,
61 new SelectedComponent { selected = true });
85 new SelectedComponent { selected = true });
62 }
86 }
87
88 foreach (ref readonly var dialogMessage in ReadMessages<SetDialogMessage>())
89 {
90 if (dialogMessage.newOption != null)
91 {
92 SetComponent(dialogMessage.Entity,
93 new DialogComponent {Dialog = dialogMessage.newOption
94 });
95 }
96 else
97 {
98 Destroy(dialogMessage.Entity);
99
100 }
101 }
63 }
102 }
64 }
103 }
65 }
104 }
@@ -290,16 +290,16
290 WorldBuilder.SetComponent(newGameWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.NewGame });
290 WorldBuilder.SetComponent(newGameWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.NewGame });
291
291
292
292
293 var gameEntity = WorldBuilder.CreateEntity();
293
294
294 var gameEntity = WorldBuilder.CreateEntity();
295 WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false});
295
296 WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false});
297
296
298 var policyEntity = WorldBuilder.CreateEntity();
297 var policyEntity = WorldBuilder.CreateEntity();
299 WorldBuilder.SetComponent(policyEntity,
298 WorldBuilder.SetComponent(policyEntity,
300 new TrespassingPolicyComponent { tresspassingPolicy = EnforcementLevel.NoEnforcement});
299 new TrespassingPolicyComponent { tresspassingPolicy = EnforcementLevel.NoEnforcement});
301 WorldBuilder.SetComponent(policyEntity,
300 WorldBuilder.SetComponent(policyEntity,
302 new BudgetLineComponent { });
301 new BudgetLineComponent { });
302
303
303
304 try {
304 try {
305 var options = Options.readOptions();
305 var options = Options.readOptions();
@@ -821,8 +821,8
821 #region window
821 #region window
822 if (this.currentNode != null)
822 if (this.currentNode != null)
823 {
823 {
824 this.currentNode = DialogInterface.RenderDialog(ref this.showInitial,
824 // this.currentNode = DialogInterface.RenderDialog(ref this.showInitial,
825 ref this.simulation.paused, debugWindow.monoFont, this.currentNode);
825 // ref this.simulation.paused, debugWindow.monoFont, this.currentNode);
826 }
826 }
827
827
828 if (this.showForest)
828 if (this.showForest)
@@ -15,7 +15,8
15 MainMenu,
15 MainMenu,
16 InGameMenu,
16 InGameMenu,
17 Options,
17 Options,
18 NewGame
18 NewGame,
19 Dialog
19 }
20 }
20
21
21
22
@@ -69,7 +69,7
69 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
69 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
70 {
70 {
71 var window_type = GetComponent<WindowTypeComponent>(entity).type;
71 var window_type = GetComponent<WindowTypeComponent>(entity).type;
72 var visible = GetComponent<VisibilityComponent>(entity).visible;
72 var visible = HasComponent<VisibilityComponent>(entity) ? GetComponent<VisibilityComponent>(entity).visible : false;
73
73
74 if (visible)
74 if (visible)
75 {
75 {
@@ -110,6 +110,13
110 case Window.NewGame:
110 case Window.NewGame:
111 NewGameWindow.Render(this.BridgeEngine.font, this.BridgeEngine.italicFont, this.BridgeEngine);
111 NewGameWindow.Render(this.BridgeEngine.font, this.BridgeEngine.italicFont, this.BridgeEngine);
112 break;
112 break;
113 case Window.Dialog:
114
115 var dialog = GetComponent<DialogComponent>(entity).Dialog;
116 var show = true;
117 var paused = true;
118 DialogInterface.RenderDialog(entity, this.BridgeEngine, ref show, ref paused, this.BridgeEngine.font, dialog);
119 break;
113 default:
120 default:
114 // Logging.Error(String.Format("Unknown window type {0} ", window_type));
121 // Logging.Error(String.Format("Unknown window type {0} ", window_type));
115 break;
122 break;
@@ -5,6 +5,10
5 using isometricparkfna.Utils;
5 using isometricparkfna.Utils;
6 using TraceryNet;
6 using TraceryNet;
7 using Num = System.Numerics;
7 using Num = System.Numerics;
8 using Encompass;
9
10 using isometricparkfna.Engines;
11 using isometricparkfna.Messages;
8
12
9 #nullable enable
13 #nullable enable
10
14
@@ -107,7 +111,8
107 {
111 {
108
112
109 public static bool hadFocus = false;
113 public static bool hadFocus = false;
110 public static Node<DialogOption> RenderDialog(ref bool show, ref bool paused, ImFontPtr font, Node<DialogOption> currentNode)
114 public static Node<DialogOption> RenderDialog(Entity entity,
115 ImGuiWindowBridgeEngine bridgeEngine, ref bool show, ref bool paused, ImFontPtr font, Node<DialogOption> currentNode)
111 {
116 {
112 Node<DialogOption> new_child = currentNode;
117 Node<DialogOption> new_child = currentNode;
113 if (show)
118 if (show)
@@ -154,7 +159,11
154 {
159 {
155 show = false;
160 show = false;
156 paused = false;
161 paused = false;
157 }
162 bridgeEngine.setDialogMessages.Add(new SetDialogMessage {
163
164 Entity = entity,
165 newOption = null });
166 }
158 }
167 }
159
168
160 if (currentNode.data.response == null)
169 if (currentNode.data.response == null)
@@ -168,10 +177,11
168 StyleSets.defaultSet.pop();
177 StyleSets.defaultSet.pop();
169 ImGui.PopFont();
178 ImGui.PopFont();
170 }
179 }
180 bridgeEngine.setDialogMessages.Add(new SetDialogMessage {
181
182 Entity = entity,
183 newOption = new_child });
171 return new_child;
184 return new_child;
172
173 }
185 }
174 }
186 }
175
176
177 }
187 }
@@ -35,8 +35,8
35
35
36 <ItemGroup>
36 <ItemGroup>
37 <Reference Include="System" />
37 <Reference Include="System" />
38 <Reference Include="Newtonsoft.Json">
38 <Reference Include="Newtonsoft.Json" Version="12.0.3">
39 <!-- <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> -->
39 <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\netstandard2.0\Newtonsoft.Json.dll</HintPath>
40 </Reference>
40 </Reference>
41 <Reference Include="Tracery.Net">
41 <Reference Include="Tracery.Net">
42 <HintPath>..\packages\Tracery.Net.1.0.0\lib\net452\Tracery.Net.dll</HintPath>
42 <HintPath>..\packages\Tracery.Net.1.0.0\lib\net452\Tracery.Net.dll</HintPath>
You need to be logged in to leave comments. Login now