Description:
Add super basic Budget UI.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -0,0 +1,96 | |||
|
1 | using System; | |
|
2 | using Microsoft.Xna.Framework; | |
|
3 | using Microsoft.Xna.Framework.Graphics; | |
|
4 | using Microsoft.Xna.Framework.Input; | |
|
5 | ||
|
6 | namespace isometricparkfna | |
|
7 | { | |
|
8 | public class BudgetWindow | |
|
9 | { | |
|
10 | private Budget budget; | |
|
11 | private SpriteFont font; | |
|
12 | public int x; | |
|
13 | public int y; | |
|
14 | ||
|
15 | ||
|
16 | private Vector2 mouseEnd; | |
|
17 | private Vector2 mouseStart; | |
|
18 | private MouseState mousePrev; | |
|
19 | ||
|
20 | public BudgetWindow(Budget budget, SpriteFont font, int start_x, int start_y) | |
|
21 | { | |
|
22 | ||
|
23 | this.budget = budget; | |
|
24 | this.font = font; | |
|
25 | this.x = start_x; | |
|
26 | this.y = start_y; | |
|
27 | } | |
|
28 | ||
|
29 | public void update(MouseState mouseCur, Budget budget) | |
|
30 | { | |
|
31 | this.budget = budget; | |
|
32 | ||
|
33 | if ((mouseCur.LeftButton == ButtonState.Pressed) | |
|
34 | && MathUtils.Between(mouseCur.X, x, 700+x) | |
|
35 | && MathUtils.Between(mouseCur.Y, y, 500 + y)) | |
|
36 | { | |
|
37 | if (mousePrev.LeftButton == ButtonState.Released) | |
|
38 | { | |
|
39 | this.mouseStart = new Vector2(mouseCur.X, mouseCur.Y); | |
|
40 | ||
|
41 | } | |
|
42 | else | |
|
43 | { | |
|
44 | this.mouseEnd = new Vector2(mouseCur.X, mouseCur.Y); | |
|
45 | } | |
|
46 | } | |
|
47 | else if (mousePrev.LeftButton == ButtonState.Pressed) | |
|
48 | { | |
|
49 | this.x = MathUtils.Clamp(this.x + (int)(this.mouseEnd.X - this.mouseStart.X), 0, 700); | |
|
50 | this.y = MathUtils.Clamp(this.y + (int)(this.mouseEnd.Y - this.mouseStart.Y), 0, 400); | |
|
51 | ||
|
52 | } | |
|
53 | ||
|
54 | this.mousePrev = mouseCur; | |
|
55 | ||
|
56 | //if ((mouseCur.LeftButton == ButtonState.Pressed) | |
|
57 | // && MathUtils.Between(mouseCur.X, x, 700 + x) | |
|
58 | // && MathUtils.Between(mouseCur.Y, y, 500 + y)) | |
|
59 | //{ | |
|
60 | // this.x += 50; | |
|
61 | //} | |
|
62 | } | |
|
63 | ||
|
64 | public void draw(SpriteBatch batch) | |
|
65 | { | |
|
66 | int bar_height = 25; | |
|
67 | int height = 500; | |
|
68 | ||
|
69 | for (int i = 1; i < (height / bar_height); i++) | |
|
70 | { | |
|
71 | Rectangle position = new Rectangle(this.x, bar_height * i + this.y, | |
|
72 | 700, bar_height); | |
|
73 | ||
|
74 | if ((i % 2) == 0) | |
|
75 | { | |
|
76 | FilledRectangle.drawFilledRectangle(batch, position, Color.LightGreen, 0.99f); | |
|
77 | } | |
|
78 | else | |
|
79 | { | |
|
80 | FilledRectangle.drawFilledRectangle(batch, position, Color.White, 0.99f); | |
|
81 | } | |
|
82 | } | |
|
83 | ||
|
84 | batch.DrawString(font, String.Format("Starting Funds.........${0:}", this.budget.money), new Vector2(x, bar_height * 1 + y), Color.Black); | |
|
85 | ||
|
86 | batch.DrawString(font, String.Format("REVENUE", this.budget.upkeep), new Vector2(x, bar_height * 3 + y), Color.Black); | |
|
87 | batch.DrawString(font, String.Format("Subsidy................${0:}", this.budget.upkeep), new Vector2(x, bar_height * 4 + y), Color.Black); | |
|
88 | ||
|
89 | batch.DrawString(font, String.Format("EXPENSES", this.budget.upkeep), new Vector2(x, bar_height * 6 + y), Color.Black); | |
|
90 | batch.DrawString(font, String.Format("Upkeep.................${0:}", this.budget.upkeep), new Vector2(x, bar_height * 7 + y), Color.Black); | |
|
91 | ||
|
92 | batch.DrawString(font, String.Format("Ending Funds.........${0:}", this.budget.final_money), new Vector2(x, bar_height * 10 + y), Color.Black); | |
|
93 | ||
|
94 | } | |
|
95 | } | |
|
96 | } |
@@ -75,11 +75,13 | |||
|
75 | 75 | private Queue<Node<DialogOption>> remainingDialog; |
|
76 | 76 | |
|
77 | 77 | |
|
78 |
private bool showGrid |
|
|
78 | private bool showGrid; | |
|
79 | 79 | private Grammar grammar; |
|
80 | 80 | private string output; |
|
81 | 81 | private bool showSecond = true; |
|
82 | 82 | private GraphicsDeviceManager gdm; |
|
83 | private bool showBudget; | |
|
84 | private BudgetWindow budgetWindow; | |
|
83 | 85 | |
|
84 | 86 | private static void Main(string[] args) |
|
85 | 87 | { |
@@ -127,6 +129,8 | |||
|
127 | 129 | |
|
128 | 130 | showInitial = true; |
|
129 | 131 | messageIndex = 0; |
|
132 | showBudget = false; | |
|
133 | showGrid = true; | |
|
130 | 134 | |
|
131 | 135 | this.Window.Title = "Isometric Park"; |
|
132 | 136 | |
@@ -134,7 +138,8 | |||
|
134 | 138 | |
|
135 | 139 | currentNode = DialogTrees.introTree; |
|
136 | 140 | |
|
137 | ||
|
141 | ||
|
142 | ||
|
138 | 143 | |
|
139 | 144 | } |
|
140 | 145 | |
@@ -193,6 +198,9 | |||
|
193 | 198 | //font = fontBakeResult.CreateSpriteFont(GraphicsDevice); |
|
194 | 199 | monoFont = bakedMono.CreateSpriteFont(GraphicsDevice); |
|
195 | 200 | |
|
201 | this.budgetWindow = new BudgetWindow(new Budget { }, this.monoFont, 0, 0); | |
|
202 | ||
|
203 | ||
|
196 | 204 | } |
|
197 | 205 | |
|
198 | 206 | protected override void UnloadContent() |
@@ -328,6 +336,11 | |||
|
328 | 336 | this.showGrid = !this.showGrid; |
|
329 | 337 | |
|
330 | 338 | } |
|
339 | if (keyboardCur.IsKeyDown(Keys.B) && keyboardPrev.IsKeyUp(Keys.B)) | |
|
340 | { | |
|
341 | this.showBudget = !this.showBudget; | |
|
342 | ||
|
343 | } | |
|
331 | 344 | if (keyboardCur.IsKeyDown(Keys.C) && keyboardPrev.IsKeyUp(Keys.C)) |
|
332 | 345 | { |
|
333 | 346 | this.camera.Jump(Vector2.Zero); |
@@ -392,8 +405,15 | |||
|
392 | 405 | |
|
393 | 406 | #endregion input |
|
394 | 407 | |
|
408 | ||
|
409 | ||
|
395 | 410 | this.simulation.update(gameTime.ElapsedGameTime); |
|
396 | 411 | |
|
412 | if (this.showBudget) | |
|
413 | { | |
|
414 | this.budgetWindow.update(mouseCur, this.simulation.latestBudget); | |
|
415 | } | |
|
416 | ||
|
397 | 417 | |
|
398 | 418 | if (!this.showInitial && this.remainingDialog.Count > 0) |
|
399 | 419 | { |
@@ -789,10 +809,20 | |||
|
789 | 809 | |
|
790 | 810 | batch.DrawString(monoFont, header_left, new Vector2(1, 1), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); |
|
791 | 811 | batch.DrawString(monoFont, header_middle, new Vector2(middle_start, 1), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); |
|
792 | #endregion draw_header | |
|
812 | #endregion draw_header | |
|
793 | 813 | |
|
794 | 814 | |
|
795 | batch.End(); | |
|
815 | #region budget | |
|
816 | ||
|
817 | if (this.showBudget) | |
|
818 | { | |
|
819 | budgetWindow.draw(batch); | |
|
820 | ||
|
821 | } | |
|
822 | ||
|
823 | #endregion budget | |
|
824 | ||
|
825 | batch.End(); | |
|
796 | 826 | |
|
797 | 827 | #region debug_window |
|
798 | 828 | //Calcs for debug window: |
@@ -7,6 +7,8 | |||
|
7 | 7 | public struct Budget |
|
8 | 8 | { |
|
9 | 9 | public DateTime DateTime; |
|
10 | ||
|
11 | //assets | |
|
10 | 12 | public decimal money; |
|
11 | 13 | |
|
12 | 14 | |
@@ -17,6 +19,9 | |||
|
17 | 19 | public decimal upkeep; |
|
18 | 20 | |
|
19 | 21 | |
|
22 | public decimal final_money; | |
|
23 | ||
|
24 | ||
|
20 | 25 | //misc |
|
21 | 26 | public int trees; |
|
22 | 27 | |
@@ -183,12 +188,15 | |||
|
183 | 188 | this.applyBudget(newBudget); ; |
|
184 | 189 | } |
|
185 | 190 | |
|
186 | public void applyBudget(Budget budget) | |
|
191 | public void applyBudget(Budget budget) ///hacky | |
|
187 | 192 | { |
|
188 | 193 | |
|
189 | 194 | this.money = budget.money |
|
190 | 195 | - (budget.upkeep) |
|
191 | 196 | + (budget.subsidy); |
|
197 | ||
|
198 | ||
|
199 | budget.final_money = this.money; | |
|
192 | 200 | } |
|
193 | 201 | |
|
194 | 202 | public void update(TimeSpan deltaTime) |
@@ -19,6 +19,22 | |||
|
19 | 19 | |
|
20 | 20 | } |
|
21 | 21 | |
|
22 | public static int Clamp(int val, int min, int max) | |
|
23 | { | |
|
24 | if(val > max) | |
|
25 | { | |
|
26 | return max; | |
|
27 | } | |
|
28 | else if (val < min) | |
|
29 | { | |
|
30 | return min; | |
|
31 | } | |
|
32 | else | |
|
33 | { | |
|
34 | return val; | |
|
35 | } | |
|
36 | } | |
|
37 | ||
|
22 | 38 | protected float Decrement(float value, float delta) |
|
23 | 39 | { |
|
24 | 40 | float magnitude = Math.Abs(value); |
You need to be logged in to leave comments.
Login now