Skip to content

Commit 295d830

Browse files
authored
Merge pull request #16 from hmlendea/fixes
Various fixes
2 parents 7e1d594 + 807003f commit 295d830

File tree

6 files changed

+63
-76
lines changed

6 files changed

+63
-76
lines changed

Gui/GuiElements/GuiHoldingCard.cs

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public void SetHoldingProperties(Holding holding)
3939
HoldingName = holding.Name;
4040
}
4141

42+
public override void Hide()
43+
{
44+
base.Hide();
45+
tooltip.Hide();
46+
}
47+
4248
protected override void DoLoadContent()
4349
{
4450
icon = new GuiImage

Gui/GuiElements/GuiPanel.cs

+7-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.Xna.Framework;
22
using Microsoft.Xna.Framework.Graphics;
3-
43
using NuciXNA.Graphics.Drawing;
54
using NuciXNA.Gui.Controls;
65
using NuciXNA.Input;
@@ -28,9 +27,12 @@ public GuiPanel()
2827
CrystalColour = Colour.Red;
2928
}
3029

31-
/// <summary>
32-
/// Loads the content.
33-
/// </summary>
30+
public virtual void Close()
31+
{
32+
Hide();
33+
Closed?.Invoke(this, new MouseButtonEventArgs(MouseButton.Left, ButtonState.Pressed, InputManager.Instance.MouseLocation));
34+
}
35+
3436
protected override void DoLoadContent()
3537
{
3638
background = new GuiImage
@@ -74,27 +76,16 @@ protected override void DoLoadContent()
7476
SetChildrenProperties();
7577
}
7678

77-
/// <summary>
78-
/// Unloads the content.
79-
/// </summary>
8079
protected override void DoUnloadContent()
8180
{
8281
UnregisterEvents();
8382
}
8483

85-
/// <summary>
86-
/// Update the content.
87-
/// </summary>
88-
/// <param name="gameTime">Game time.</param>
8984
protected override void DoUpdate(GameTime gameTime)
9085
{
9186
SetChildrenProperties();
9287
}
9388

94-
/// <summary>
95-
/// Draw the content on the specified <see cref="SpriteBatch"/>.
96-
/// </summary>
97-
/// <param name="spriteBatch">Sprite batch.</param>
9889
protected override void DoDraw(SpriteBatch spriteBatch)
9990
{
10091

@@ -117,9 +108,6 @@ void SetChildrenProperties()
117108
}
118109

119110
void OnCloseButtonClicked(object sender, MouseButtonEventArgs e)
120-
{
121-
Hide();
122-
Closed?.Invoke(this, e);
123-
}
111+
=> Close();
124112
}
125113
}

Gui/GuiElements/GuiProvincePanel.cs

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ public GuiProvincePanel(
5353
this.holdingManager = holdingManager;
5454
}
5555

56+
public override void Close()
57+
{
58+
base.Close();
59+
60+
ProvinceId = string.Empty;
61+
currentProvinceId = string.Empty;
62+
}
63+
5664
/// <summary>
5765
/// Loads the content.
5866
/// </summary>

Gui/GuiElements/GuiRecruitmentPanel.cs

+37-57
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Linq;
33

44
using Microsoft.Xna.Framework;
5-
using Microsoft.Xna.Framework.Graphics;
65

76
using NuciXNA.Graphics.Drawing;
87
using NuciXNA.Gui.Controls;
@@ -15,13 +14,8 @@
1514

1615
namespace Narivia.Gui.Controls
1716
{
18-
/// <summary>
19-
/// Unit recruitment panel GUI element.
20-
/// </summary>
2117
public class GuiRecruitmentPanel : GuiPanel
2218
{
23-
const int IconSize = 22;
24-
2519
readonly IGameManager gameManager;
2620
readonly IWorldManager worldManager;
2721
readonly IMilitaryManager militaryManager;
@@ -69,9 +63,6 @@ public GuiRecruitmentPanel(
6963
FontName = "ButtonFont";
7064
}
7165

72-
/// <summary>
73-
/// Loads the content.
74-
/// </summary>
7566
protected override void DoLoadContent()
7667
{
7768
base.DoLoadContent();
@@ -121,8 +112,8 @@ protected override void DoLoadContent()
121112
{
122113
Id = $"{Id}_{nameof(healthIcon)}",
123114
ContentFile = "Interface/game_icons",
124-
SourceRectangle = new Rectangle2D(0, 0, IconSize, IconSize),
125-
Size = new Size2D(IconSize, IconSize),
115+
SourceRectangle = new Rectangle2D(0, 0, GameDefines.GuiIconSize, GameDefines.GuiIconSize),
116+
Size = new Size2D(GameDefines.GuiIconSize),
126117
Location = new Point2D(
127118
paper.Location.X + GameDefines.GuiSpacing * 2,
128119
paper.Location.Y + GameDefines.GuiSpacing * 2)
@@ -131,31 +122,31 @@ protected override void DoLoadContent()
131122
{
132123
Id = $"{Id}_{nameof(powerIcon)}",
133124
ContentFile = "Interface/game_icons",
134-
SourceRectangle = new Rectangle2D(IconSize, 0, IconSize, IconSize),
135-
Size = new Size2D(IconSize, IconSize),
125+
SourceRectangle = new Rectangle2D(GameDefines.GuiIconSize, 0, GameDefines.GuiIconSize, GameDefines.GuiIconSize),
126+
Size = new Size2D(GameDefines.GuiIconSize),
136127
Location = new Point2D(
137128
paper.ClientRectangle.Left + GameDefines.GuiSpacing * 2,
138-
paper.ClientRectangle.Bottom - GameDefines.GuiSpacing * 2 - IconSize)
129+
paper.ClientRectangle.Bottom - GameDefines.GuiSpacing * 2 - GameDefines.GuiIconSize)
139130
};
140131
priceIcon = new GuiImage
141132
{
142133
Id = $"{Id}_{nameof(priceIcon)}",
143134
ContentFile = "Interface/game_icons",
144-
SourceRectangle = new Rectangle2D(IconSize * 3, 0, IconSize, IconSize),
145-
Size = new Size2D(IconSize, IconSize),
135+
SourceRectangle = new Rectangle2D(GameDefines.GuiIconSize * 3, 0, GameDefines.GuiIconSize, GameDefines.GuiIconSize),
136+
Size = new Size2D(GameDefines.GuiIconSize),
146137
Location = new Point2D(
147-
paper.ClientRectangle.Right - GameDefines.GuiSpacing * 2 - IconSize,
138+
paper.ClientRectangle.Right - GameDefines.GuiSpacing * 2 - GameDefines.GuiIconSize,
148139
paper.ClientRectangle.Top + GameDefines.GuiSpacing * 2)
149140
};
150141
maintenanceIcon = new GuiImage
151142
{
152143
Id = $"{Id}_{nameof(maintenanceIcon)}",
153144
ContentFile = "Interface/game_icons",
154-
SourceRectangle = new Rectangle2D(IconSize * 3, 0, IconSize, IconSize),
155-
Size = new Size2D(IconSize, IconSize),
156-
Location = new Point2D(
157-
paper.ClientRectangle.Right - GameDefines.GuiSpacing * 2 - IconSize,
158-
paper.ClientRectangle.Bottom - GameDefines.GuiSpacing * 2 - IconSize)
145+
SourceRectangle = new Rectangle2D(GameDefines.GuiIconSize * 3, 0, GameDefines.GuiIconSize, GameDefines.GuiIconSize),
146+
Size = new Size2D(GameDefines.GuiIconSize),
147+
Location = paper.ClientRectangle.BottomRight - new Point2D(
148+
GameDefines.GuiSpacing * 2 + GameDefines.GuiIconSize,
149+
GameDefines.GuiSpacing * 2 + GameDefines.GuiIconSize)
159150
};
160151

161152
healthText = new GuiText
@@ -165,9 +156,7 @@ protected override void DoLoadContent()
165156
Size = new Size2D(
166157
healthIcon.Size.Width * 2,
167158
healthIcon.Size.Height),
168-
Location = new Point2D(
169-
healthIcon.Location.X + healthIcon.Size.Width + GameDefines.GuiSpacing,
170-
healthIcon.Location.Y)
159+
Location = healthIcon.Location + new Point2D(healthIcon.Size.Width + GameDefines.GuiSpacing, 0)
171160
};
172161
powerText = new GuiText
173162
{
@@ -176,9 +165,7 @@ protected override void DoLoadContent()
176165
Size = new Size2D(
177166
powerIcon.Size.Width * 2,
178167
powerIcon.Size.Height),
179-
Location = new Point2D(
180-
powerIcon.Location.X + healthIcon.Size.Width + GameDefines.GuiSpacing,
181-
powerIcon.Location.Y)
168+
Location = powerIcon.Location + new Point2D(healthIcon.Size.Width + GameDefines.GuiSpacing, 0)
182169
};
183170
priceText = new GuiText
184171
{
@@ -187,9 +174,7 @@ protected override void DoLoadContent()
187174
Size = new Size2D(
188175
priceIcon.Size.Width * 2,
189176
priceIcon.Size.Height),
190-
Location = new Point2D(
191-
priceIcon.Location.X - priceIcon.Size.Width * 2 - GameDefines.GuiSpacing,
192-
priceIcon.Location.Y)
177+
Location = priceIcon.Location - new Point2D(priceIcon.Size.Width * 2 + GameDefines.GuiSpacing, 0)
193178
};
194179
maintenanceText = new GuiText
195180
{
@@ -198,13 +183,12 @@ protected override void DoLoadContent()
198183
Size = new Size2D(
199184
maintenanceIcon.Size.Width * 2,
200185
maintenanceIcon.Size.Height),
201-
Location = new Point2D(
202-
maintenanceIcon.Location.X - maintenanceIcon.Size.Width * 2 - GameDefines.GuiSpacing,
203-
maintenanceIcon.Location.Y)
186+
Location = maintenanceIcon.Location - new Point2D(maintenanceIcon.Size.Width * 2 + GameDefines.GuiSpacing, 0)
204187
};
205188
troopsText = new GuiText
206189
{
207190
Id = $"{Id}_{nameof(troopsText)}",
191+
ForegroundColour = Colour.Gold,
208192
Size = new Size2D(unitBackground.Size.Height, 18),
209193
Location = new Point2D(
210194
unitBackground.ClientRectangle.Left,
@@ -258,31 +242,32 @@ protected override void DoLoadContent()
258242
(Size.Width - 128) / 2,
259243
Size.Height - 42 - GameDefines.GuiSpacing)
260244
};
261-
245+
262246
RegisterChildren(unitBackground, unitImage, paper);
263247
RegisterChildren(unitText, troopsText);
264248
RegisterChildren(healthIcon, powerIcon, priceIcon, maintenanceIcon);
265249
RegisterChildren(healthText, powerText, priceText, maintenanceText);
266250
RegisterChildren(nextUnitButton, previousUnitButton, addUnitButton, substractUnitButton, recruitButton);
267-
251+
268252
RegisterEvents();
269253
SetChildrenProperties();
270254
}
271255

272-
/// <summary>
273-
/// Unloads the content.
274-
/// </summary>
256+
public override void Close()
257+
{
258+
base.Close();
259+
260+
currentUnitIndex = 0;
261+
troopsAmount = 1;
262+
}
263+
275264
protected override void DoUnloadContent()
276265
{
277266
base.DoUnloadContent();
278267

279268
UnregisterEvents();
280269
}
281270

282-
/// <summary>
283-
/// Update the content.
284-
/// </summary>
285-
/// <param name="gameTime">Game time.</param>
286271
protected override void DoUpdate(GameTime gameTime)
287272
{
288273
base.DoUpdate(gameTime);
@@ -310,15 +295,17 @@ void UnregisterEvents()
310295

311296
void SetChildrenProperties()
312297
{
313-
unitText.Text = units[currentUnitIndex].Name;
298+
Unit unit = units[currentUnitIndex];
299+
300+
unitText.Text = unit.Name;
314301
troopsText.Text = $"x{troopsAmount}";
315-
healthText.Text = units[currentUnitIndex].Health.ToString();
316-
powerText.Text = units[currentUnitIndex].Power.ToString();
317-
priceText.Text = units[currentUnitIndex].Price.ToString();
318-
maintenanceText.Text = units[currentUnitIndex].Maintenance.ToString();
319-
recruitButton.Text = $"Recruit ({units[currentUnitIndex].Price * troopsAmount}g)";
302+
healthText.Text = unit.Health.ToString();
303+
powerText.Text = unit.Power.ToString();
304+
priceText.Text = unit.Price.ToString();
305+
maintenanceText.Text = unit.Maintenance.ToString();
306+
recruitButton.Text = $"Recruit ({unit.Price * troopsAmount}g)";
320307

321-
unitImage.ContentFile = $"World/Assets/{world.AssetsPack}/units/{units[currentUnitIndex].Id}";
308+
unitImage.ContentFile = $"World/Assets/{world.AssetsPack}/units/{unit.Id}";
322309
}
323310

324311
void SelectUnit(int index)
@@ -353,13 +340,6 @@ void AddTroops(int delta)
353340
}
354341
}
355342

356-
void OnCancelButtonClick(object sender, MouseButtonEventArgs e)
357-
{
358-
Hide();
359-
SelectUnit(0);
360-
troopsAmount = 0;
361-
}
362-
363343
void OnRecruitButtonClick(object sender, MouseButtonEventArgs e)
364344
{
365345
militaryManager.RecruitUnits(gameManager.PlayerFactionId, units[currentUnitIndex].Id, troopsAmount);

Gui/Screens/GameplayScreen.cs

+3
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ void NextTurn()
270270
{
271271
notificationBar.Clear();
272272

273+
recruitmentPanel.Close();
274+
provincePanel.Close();
275+
273276
GameManager.PassTurn();
274277

275278
Dictionary<string, int> troopsNew = new Dictionary<string, int>();

Settings/GameDefines.cs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ public static class GameDefines
44
{
55
public const int MapTileSize = 32;
66

7+
public const int GuiIconSize = 22;
8+
79
public const int GuiTileSize = 32;
810

911
public const int GuiSpacing = 6;

0 commit comments

Comments
 (0)