Description:
Refactor dialog into Encompass.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -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 | 21 | typeof(SetFontMessage), |
|
22 | 22 | typeof(SetTrespassingPolicyMessage), |
|
23 | 23 | typeof(SpawnGameMessage), |
|
24 |
typeof(SetTextVariableMessage) |
|
|
24 | typeof(SetTextVariableMessage), | |
|
25 | typeof(SetDialogMessage))] | |
|
25 | 26 | [Reads(typeof(VisibilityComponent), |
|
26 | 27 | typeof(WindowTypeComponent), |
|
27 | 28 | typeof(TrespassingPolicyComponent) |
@@ -42,6 +43,7 | |||
|
42 | 43 | public List<SetTrespassingPolicyMessage> trespassingPolicyMessages; |
|
43 | 44 | public List<SpawnGameMessage> spawnGameMessages; |
|
44 | 45 | public List<SetTextVariableMessage> setTextVariableMessages; |
|
46 | public List<SetDialogMessage> setDialogMessages; | |
|
45 | 47 | |
|
46 | 48 | bool showBudget {get;} |
|
47 | 49 | bool showForest {get;} |
@@ -70,6 +72,7 | |||
|
70 | 72 | this.trespassingPolicyMessages = new List<SetTrespassingPolicyMessage>(); |
|
71 | 73 | this.spawnGameMessages = new List<SpawnGameMessage>(); |
|
72 | 74 | this.setTextVariableMessages = new List<SetTextVariableMessage>(); |
|
75 | this.setDialogMessages = new List<SetDialogMessage>(); | |
|
73 | 76 | this.windowStatuses = new Dictionary<Window, bool>(); |
|
74 | 77 | |
|
75 | 78 | |
@@ -109,6 +112,11 | |||
|
109 | 112 | SendMessage(message); |
|
110 | 113 | } |
|
111 | 114 | |
|
115 | // | |
|
116 | foreach (var message in this.setTextVariableMessages) | |
|
117 | { | |
|
118 | SendMessage(message); | |
|
119 | } | |
|
112 | 120 | foreach(var message in this.gameStateMessages) |
|
113 | 121 | { |
|
114 | 122 | SendMessage(message); |
@@ -144,8 +152,8 | |||
|
144 | 152 | SendMessage(message); |
|
145 | 153 | } |
|
146 | 154 | |
|
147 | //This may need to be moved up. | |
|
148 |
foreach (var message in this.set |
|
|
155 | ||
|
156 | foreach (var message in this.setDialogMessages) | |
|
149 | 157 | { |
|
150 | 158 | SendMessage(message); |
|
151 | 159 | } |
@@ -157,11 +165,12 | |||
|
157 | 165 | foreach(var entity in ReadEntities<WindowTypeComponent>()) |
|
158 | 166 | { |
|
159 | 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 | 169 | windowStatuses[type] = visibility; |
|
162 | 170 | |
|
163 | 171 | } |
|
164 | 172 | |
|
173 | ||
|
165 | 174 | this.messages.Clear(); |
|
166 | 175 | this.typeMessages.Clear(); |
|
167 | 176 | this.contractStatusMessages.Clear(); |
@@ -173,6 +182,7 | |||
|
173 | 182 | this.trespassingPolicyMessages.Clear(); |
|
174 | 183 | this.spawnGameMessages.Clear(); |
|
175 | 184 | this.setTextVariableMessages.Clear(); |
|
185 | this.setDialogMessages.Clear(); | |
|
176 | 186 | } |
|
177 | 187 | } |
|
178 | 188 | } |
@@ -5,6 +5,7 | |||
|
5 | 5 | using Microsoft.Xna.Framework; |
|
6 | 6 | |
|
7 | 7 | using isometricparkfna.Messages; |
|
8 | using isometricparkfna.Components; | |
|
8 | 9 | using static isometricparkfna.CellMap; |
|
9 | 10 | using isometricparkfna.UI; |
|
10 | 11 | |
@@ -15,7 +16,11 | |||
|
15 | 16 | |
|
16 | 17 | [Receives(typeof(SpawnGameMessage))] |
|
17 | 18 | [Sends(typeof(SpawnContractMessage), |
|
18 |
typeof(SpawnOrganizationtMessage) |
|
|
19 | typeof(SpawnOrganizationtMessage), | |
|
20 | typeof(ToggleWindowMessage))] | |
|
21 | [Writes(typeof(WindowTypeComponent) | |
|
22 | //, typeof(DialogComponent) | |
|
23 | )] | |
|
19 | 24 | class GameSpawner : Spawner<SpawnGameMessage> |
|
20 | 25 | |
|
21 | 26 | { |
@@ -106,7 +111,34 | |||
|
106 | 111 | #endregion |
|
107 | 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 | 142 | #endregion |
|
111 | 143 | this.simulation.Subsidy = message.Difficulty switch { |
|
112 | 144 | DifficultyLevel.Hard => 0M, |
@@ -8,11 +8,18 | |||
|
8 | 8 | namespace isometricparkfna.Engines |
|
9 | 9 | { |
|
10 | 10 | |
|
11 | [Receives(typeof(ToggleWindowMessage), typeof(ToggleWindowTypeMessage), typeof(ToggleVisibilityMessage), | |
|
12 |
typeof( |
|
|
13 | [Reads(typeof(WindowTypeComponent), typeof(VisibilityComponent), | |
|
14 | typeof(SelectedComponent))] | |
|
15 | [Writes(typeof(VisibilityComponent), typeof(SelectedComponent))] | |
|
11 | [Receives(typeof(ToggleWindowMessage), | |
|
12 | typeof(ToggleWindowTypeMessage), | |
|
13 | typeof(ToggleVisibilityMessage), | |
|
14 | typeof(SetWindowVisibilityMessage), | |
|
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 | 23 | class UIEngine : Engine |
|
17 | 24 | { |
|
18 | 25 | |
@@ -23,6 +30,23 | |||
|
23 | 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 | 50 | foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowMessage>()) |
|
27 | 51 | { |
|
28 | 52 | Logging.Spy(windowMessage, "message"); |
@@ -33,7 +57,7 | |||
|
33 | 57 | if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID) |
|
34 | 58 | { |
|
35 | 59 | var visibilityComponent = GetComponent<VisibilityComponent>(entity); |
|
36 |
|
|
|
60 | AddComponent(entity, new VisibilityComponent { visible = !visibilityComponent.visible }); | |
|
37 | 61 | |
|
38 | 62 | } |
|
39 | 63 | } |
@@ -60,6 +84,21 | |||
|
60 | 84 | SetComponent<SelectedComponent>(selectedMessage.Entity, |
|
61 | 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 | 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 | ||
|
296 | WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false}); | |
|
295 | WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false}); | |
|
297 | 296 | |
|
298 |
|
|
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
297 | var policyEntity = WorldBuilder.CreateEntity(); | |
|
298 | WorldBuilder.SetComponent(policyEntity, | |
|
299 | new TrespassingPolicyComponent { tresspassingPolicy = EnforcementLevel.NoEnforcement}); | |
|
300 | WorldBuilder.SetComponent(policyEntity, | |
|
301 | new BudgetLineComponent { }); | |
|
302 | ||
|
303 | 303 | |
|
304 | 304 | try { |
|
305 | 305 | var options = Options.readOptions(); |
@@ -821,8 +821,8 | |||
|
821 | 821 | #region window |
|
822 | 822 | if (this.currentNode != null) |
|
823 | 823 | { |
|
824 | this.currentNode = DialogInterface.RenderDialog(ref this.showInitial, | |
|
825 | ref this.simulation.paused, debugWindow.monoFont, this.currentNode); | |
|
824 | // this.currentNode = DialogInterface.RenderDialog(ref this.showInitial, | |
|
825 | // ref this.simulation.paused, debugWindow.monoFont, this.currentNode); | |
|
826 | 826 | } |
|
827 | 827 | |
|
828 | 828 | if (this.showForest) |
@@ -15,7 +15,8 | |||
|
15 | 15 | MainMenu, |
|
16 | 16 | InGameMenu, |
|
17 | 17 | Options, |
|
18 | NewGame | |
|
18 | NewGame, | |
|
19 | Dialog | |
|
19 | 20 | } |
|
20 | 21 | |
|
21 | 22 |
@@ -69,7 +69,7 | |||
|
69 | 69 | foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>()) |
|
70 | 70 | { |
|
71 | 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 | 74 | if (visible) |
|
75 | 75 | { |
@@ -110,6 +110,13 | |||
|
110 | 110 | case Window.NewGame: |
|
111 | 111 | NewGameWindow.Render(this.BridgeEngine.font, this.BridgeEngine.italicFont, this.BridgeEngine); |
|
112 | 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 | 120 | default: |
|
114 | 121 | // Logging.Error(String.Format("Unknown window type {0} ", window_type)); |
|
115 | 122 | break; |
@@ -5,6 +5,10 | |||
|
5 | 5 | using isometricparkfna.Utils; |
|
6 | 6 | using TraceryNet; |
|
7 | 7 | using Num = System.Numerics; |
|
8 | using Encompass; | |
|
9 | ||
|
10 | using isometricparkfna.Engines; | |
|
11 | using isometricparkfna.Messages; | |
|
8 | 12 | |
|
9 | 13 | #nullable enable |
|
10 | 14 | |
@@ -107,7 +111,8 | |||
|
107 | 111 | { |
|
108 | 112 | |
|
109 | 113 | public static bool hadFocus = false; |
|
110 |
public static Node<DialogOption> RenderDialog( |
|
|
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 | 117 | Node<DialogOption> new_child = currentNode; |
|
113 | 118 | if (show) |
@@ -154,7 +159,11 | |||
|
154 | 159 | { |
|
155 | 160 | show = false; |
|
156 | 161 | paused = false; |
|
157 | } | |
|
162 | bridgeEngine.setDialogMessages.Add(new SetDialogMessage { | |
|
163 | ||
|
164 | Entity = entity, | |
|
165 | newOption = null }); | |
|
166 | } | |
|
158 | 167 | } |
|
159 | 168 | |
|
160 | 169 | if (currentNode.data.response == null) |
@@ -168,10 +177,11 | |||
|
168 | 177 | StyleSets.defaultSet.pop(); |
|
169 | 178 | ImGui.PopFont(); |
|
170 | 179 | } |
|
180 | bridgeEngine.setDialogMessages.Add(new SetDialogMessage { | |
|
181 | ||
|
182 | Entity = entity, | |
|
183 | newOption = new_child }); | |
|
171 | 184 | return new_child; |
|
172 | ||
|
173 | 185 | } |
|
174 | 186 | } |
|
175 | ||
|
176 | ||
|
177 | 187 | } |
@@ -35,8 +35,8 | |||
|
35 | 35 | |
|
36 | 36 | <ItemGroup> |
|
37 | 37 | <Reference Include="System" /> |
|
38 | <Reference Include="Newtonsoft.Json"> | |
|
39 |
< |
|
|
38 | <Reference Include="Newtonsoft.Json" Version="12.0.3"> | |
|
39 | <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\netstandard2.0\Newtonsoft.Json.dll</HintPath> | |
|
40 | 40 | </Reference> |
|
41 | 41 | <Reference Include="Tracery.Net"> |
|
42 | 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