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