comparison NewUnitDialog.cs @ 29:246237c88b9b

Re #244: Create "New Unit" dialog in Qt# app * Add NewUnit dialog * Fix layout (rename layout and make list enabled) * Call dialog when clicking on buttons
author IBBoard <dev@ibboard.co.uk>
date Tue, 03 Aug 2010 19:36:49 +0000
parents
children d586244177ff
comparison
equal deleted inserted replaced
28:5ee15def17e7 29:246237c88b9b
1 // This file (NewUnitDialog.cs) is a part of the IBBoard.WarFoundry.GUI.QtSharp project and is copyright 2010 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 using System;
5 using Qyoto;
6 using IBBoard.WarFoundry.API;
7 using IBBoard.WarFoundry.API.Objects;
8
9 namespace IBBoard.WarFoundry.GUI.QtSharp
10 {
11 public class NewUnitDialog : QDialog
12 {
13 private Ui_CreateNewUnitLayout layout;
14
15 private Army army;
16 private UnitType[] units;
17 private bool[] allowed;
18
19 public NewUnitDialog(QWidget parent, Race race, Category cat, Army army) : base(parent)
20 {
21 layout = new Ui_CreateNewUnitLayout();
22 layout.SetupUi(this);
23
24 units = race.GetUnitTypes(cat);
25 allowed = new bool[units.Length];
26 this.army = army;
27
28 for (int i = 0; i < units.Length; i++)
29 {
30 UnitType unit = units[i];
31 allowed[i] = army.CanAddUnitType(unit).Count == 0;
32 layout.unitTypeList.AddItem(unit.Name);
33 }
34
35 QObject.Connect(layout.unitTypeList, SIGNAL("currentRowChanged(int)"), UnitTypeSelectionChanged);
36 SetOkayButtonState(false);
37 }
38
39 private void UnitTypeSelectionChanged()
40 {
41 SetOkayButtonState(layout.unitTypeList.CurrentRow != -1);
42 }
43
44 public UnitType SelectedUnit
45 {
46 get { return units[layout.unitTypeList.CurrentRow]; }
47 }
48
49 private void SetOkayButtonState(bool boolValue)
50 {
51 layout.buttonBox.Button(QDialogButtonBox.StandardButton.Ok).Enabled = boolValue;
52 }
53 }
54 }
55