annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (NewUnitDialog.cs) is a part of the IBBoard.WarFoundry.GUI.QtSharp project and is copyright 2010 IBBoard
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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.
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System;
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using Qyoto;
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.WarFoundry.API;
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.WarFoundry.API.Objects;
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 namespace IBBoard.WarFoundry.GUI.QtSharp
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 {
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 public class NewUnitDialog : QDialog
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 {
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 private Ui_CreateNewUnitLayout layout;
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 private Army army;
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 private UnitType[] units;
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 private bool[] allowed;
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 public NewUnitDialog(QWidget parent, Race race, Category cat, Army army) : base(parent)
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 {
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 layout = new Ui_CreateNewUnitLayout();
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 layout.SetupUi(this);
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 units = race.GetUnitTypes(cat);
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 allowed = new bool[units.Length];
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 this.army = army;
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 for (int i = 0; i < units.Length; i++)
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 {
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 UnitType unit = units[i];
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 allowed[i] = army.CanAddUnitType(unit).Count == 0;
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 layout.unitTypeList.AddItem(unit.Name);
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 QObject.Connect(layout.unitTypeList, SIGNAL("currentRowChanged(int)"), UnitTypeSelectionChanged);
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 SetOkayButtonState(false);
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 private void UnitTypeSelectionChanged()
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 {
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 SetOkayButtonState(layout.unitTypeList.CurrentRow != -1);
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 public UnitType SelectedUnit
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 {
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 get { return units[layout.unitTypeList.CurrentRow]; }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 private void SetOkayButtonState(bool boolValue)
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 {
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 layout.buttonBox.Button(QDialogButtonBox.StandardButton.Ok).Enabled = boolValue;
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55