Description:
Add InGameMenu.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -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 | 180 | SendMessage(new GameStateMessage {isPlaying = false}); |
|
181 | 181 | } |
|
182 | 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 | 190 | if (keyboardCur.IsKeyDown(Keys.Q) && keyboardPrev.IsKeyUp(Keys.Q)) |
|
185 | 191 | { |
@@ -47,7 +47,10 | |||
|
47 | 47 | foreach (ref readonly var message in ReadMessages<GameRateMessage>()) |
|
48 | 48 | { |
|
49 | 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 | 56 | foreach (ref readonly var message in ReadMessages<TogglePauseMessage>()) |
@@ -239,7 +239,7 | |||
|
239 | 239 | WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar)); |
|
240 | 240 | |
|
241 | 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 | 243 | var contractWindow = WorldBuilder.CreateEntity(); |
|
244 | 244 | WorldBuilder.SetComponent(contractWindow, new VisibilityComponent { visible = false }); |
|
245 | 245 | WorldBuilder.SetComponent(contractWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Contracts }); |
@@ -257,6 +257,11 | |||
|
257 | 257 | WorldBuilder.SetComponent(mainMenu, new VisibilityComponent { visible = true }); |
|
258 | 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 | 265 | // var budgetWindow = WorldBuilder.CreateEntity(); |
|
261 | 266 | // WorldBuilder.SetComponent(budgetWindow, new VisibilityComponent{visible = true}); |
|
262 | 267 | // WorldBuilder.SetComponent(budgetWindow, new BudgetComponent()); |
@@ -8,6 +8,6 | |||
|
8 | 8 | public struct GameRateMessage : IMessage//, IHasEntity |
|
9 | 9 | { |
|
10 | 10 | public bool paused; |
|
11 | public int rate; | |
|
11 | public int? rate; | |
|
12 | 12 | } |
|
13 | 13 | } |
@@ -22,11 +22,13 | |||
|
22 | 22 | private ImFontPtr font; |
|
23 | 23 | private ImFontPtr italicFont; |
|
24 | 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 | 28 | this.font = font; |
|
28 | 29 | this.italicFont = italicFont; |
|
29 | 30 | this.BridgeEngine = engine; |
|
31 | this.width = width; | |
|
30 | 32 | } |
|
31 | 33 | |
|
32 | 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 | 94 | break; |
|
93 | 95 | case Window.MainMenu: |
|
94 | 96 | MainMenu.Render(this.font, this.BridgeEngine); |
|
95 | ||
|
97 | break; | |
|
98 | case Window.InGameMenu: | |
|
99 | InGameMenu.Render(this.font, this.BridgeEngine, width); | |
|
96 | 100 | break; |
|
97 | 101 | default: |
|
98 | 102 | break; |
You need to be logged in to leave comments.
Login now