Description:
Add menu.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -0,0 +1,98 | |||||
|
|
1 | using ImGuiNET; | ||
|
|
2 | |||
|
|
3 | using Num = System.Numerics; | ||
|
|
4 | |||
|
|
5 | namespace isometricparkfna.UI | ||
|
|
6 | { | ||
|
|
7 | |||
|
|
8 | public static class Menu | ||
|
|
9 | { | ||
|
|
10 | public static void Render(ImFontPtr font, ref bool quit, ref bool paused, ref int rate, ref bool show_budget, ref bool show_forest) | ||
|
|
11 | { | ||
|
|
12 | ImGui.PushFont(font); | ||
|
|
13 | |||
|
|
14 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None; | ||
|
|
15 | ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 0.0f); | ||
|
|
16 | ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0.0f); | ||
|
|
17 | ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 1.0f); | ||
|
|
18 | ImGui.PushStyleColor(ImGuiCol.WindowBg, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | ||
|
|
19 | ImGui.PushStyleColor(ImGuiCol.MenuBarBg, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | ||
|
|
20 | ImGui.PushStyleColor(ImGuiCol.PopupBg, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | ||
|
|
21 | |||
|
|
22 | var title_bar = new Num.Vector4(0.65f, 0.65f, 0.65f, 1f); | ||
|
|
23 | ImGui.PushStyleColor(ImGuiCol.TitleBg, title_bar); | ||
|
|
24 | ImGui.PushStyleColor(ImGuiCol.TitleBgActive, title_bar); | ||
|
|
25 | ImGui.PushStyleColor(ImGuiCol.TitleBgCollapsed, title_bar); | ||
|
|
26 | |||
|
|
27 | ImGui.PushStyleColor(ImGuiCol.Border, new Num.Vector4(0f, 0f, 0f, 1f)); | ||
|
|
28 | ImGui.PushStyleColor(ImGuiCol.BorderShadow, new Num.Vector4(0f, 0f, 0f, 0.5f)); | ||
|
|
29 | |||
|
|
30 | |||
|
|
31 | |||
|
|
32 | ImGui.PushStyleColor(ImGuiCol.Button, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | ||
|
|
33 | ImGui.PushStyleColor(ImGuiCol.Text, new Num.Vector4(0f, 0f, 0f, 1f)); | ||
|
|
34 | |||
|
|
35 | if (ImGui.BeginMainMenuBar()) { | ||
|
|
36 | if (ImGui.BeginMenu("File")) { | ||
|
|
37 | |||
|
|
38 | if (ImGui.MenuItem("Exit (Q)")) | ||
|
|
39 | { | ||
|
|
40 | quit = true; | ||
|
|
41 | } | ||
|
|
42 | ImGui.EndMenu(); | ||
|
|
43 | } | ||
|
|
44 | if (ImGui.BeginMenu("Speed")) { | ||
|
|
45 | |||
|
|
46 | if (ImGui.MenuItem("Pause", "", paused)) { | ||
|
|
47 | paused = !paused; | ||
|
|
48 | } | ||
|
|
49 | |||
|
|
50 | ImGui.Separator(); | ||
|
|
51 | |||
|
|
52 | if (ImGui.MenuItem("1 - Slow", "1", (rate == 0))) { | ||
|
|
53 | paused = false; | ||
|
|
54 | rate = 0; | ||
|
|
55 | } | ||
|
|
56 | else if (ImGui.MenuItem("2 - Normal", "2", (rate == 1))) { | ||
|
|
57 | paused = false; | ||
|
|
58 | rate = 1; | ||
|
|
59 | } | ||
|
|
60 | else if (ImGui.MenuItem("3 - Fast", "3", (rate == 2))) { | ||
|
|
61 | paused = false; | ||
|
|
62 | rate = 2; | ||
|
|
63 | } | ||
|
|
64 | else if (ImGui.MenuItem("4 - Fastest", "4", (rate == 3))) { | ||
|
|
65 | paused = false; | ||
|
|
66 | rate = 3; | ||
|
|
67 | } | ||
|
|
68 | |||
|
|
69 | |||
|
|
70 | ImGui.EndMenu(); | ||
|
|
71 | } | ||
|
|
72 | |||
|
|
73 | if (ImGui.BeginMenu("Window")) { | ||
|
|
74 | |||
|
|
75 | if (ImGui.MenuItem("(B)udget", "", show_budget)) { | ||
|
|
76 | show_budget = !show_budget; | ||
|
|
77 | |||
|
|
78 | } | ||
|
|
79 | else if (ImGui.MenuItem("(F)orest Policy", "", show_forest)) { | ||
|
|
80 | show_forest = !show_forest; | ||
|
|
81 | |||
|
|
82 | } | ||
|
|
83 | |||
|
|
84 | ImGui.EndMenu(); | ||
|
|
85 | } | ||
|
|
86 | ImGui.EndMainMenuBar(); | ||
|
|
87 | // ImGui.Button("Toolbar goes here", new Num.Vector2(0, 37)); | ||
|
|
88 | |||
|
|
89 | |||
|
|
90 | // ImGui.End(); | ||
|
|
91 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; | ||
|
|
92 | ImGui.PopStyleVar(3); | ||
|
|
93 | ImGui.PopStyleColor(9); | ||
|
|
94 | ImGui.PopFont(); | ||
|
|
95 | } | ||
|
|
96 | } | ||
|
|
97 | } | ||
|
|
98 | } No newline at end of file |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -111,7 +111,7 | |||||
|
111 | //gdm.SynchronizeWithVerticalRetrace = false; |
|
111 | //gdm.SynchronizeWithVerticalRetrace = false; |
|
112 | IsFixedTimeStep = false; |
|
112 | IsFixedTimeStep = false; |
|
113 |
|
113 | ||
|
114 | this.simulation = new Simulation(this.squaresAcross, this.squaresDown, 16.66667f*30); |
|
114 | this.simulation = new Simulation(this.squaresAcross, this.squaresDown, new float[] {16.66667f*60, 16.66667f*30, 16.66667f*15, 16.66667f*1 }); |
|
115 |
|
115 | ||
|
116 | foreach (List<Cell> row in this.simulation.map.cells) |
|
116 | foreach (List<Cell> row in this.simulation.map.cells) |
|
117 | { |
|
117 | { |
@@ -358,13 +358,42 | |||||
|
358 |
|
358 | ||
|
359 |
|
359 | ||
|
360 | #region gamerate_keys |
|
360 | #region gamerate_keys |
|
|
361 | if (keyboardCur.IsKeyDown(Keys.P) && keyboardPrev.IsKeyUp(Keys.P) ) | ||
|
|
362 | { | ||
|
|
363 | this.simulation.paused = !this.simulation.paused; | ||
|
|
364 | |||
|
|
365 | } | ||
|
361 | if (keyboardCur.IsKeyDown(Keys.D0) && keyboardPrev.IsKeyUp(Keys.D0) ) |
|
366 | if (keyboardCur.IsKeyDown(Keys.D0) && keyboardPrev.IsKeyUp(Keys.D0) ) |
|
362 | { |
|
367 | { |
|
363 | this.simulation.paused = !this.simulation.paused; |
|
368 | this.simulation.paused = !this.simulation.paused; |
|
364 |
|
369 | ||
|
365 | } |
|
370 | } |
|
|
371 | if (keyboardCur.IsKeyDown(Keys.D1) && keyboardPrev.IsKeyUp(Keys.D1) ) | ||
|
|
372 | { | ||
|
|
373 | this.simulation.paused = false; | ||
|
|
374 | this.simulation.setRate(0); | ||
|
|
375 | } | ||
|
|
376 | if (keyboardCur.IsKeyDown(Keys.D2) && keyboardPrev.IsKeyUp(Keys.D2) ) | ||
|
|
377 | { | ||
|
|
378 | this.simulation.paused = false; | ||
|
|
379 | this.simulation.setRate(1); | ||
|
|
380 | } | ||
|
|
381 | if (keyboardCur.IsKeyDown(Keys.D3) && keyboardPrev.IsKeyUp(Keys.D3) ) | ||
|
|
382 | { | ||
|
|
383 | this.simulation.paused = false; | ||
|
|
384 | this.simulation.setRate(2); | ||
|
|
385 | } | ||
|
|
386 | if (keyboardCur.IsKeyDown(Keys.D4) && keyboardPrev.IsKeyUp(Keys.D4) ) | ||
|
|
387 | { | ||
|
|
388 | this.simulation.paused = false; | ||
|
|
389 | this.simulation.setRate(3); | ||
|
|
390 | } | ||
|
366 | #endregion gamerate_keys |
|
391 | #endregion gamerate_keys |
|
367 |
|
392 | ||
|
|
393 | #if DEBUG | ||
|
|
394 | Console.Out.WriteLine(String.Format("Rate: {0}", this.simulation.currentRate)); | ||
|
|
395 | #endif | ||
|
|
396 | |||
|
368 |
|
397 | ||
|
369 |
|
398 | ||
|
370 |
|
399 | ||
@@ -838,6 +867,14 | |||||
|
838 | ForestWindow.Render(ref this.showForest, debugWindow.monoFont, this.simulation); |
|
867 | ForestWindow.Render(ref this.showForest, debugWindow.monoFont, this.simulation); |
|
839 | } |
|
868 | } |
|
840 |
|
869 | ||
|
|
870 | bool quit = false; | ||
|
|
871 | Menu.Render(debugWindow.monoFont, ref quit, ref this.simulation.paused, ref this.simulation.currentRate, | ||
|
|
872 | ref this.showBudget, ref this.showForest); | ||
|
|
873 | |||
|
|
874 | if (quit) { | ||
|
|
875 | System.Environment.Exit(0); | ||
|
|
876 | } | ||
|
|
877 | |||
|
841 |
|
878 | ||
|
842 | _imGuiRenderer.AfterLayout(); |
|
879 | _imGuiRenderer.AfterLayout(); |
|
843 |
|
880 |
@@ -109,7 +109,7 | |||||
|
109 | } |
|
109 | } |
|
110 | } |
|
110 | } |
|
111 |
|
111 | ||
|
112 | public float millisecondsPerAdvance { get; private set; } |
|
112 | public float[] millisecondsPerAdvance { get; private set; } |
|
113 | public String Season { get |
|
113 | public String Season { get |
|
114 | { |
|
114 | { |
|
115 | if (MathUtils.Between(this.DateTime.Month, 3, 5)) |
|
115 | if (MathUtils.Between(this.DateTime.Month, 3, 5)) |
@@ -136,6 +136,7 | |||||
|
136 | public int ticksPerAdvance; |
|
136 | public int ticksPerAdvance; |
|
137 | private float lastAdvance; |
|
137 | private float lastAdvance; |
|
138 | public bool paused; |
|
138 | public bool paused; |
|
|
139 | public int currentRate; | ||
|
139 |
|
140 | ||
|
140 | private Random random; |
|
141 | private Random random; |
|
141 |
|
142 | ||
@@ -194,7 +195,7 | |||||
|
194 |
|
195 | ||
|
195 |
|
196 | ||
|
196 |
|
197 | ||
|
197 | public Simulation(int width, int height, float millisecondsPerAdvance) |
|
198 | public Simulation(int width, int height, float[] millisecondsPerAdvance) |
|
198 | { |
|
199 | { |
|
199 | this.random = new Random(); |
|
200 | this.random = new Random(); |
|
200 |
|
201 | ||
@@ -299,6 +300,12 | |||||
|
299 | return budget; |
|
300 | return budget; |
|
300 | } |
|
301 | } |
|
301 |
|
302 | ||
|
|
303 | public void setRate(int newRate) { | ||
|
|
304 | if ((newRate >= 0) && (newRate <= this.millisecondsPerAdvance.Length)) { | ||
|
|
305 | this.currentRate = newRate; | ||
|
|
306 | } | ||
|
|
307 | } | ||
|
|
308 | |||
|
302 | public void update(TimeSpan deltaTime) |
|
309 | public void update(TimeSpan deltaTime) |
|
303 | { |
|
310 | { |
|
304 | //this.Tick++; |
|
311 | //this.Tick++; |
@@ -307,7 +314,9 | |||||
|
307 | { |
|
314 | { |
|
308 | this.Elapsed += deltaTime.Milliseconds; |
|
315 | this.Elapsed += deltaTime.Milliseconds; |
|
309 |
|
316 | ||
|
310 | int advancesToSimulate = (int)((this.Elapsed - this.lastAdvance) / this.millisecondsPerAdvance); |
|
317 | float millisecondsPerAdvance = this.millisecondsPerAdvance[this.currentRate]; |
|
|
318 | |||
|
|
319 | int advancesToSimulate = (int)((this.Elapsed - this.lastAdvance) / millisecondsPerAdvance); | ||
|
311 |
|
320 | ||
|
312 | for (int i = 0; i < advancesToSimulate; i++) |
|
321 | for (int i = 0; i < advancesToSimulate; i++) |
|
313 | { |
|
322 | { |
@@ -320,7 +329,7 | |||||
|
320 | //it's t=125, we have 2.5 steps to simulate. However, we only want to simulate |
|
329 | //it's t=125, we have 2.5 steps to simulate. However, we only want to simulate |
|
321 | //whole steps for simplicity's sake, so that means we'll simulate 2. But that means we've only simulated |
|
330 | //whole steps for simplicity's sake, so that means we'll simulate 2. But that means we've only simulated |
|
322 | //through t=120, so that's what we want to track in lastAdvance. |
|
331 | //through t=120, so that's what we want to track in lastAdvance. |
|
323 |
this.lastAdvance += advancesToSimulate * |
|
332 | this.lastAdvance += advancesToSimulate * millisecondsPerAdvance; |
|
324 | } |
|
333 | } |
|
325 |
|
334 | ||
|
326 | /* |
|
335 | /* |
@@ -127,10 +127,28 | |||||
|
127 |
|
127 | ||
|
128 | ImGui.Text(string.Format("Application average {0:F3} ms/frame ({1:F1} FPS", 1000f / ImGui.GetIO().Framerate, ImGui.GetIO().Framerate)); |
|
128 | ImGui.Text(string.Format("Application average {0:F3} ms/frame ({1:F1} FPS", 1000f / ImGui.GetIO().Framerate, ImGui.GetIO().Framerate)); |
|
129 |
|
129 | ||
|
130 |
|
|||
|
131 |
|
|||
|
132 |
|
130 | ||
|
133 |
if (ImGui.B |
|
131 | if (ImGui.BeginMainMenuBar()) |
|
|
132 | { | ||
|
|
133 | if (ImGui.BeginMenu("File")) | ||
|
|
134 | { | ||
|
|
135 | if (ImGui.MenuItem("New")) | ||
|
|
136 | { | ||
|
|
137 | //Do something | ||
|
|
138 | } | ||
|
|
139 | ImGui.EndMenu(); | ||
|
|
140 | } | ||
|
|
141 | |||
|
|
142 | ImGui.EndMainMenuBar(); | ||
|
|
143 | } | ||
|
|
144 | if (ImGui.BeginMainMenuBar()) | ||
|
|
145 | { | ||
|
|
146 | ImGui.EndMainMenuBar(); | ||
|
|
147 | } | ||
|
|
148 | |||
|
|
149 | |||
|
|
150 | |||
|
|
151 | if (ImGui.Button("Test Window")) | ||
|
134 | { |
|
152 | { |
|
135 | this.show_test_window = !this.show_test_window; |
|
153 | this.show_test_window = !this.show_test_window; |
|
136 | } |
|
154 | } |
@@ -49,6 +49,7 | |||||
|
49 | <Compile Include="UI\DebugWindow.cs" /> |
|
49 | <Compile Include="UI\DebugWindow.cs" /> |
|
50 | <Compile Include="UI\Dialog.cs" /> |
|
50 | <Compile Include="UI\Dialog.cs" /> |
|
51 | <Compile Include="UI\ForestWindow.cs" /> |
|
51 | <Compile Include="UI\ForestWindow.cs" /> |
|
|
52 | <Compile Include="UI\Menu.cs" /> | ||
|
52 | </ItemGroup> |
|
53 | </ItemGroup> |
|
53 | <ItemGroup> |
|
54 | <ItemGroup> |
|
54 | <ProjectReference Include="..\FNA\FNA.csproj"> |
|
55 | <ProjectReference Include="..\FNA\FNA.csproj"> |
You need to be logged in to leave comments.
Login now