diff --git a/isometric-park-fna/Engines/GameStateEngine.cs b/isometric-park-fna/Engines/GameStateEngine.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Engines/GameStateEngine.cs @@ -0,0 +1,36 @@ + +using Encompass; + +using isometricparkfna.Messages; +using isometricparkfna.Components; + +namespace isometricparkfna.Engines { + + [Receives(typeof(GameStateMessage))] + [Sends(typeof(ToggleWindowTypeMessage))] + [Reads()] + [Writes()] + class GameStateEngine : Engine + { + + public override void Update(double dt) + { + + foreach (var message in ReadMessages()) + { + if (message.isPlaying) + { + startGame(); + } + SendMessage(new ToggleWindowTypeMessage { Window = Window.MainMenu}); + } + + } + + public void startGame() + { + + } + + } +} diff --git a/isometric-park-fna/Engines/InputEngine.cs b/isometric-park-fna/Engines/InputEngine.cs --- a/isometric-park-fna/Engines/InputEngine.cs +++ b/isometric-park-fna/Engines/InputEngine.cs @@ -180,6 +180,12 @@ SendMessage(new GameStateMessage {isPlaying = false}); } #endif + if (keyboardCur.IsKeyDown(Keys.Escape) && keyboardPrev.IsKeyUp(Keys.Escape)) + { + // SendMessage(new TogglePauseMessage()); + SendMessage(new ToggleWindowTypeMessage{Window = Window.InGameMenu}); + SendMessage(new GameRateMessage { paused = true, rate = null }); + } if (keyboardCur.IsKeyDown(Keys.Q) && keyboardPrev.IsKeyUp(Keys.Q)) { diff --git a/isometric-park-fna/Engines/SimulationBridgeEngine.cs b/isometric-park-fna/Engines/SimulationBridgeEngine.cs --- a/isometric-park-fna/Engines/SimulationBridgeEngine.cs +++ b/isometric-park-fna/Engines/SimulationBridgeEngine.cs @@ -47,7 +47,10 @@ foreach (ref readonly var message in ReadMessages()) { this.simulation.paused = message.paused; - this.simulation.setRate(message.rate); + if(message.rate != null) + { + this.simulation.setRate(message.rate ?? 0); + } } foreach (ref readonly var message in ReadMessages()) 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 @@ -239,7 +239,7 @@ WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar)); WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.batch, this.monoFont), 1); - WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(debugWindow.monoFont, debugWindow.italicFont, this.imGuiWindowBridgeEngine), 2); + WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(debugWindow.monoFont, debugWindow.italicFont, this.imGuiWindowBridgeEngine, FNAGame.width), 2); var contractWindow = WorldBuilder.CreateEntity(); WorldBuilder.SetComponent(contractWindow, new VisibilityComponent { visible = false }); WorldBuilder.SetComponent(contractWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Contracts }); @@ -257,6 +257,11 @@ WorldBuilder.SetComponent(mainMenu, new VisibilityComponent { visible = true }); WorldBuilder.SetComponent(mainMenu, new WindowTypeComponent { type = isometricparkfna.Messages.Window.MainMenu }); + var inputMenu = WorldBuilder.CreateEntity(); + WorldBuilder.SetComponent(inputMenu, new VisibilityComponent { visible = false }); + WorldBuilder.SetComponent(inputMenu, new WindowTypeComponent { type = isometricparkfna.Messages.Window.InGameMenu }); + + // var budgetWindow = WorldBuilder.CreateEntity(); // WorldBuilder.SetComponent(budgetWindow, new VisibilityComponent{visible = true}); // WorldBuilder.SetComponent(budgetWindow, new BudgetComponent()); diff --git a/isometric-park-fna/Messages/GameRateMessage.cs b/isometric-park-fna/Messages/GameRateMessage.cs --- a/isometric-park-fna/Messages/GameRateMessage.cs +++ b/isometric-park-fna/Messages/GameRateMessage.cs @@ -8,6 +8,6 @@ public struct GameRateMessage : IMessage//, IHasEntity { public bool paused; - public int rate; + public int? rate; } } 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 @@ -22,11 +22,13 @@ private ImFontPtr font; private ImFontPtr italicFont; private ImGuiWindowBridgeEngine BridgeEngine; - public ImGuiWindowRenderer(ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine) + private int width; + public ImGuiWindowRenderer(ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine, int width) { this.font = font; this.italicFont = italicFont; this.BridgeEngine = engine; + this.width = width; } private (Entity entity, string name, string description, ContractStatus status, decimal amount, string delta_trees, int image_index, Vector2 square) @@ -92,7 +94,9 @@ break; case Window.MainMenu: MainMenu.Render(this.font, this.BridgeEngine); - + break; + case Window.InGameMenu: + InGameMenu.Render(this.font, this.BridgeEngine, width); break; default: break; diff --git a/isometric-park-fna/UI/InGameMenu.cs b/isometric-park-fna/UI/InGameMenu.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/UI/InGameMenu.cs @@ -0,0 +1,62 @@ + +using System; +using ImGuiNET; + +using Num = System.Numerics; + +using isometricparkfna.Engines; +using isometricparkfna.Messages; +using isometricparkfna.UI; + +namespace isometricparkfna.UI +{ + + public static class InGameMenu + { + + + public static void Render(ImFontPtr font, ImGuiWindowBridgeEngine bridgeEngine, int width) + { + + ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None; + bool newShow = true; + Num.Vector2 button_size = new Num.Vector2(120, 20); + StyleSet.pushStyleVarSet(StyleSet.defaultWindowVars); + StyleSet.pushColorSet(StyleSet.defaultWindowColors); + + + ImGui.SetNextWindowPos(new Num.Vector2(width/2, 200)); + + ImGui.PushFont(font); + // ImGui.PushFont(smallFont); + ImGui.Begin("##In-game Toolbar", ref newShow, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoTitleBar); + + ImGui.Text("In-game menu"); + + if (ImGui.Button("Options", button_size)) + { + + } + if (ImGui.Button("Quit", button_size)) + { + + System.Console.WriteLine("Quitting"); + Environment.Exit(0); + } + if (ImGui.Button("Quit to Main Menu", button_size)) + { + + bridgeEngine.gameStateMessages.Add(new GameStateMessage{isPlaying = false}); + bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage{Window = Window.InGameMenu}); + } + + ImGui.End(); + + + ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; + StyleSet.popStyleVarSet(StyleSet.defaultWindowVars); + StyleSet.popColorSet(StyleSet.defaultWindowColors); + ImGui.PopFont(); + } + } +} 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 @@ -66,6 +66,7 @@ +