Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmUnit.cs @ 235:5b8f0a6bf0b2
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
* Add missing file to VCS
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 03 Dec 2011 15:03:12 +0000 |
parents | 72beddaffb71 |
children |
rev | line source |
---|---|
193 | 1 // This file (FrmUnit.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2007, 2008, 2009 IBBoard. |
2 // | |
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. | |
4 | |
5 using System; | |
6 using System.Drawing; | |
7 using System.Data; | |
8 using System.Collections.Generic; | |
9 using System.ComponentModel; | |
10 using System.Windows.Forms; | |
11 using IBBoard.Commands; | |
12 using IBBoard.Lang; | |
13 using IBBoard.Windows.Forms; | |
14 using IBBoard.Windows.Forms.I18N; | |
15 using IBBoard.WarFoundry.API; | |
16 using IBBoard.WarFoundry.API.Commands; | |
17 using IBBoard.WarFoundry.API.Objects; | |
18 using IBBoard.WarFoundry.GUI.WinForms.UI; | |
19 using IBBoard.WarFoundry.GUI.WinForms.Util; | |
20 using log4net; | |
21 | |
22 namespace IBBoard.WarFoundry.GUI.WinForms | |
23 { | |
24 /// <summary> | |
25 /// Summary description for FrmUnit. | |
26 /// </summary> | |
27 public class FrmUnit : IBBoard.Windows.Forms.IBBForm | |
28 { | |
29 private static readonly ILog log = LogManager.GetLogger(typeof(FrmUnit)); | |
30 private static readonly int NAME_COL_WIDTH_MULTIPLIER = 3; | |
31 private Unit unit; | |
32 private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>(); | |
33 private Dictionary<string, DataGridView> DataGridViews = new Dictionary<string, DataGridView>(); | |
34 private CommandStack commandStack; | |
35 private System.Windows.Forms.TextBox tbUnitName; | |
36 private System.Windows.Forms.NumericUpDown unitSize; | |
37 private IBBLabel lblUnitSize; | |
38 private IBBButton bttnAddWeapon; | |
39 private IBBButton bttnRemoveWeapon; | |
40 private IBBLabel lblEquip; | |
41 private System.Windows.Forms.ListBox equipmentList; | |
42 private IBBButton bttnReplaceWeapon; | |
43 private IBBButton bttnEditWeapon; | |
44 private Label lblPoints; | |
45 private IBBLabel lblNotes; | |
46 private TextBox notes; | |
47 private ListBox abilitiesList; | |
48 private IBBLabel lblAbilities; | |
190 | 49 private FlowLayoutPanel statsPanel; |
50 public GameSystem CurrentGameSystem | |
51 { | |
52 get { return WarFoundryCore.CurrentGameSystem; } | |
53 set { WarFoundryCore.CurrentGameSystem = value; } | |
193 | 54 } |
55 | |
56 /// <summary> | |
57 /// Required designer variable. | |
58 /// </summary> | |
59 private System.ComponentModel.Container components = null; | |
60 | |
61 public FrmUnit(Unit toDisplay, CommandStack cmdStack) | |
62 { | |
63 unit = toDisplay; | |
64 commandStack = cmdStack; | |
65 // | |
66 // Required for Windows Form Designer support | |
67 // | |
68 InitializeComponent(); | |
69 TranslateForm(); | |
70 Translation.TranslationChanged += new MethodInvoker(TranslateForm); | |
71 unit.NameChanged += new StringValChangedDelegate(unit_NameChanged); | |
72 unit.UnitSizeChanged += new IntValChangedDelegate(unit_UnitSizeChanged); | |
73 unit.UnitEquipmentAmountChanged += new DoubleValChangedDelegate(unit_UnitEquipmentAmountChanged); | |
74 unit.PointsValueChanged += new DoubleValChangedDelegate(unit_PointsValueChanged); | |
75 | |
76 unitSize.Value = unit.Size; | |
77 unitSize.Maximum = (unit.UnitType.MaxSize == WarFoundryCore.INFINITY ? int.MaxValue : unit.UnitType.MaxSize); | |
78 unitSize.Minimum = unit.UnitType.MinSize; | |
79 unitSize.Enabled = (unitSize.Maximum != unitSize.Minimum); | |
80 | |
81 notes.Text = unit.UnitType.Notes; | |
82 abilitiesList.DataSource = new List<Ability>(unit.UnitType.GetRequiredAbilities()); | |
83 abilitiesList.DisplayMember = "Name"; | |
84 SetPointsValueText(); | |
85 SetStats(); | |
86 SetWeapons(); | |
87 } | |
88 | |
89 private void TranslateForm() | |
90 { | |
91 ControlTranslator.TranslateControl(this); | |
92 SetUnitName(); | |
93 RefreshUnitEquipment(); | |
94 } | |
95 | |
96 private void SetUnitName() | |
97 { | |
98 tbUnitName.Text = unit.Name; | |
99 Text = Translation.GetTranslation("FrmUnit", "{0} ({1})", unit.Name, unit.UnitType.Name); | |
100 } | |
101 | |
102 void unit_PointsValueChanged(WarFoundryObject obj, double oldValue, double newValue) | |
103 { | |
104 SetPointsValueText(); | |
105 } | |
106 | |
107 private void SetPointsValueText() | |
108 { | |
109 lblPoints.Text = Translation.GetTranslation("FrmUnitlblPoints", "(" + unit.Points + " pts)", unit.Points, CurrentGameSystem.GetPointsAbbrev(unit.Points)); | |
110 } | |
111 | |
112 private void SetStats() | |
113 { | |
114 Stat[][] stats = unit.UnitStatsArraysWithName; | |
115 string[] statsIDs = unit.UnitStatsArrayIDs; | |
116 int statsCount = stats.Length; | |
117 log.DebugFormat("Unit {0} has {1} stats arrays", unit.UnitType.Name, statsCount); | |
118 | |
119 for (int i = 0; i < statsCount; i++) | |
120 { | |
121 DataGridView statsGrid = GetDataGridView(statsIDs[i]); | |
122 DataTable dt = (DataTable)statsGrid.DataSource; | |
123 DataRow dr = dt.NewRow(); | |
124 dr.ItemArray = stats[i]; | |
125 log.DebugFormat("Add row to data table for {0}", statsIDs[i]); | |
126 dt.Rows.Add(dr); | |
127 statsGrid.ClearSelection(); | |
128 } | |
129 } | |
130 | |
131 private DataGridView GetDataGridView(string statsID) | |
132 { | |
133 DataGridView grid; | |
134 | |
135 if (DataGridViews.ContainsKey(statsID)) | |
136 { | |
137 grid = DictionaryUtils.GetValue(DataGridViews, statsID); | |
138 } | |
139 else | |
140 { | |
141 grid = CreateDataGridView(statsID); | |
142 DataGridViews[statsID] = grid; | |
143 } | |
144 | |
145 return grid; | |
146 } | |
147 | |
148 private DataGridView CreateDataGridView(string statsID) | |
149 { | |
150 log.DebugFormat("Create DataGridView for stats ID {0}", statsID); | |
151 SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID); | |
152 StatSlot[] sysStatSlots = sysStats.StatSlots; | |
153 int statsCount = sysStatSlots.Length; | |
154 int statsWithNameCount = statsCount + 1; | |
155 StatSlot[] statsWithName = new StatSlot[statsWithNameCount]; | |
156 statsWithName[0] = new StatSlot("Name"); | |
157 sysStatSlots.CopyTo(statsWithName, 1); | |
158 DataTable dt = new DataTable(); | |
159 DataGridView statsGrid = CreateDataGridView(); | |
160 statsGrid.DataSource = dt; | |
161 int columnWidth = statsGrid.Width / (statsCount + NAME_COL_WIDTH_MULTIPLIER); | |
162 | |
163 for (int i = 0; i < statsWithNameCount; i++) | |
164 { | |
165 StatSlot stat = statsWithName[i]; | |
166 string slotName = stat.Name; | |
167 statsGrid.Columns.Add(CreateStatColumn(slotName, columnWidth)); | |
168 dt.Columns.Add(CreateDataColumn(slotName)); | |
169 } | |
170 | |
171 int otherStatsWidth = statsCount * columnWidth; | |
172 SetNameColumnWidth(statsGrid, otherStatsWidth); | |
173 | |
174 return statsGrid; | |
175 } | |
176 | |
177 private static DataGridViewColumn CreateStatColumn(string slotName, int columnWidth) | |
178 { | |
179 DataGridViewColumn col = new DataGridViewTextBoxColumn(); | |
180 col.Width = columnWidth; | |
181 col.Name = slotName; | |
182 col.HeaderText = slotName; | |
183 col.DataPropertyName = slotName; | |
184 col.SortMode = DataGridViewColumnSortMode.NotSortable; | |
185 col.CellTemplate = new StatsDataGridViewCell(); | |
186 col.HeaderCell.Style.WrapMode = DataGridViewTriState.False; | |
187 return col; | |
188 } | |
189 | |
190 private static void SetNameColumnWidth(DataGridView statsGrid, int otherStatsWidth) | |
191 { | |
192 | |
193 DataGridViewColumn nameColumn = statsGrid.Columns[0]; | |
194 nameColumn.HeaderText = Translation.GetTranslation("StatLineName", "name"); | |
195 nameColumn.Width = statsGrid.Width - otherStatsWidth; | |
196 } | |
197 | |
198 private static DataColumn CreateDataColumn(string slotName) | |
199 { | |
200 log.DebugFormat("Create column {0}", slotName); | |
201 DataColumn tempCol = new DataColumn(slotName, typeof(Stat)); | |
202 return tempCol; | |
203 } | |
204 | |
205 public DataGridView CreateDataGridView() | |
206 { | |
207 log.Debug("Create DataGridView widget"); | |
208 DataGridView statsGrid = new DataGridView(); | |
209 statsGrid.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | |
210 | System.Windows.Forms.AnchorStyles.Right))); | |
211 statsGrid.CausesValidation = false; | |
212 statsGrid.ReadOnly = true; | |
213 statsGrid.RowHeadersVisible = false; | |
214 statsGrid.Size = new System.Drawing.Size(600, 88); | |
215 statsGrid.TabStop = false; | |
216 statsGrid.AllowUserToAddRows = false; | |
217 statsGrid.ScrollBars = ScrollBars.None; | |
218 statsGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; | |
219 statsGrid.BorderStyle = BorderStyle.None; | |
220 statsGrid.BackgroundColor = SystemColors.Control; | |
221 statsGrid.RowsAdded += new DataGridViewRowsAddedEventHandler(statsGrid_RowsAdded); | |
222 statsPanel.Controls.Add(statsGrid); | |
223 statsGrid.Width = statsPanel.Width - (int)Math.Round(SystemInformation.VerticalScrollBarWidth * 1.4); | |
224 return statsGrid; | |
225 } | |
226 | |
227 private void statsGrid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) | |
228 { | |
229 if (sender is DataGridView) | |
230 { | |
231 SetGridHeight((DataGridView)sender); | |
232 } | |
233 } | |
234 | |
235 private static void SetGridHeight(DataGridView statsGrid) | |
236 { | |
237 DataGridViewRowCollection rows = statsGrid.Rows; | |
238 statsGrid.Height = statsGrid.Columns[0].HeaderCell.Size.Height + (rows.Count * rows[0].Height); | |
239 log.DebugFormat("Set height to {0} for grid of {1} rows", statsGrid.Height, rows.Count); | |
240 } | |
241 | |
242 private void SetWeapons() | |
243 { | |
244 foreach (UnitEquipmentItem item in unit.GetEquipment()) | |
245 { | |
246 equipmentList.Items.Add(GetEquipmentChoice(item)); | |
247 } | |
248 } | |
249 | |
250 private UnitEquipmentChoice GetEquipmentChoice(UnitEquipmentItem item) | |
251 { | |
252 UnitEquipmentChoice choice = null; | |
253 equipmentChoices.TryGetValue(item, out choice); | |
254 | |
255 if (choice == null) | |
256 { | |
257 choice = new UnitEquipmentChoice(Unit, item); | |
258 equipmentChoices[item] = choice; | |
259 } | |
260 | |
261 return choice; | |
262 } | |
263 | |
264 /// <summary> | |
265 /// Clean up any resources being used. | |
266 /// </summary> | |
267 protected override void Dispose(bool disposing) | |
268 { | |
269 //remove our leave events so that disposing doesn't trigger them | |
270 tbUnitName.Leave -= new System.EventHandler(this.tbUnitName_Leave); | |
271 unitSize.Leave -= new System.EventHandler(this.unitSize_Leave); | |
272 | |
273 if (disposing) | |
274 { | |
275 if (components != null) | |
276 { | |
277 components.Dispose(); | |
278 } | |
279 } | |
280 base.Dispose(disposing); | |
281 } | |
282 | |
283 #region Windows Form Designer generated code | |
284 /// <summary> | |
285 /// Required method for Designer support - do not modify | |
286 /// the contents of this method with the code editor. | |
287 /// </summary> | |
288 private void InitializeComponent() | |
289 { | |
290 this.tbUnitName = new System.Windows.Forms.TextBox(); | |
291 this.unitSize = new System.Windows.Forms.NumericUpDown(); | |
292 this.lblUnitSize = new IBBoard.Windows.Forms.IBBLabel(); | |
293 this.lblEquip = new IBBoard.Windows.Forms.IBBLabel(); | |
294 this.bttnAddWeapon = new IBBoard.Windows.Forms.IBBButton(); | |
295 this.bttnRemoveWeapon = new IBBoard.Windows.Forms.IBBButton(); | |
296 this.equipmentList = new System.Windows.Forms.ListBox(); | |
297 this.bttnReplaceWeapon = new IBBoard.Windows.Forms.IBBButton(); | |
298 this.bttnEditWeapon = new IBBoard.Windows.Forms.IBBButton(); | |
299 this.lblPoints = new System.Windows.Forms.Label(); | |
300 this.lblNotes = new IBBoard.Windows.Forms.IBBLabel(); | |
301 this.notes = new System.Windows.Forms.TextBox(); | |
302 this.abilitiesList = new System.Windows.Forms.ListBox(); | |
303 this.lblAbilities = new IBBoard.Windows.Forms.IBBLabel(); | |
304 this.statsPanel = new System.Windows.Forms.FlowLayoutPanel(); | |
305 ((System.ComponentModel.ISupportInitialize)(this.unitSize)).BeginInit(); | |
306 this.SuspendLayout(); | |
307 // | |
308 // tbUnitName | |
309 // | |
310 this.tbUnitName.Location = new System.Drawing.Point(8, 8); | |
311 this.tbUnitName.Name = "tbUnitName"; | |
312 this.tbUnitName.Size = new System.Drawing.Size(344, 20); | |
313 this.tbUnitName.TabIndex = 1; | |
314 this.tbUnitName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbUnitName_KeyDown); | |
315 this.tbUnitName.Leave += new System.EventHandler(this.tbUnitName_Leave); | |
316 // | |
317 // unitSize | |
318 // | |
319 this.unitSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); | |
320 this.unitSize.Location = new System.Drawing.Point(528, 8); | |
321 this.unitSize.Name = "unitSize"; | |
322 this.unitSize.Size = new System.Drawing.Size(80, 20); | |
323 this.unitSize.TabIndex = 1; | |
324 this.unitSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; | |
325 this.unitSize.Value = new decimal(new int[] { | |
326 1, | |
327 0, | |
328 0, | |
329 0}); | |
330 this.unitSize.Leave += new System.EventHandler(this.unitSize_Leave); | |
331 this.unitSize.KeyDown += new System.Windows.Forms.KeyEventHandler(this.unitSize_KeyDown); | |
332 // | |
333 // lblUnitSize | |
334 // | |
335 this.lblUnitSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); | |
336 this.lblUnitSize.Location = new System.Drawing.Point(426, 8); | |
337 this.lblUnitSize.Name = "lblUnitSize"; | |
338 this.lblUnitSize.Size = new System.Drawing.Size(98, 23); | |
339 this.lblUnitSize.TabIndex = 0; | |
340 this.lblUnitSize.Text = "unit size"; | |
341 this.lblUnitSize.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
342 // | |
343 // lblEquip | |
344 // | |
345 this.lblEquip.Location = new System.Drawing.Point(15, 126); | |
346 this.lblEquip.Name = "lblEquip"; | |
347 this.lblEquip.Size = new System.Drawing.Size(81, 108); | |
348 this.lblEquip.TabIndex = 3; | |
349 this.lblEquip.Text = "equipment"; | |
350 this.lblEquip.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
351 // | |
352 // bttnAddWeapon | |
353 // | |
354 this.bttnAddWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); | |
355 this.bttnAddWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
356 this.bttnAddWeapon.Location = new System.Drawing.Point(516, 126); | |
357 this.bttnAddWeapon.Name = "bttnAddWeapon"; | |
358 this.bttnAddWeapon.Size = new System.Drawing.Size(88, 22); | |
359 this.bttnAddWeapon.TabIndex = 4; | |
360 this.bttnAddWeapon.Text = "add"; | |
361 this.bttnAddWeapon.Click += new System.EventHandler(this.bttnAddWeapon_Click); | |
362 // | |
363 // bttnRemoveWeapon | |
364 // | |
365 this.bttnRemoveWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); | |
366 this.bttnRemoveWeapon.Enabled = false; | |
367 this.bttnRemoveWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
368 this.bttnRemoveWeapon.Location = new System.Drawing.Point(516, 210); | |
369 this.bttnRemoveWeapon.Name = "bttnRemoveWeapon"; | |
370 this.bttnRemoveWeapon.Size = new System.Drawing.Size(88, 22); | |
371 this.bttnRemoveWeapon.TabIndex = 5; | |
372 this.bttnRemoveWeapon.Text = "remove"; | |
373 this.bttnRemoveWeapon.Click += new System.EventHandler(this.bttnRemoveWeapon_Click); | |
374 // | |
375 // equipmentList | |
376 // | |
377 this.equipmentList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | |
378 | System.Windows.Forms.AnchorStyles.Right))); | |
379 this.equipmentList.Location = new System.Drawing.Point(102, 126); | |
380 this.equipmentList.Name = "equipmentList"; | |
381 this.equipmentList.Size = new System.Drawing.Size(408, 108); | |
382 this.equipmentList.TabIndex = 6; | |
383 this.equipmentList.SelectedIndexChanged += new System.EventHandler(this.equipmentList_SelectedIndexChanged); | |
384 this.equipmentList.DoubleClick += new System.EventHandler(this.equipmentList_DoubleClick); | |
385 // | |
386 // bttnReplaceWeapon | |
387 // | |
388 this.bttnReplaceWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); | |
389 this.bttnReplaceWeapon.Enabled = false; | |
390 this.bttnReplaceWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
391 this.bttnReplaceWeapon.Location = new System.Drawing.Point(516, 182); | |
392 this.bttnReplaceWeapon.Name = "bttnReplaceWeapon"; | |
393 this.bttnReplaceWeapon.Size = new System.Drawing.Size(88, 22); | |
394 this.bttnReplaceWeapon.TabIndex = 10; | |
395 this.bttnReplaceWeapon.Text = "replace"; | |
396 this.bttnReplaceWeapon.Click += new System.EventHandler(this.bttnReplaceWeapon_Click); | |
397 // | |
398 // bttnEditWeapon | |
399 // | |
400 this.bttnEditWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); | |
401 this.bttnEditWeapon.Enabled = false; | |
402 this.bttnEditWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
403 this.bttnEditWeapon.Location = new System.Drawing.Point(516, 154); | |
404 this.bttnEditWeapon.Name = "bttnEditWeapon"; | |
405 this.bttnEditWeapon.Size = new System.Drawing.Size(88, 22); | |
406 this.bttnEditWeapon.TabIndex = 11; | |
407 this.bttnEditWeapon.Text = "edit"; | |
408 this.bttnEditWeapon.Click += new System.EventHandler(this.bttnEditWeapon_Click); | |
409 // | |
410 // lblPoints | |
411 // | |
412 this.lblPoints.Location = new System.Drawing.Point(358, 8); | |
413 this.lblPoints.Name = "lblPoints"; | |
414 this.lblPoints.Size = new System.Drawing.Size(77, 21); | |
415 this.lblPoints.TabIndex = 12; | |
416 this.lblPoints.Text = "(points)"; | |
417 // | |
418 // lblNotes | |
419 // | |
420 this.lblNotes.Location = new System.Drawing.Point(13, 317); | |
421 this.lblNotes.Name = "lblNotes"; | |
422 this.lblNotes.Size = new System.Drawing.Size(84, 62); | |
423 this.lblNotes.TabIndex = 13; | |
424 this.lblNotes.Text = "notes"; | |
425 this.lblNotes.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
426 // | |
427 // notes | |
428 // | |
429 this.notes.Location = new System.Drawing.Point(102, 317); | |
430 this.notes.Multiline = true; | |
431 this.notes.Name = "notes"; | |
432 this.notes.ReadOnly = true; | |
433 this.notes.Size = new System.Drawing.Size(408, 62); | |
434 this.notes.TabIndex = 14; | |
435 // | |
436 // abilitiesList | |
437 // | |
438 this.abilitiesList.FormattingEnabled = true; | |
439 this.abilitiesList.Location = new System.Drawing.Point(102, 240); | |
440 this.abilitiesList.Name = "abilitiesList"; | |
441 this.abilitiesList.Size = new System.Drawing.Size(408, 69); | |
442 this.abilitiesList.TabIndex = 15; | |
443 // | |
444 // lblAbilities | |
445 // | |
446 this.lblAbilities.Location = new System.Drawing.Point(13, 240); | |
447 this.lblAbilities.Name = "lblAbilities"; | |
448 this.lblAbilities.Size = new System.Drawing.Size(84, 62); | |
449 this.lblAbilities.TabIndex = 16; | |
450 this.lblAbilities.Text = "abilities"; | |
451 this.lblAbilities.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
452 // | |
453 // statsPanel | |
454 // | |
455 this.statsPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | |
456 | System.Windows.Forms.AnchorStyles.Right))); | |
457 this.statsPanel.AutoScroll = true; | |
458 this.statsPanel.Location = new System.Drawing.Point(8, 35); | |
459 this.statsPanel.Name = "statsPanel"; | |
460 this.statsPanel.Size = new System.Drawing.Size(600, 85); | |
461 this.statsPanel.TabIndex = 17; | |
462 // | |
463 // FrmUnit | |
464 // | |
465 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
466 this.ClientSize = new System.Drawing.Size(616, 391); | |
467 this.Controls.Add(this.statsPanel); | |
468 this.Controls.Add(this.lblAbilities); | |
469 this.Controls.Add(this.abilitiesList); | |
470 this.Controls.Add(this.notes); | |
471 this.Controls.Add(this.lblNotes); | |
472 this.Controls.Add(this.lblPoints); | |
473 this.Controls.Add(this.bttnEditWeapon); | |
474 this.Controls.Add(this.bttnReplaceWeapon); | |
475 this.Controls.Add(this.equipmentList); | |
476 this.Controls.Add(this.bttnRemoveWeapon); | |
477 this.Controls.Add(this.bttnAddWeapon); | |
478 this.Controls.Add(this.lblEquip); | |
479 this.Controls.Add(this.lblUnitSize); | |
480 this.Controls.Add(this.unitSize); | |
481 this.Controls.Add(this.tbUnitName); | |
482 this.Name = "FrmUnit"; | |
483 this.ShowIcon = false; | |
484 this.ShowInTaskbar = false; | |
485 this.Text = "FrmUnit"; | |
486 this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmUnit_FormClosing); | |
487 ((System.ComponentModel.ISupportInitialize)(this.unitSize)).EndInit(); | |
488 this.ResumeLayout(false); | |
489 this.PerformLayout(); | |
490 | |
491 } | |
492 #endregion | |
493 | |
494 public Unit Unit | |
495 { | |
496 get { return unit; } | |
497 } | |
498 | |
499 private void tbUnitName_Leave(object sender, System.EventArgs e) | |
500 { | |
501 UpdateUnitName(); | |
502 } | |
503 | |
504 private void tbUnitName_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) | |
505 { | |
506 if (e.KeyCode == Keys.Enter) | |
507 { | |
508 UpdateUnitName(); | |
509 } | |
510 } | |
511 | |
512 private void UpdateUnitName() | |
513 { | |
514 if (unit.Name != tbUnitName.Text) | |
515 { | |
516 commandStack.Execute(new SetNameCommand(unit, tbUnitName.Text)); | |
517 } | |
518 } | |
519 | |
520 private void unitSize_Leave(object sender, System.EventArgs e) | |
521 { | |
522 UpdateUnitSize(); | |
523 } | |
524 | |
525 private void unitSize_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) | |
526 { | |
527 if (e.KeyCode == Keys.Enter) | |
528 { | |
529 UpdateUnitSize(); | |
530 } | |
531 } | |
532 | |
533 private void UpdateUnitSize() | |
534 { | |
535 if (unit.Size != unitSize.Value) | |
536 { | |
537 commandStack.Execute(new SetUnitSizeCommand(unit, (int) unitSize.Value)); | |
538 } | |
539 } | |
540 | |
541 private void unit_NameChanged(WarFoundryObject obj, string oldValue, string newValue) | |
542 { | |
543 if (obj is Unit && obj.Equals(unit)) | |
544 { | |
545 SetUnitName(); | |
546 } | |
547 } | |
548 | |
549 private void unit_UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue) | |
550 { | |
551 if (obj is Unit && obj.Equals(unit)) | |
552 { | |
553 unitSize.Value = newValue; | |
554 } | |
555 } | |
556 | |
557 private void RefreshUnitEquipment() | |
558 { | |
559 foreach (UnitEquipmentChoice choice in equipmentChoices.Values) | |
560 { | |
561 SetEquipmentListValue(choice); | |
562 } | |
563 } | |
564 | |
565 private void equipmentList_SelectedIndexChanged(object sender, System.EventArgs e) | |
566 { | |
567 SetButtonsEnabledState(); | |
568 } | |
569 | |
570 private void SetButtonsEnabledState() | |
571 { | |
572 | |
573 UnitEquipmentItem equipItem = GetSelectedUnitEquipmentItem(); | |
574 bttnReplaceWeapon.Enabled = (equipItem != null && equipItem.HasAlternatives()); | |
575 bttnEditWeapon.Enabled = (equipItem != null); | |
576 bttnRemoveWeapon.Enabled = (equipItem != null && !equipItem.IsRequired); | |
577 } | |
578 | |
579 private void unit_UnitEquipmentAmountChanged(WarFoundryObject obj, double oldValue, double newValue) | |
580 { | |
581 if (obj is UnitEquipmentItem) | |
582 { | |
583 UnitEquipmentItem equip = (UnitEquipmentItem) obj; | |
584 UnitEquipmentChoice equipChoice = GetEquipmentChoice(equip); | |
585 | |
586 if (newValue == 0) | |
587 { | |
588 equipmentList.Items.Remove(equipChoice); | |
589 } | |
590 else | |
591 { | |
592 SetEquipmentListValue(equipChoice); | |
593 } | |
594 } | |
595 } | |
596 | |
597 private void SetEquipmentListValue(UnitEquipmentChoice equipChoice) | |
598 { | |
599 int idx = equipmentList.Items.IndexOf(equipChoice); | |
600 | |
601 if (idx > -1) | |
602 { | |
603 equipmentList.Items[idx] = equipChoice; | |
604 } | |
605 else | |
606 { | |
607 equipmentList.Items.Add(equipChoice); | |
608 } | |
609 } | |
610 | |
611 private void EditWeapon() | |
612 { | |
613 UnitEquipmentItem item = GetSelectedUnitEquipmentItem(); | |
614 | |
615 if (item != null) | |
616 { | |
617 FrmEditUnitEquipment editEquip = new FrmEditUnitEquipment(Unit, item, commandStack); | |
618 editEquip.ShowDialog(this); | |
619 } | |
620 } | |
621 | |
622 private UnitEquipmentItem GetSelectedUnitEquipmentItem() | |
623 { | |
624 UnitEquipmentChoice selectedItem = GetSelectedUnitEquipmentChoice(); | |
625 UnitEquipmentItem equipItem = null; | |
626 | |
627 if (selectedItem!=null) | |
628 { | |
629 equipItem = selectedItem.Item; | |
630 } | |
631 | |
632 return equipItem; | |
633 } | |
634 | |
635 private UnitEquipmentChoice GetSelectedUnitEquipmentChoice() | |
636 { | |
637 return (UnitEquipmentChoice) equipmentList.SelectedItem; | |
638 } | |
639 | |
640 private void bttnEditWeapon_Click(object sender, System.EventArgs e) | |
641 { | |
642 EditWeapon(); | |
643 } | |
644 | |
645 private void equipmentList_DoubleClick(object sender, System.EventArgs e) | |
646 { | |
647 EditWeapon(); | |
648 } | |
649 | |
650 private void AddWeapon() | |
651 { | |
652 FrmNewUnitEquipment newEquip = new FrmNewUnitEquipment(Unit, commandStack); | |
653 newEquip.ShowDialog(this); | |
654 } | |
655 | |
656 private void bttnAddWeapon_Click(object sender, System.EventArgs e) | |
657 { | |
658 AddWeapon(); | |
659 } | |
660 | |
661 private void RemoveWeapon() | |
662 { | |
663 commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, GetSelectedUnitEquipmentItem(), 0)); | |
664 } | |
665 | |
666 private void bttnRemoveWeapon_Click(object sender, System.EventArgs e) | |
667 { | |
668 RemoveWeapon(); | |
669 } | |
670 | |
671 private void bttnReplaceWeapon_Click(object sender, System.EventArgs e) | |
672 { | |
673 FrmReplaceUnitEquipment replace = new FrmReplaceUnitEquipment(unit, GetSelectedUnitEquipmentItem(), commandStack); | |
674 replace.ShowDialog(this); | |
675 } | |
676 | |
677 private void FrmUnit_FormClosing(object sender, FormClosingEventArgs e) | |
678 { | |
679 UpdateUnitName(); | |
680 UpdateUnitSize(); | |
681 } | |
682 } | |
27
526fefefb16b
Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
24
diff
changeset
|
683 } |