2
2
using System . Linq ;
3
3
4
4
using Microsoft . Xna . Framework ;
5
- using Microsoft . Xna . Framework . Graphics ;
6
5
7
6
using NuciXNA . Graphics . Drawing ;
8
7
using NuciXNA . Gui . Controls ;
15
14
16
15
namespace Narivia . Gui . Controls
17
16
{
18
- /// <summary>
19
- /// Unit recruitment panel GUI element.
20
- /// </summary>
21
17
public class GuiRecruitmentPanel : GuiPanel
22
18
{
23
- const int IconSize = 22 ;
24
-
25
19
readonly IGameManager gameManager ;
26
20
readonly IWorldManager worldManager ;
27
21
readonly IMilitaryManager militaryManager ;
@@ -69,9 +63,6 @@ public GuiRecruitmentPanel(
69
63
FontName = "ButtonFont" ;
70
64
}
71
65
72
- /// <summary>
73
- /// Loads the content.
74
- /// </summary>
75
66
protected override void DoLoadContent ( )
76
67
{
77
68
base . DoLoadContent ( ) ;
@@ -121,8 +112,8 @@ protected override void DoLoadContent()
121
112
{
122
113
Id = $ "{ Id } _{ nameof ( healthIcon ) } ",
123
114
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 ) ,
126
117
Location = new Point2D (
127
118
paper . Location . X + GameDefines . GuiSpacing * 2 ,
128
119
paper . Location . Y + GameDefines . GuiSpacing * 2 )
@@ -131,31 +122,31 @@ protected override void DoLoadContent()
131
122
{
132
123
Id = $ "{ Id } _{ nameof ( powerIcon ) } ",
133
124
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 ) ,
136
127
Location = new Point2D (
137
128
paper . ClientRectangle . Left + GameDefines . GuiSpacing * 2 ,
138
- paper . ClientRectangle . Bottom - GameDefines . GuiSpacing * 2 - IconSize )
129
+ paper . ClientRectangle . Bottom - GameDefines . GuiSpacing * 2 - GameDefines . GuiIconSize )
139
130
} ;
140
131
priceIcon = new GuiImage
141
132
{
142
133
Id = $ "{ Id } _{ nameof ( priceIcon ) } ",
143
134
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 ) ,
146
137
Location = new Point2D (
147
- paper . ClientRectangle . Right - GameDefines . GuiSpacing * 2 - IconSize ,
138
+ paper . ClientRectangle . Right - GameDefines . GuiSpacing * 2 - GameDefines . GuiIconSize ,
148
139
paper . ClientRectangle . Top + GameDefines . GuiSpacing * 2 )
149
140
} ;
150
141
maintenanceIcon = new GuiImage
151
142
{
152
143
Id = $ "{ Id } _{ nameof ( maintenanceIcon ) } ",
153
144
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 )
159
150
} ;
160
151
161
152
healthText = new GuiText
@@ -165,9 +156,7 @@ protected override void DoLoadContent()
165
156
Size = new Size2D (
166
157
healthIcon . Size . Width * 2 ,
167
158
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 )
171
160
} ;
172
161
powerText = new GuiText
173
162
{
@@ -176,9 +165,7 @@ protected override void DoLoadContent()
176
165
Size = new Size2D (
177
166
powerIcon . Size . Width * 2 ,
178
167
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 )
182
169
} ;
183
170
priceText = new GuiText
184
171
{
@@ -187,9 +174,7 @@ protected override void DoLoadContent()
187
174
Size = new Size2D (
188
175
priceIcon . Size . Width * 2 ,
189
176
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 )
193
178
} ;
194
179
maintenanceText = new GuiText
195
180
{
@@ -198,13 +183,12 @@ protected override void DoLoadContent()
198
183
Size = new Size2D (
199
184
maintenanceIcon . Size . Width * 2 ,
200
185
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 )
204
187
} ;
205
188
troopsText = new GuiText
206
189
{
207
190
Id = $ "{ Id } _{ nameof ( troopsText ) } ",
191
+ ForegroundColour = Colour . Gold ,
208
192
Size = new Size2D ( unitBackground . Size . Height , 18 ) ,
209
193
Location = new Point2D (
210
194
unitBackground . ClientRectangle . Left ,
@@ -258,31 +242,32 @@ protected override void DoLoadContent()
258
242
( Size . Width - 128 ) / 2 ,
259
243
Size . Height - 42 - GameDefines . GuiSpacing )
260
244
} ;
261
-
245
+
262
246
RegisterChildren ( unitBackground , unitImage , paper ) ;
263
247
RegisterChildren ( unitText , troopsText ) ;
264
248
RegisterChildren ( healthIcon , powerIcon , priceIcon , maintenanceIcon ) ;
265
249
RegisterChildren ( healthText , powerText , priceText , maintenanceText ) ;
266
250
RegisterChildren ( nextUnitButton , previousUnitButton , addUnitButton , substractUnitButton , recruitButton ) ;
267
-
251
+
268
252
RegisterEvents ( ) ;
269
253
SetChildrenProperties ( ) ;
270
254
}
271
255
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
+
275
264
protected override void DoUnloadContent ( )
276
265
{
277
266
base . DoUnloadContent ( ) ;
278
267
279
268
UnregisterEvents ( ) ;
280
269
}
281
270
282
- /// <summary>
283
- /// Update the content.
284
- /// </summary>
285
- /// <param name="gameTime">Game time.</param>
286
271
protected override void DoUpdate ( GameTime gameTime )
287
272
{
288
273
base . DoUpdate ( gameTime ) ;
@@ -310,15 +295,17 @@ void UnregisterEvents()
310
295
311
296
void SetChildrenProperties ( )
312
297
{
313
- unitText . Text = units [ currentUnitIndex ] . Name ;
298
+ Unit unit = units [ currentUnitIndex ] ;
299
+
300
+ unitText . Text = unit . Name ;
314
301
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)";
320
307
321
- unitImage . ContentFile = $ "World/Assets/{ world . AssetsPack } /units/{ units [ currentUnitIndex ] . Id } ";
308
+ unitImage . ContentFile = $ "World/Assets/{ world . AssetsPack } /units/{ unit . Id } ";
322
309
}
323
310
324
311
void SelectUnit ( int index )
@@ -353,13 +340,6 @@ void AddTroops(int delta)
353
340
}
354
341
}
355
342
356
- void OnCancelButtonClick ( object sender , MouseButtonEventArgs e )
357
- {
358
- Hide ( ) ;
359
- SelectUnit ( 0 ) ;
360
- troopsAmount = 0 ;
361
- }
362
-
363
343
void OnRecruitButtonClick ( object sender , MouseButtonEventArgs e )
364
344
{
365
345
militaryManager . RecruitUnits ( gameManager . PlayerFactionId , units [ currentUnitIndex ] . Id , troopsAmount ) ;
0 commit comments