Description:
Add InGameMenu.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r305:6aef2f413cb1 -

@@ -0,0 +1,36
1
2 using Encompass;
3
4 using isometricparkfna.Messages;
5 using isometricparkfna.Components;
6
7 namespace isometricparkfna.Engines {
8
9 [Receives(typeof(GameStateMessage))]
10 [Sends(typeof(ToggleWindowTypeMessage))]
11 [Reads()]
12 [Writes()]
13 class GameStateEngine : Engine
14 {
15
16 public override void Update(double dt)
17 {
18
19 foreach (var message in ReadMessages<GameStateMessage>())
20 {
21 if (message.isPlaying)
22 {
23 startGame();
24 }
25 SendMessage(new ToggleWindowTypeMessage { Window = Window.MainMenu});
26 }
27
28 }
29
30 public void startGame()
31 {
32
33 }
34
35 }
36 }
@@ -0,0 +1,62
1
2 using System;
3 using ImGuiNET;
4
5 using Num = System.Numerics;
6
7 using isometricparkfna.Engines;
8 using isometricparkfna.Messages;
9 using isometricparkfna.UI;
10
11 namespace isometricparkfna.UI
12 {
13
14 public static class InGameMenu
15 {
16
17
18 public static void Render(ImFontPtr font, ImGuiWindowBridgeEngine bridgeEngine, int width)
19 {
20
21 ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None;
22 bool newShow = true;
23 Num.Vector2 button_size = new Num.Vector2(120, 20);
24 StyleSet.pushStyleVarSet(StyleSet.defaultWindowVars);
25 StyleSet.pushColorSet(StyleSet.defaultWindowColors);
26
27
28 ImGui.SetNextWindowPos(new Num.Vector2(width/2, 200));
29
30 ImGui.PushFont(font);
31 // ImGui.PushFont(smallFont);
32 ImGui.Begin("##In-game Toolbar", ref newShow, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoTitleBar);
33
34 ImGui.Text("In-game menu");
35
36 if (ImGui.Button("Options", button_size))
37 {
38
39 }
40 if (ImGui.Button("Quit", button_size))
41 {
42
43 System.Console.WriteLine("Quitting");
44 Environment.Exit(0);
45 }
46 if (ImGui.Button("Quit to Main Menu", button_size))
47 {
48
49 bridgeEngine.gameStateMessages.Add(new GameStateMessage{isPlaying = false});
50 bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage{Window = Window.InGameMenu});
51 }
52
53 ImGui.End();
54
55
56 ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
57 StyleSet.popStyleVarSet(StyleSet.defaultWindowVars);
58 StyleSet.popColorSet(StyleSet.defaultWindowColors);
59 ImGui.PopFont();
60 }
61 }
62 }
@@ -180,6 +180,12
180 SendMessage(new GameStateMessage {isPlaying = false});
180 SendMessage(new GameStateMessage {isPlaying = false});
181 }
181 }
182 #endif
182 #endif
183 if (keyboardCur.IsKeyDown(Keys.Escape) && keyboardPrev.IsKeyUp(Keys.Escape))
184 {
185 // SendMessage(new TogglePauseMessage());
186 SendMessage(new ToggleWindowTypeMessage{Window = Window.InGameMenu});
187 SendMessage(new GameRateMessage { paused = true, rate = null });
188 }
183
189
184 if (keyboardCur.IsKeyDown(Keys.Q) && keyboardPrev.IsKeyUp(Keys.Q))
190 if (keyboardCur.IsKeyDown(Keys.Q) && keyboardPrev.IsKeyUp(Keys.Q))
185 {
191 {
@@ -47,7 +47,10
47 foreach (ref readonly var message in ReadMessages<GameRateMessage>())
47 foreach (ref readonly var message in ReadMessages<GameRateMessage>())
48 {
48 {
49 this.simulation.paused = message.paused;
49 this.simulation.paused = message.paused;
50 this.simulation.setRate(message.rate);
50 if(message.rate != null)
51 {
52 this.simulation.setRate(message.rate ?? 0);
53 }
51 }
54 }
52
55
53 foreach (ref readonly var message in ReadMessages<TogglePauseMessage>())
56 foreach (ref readonly var message in ReadMessages<TogglePauseMessage>())
@@ -239,7 +239,7
239 WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar));
239 WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar));
240
240
241 WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.batch, this.monoFont), 1);
241 WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.batch, this.monoFont), 1);
242 WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(debugWindow.monoFont, debugWindow.italicFont, this.imGuiWindowBridgeEngine), 2);
242 WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(debugWindow.monoFont, debugWindow.italicFont, this.imGuiWindowBridgeEngine, FNAGame.width), 2);
243 var contractWindow = WorldBuilder.CreateEntity();
243 var contractWindow = WorldBuilder.CreateEntity();
244 WorldBuilder.SetComponent(contractWindow, new VisibilityComponent { visible = false });
244 WorldBuilder.SetComponent(contractWindow, new VisibilityComponent { visible = false });
245 WorldBuilder.SetComponent(contractWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Contracts });
245 WorldBuilder.SetComponent(contractWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Contracts });
@@ -257,6 +257,11
257 WorldBuilder.SetComponent(mainMenu, new VisibilityComponent { visible = true });
257 WorldBuilder.SetComponent(mainMenu, new VisibilityComponent { visible = true });
258 WorldBuilder.SetComponent(mainMenu, new WindowTypeComponent { type = isometricparkfna.Messages.Window.MainMenu });
258 WorldBuilder.SetComponent(mainMenu, new WindowTypeComponent { type = isometricparkfna.Messages.Window.MainMenu });
259
259
260 var inputMenu = WorldBuilder.CreateEntity();
261 WorldBuilder.SetComponent(inputMenu, new VisibilityComponent { visible = false });
262 WorldBuilder.SetComponent(inputMenu, new WindowTypeComponent { type = isometricparkfna.Messages.Window.InGameMenu });
263
264
260 // var budgetWindow = WorldBuilder.CreateEntity();
265 // var budgetWindow = WorldBuilder.CreateEntity();
261 // WorldBuilder.SetComponent(budgetWindow, new VisibilityComponent{visible = true});
266 // WorldBuilder.SetComponent(budgetWindow, new VisibilityComponent{visible = true});
262 // WorldBuilder.SetComponent(budgetWindow, new BudgetComponent());
267 // WorldBuilder.SetComponent(budgetWindow, new BudgetComponent());
@@ -8,6 +8,6
8 public struct GameRateMessage : IMessage//, IHasEntity
8 public struct GameRateMessage : IMessage//, IHasEntity
9 {
9 {
10 public bool paused;
10 public bool paused;
11 public int rate;
11 public int? rate;
12 }
12 }
13 }
13 }
@@ -22,11 +22,13
22 private ImFontPtr font;
22 private ImFontPtr font;
23 private ImFontPtr italicFont;
23 private ImFontPtr italicFont;
24 private ImGuiWindowBridgeEngine BridgeEngine;
24 private ImGuiWindowBridgeEngine BridgeEngine;
25 public ImGuiWindowRenderer(ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine)
25 private int width;
26 public ImGuiWindowRenderer(ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine, int width)
26 {
27 {
27 this.font = font;
28 this.font = font;
28 this.italicFont = italicFont;
29 this.italicFont = italicFont;
29 this.BridgeEngine = engine;
30 this.BridgeEngine = engine;
31 this.width = width;
30 }
32 }
31
33
32 private (Entity entity, string name, string description, ContractStatus status, decimal amount, string delta_trees, int image_index, Vector2 square)
34 private (Entity entity, string name, string description, ContractStatus status, decimal amount, string delta_trees, int image_index, Vector2 square)
@@ -92,7 +94,9
92 break;
94 break;
93 case Window.MainMenu:
95 case Window.MainMenu:
94 MainMenu.Render(this.font, this.BridgeEngine);
96 MainMenu.Render(this.font, this.BridgeEngine);
95
97 break;
98 case Window.InGameMenu:
99 InGameMenu.Render(this.font, this.BridgeEngine, width);
96 break;
100 break;
97 default:
101 default:
98 break;
102 break;
@@ -66,6 +66,7
66 <Compile Include="UI\NewsWindow.cs" />
66 <Compile Include="UI\NewsWindow.cs" />
67 <Compile Include="UI\StyleSet.cs" />
67 <Compile Include="UI\StyleSet.cs" />
68 <Compile Include="UI\MainMenu.cs" />
68 <Compile Include="UI\MainMenu.cs" />
69 <Compile Include="UI\InGameMenu.cs" />
69 </ItemGroup>
70 </ItemGroup>
70 <ItemGroup>
71 <ItemGroup>
71 <ProjectReference Include="..\FNA\FNA.csproj">
72 <ProjectReference Include="..\FNA\FNA.csproj">
You need to be logged in to leave comments. Login now