Description:
Add (hacky) option saving.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -1,6 +1,8 | |||
|
1 | ||
|
2 | using System.IO; | |
|
1 | 3 | |
|
2 | 4 | using Microsoft.Xna.Framework.Input; |
|
3 | ||
|
5 | using Newtonsoft.Json; | |
|
4 | 6 | using Encompass; |
|
5 | 7 | |
|
6 | 8 | using isometricparkfna.Messages; |
@@ -8,6 +10,7 | |||
|
8 | 10 | |
|
9 | 11 | namespace isometricparkfna.Engines { |
|
10 | 12 | |
|
13 | ||
|
11 | 14 | [Receives(typeof(ToggleWindowTypeMessage), typeof(ToggleWindowMessage), |
|
12 | 15 | typeof(GameStateMessage), |
|
13 | 16 | typeof(ToggleVisibilityMessage), |
@@ -24,6 +27,33 | |||
|
24 | 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 | 57 | public override void Update(double dt) |
|
28 | 58 | { |
|
29 | 59 | |
@@ -70,6 +100,7 | |||
|
70 | 100 | foreach (ref readonly var fontMessage in ReadMessages<SetFontMessage>()) |
|
71 | 101 | { |
|
72 | 102 | game.setFont(fontMessage.fontName, fontMessage.fontSize); |
|
103 | writeOptions(fontMessage.fontName, fontMessage.fontSize); | |
|
73 | 104 | |
|
74 | 105 | } |
|
75 | 106 |
@@ -209,6 +209,39 | |||
|
209 | 209 | ContractWindow.LoadContent(this._imGuiRenderer, this.imageMap); |
|
210 | 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 | 245 | //Has to happen before Encompass stuff, because the Encompass machinery around ImGui requires debugWindow's monoFont to be loaded: |
|
213 | 246 | this.debugWindow = new DebugWindow(this._imGuiRenderer, GraphicsDevice, this.imageMap); |
|
214 | 247 | |
@@ -221,7 +254,9 | |||
|
221 | 254 | WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm)); |
|
222 | 255 | WorldBuilder.AddEngine(new UIEngine()); |
|
223 | 256 | |
|
224 |
|
|
|
257 | var gameBridgeEngine = new GameBridgeEngine(this); | |
|
258 | ||
|
259 | WorldBuilder.AddEngine(gameBridgeEngine); | |
|
225 | 260 | WorldBuilder.AddEngine(new GameStateEngine()); |
|
226 | 261 | WorldBuilder.AddEngine(this.simulation.BridgeEngine); |
|
227 | 262 | WorldBuilder.AddEngine(new CameraBridgeEngine(this.camera)); |
@@ -260,6 +295,7 | |||
|
260 | 295 | WorldBuilder.SetComponent(optionsWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Options }); |
|
261 | 296 | |
|
262 | 297 | |
|
298 | ||
|
263 | 299 | var gameEntity = WorldBuilder.CreateEntity(); |
|
264 | 300 | |
|
265 | 301 | WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false}); |
@@ -311,37 +347,19 | |||
|
311 | 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"), | |
|
317 | 15, | |
|
318 | 1024, | |
|
319 | 1024, | |
|
320 | new[] | |
|
321 |
|
|
|
322 | CharacterRange.BasicLatin, | |
|
323 | CharacterRange.Latin1Supplement, | |
|
324 | CharacterRange.LatinExtendedA, | |
|
325 | CharacterRange.Cyrillic, | |
|
326 | CharacterRange.LatinExtendedB, | |
|
327 | new CharacterRange((char) 0x00B7) | |
|
328 | } | |
|
329 | ); | |
|
354 | this.imGuiWindowBridgeEngine.fontMessages.Add(new SetFontMessage{ | |
|
355 | fontSize = options.fontSize, | |
|
356 | fontName = options.fontName}); | |
|
357 | } | |
|
358 | catch (FileNotFoundException e) | |
|
359 | { | |
|
360 | } | |
|
330 | 361 | |
|
331 | var bakedMonoLarge = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"), | |
|
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 | ); | |
|
362 | World = WorldBuilder.Build(); | |
|
345 | 363 | |
|
346 | 364 | |
|
347 | 365 | this.output = grammar.Flatten("#greeting#"); |
@@ -376,11 +394,12 | |||
|
376 | 394 | #endif |
|
377 | 395 | |
|
378 | 396 | //font = fontBakeResult.CreateSpriteFont(GraphicsDevice); |
|
379 | monoFont = bakedMono.CreateSpriteFont(GraphicsDevice); | |
|
380 | largeMonoFont = bakedMonoLarge.CreateSpriteFont(GraphicsDevice); | |
|
381 | 397 | |
|
382 | 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 | 403 | Logging.Success("Content loaded."); |
|
385 | 404 | } |
|
386 | 405 |
@@ -22,6 +22,7 | |||
|
22 | 22 | {ImGuiStyleVar.WindowRounding, 0.0f}, |
|
23 | 23 | {ImGuiStyleVar.FrameBorderSize, 1.0f}, |
|
24 | 24 | {ImGuiStyleVar.TabRounding, 0.0f}, |
|
25 | {ImGuiStyleVar.GrabRounding, 0.0f}, | |
|
25 | 26 | }; |
|
26 | 27 | public static Dictionary<ImGuiCol, Num.Vector4> defaultWindowColors = new Dictionary<ImGuiCol, Num.Vector4>{ |
|
27 | 28 |
@@ -47,6 +47,7 | |||
|
47 | 47 | <Compile Include="FilledRectangle.cs" /> |
|
48 | 48 | <Compile Include="Simulation.cs" /> |
|
49 | 49 | <Compile Include="Logging.cs" /> |
|
50 | <Compile Include="Options.cs" /> | |
|
50 | 51 | <Compile Include="Components\*.cs" /> |
|
51 | 52 | <Compile Include="Engines\*.cs" /> |
|
52 | 53 | <Compile Include="Messages\*.cs" /> |
You need to be logged in to leave comments.
Login now