# HG changeset patch # User Alys Brooks # Date 2021-10-23 06:34:56 # Node ID c3ff02bb2f859611190e8ab69589e40ca2eea1cf # Parent 86a475320ee34f4c7358a30d8cc6df03abaa5f42 Refactor some window code out of FNAGame. 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 @@ -45,12 +45,6 @@ case Window.Budget: game.showBudget = !game.showBudget; break; - case Window.Forest: - game.showForest = !game.showForest; - break; - case Window.News: - game.showNews = !game.showNews; - break; } } diff --git a/isometric-park-fna/Engines/PolicyEngine.cs b/isometric-park-fna/Engines/PolicyEngine.cs --- a/isometric-park-fna/Engines/PolicyEngine.cs +++ b/isometric-park-fna/Engines/PolicyEngine.cs @@ -37,6 +37,7 @@ }); var newCost = message.newEnforcementLevel switch { + EnforcementLevel.Unspecified => 0, EnforcementLevel.NoEnforcement => 0, EnforcementLevel.EnforcedWithWarnings => 100, EnforcementLevel.EnforcedWithFines => 100 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 @@ -101,8 +101,6 @@ private GraphicsDeviceManager gdm; public bool showBudget; private BudgetWindow budgetWindow; - public bool showForest; - public bool showNews; //Encompass private WorldBuilder WorldBuilder = new WorldBuilder(); @@ -158,8 +156,6 @@ showBudget = false; - showForest = false; - showNews = false; showGrid = true; showTrees = true; @@ -276,7 +272,7 @@ WorldBuilder.AddEngine(new TraceryBridgeEngine(this.grammar)); WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.batch, this.monoFont), 1); - WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(this, debugWindow.monoFont, debugWindow.italicFont, this.imGuiWindowBridgeEngine, this.gdm) , 2); + WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(this, this.simulation, debugWindow.monoFont, debugWindow.italicFont, this.imGuiWindowBridgeEngine, this.gdm) , 2); var contractWindow = WorldBuilder.CreateEntity(); WorldBuilder.SetComponent(contractWindow, new VisibilityComponent { visible = false }); WorldBuilder.SetComponent(contractWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Contracts }); @@ -834,16 +830,6 @@ #region window - if (this.showForest) - { - ForestWindow.Render(this.showForest, debugWindow.monoFont, this.simulation, this.imGuiWindowBridgeEngine); - } - - if (this.showNews) - { - NewsWindow.Render(this.showNews, debugWindow.monoFont, this.simulation, this.imGuiWindowBridgeEngine); - } - bool quit = false; Menu.Render(debugWindow.monoFont, FNAGame.width, this.imGuiWindowBridgeEngine, ref quit, ref this.simulation.paused, ref this.simulation.currentRate, ref this.showBudget, header_left); diff --git a/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs b/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs --- a/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs +++ b/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs @@ -24,15 +24,17 @@ private ImFontPtr italicFont; private ImGuiWindowBridgeEngine BridgeEngine; private FNAGame game; + private Simulation simulation; private GraphicsDeviceManager gdm; - public ImGuiWindowRenderer(FNAGame game, ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine, GraphicsDeviceManager gdm) + public ImGuiWindowRenderer(FNAGame game, Simulation simulation, ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine, GraphicsDeviceManager gdm) { // this.font = font; this.italicFont = italicFont; this.BridgeEngine = engine; this.game = game; + this.simulation = simulation; this.gdm = gdm; } @@ -128,6 +130,12 @@ ContractWindow.Render(this.BridgeEngine.font, this.italicFont, this.BridgeEngine, data); break; + case Window.News: + NewsWindow.Render(this.BridgeEngine.font, this.simulation, this.BridgeEngine); + break; + case Window.Forest: + ForestWindow.Render(this.BridgeEngine.font, this.simulation, this.BridgeEngine); + break; case Window.MainMenu: MainMenu.Render(this.BridgeEngine.font, this.BridgeEngine, width); break; diff --git a/isometric-park-fna/UI/ForestWindow.cs b/isometric-park-fna/UI/ForestWindow.cs --- a/isometric-park-fna/UI/ForestWindow.cs +++ b/isometric-park-fna/UI/ForestWindow.cs @@ -15,12 +15,12 @@ public static bool hadFocus = false; private static bool enforceTresspassing1 = false; - private static string enforceTresspassing2 = "None"; + private static string enforceTresspassing2 = "Unspecified"; - public static void Render(bool show, ImFontPtr font, Simulation sim, ImGuiWindowBridgeEngine engine) + public static void Render(ImFontPtr font, Simulation sim, ImGuiWindowBridgeEngine engine) { - bool newShow = show; - if (show) + bool newShow = true; + if (newShow) { ImGui.PushFont(font); @@ -33,7 +33,7 @@ ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white); } - ImGui.Begin("Forest Policy", ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings); + ImGui.Begin("Forest Policy", ref newShow, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings); if (ForestWindow.hadFocus) { ImGui.PopStyleColor(); @@ -102,7 +102,7 @@ if (ImGui.Button("Okay")) { - show = false; + newShow = false; Logging.Spy(new {newEnforcementLevel = (EnforcementLevel)Enum.Parse(typeof(EnforcementLevel), enforceTresspassing2)}); engine.trespassingPolicyMessages.Add(new SetTrespassingPolicyMessage{newEnforcementLevel = (EnforcementLevel)Enum.Parse(typeof(EnforcementLevel), enforceTresspassing2)}); } @@ -112,7 +112,7 @@ StyleSets.defaultSet.pop(); ImGui.PopFont(); } - if (show != newShow) + if (!newShow) { engine.typeMessages.Add(new ToggleWindowTypeMessage {Window = Window.Forest }); } diff --git a/isometric-park-fna/UI/NewsWindow.cs b/isometric-park-fna/UI/NewsWindow.cs --- a/isometric-park-fna/UI/NewsWindow.cs +++ b/isometric-park-fna/UI/NewsWindow.cs @@ -68,10 +68,10 @@ public static bool had_focus = false; - public static void Render(bool show, ImFontPtr font, Simulation sim, ImGuiWindowBridgeEngine engine) + public static void Render(ImFontPtr font, Simulation sim, ImGuiWindowBridgeEngine engine) { - bool newShow = show; - if (show) + bool newShow = true; + if (newShow) { ImGui.PushFont(font); @@ -145,7 +145,7 @@ if (ImGui.Button("Okay")) { - show = false; + newShow = false; } ImGui.End(); @@ -156,7 +156,7 @@ ImGui.PopFont(); } - if (show != newShow) + if (!newShow) { engine.typeMessages.Add(new ToggleWindowTypeMessage { Window = Window.News }); }