Description:
Do some basic reformatting.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r424:9d9763fb5147 -

@@ -9,240 +9,248
9 using isometricparkfna.Components;
9 using isometricparkfna.Components;
10 using isometricparkfna.UI;
10 using isometricparkfna.UI;
11
11
12 namespace isometricparkfna.Engines {
12 namespace isometricparkfna.Engines
13 {
13
14
14 [Sends(typeof(ToggleWindowMessage),
15 [Sends(typeof(ToggleWindowMessage),
15 typeof(ToggleWindowTypeMessage),
16 typeof(ToggleWindowTypeMessage),
16 typeof(ChangeContractStatusMessage),
17 typeof(ChangeContractStatusMessage),
17 typeof(SelectMessage),
18 typeof(SelectMessage),
18 typeof(JumpCameraMessage),
19 typeof(JumpCameraMessage),
19 typeof(GameStateMessage),
20 typeof(GameStateMessage),
20 typeof(GameStateMessage),
21 typeof(GameStateMessage),
21 typeof(SetResolutionMessage),
22 typeof(SetResolutionMessage),
22 typeof(SetFontMessage),
23 typeof(SetFontMessage),
23 typeof(SetTrespassingPolicyMessage),
24 typeof(SetTrespassingPolicyMessage),
24 typeof(SpawnGameMessage),
25 typeof(SpawnGameMessage),
25 typeof(SetTextVariableMessage),
26 typeof(SetTextVariableMessage),
26 typeof(SetDialogMessage),
27 typeof(SetDialogMessage),
27 typeof(DialogChoiceMessage),
28 typeof(DialogChoiceMessage),
28 typeof(SetOptionMessage))]
29 typeof(SetOptionMessage))]
29 [Reads(typeof(VisibilityComponent),
30 [Reads(typeof(VisibilityComponent),
30 typeof(WindowTypeComponent),
31 typeof(WindowTypeComponent),
31 typeof(TrespassingPolicyComponent),
32 typeof(TrespassingPolicyComponent),
32 typeof(ContractStatusComponent),
33 typeof(ContractStatusComponent),
33 typeof(RelatedOrganizationComponent),
34 typeof(RelatedOrganizationComponent),
34 typeof(NameAndDescriptionComponent),
35 typeof(NameAndDescriptionComponent),
35 typeof(OptionsComponent))]
36 typeof(OptionsComponent))]
36 [Writes(typeof(OptionsComponent))]
37 [Writes(typeof(OptionsComponent))]
37 public class ImGuiWindowBridgeEngine : Engine
38 public class ImGuiWindowBridgeEngine : Engine
38 {
39 {
39 public List<ToggleWindowMessage> messages;
40 public List<ToggleWindowMessage> messages;
40 public List<ToggleWindowTypeMessage> typeMessages;
41 public List<ToggleWindowTypeMessage> typeMessages;
41 public List<ChangeContractStatusMessage> contractStatusMessages;
42 public List<ChangeContractStatusMessage> contractStatusMessages;
42 public List<SelectMessage> selectedMessages;
43 public List<SelectMessage> selectedMessages;
43 public List<JumpCameraMessage> jumpCameraMessages;
44 public List<JumpCameraMessage> jumpCameraMessages;
44 public List<GameStateMessage> gameStateMessages;
45 public List<GameStateMessage> gameStateMessages;
45 public List<SetResolutionMessage> resolutionMessages;
46 public List<SetResolutionMessage> resolutionMessages;
46 public List<SetFontMessage> fontMessages;
47 public List<SetFontMessage> fontMessages;
47 public List<SetTrespassingPolicyMessage> trespassingPolicyMessages;
48 public List<SetTrespassingPolicyMessage> trespassingPolicyMessages;
48 public List<SpawnGameMessage> spawnGameMessages;
49 public List<SpawnGameMessage> spawnGameMessages;
49 public List<SetTextVariableMessage> setTextVariableMessages;
50 public List<SetTextVariableMessage> setTextVariableMessages;
50 public List<SetDialogMessage> setDialogMessages;
51 public List<SetDialogMessage> setDialogMessages;
51 public List<DialogChoiceMessage> dialogChoiceMessages;
52 public List<DialogChoiceMessage> dialogChoiceMessages;
52 public List<SetOptionMessage> setOptionMessages;
53 public List<SetOptionMessage> setOptionMessages;
53
54
54 bool showBudget {get;}
55 bool showBudget { get; }
55 bool showForest {get;}
56 bool showForest { get; }
56 bool showNews {get;}
57 bool showNews { get; }
57 bool showGrid {get;}
58 bool showGrid { get; }
58 bool showTrees {get;}
59 bool showTrees { get; }
59
60
60 public Dictionary<Window, bool> windowStatuses {get;}
61 public Dictionary<Window, bool> windowStatuses { get; }
62
63 public bool showContractIndicator;
64 public List<string> contracts;
61
65
62 public bool showContractIndicator;
66 public ImFontPtr font;
63 public List<string> contracts;
67 public ImFontPtr italicFont;
68 private DebugWindow debugWindow;
69
70 private Simulation Simulation;
64
71
65 public ImFontPtr font;
72 public DateTime DateTime
66 public ImFontPtr italicFont;
73 {
67 private DebugWindow debugWindow;
74 get
68
75 {
69 private Simulation Simulation;
76 return this.Simulation.DateTime;
70
77 }
71 public DateTime DateTime { get {
78 }
72 return this.Simulation.DateTime;
73 }}
74
79
75 public ImGuiWindowBridgeEngine(DebugWindow debugWindow,
80 public ImGuiWindowBridgeEngine(DebugWindow debugWindow,
76 ImFontPtr font, ImFontPtr italicFont,
81 ImFontPtr font, ImFontPtr italicFont,
77 Simulation simulation)
82 Simulation simulation)
78 {
83 {
79 this.messages = new List<ToggleWindowMessage>();
84 this.messages = new List<ToggleWindowMessage>();
80 this.typeMessages = new List<ToggleWindowTypeMessage>();
85 this.typeMessages = new List<ToggleWindowTypeMessage>();
81 this.contractStatusMessages = new List<ChangeContractStatusMessage>();
86 this.contractStatusMessages = new List<ChangeContractStatusMessage>();
82 this.selectedMessages = new List<SelectMessage>();
87 this.selectedMessages = new List<SelectMessage>();
83 this.jumpCameraMessages = new List<JumpCameraMessage>();
88 this.jumpCameraMessages = new List<JumpCameraMessage>();
84 this.gameStateMessages = new List<GameStateMessage>();
89 this.gameStateMessages = new List<GameStateMessage>();
85 this.resolutionMessages = new List<SetResolutionMessage>();
90 this.resolutionMessages = new List<SetResolutionMessage>();
86 this.fontMessages = new List<SetFontMessage>();
91 this.fontMessages = new List<SetFontMessage>();
87 this.trespassingPolicyMessages = new List<SetTrespassingPolicyMessage>();
92 this.trespassingPolicyMessages = new List<SetTrespassingPolicyMessage>();
88 this.spawnGameMessages = new List<SpawnGameMessage>();
93 this.spawnGameMessages = new List<SpawnGameMessage>();
89 this.setTextVariableMessages = new List<SetTextVariableMessage>();
94 this.setTextVariableMessages = new List<SetTextVariableMessage>();
90 this.setDialogMessages = new List<SetDialogMessage>();
95 this.setDialogMessages = new List<SetDialogMessage>();
91 this.dialogChoiceMessages = new List<DialogChoiceMessage>();
96 this.dialogChoiceMessages = new List<DialogChoiceMessage>();
92 this.setOptionMessages = new List<SetOptionMessage>();
97 this.setOptionMessages = new List<SetOptionMessage>();
93 this.windowStatuses = new Dictionary<Window, bool>();
98 this.windowStatuses = new Dictionary<Window, bool>();
94
99
95 this.showContractIndicator = false;
100 this.showContractIndicator = false;
96
101
97 this.font = font;
102 this.font = font;
98 this.italicFont = italicFont;
103 this.italicFont = italicFont;
99 this.debugWindow = debugWindow;
104 this.debugWindow = debugWindow;
100 this.Simulation = simulation;
105 this.Simulation = simulation;
101
106
102
107
103 this.contracts = new List<string>();
108 this.contracts = new List<string>();
104
109
105
110
106 //Prepopulate:
111 //Prepopulate:
107 foreach(var type in System.Enum.GetValues(typeof(Window)))
112 foreach (var type in System.Enum.GetValues(typeof(Window)))
108 {
113 {
109 windowStatuses.Add((Window)type, false);
114 windowStatuses.Add((Window)type, false);
110 }
115 }
111 }
116 }
112
117
113 public override void Update(double dt)
118 public override void Update(double dt)
114 {
119 {
115 foreach(var message in this.messages)
120 foreach (var message in this.messages)
116 {
121 {
117 SendMessage(message);
122 SendMessage(message);
118 }
123 }
119 foreach(var message in this.typeMessages)
124 foreach (var message in this.typeMessages)
120 {
125 {
121 SendMessage(message);
126 SendMessage(message);
122 }
127 }
123 foreach(var message in this.contractStatusMessages)
128 foreach (var message in this.contractStatusMessages)
124 {
129 {
125 SendMessage(message);
130 SendMessage(message);
126 }
131 }
127 foreach(var message in this.selectedMessages)
132 foreach (var message in this.selectedMessages)
128 {
133 {
129 SendMessage(message);
134 SendMessage(message);
130 // SetComponent<SelectedComponent>(message.Entity, new SelectedComponent { selected = true});
135 // SetComponent<SelectedComponent>(message.Entity, new SelectedComponent { selected = true});
131 }
136 }
132 foreach(var message in this.jumpCameraMessages)
137 foreach (var message in this.jumpCameraMessages)
133 {
138 {
134 SendMessage(message);
139 SendMessage(message);
135 }
140 }
136
141
137 //
142 //
138 foreach (var message in this.setTextVariableMessages)
143 foreach (var message in this.setTextVariableMessages)
139 {
144 {
140 SendMessage(message);
145 SendMessage(message);
141 }
146 }
142 foreach(var message in this.gameStateMessages)
147 foreach (var message in this.gameStateMessages)
143 {
148 {
144 SendMessage(message);
149 SendMessage(message);
145 }
150 }
146 foreach(var message in this.resolutionMessages)
151 foreach (var message in this.resolutionMessages)
147 {
152 {
148 SendMessage(message);
153 SendMessage(message);
149 }
154 }
150 foreach(var message in this.fontMessages)
155 foreach (var message in this.fontMessages)
151 {
156 {
152 this.font = debugWindow.addFont(message.fontName,
157 this.font = debugWindow.addFont(message.fontName,
153 message.fontSize, false);
158 message.fontSize, false);
154
159
155 debugWindow.setMonoFont(this.font);
160 debugWindow.setMonoFont(this.font);
156
161
157 this.italicFont = debugWindow.addFont(message.fontName,
162 this.italicFont = debugWindow.addFont(message.fontName,
158 message.fontSize, true);
163 message.fontSize, true);
159
164
160 debugWindow.setItalicFont(this.italicFont);
165 debugWindow.setItalicFont(this.italicFont);
161 SendMessage(message);
166 SendMessage(message);
162
167
163 OptionsWindow.setFont(message.fontName,
168 OptionsWindow.setFont(message.fontName,
164 message.fontSize);
169 message.fontSize);
165 }
170 }
166
171
167 foreach (var message in this.trespassingPolicyMessages)
172 foreach (var message in this.trespassingPolicyMessages)
168 {
173 {
169 SendMessage(message);
174 SendMessage(message);
170 }
175 }
171
176
172 foreach (var message in this.spawnGameMessages)
177 foreach (var message in this.spawnGameMessages)
173 {
178 {
174 SendMessage(message);
179 SendMessage(message);
175 }
180 }
176
181
177
182
178 foreach (var message in this.setDialogMessages)
183 foreach (var message in this.setDialogMessages)
179 {
184 {
180 SendMessage(message);
185 SendMessage(message);
181 }
186 }
182 foreach (var message in this.dialogChoiceMessages)
187 foreach (var message in this.dialogChoiceMessages)
183 {
188 {
184 SendMessage(message);
189 SendMessage(message);
185 }
190 }
191
192 foreach (var message in this.setOptionMessages)
193 {
194 foreach (var entity in ReadEntities<OptionsComponent>())
195 {
186
196
187 foreach(var message in this.setOptionMessages)
197 SetComponent(entity, new OptionsComponent
188 {
198 {
189 foreach(var entity in ReadEntities<OptionsComponent>())
199 ProfanitySetting = message.NewProfanitySetting
190 {
200 });
191
201 }
192 SetComponent(entity, new OptionsComponent {
193 ProfanitySetting = message.NewProfanitySetting});
194 }
195
202
196 }
203 }
197
204
198 foreach(var entity in ReadEntities<WindowTypeComponent>())
205 foreach (var entity in ReadEntities<WindowTypeComponent>())
199 {
206 {
200 var type = GetComponent<WindowTypeComponent>(entity).type;
207 var type = GetComponent<WindowTypeComponent>(entity).type;
201 var visibility = HasComponent<VisibilityComponent>(entity) ? GetComponent<VisibilityComponent>(entity).visible : false;
208 var visibility = HasComponent<VisibilityComponent>(entity) ? GetComponent<VisibilityComponent>(entity).visible : false;
202 windowStatuses[type] = visibility;
209 windowStatuses[type] = visibility;
203 }
210 }
204
211
205 //reset
212 //reset
206 this.showContractIndicator = false;
213 this.showContractIndicator = false;
207 this.contracts.Clear();
214 this.contracts.Clear();
208 foreach(var entity in ReadEntities<ContractStatusComponent>())
215 foreach (var entity in ReadEntities<ContractStatusComponent>())
209 {
216 {
210 var contractStatus = GetComponent<ContractStatusComponent>(entity);
217 var contractStatus = GetComponent<ContractStatusComponent>(entity);
211 var age = this.Simulation.DateTime - contractStatus.date;
218 var age = this.Simulation.DateTime - contractStatus.date;
212 if((age.TotalDays > (5*30) )
219 if ((age.TotalDays > (5 * 30))
213 && (contractStatus.status == ContractStatus.Proposed))
220 && (contractStatus.status == ContractStatus.Proposed))
214 {
221 {
215 try {
222 try
216 this.showContractIndicator = true;
223 {
217 if (HasComponent<RelatedOrganizationComponent>(entity))
224 this.showContractIndicator = true;
218 {
225 if (HasComponent<RelatedOrganizationComponent>(entity))
219 var organizationEntity = GetComponent<RelatedOrganizationComponent>(entity).Entity;
226 {
220 var name = GetComponent<NameAndDescriptionComponent>(organizationEntity).DisplayName;
227 var organizationEntity = GetComponent<RelatedOrganizationComponent>(entity).Entity;
221 this.contracts.Add(name);
228 var name = GetComponent<NameAndDescriptionComponent>(organizationEntity).DisplayName;
229 this.contracts.Add(name);
222
230
223 }
231 }
224 }
232 }
225 catch (Exception e)
233 catch (Exception e)
226 {
234 {
227 Logging.Error(string.Format("Exception: {0}", e.ToString()));
235 Logging.Error(string.Format("Exception: {0}", e.ToString()));
228 }
236 }
229 }
237 }
230 }
238 }
231
239
232 this.messages.Clear();
240 this.messages.Clear();
233 this.typeMessages.Clear();
241 this.typeMessages.Clear();
234 this.contractStatusMessages.Clear();
242 this.contractStatusMessages.Clear();
235 this.selectedMessages.Clear();
243 this.selectedMessages.Clear();
236 this.jumpCameraMessages.Clear();
244 this.jumpCameraMessages.Clear();
237 this.gameStateMessages.Clear();
245 this.gameStateMessages.Clear();
238 this.resolutionMessages.Clear();
246 this.resolutionMessages.Clear();
239 this.fontMessages.Clear();
247 this.fontMessages.Clear();
240 this.trespassingPolicyMessages.Clear();
248 this.trespassingPolicyMessages.Clear();
241 this.spawnGameMessages.Clear();
249 this.spawnGameMessages.Clear();
242 this.setTextVariableMessages.Clear();
250 this.setTextVariableMessages.Clear();
243 this.setDialogMessages.Clear();
251 this.setDialogMessages.Clear();
244 this.dialogChoiceMessages.Clear();
252 this.dialogChoiceMessages.Clear();
245 this.setOptionMessages.Clear();
253 this.setOptionMessages.Clear();
246 }
254 }
247 }
255 }
248 }
256 }
@@ -20,37 +20,38
20 }
20 }
21
21
22
22
23 public override void Update(double dt)
23 public override void Update(double dt)
24 {
24 {
25 foreach (ref readonly var message
25 foreach (ref readonly var message
26 in ReadMessages<SetTrespassingPolicyMessage>())
26 in ReadMessages<SetTrespassingPolicyMessage>())
27 {
27 {
28 foreach (ref readonly var entity
28 foreach (ref readonly var entity
29 in ReadEntities<TrespassingPolicyComponent>())
29 in ReadEntities<TrespassingPolicyComponent>())
30 {
30 {
31
31
32 SetComponent<TrespassingPolicyComponent>(entity,
32 SetComponent<TrespassingPolicyComponent>(entity,
33 new TrespassingPolicyComponent {tresspassingPolicy
33 new TrespassingPolicyComponent
34 = message.newEnforcementLevel });
34 {
35 tresspassingPolicy
36 = message.newEnforcementLevel
37 });
35
38
36 var newCost =message.newEnforcementLevel switch {
39 var newCost = message.newEnforcementLevel switch {
37 EnforcementLevel.NoEnforcement => 0,
40 EnforcementLevel.NoEnforcement => 0,
38 EnforcementLevel.EnforcedWithWarnings => 100,
41 EnforcementLevel.EnforcedWithWarnings => 100,
39 EnforcementLevel.EnforcedWithFines => 100,
42 EnforcementLevel.EnforcedWithFines => 100
40
43 };
41
42 };
43
44
44
45 SetComponent<BudgetLineComponent>(entity,
45 SetComponent<BudgetLineComponent>(entity,
46 new BudgetLineComponent {category = "Enforcement",
46 new BudgetLineComponent
47 amount = newCost
47 {
48 });
48 category = "Enforcement",
49 amount = newCost
50 });
51 }
52 }
49
53
50 }
54 }
51 }
52
53 }
54
55
55 }
56 }
56 }
57 }
@@ -15,21 +15,21
15 {
15 {
16
16
17 [Receives(typeof(ToggleWindowMessage),
17 [Receives(typeof(ToggleWindowMessage),
18 typeof(ToggleWindowTypeMessage),
18 typeof(ToggleWindowTypeMessage),
19 typeof(ToggleVisibilityMessage),
19 typeof(ToggleVisibilityMessage),
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 [Reads(typeof(DialogComponent),
24 [Reads(typeof(DialogComponent),
25 typeof(WindowTypeComponent),
25 typeof(WindowTypeComponent),
26 typeof(VisibilityComponent),
26 typeof(VisibilityComponent),
27 typeof(SelectedComponent))]
27 typeof(SelectedComponent))]
28 [Writes(typeof(VisibilityComponent),
28 [Writes(typeof(VisibilityComponent),
29 typeof(SelectedComponent))]
29 typeof(SelectedComponent))]
30 class UIEngine : Engine
30 class UIEngine : Engine
31 {
31 {
32 public Story Story;
32 public Story Story;
33
33
34 public UIEngine(Story story)
34 public UIEngine(Story story)
35 {
35 {
@@ -23,7 +23,7
23 {
23 {
24 public String? choice;
24 public String? choice;
25 public String response;
25 public String response;
26 public String speaker;
26 public String speaker;
27 }
27 }
28
28
29
29
@@ -31,177 +31,187
31 {
31 {
32
32
33 public static Node<DialogOption> introTree = new Node<DialogOption>(
33 public static Node<DialogOption> introTree = new Node<DialogOption>(
34 new DialogOption{response = "Welcome to your new park, director! You can use the mouse or arrow keys to move around, and the plus and minus keys to zoom in and out. B opens the budget and F lets you adjust Forest Policy.",
34 new DialogOption
35 speaker = "The Governor"
35 {
36 },
36 response = "Welcome to your new park, director! You can use the mouse or arrow keys to move around, and the plus and minus keys to zoom in and out. B opens the budget and F lets you adjust Forest Policy.",
37 new Node<DialogOption>(new DialogOption { choice = "Okay",
37 speaker = "The Governor"
38 response = "Make sure that you keep visitors happy and the budget in the black! You're currently getting an annual grant out of my budgetβ€”it'd sure be nice if you park were self-sufficient so we could drop that expense!",
38 },
39 speaker = "The Governor"
39 new Node<DialogOption>(new DialogOption
40 },
40 {
41 new Node<DialogOption>[]{
41 choice = "Okay",
42 response = "Make sure that you keep visitors happy and the budget in the black! You're currently getting an annual grant out of my budgetβ€”it'd sure be nice if you park were self-sufficient so we could drop that expense!",
43 speaker = "The Governor"
44 },
45 new Node<DialogOption>[]{
42 new Node<DialogOption>(new DialogOption {choice="And I need to keep the forest healthy, too, right?", response="Uhh yeah.", speaker = "The Governor" },
46 new Node<DialogOption>(new DialogOption {choice="And I need to keep the forest healthy, too, right?", response="Uhh yeah.", speaker = "The Governor" },
43 new Node<DialogOption>(new DialogOption {choice="...", speaker = "The Governor"})),
47 new Node<DialogOption>(new DialogOption {choice="...", speaker = "The Governor"})),
44 new Node<DialogOption>(new DialogOption {choice="Sounds good!", response="I'll check in soon.", speaker = "The Governor" })
48 new Node<DialogOption>(new DialogOption {choice="Sounds good!", response="I'll check in soon.", speaker = "The Governor" })
45
49
46 })
50 })
47 );
51 );
48
52
49 public static Node<DialogOption> testTree = new Node<DialogOption>(
53 public static Node<DialogOption> testTree = new Node<DialogOption>(
50 new DialogOption
54 new DialogOption
51 {
55 {
52 response = "#addressGreetingFormal#",
56 response = "#addressGreetingFormal#",
53 speaker = "#assistantName#"
57 speaker = "#assistantName#"
54 },
58 },
55 new Node<DialogOption>[]{
59 new Node<DialogOption>[]{
56 new Node<DialogOption>(new DialogOption {choice="Call me #playerCasual#", response="Sure",
60 new Node<DialogOption>(new DialogOption {choice="Call me #playerCasual#", response="Sure",
57 speaker = "#assistantName#" }),
61 speaker = "#assistantName#" }),
58 new Node<DialogOption>(new DialogOption {choice="Hi.", response="Bye!",
62 new Node<DialogOption>(new DialogOption {choice="Hi.", response="Bye!",
59 speaker = "#assistantName#" }),
63 speaker = "#assistantName#" }),
60 new Node<DialogOption>(new DialogOption {choice="How are you?", response="#howdoing#",
64 new Node<DialogOption>(new DialogOption {choice="How are you?", response="#howdoing#",
61 speaker = "#assistantName#" })
65 speaker = "#assistantName#" })
62
66
63 }
67 }
64 );
68 );
65
69
66 public static Node<DialogOption> testTree2 = new Node<DialogOption>(
70 public static Node<DialogOption> testTree2 = new Node<DialogOption>(
67 new DialogOption
71 new DialogOption
68 {
72 {
69 response = "#whatever#",
73 response = "#whatever#",
70 speaker = "#assistantName#"
74 speaker = "#assistantName#"
71 },
75 },
72
76
73 new Node<DialogOption>[]{
77 new Node<DialogOption>[]{
74 new Node<DialogOption>(new DialogOption {choice="Hi.", response="Bye!",
78 new Node<DialogOption>(new DialogOption {choice="Hi.", response="Bye!",
75 speaker = "#assistantName#" }),
79 speaker = "#assistantName#" }),
76 new Node<DialogOption>(new DialogOption {choice="How are you?", response="#howdoing#",
80 new Node<DialogOption>(new DialogOption {choice="How are you?", response="#howdoing#",
77 speaker = "#assistantName#" })
81 speaker = "#assistantName#" })
78
82
79 }
83 }
80 );
84 );
81
85
82
86
83 public static Node<DialogOption> flatten (Node<DialogOption> node, Grammar grammar) {
87 public static Node<DialogOption> flatten(Node<DialogOption> node, Grammar grammar)
88 {
84
89
85 DialogOption new_data = new DialogOption
90 DialogOption new_data = new DialogOption
86 {
91 {
87 choice = node.data.choice != null ? grammar.Flatten(node.data.choice) : node.data.choice,
92 choice = node.data.choice != null ? grammar.Flatten(node.data.choice) : node.data.choice,
88 response = grammar.Flatten(node.data.response),
93 response = grammar.Flatten(node.data.response),
89 speaker = grammar.Flatten(node.data.speaker)
94 speaker = grammar.Flatten(node.data.speaker)
90 };
95 };
91
96
92
97
93 if (node.children != null) {
98 if (node.children != null)
94 List<Node<DialogOption>> new_children = new List<Node<DialogOption>>();
99 {
95 foreach (Node<DialogOption> child in node.children)
100 List<Node<DialogOption>> new_children = new List<Node<DialogOption>>();
96 {
101 foreach (Node<DialogOption> child in node.children)
97 new_children.Add(flatten(child, grammar));
102 {
98 }
103 new_children.Add(flatten(child, grammar));
104 }
99
105
100 return new Node<DialogOption>(new_data, new_children.ToArray());
106 return new Node<DialogOption>(new_data, new_children.ToArray());
101 }
107 }
102 else
108 else
103 {
109 {
104 return new Node<DialogOption>(new_data);
110 return new Node<DialogOption>(new_data);
105
111
106 }
112 }
107
113
108 }
114 }
109
115
110 }
116 }
111
117
112 public static class DialogInterface
118 public static class DialogInterface
113 {
119 {
114
120
115 public static bool hadFocus = false;
121 public static bool hadFocus = false;
116
122
117 public static ImGuiImageMap map;
123 public static ImGuiImageMap map;
118 private static IntPtr _imGuiTexture;
124 private static IntPtr _imGuiTexture;
119
125
120 public static void LoadContent(ImGuiRenderer _imGuiRenderer,
126 public static void LoadContent(ImGuiRenderer _imGuiRenderer,
121 ImGuiImageMap map)
127 ImGuiImageMap map)
122 {
128 {
123 DialogInterface.map = map;
129 DialogInterface.map = map;
124 var _xnaTexture = map.ImageMapTexture;
130 var _xnaTexture = map.ImageMapTexture;
125 DialogInterface._imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture);
131 DialogInterface._imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture);
126 }
132 }
127
133
128 public static void RenderDialog(Entity entity,
134 public static void RenderDialog(Entity entity,
129 ImGuiWindowBridgeEngine bridgeEngine, ref bool show, ref bool paused, ImFontPtr font, DialogComponent dialogComponent)
135 ImGuiWindowBridgeEngine bridgeEngine, ref bool show, ref bool paused, ImFontPtr font, DialogComponent dialogComponent)
130 {
136 {
131 if (show)
137 if (show)
132 {
138 {
133 ImGui.PushFont(font);
139 ImGui.PushFont(font);
134 ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None;
140 ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None;
135
141
136 StyleSets.defaultSet.push();
142 StyleSets.defaultSet.push();
137
143
138 ImGui.SetNextWindowSize(new Num.Vector2(400, 200));
144 ImGui.SetNextWindowSize(new Num.Vector2(400, 200));
139 if(DialogInterface.hadFocus)
145 if (DialogInterface.hadFocus)
140 {
146 {
141 ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white);
147 ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white);
142 }
148 }
143
149
144 ImGui.Begin(dialogComponent.CurrentSpeaker, ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings);
150 ImGui.Begin(dialogComponent.CurrentSpeaker, ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings);
145 if (DialogInterface.hadFocus)
151 if (DialogInterface.hadFocus)
146 {
152 {
147 ImGui.PopStyleColor();
153 ImGui.PopStyleColor();
148 }
154 }
149 DialogInterface.hadFocus = ImGui.IsWindowFocused();
155 DialogInterface.hadFocus = ImGui.IsWindowFocused();
150
156
151 ImGui.Columns(2);
157 ImGui.Columns(2);
152
158
153 Widgets.MapImage(DialogInterface.map, new Num.Vector2(150, 100), 1);
159 Widgets.MapImage(DialogInterface.map, new Num.Vector2(150, 100), 1);
154
160
155 ImGui.NextColumn();
161 ImGui.NextColumn();
156
162
157
163
158 if (dialogComponent.CurrentDialog != null)
164 if (dialogComponent.CurrentDialog != null)
159 {
165 {
160 string messageText = dialogComponent.CurrentDialog;
166 string messageText = dialogComponent.CurrentDialog;
161 ImGui.TextWrapped(messageText);
167 ImGui.TextWrapped(messageText);
162 }
168 }
163
169
164 ImGui.Columns(1);
170 ImGui.Columns(1);
165
171
166 if ((dialogComponent.Options != null) && dialogComponent.Options.Count > 0)
172 if ((dialogComponent.Options != null) && dialogComponent.Options.Count > 0)
167 {
173 {
168 for(int i = 0; i < dialogComponent.Options.Count; i++)
174 for (int i = 0; i < dialogComponent.Options.Count; i++)
169 {
175 {
170 string buttonText = dialogComponent.Options[i];
176 string buttonText = dialogComponent.Options[i];
171 if (ImGui.Button(buttonText))
177 if (ImGui.Button(buttonText))
172 {
178 {
173 bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage {
179 bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage
180 {
174
181
175 Entity = entity,
182 Entity = entity,
176 Choice = i });
183 Choice = i
184 });
177
185
178 }
186 }
179 }
187 }
180 }
188 }
181 else
189 else
182 {
190 {
183 if (ImGui.Button("Okay"))
191 if (ImGui.Button("Okay"))
184 {
192 {
185 show = false;
193 show = false;
186 paused = false;
194 paused = false;
187 bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage {
195 bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage
196 {
188
197
189 Entity = entity,
198 Entity = entity,
190 Choice = -1 });
199 Choice = -1
191 }
200 });
192 }
201 }
193
202 }
194 if (dialogComponent.CurrentDialog == null)
195 {
196 show = false;
197 paused = false;
198
203
199 }
204 if (dialogComponent.CurrentDialog == null)
200 ImGui.End();
205 {
201 ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
206 show = false;
202 StyleSets.defaultSet.pop();
207 paused = false;
203 ImGui.PopFont();
208
204 }
209 }
205 }
210 ImGui.End();
206 }
211 ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
212 StyleSets.defaultSet.pop();
213 ImGui.PopFont();
214 }
215 }
216 }
207 }
217 }
You need to be logged in to leave comments. Login now