Description:
Add (hacky) option saving.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r350:a3057df945f0 -

@@ -1,6 +1,8
1
2 using System.IO;
1
3
2 using Microsoft.Xna.Framework.Input;
4 using Microsoft.Xna.Framework.Input;
3
5 using Newtonsoft.Json;
4 using Encompass;
6 using Encompass;
5
7
6 using isometricparkfna.Messages;
8 using isometricparkfna.Messages;
@@ -8,6 +10,7
8
10
9 namespace isometricparkfna.Engines {
11 namespace isometricparkfna.Engines {
10
12
13
11 [Receives(typeof(ToggleWindowTypeMessage), typeof(ToggleWindowMessage),
14 [Receives(typeof(ToggleWindowTypeMessage), typeof(ToggleWindowMessage),
12 typeof(GameStateMessage),
15 typeof(GameStateMessage),
13 typeof(ToggleVisibilityMessage),
16 typeof(ToggleVisibilityMessage),
@@ -24,6 +27,33
24 this.game = game;
27 this.game = game;
25 }
28 }
26
29
30 public void writeOptions(string fontName, int fontSize)
31 {
32
33 var options = new Options(fontName, fontSize);
34
35 string json = JsonConvert.SerializeObject(options,
36 Formatting.Indented);
37
38 File.WriteAllText(@"options.json", json);
39 Logging.Success("Writing options to file.");
40
41 }
42
43 public Options readOptions()
44 {
45 var json = File.ReadAllText(@"options.json");
46 Logging.Spy(new {json=json});
47
48 Options options = JsonConvert.DeserializeObject<Options>(json);
49
50 Logging.Spy(new {name=options.fontName,
51 size=options.fontSize});
52 Logging.Success("Read options.");
53
54 return options;
55 }
56
27 public override void Update(double dt)
57 public override void Update(double dt)
28 {
58 {
29
59
@@ -70,6 +100,7
70 foreach (ref readonly var fontMessage in ReadMessages<SetFontMessage>())
100 foreach (ref readonly var fontMessage in ReadMessages<SetFontMessage>())
71 {
101 {
72 game.setFont(fontMessage.fontName, fontMessage.fontSize);
102 game.setFont(fontMessage.fontName, fontMessage.fontSize);
103 writeOptions(fontMessage.fontName, fontMessage.fontSize);
73
104
74 }
105 }
75
106
@@ -209,6 +209,39
209 ContractWindow.LoadContent(this._imGuiRenderer, this.imageMap);
209 ContractWindow.LoadContent(this._imGuiRenderer, this.imageMap);
210 OptionsWindow.Initialize(new Vector2(FNAGame.width, FNAGame.height), gdm.IsFullScreen);
210 OptionsWindow.Initialize(new Vector2(FNAGame.width, FNAGame.height), gdm.IsFullScreen);
211
211
212 //Must be done before SetFontMessage is sent
213 var bakedMono = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"),
214 15,
215 1024,
216 1024,
217 new[]
218 {
219 CharacterRange.BasicLatin,
220 CharacterRange.Latin1Supplement,
221 CharacterRange.LatinExtendedA,
222 CharacterRange.Cyrillic,
223 CharacterRange.LatinExtendedB,
224 new CharacterRange((char) 0x00B7)
225 }
226 );
227
228 var bakedMonoLarge = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"),
229 30,
230 1024,
231 1024,
232 new[]
233 {
234 CharacterRange.BasicLatin,
235 CharacterRange.Latin1Supplement,
236 CharacterRange.LatinExtendedA,
237 CharacterRange.Cyrillic,
238 CharacterRange.LatinExtendedB,
239 new CharacterRange((char) 0x00B7)
240 }
241 );
242 monoFont = bakedMono.CreateSpriteFont(GraphicsDevice);
243 largeMonoFont = bakedMonoLarge.CreateSpriteFont(GraphicsDevice);
244
212 //Has to happen before Encompass stuff, because the Encompass machinery around ImGui requires debugWindow's monoFont to be loaded:
245 //Has to happen before Encompass stuff, because the Encompass machinery around ImGui requires debugWindow's monoFont to be loaded:
213 this.debugWindow = new DebugWindow(this._imGuiRenderer, GraphicsDevice, this.imageMap);
246 this.debugWindow = new DebugWindow(this._imGuiRenderer, GraphicsDevice, this.imageMap);
214
247
@@ -221,7 +254,9
221 WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm));
254 WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm));
222 WorldBuilder.AddEngine(new UIEngine());
255 WorldBuilder.AddEngine(new UIEngine());
223
256
224 WorldBuilder.AddEngine(new GameBridgeEngine(this));
257 var gameBridgeEngine = new GameBridgeEngine(this);
258
259 WorldBuilder.AddEngine(gameBridgeEngine);
225 WorldBuilder.AddEngine(new GameStateEngine());
260 WorldBuilder.AddEngine(new GameStateEngine());
226 WorldBuilder.AddEngine(this.simulation.BridgeEngine);
261 WorldBuilder.AddEngine(this.simulation.BridgeEngine);
227 WorldBuilder.AddEngine(new CameraBridgeEngine(this.camera));
262 WorldBuilder.AddEngine(new CameraBridgeEngine(this.camera));
@@ -260,6 +295,7
260 WorldBuilder.SetComponent(optionsWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Options });
295 WorldBuilder.SetComponent(optionsWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Options });
261
296
262
297
298
263 var gameEntity = WorldBuilder.CreateEntity();
299 var gameEntity = WorldBuilder.CreateEntity();
264
300
265 WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false});
301 WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false});
@@ -311,37 +347,19
311 name = "Aeres Maximalis Ltd."
347 name = "Aeres Maximalis Ltd."
312 });
348 });
313
349
314 World = WorldBuilder.Build();
350
351 try {
352 var options = gameBridgeEngine.readOptions();
315
353
316 var bakedMono = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"),
354 this.imGuiWindowBridgeEngine.fontMessages.Add(new SetFontMessage{
317 15,
355 fontSize = options.fontSize,
318 1024,
356 fontName = options.fontName});
319 1024,
357 }
320 new[]
358 catch (FileNotFoundException e)
321 {
359 {
322 CharacterRange.BasicLatin,
360 }
323 CharacterRange.Latin1Supplement,
324 CharacterRange.LatinExtendedA,
325 CharacterRange.Cyrillic,
326 CharacterRange.LatinExtendedB,
327 new CharacterRange((char) 0x00B7)
328 }
329 );
330
361
331 var bakedMonoLarge = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"),
362 World = WorldBuilder.Build();
332 30,
333 1024,
334 1024,
335 new[]
336 {
337 CharacterRange.BasicLatin,
338 CharacterRange.Latin1Supplement,
339 CharacterRange.LatinExtendedA,
340 CharacterRange.Cyrillic,
341 CharacterRange.LatinExtendedB,
342 new CharacterRange((char) 0x00B7)
343 }
344 );
345
363
346
364
347 this.output = grammar.Flatten("#greeting#");
365 this.output = grammar.Flatten("#greeting#");
@@ -376,11 +394,12
376 #endif
394 #endif
377
395
378 //font = fontBakeResult.CreateSpriteFont(GraphicsDevice);
396 //font = fontBakeResult.CreateSpriteFont(GraphicsDevice);
379 monoFont = bakedMono.CreateSpriteFont(GraphicsDevice);
380 largeMonoFont = bakedMonoLarge.CreateSpriteFont(GraphicsDevice);
381
397
382 this.budgetWindow = new BudgetWindow(new Budget { }, this.monoFont, 0, 0);
398 this.budgetWindow = new BudgetWindow(new Budget { }, this.monoFont, 0, 0);
383
399
400 // this.setFont(options.fontName, options.fontSize);
401 // debugWindow.setMonoFont(debugWindow.addFont(options.fontName, options.fontSize, false));
402
384 Logging.Success("Content loaded.");
403 Logging.Success("Content loaded.");
385 }
404 }
386
405
@@ -22,6 +22,7
22 {ImGuiStyleVar.WindowRounding, 0.0f},
22 {ImGuiStyleVar.WindowRounding, 0.0f},
23 {ImGuiStyleVar.FrameBorderSize, 1.0f},
23 {ImGuiStyleVar.FrameBorderSize, 1.0f},
24 {ImGuiStyleVar.TabRounding, 0.0f},
24 {ImGuiStyleVar.TabRounding, 0.0f},
25 {ImGuiStyleVar.GrabRounding, 0.0f},
25 };
26 };
26 public static Dictionary<ImGuiCol, Num.Vector4> defaultWindowColors = new Dictionary<ImGuiCol, Num.Vector4>{
27 public static Dictionary<ImGuiCol, Num.Vector4> defaultWindowColors = new Dictionary<ImGuiCol, Num.Vector4>{
27
28
@@ -47,6 +47,7
47 <Compile Include="FilledRectangle.cs" />
47 <Compile Include="FilledRectangle.cs" />
48 <Compile Include="Simulation.cs" />
48 <Compile Include="Simulation.cs" />
49 <Compile Include="Logging.cs" />
49 <Compile Include="Logging.cs" />
50 <Compile Include="Options.cs" />
50 <Compile Include="Components\*.cs" />
51 <Compile Include="Components\*.cs" />
51 <Compile Include="Engines\*.cs" />
52 <Compile Include="Engines\*.cs" />
52 <Compile Include="Messages\*.cs" />
53 <Compile Include="Messages\*.cs" />
You need to be logged in to leave comments. Login now