diff --git a/isometric-park-fna/Engines/GameBridgeEngine.cs b/isometric-park-fna/Engines/GameBridgeEngine.cs --- a/isometric-park-fna/Engines/GameBridgeEngine.cs +++ b/isometric-park-fna/Engines/GameBridgeEngine.cs @@ -1,6 +1,8 @@ + +using System.IO; using Microsoft.Xna.Framework.Input; - +using Newtonsoft.Json; using Encompass; using isometricparkfna.Messages; @@ -8,6 +10,7 @@ namespace isometricparkfna.Engines { + [Receives(typeof(ToggleWindowTypeMessage), typeof(ToggleWindowMessage), typeof(GameStateMessage), typeof(ToggleVisibilityMessage), @@ -24,6 +27,33 @@ this.game = game; } + public void writeOptions(string fontName, int fontSize) + { + + var options = new Options(fontName, fontSize); + + string json = JsonConvert.SerializeObject(options, + Formatting.Indented); + + File.WriteAllText(@"options.json", json); + Logging.Success("Writing options to file."); + + } + + public Options readOptions() + { + var json = File.ReadAllText(@"options.json"); + Logging.Spy(new {json=json}); + + Options options = JsonConvert.DeserializeObject(json); + + Logging.Spy(new {name=options.fontName, + size=options.fontSize}); + Logging.Success("Read options."); + + return options; + } + public override void Update(double dt) { @@ -70,6 +100,7 @@ foreach (ref readonly var fontMessage in ReadMessages()) { game.setFont(fontMessage.fontName, fontMessage.fontSize); + writeOptions(fontMessage.fontName, fontMessage.fontSize); } diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs --- a/isometric-park-fna/FNAGame.cs +++ b/isometric-park-fna/FNAGame.cs @@ -209,6 +209,39 @@ ContractWindow.LoadContent(this._imGuiRenderer, this.imageMap); OptionsWindow.Initialize(new Vector2(FNAGame.width, FNAGame.height), gdm.IsFullScreen); + //Must be done before SetFontMessage is sent + var bakedMono = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"), + 15, + 1024, + 1024, + new[] + { + CharacterRange.BasicLatin, + CharacterRange.Latin1Supplement, + CharacterRange.LatinExtendedA, + CharacterRange.Cyrillic, + CharacterRange.LatinExtendedB, + new CharacterRange((char) 0x00B7) + } + ); + + var bakedMonoLarge = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"), + 30, + 1024, + 1024, + new[] + { + CharacterRange.BasicLatin, + CharacterRange.Latin1Supplement, + CharacterRange.LatinExtendedA, + CharacterRange.Cyrillic, + CharacterRange.LatinExtendedB, + new CharacterRange((char) 0x00B7) + } + ); + monoFont = bakedMono.CreateSpriteFont(GraphicsDevice); + largeMonoFont = bakedMonoLarge.CreateSpriteFont(GraphicsDevice); + //Has to happen before Encompass stuff, because the Encompass machinery around ImGui requires debugWindow's monoFont to be loaded: this.debugWindow = new DebugWindow(this._imGuiRenderer, GraphicsDevice, this.imageMap); @@ -221,7 +254,9 @@ WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm)); WorldBuilder.AddEngine(new UIEngine()); - WorldBuilder.AddEngine(new GameBridgeEngine(this)); + var gameBridgeEngine = new GameBridgeEngine(this); + + WorldBuilder.AddEngine(gameBridgeEngine); WorldBuilder.AddEngine(new GameStateEngine()); WorldBuilder.AddEngine(this.simulation.BridgeEngine); WorldBuilder.AddEngine(new CameraBridgeEngine(this.camera)); @@ -260,6 +295,7 @@ WorldBuilder.SetComponent(optionsWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Options }); + var gameEntity = WorldBuilder.CreateEntity(); WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false}); @@ -311,37 +347,19 @@ name = "Aeres Maximalis Ltd." }); - World = WorldBuilder.Build(); + + try { + var options = gameBridgeEngine.readOptions(); - var bakedMono = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"), - 15, - 1024, - 1024, - new[] - { - CharacterRange.BasicLatin, - CharacterRange.Latin1Supplement, - CharacterRange.LatinExtendedA, - CharacterRange.Cyrillic, - CharacterRange.LatinExtendedB, - new CharacterRange((char) 0x00B7) - } - ); + this.imGuiWindowBridgeEngine.fontMessages.Add(new SetFontMessage{ + fontSize = options.fontSize, + fontName = options.fontName}); + } + catch (FileNotFoundException e) + { + } - var bakedMonoLarge = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"), - 30, - 1024, - 1024, - new[] - { - CharacterRange.BasicLatin, - CharacterRange.Latin1Supplement, - CharacterRange.LatinExtendedA, - CharacterRange.Cyrillic, - CharacterRange.LatinExtendedB, - new CharacterRange((char) 0x00B7) - } - ); + World = WorldBuilder.Build(); this.output = grammar.Flatten("#greeting#"); @@ -376,11 +394,12 @@ #endif //font = fontBakeResult.CreateSpriteFont(GraphicsDevice); - monoFont = bakedMono.CreateSpriteFont(GraphicsDevice); - largeMonoFont = bakedMonoLarge.CreateSpriteFont(GraphicsDevice); this.budgetWindow = new BudgetWindow(new Budget { }, this.monoFont, 0, 0); + // this.setFont(options.fontName, options.fontSize); + // debugWindow.setMonoFont(debugWindow.addFont(options.fontName, options.fontSize, false)); + Logging.Success("Content loaded."); } diff --git a/isometric-park-fna/UI/StyleSets.cs b/isometric-park-fna/UI/StyleSets.cs --- a/isometric-park-fna/UI/StyleSets.cs +++ b/isometric-park-fna/UI/StyleSets.cs @@ -22,6 +22,7 @@ {ImGuiStyleVar.WindowRounding, 0.0f}, {ImGuiStyleVar.FrameBorderSize, 1.0f}, {ImGuiStyleVar.TabRounding, 0.0f}, + {ImGuiStyleVar.GrabRounding, 0.0f}, }; public static Dictionary defaultWindowColors = new Dictionary{ diff --git a/isometric-park-fna/isometric-park-fna.csproj b/isometric-park-fna/isometric-park-fna.csproj --- a/isometric-park-fna/isometric-park-fna.csproj +++ b/isometric-park-fna/isometric-park-fna.csproj @@ -47,6 +47,7 @@ +