annotate NewUnitDialog.cs @ 34:c3c64e139e5f default tip

Re #245: Create unit tab implementation * Create layout for unit tab widget * Start to populate values WARNING: Qyoto/Qt# seems unstable now and segfaults when new units are added!
author IBBoard <dev@ibboard.co.uk>
date Sat, 07 Aug 2010 16:02:53 +0000
parents d586244177ff
children
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);
31
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
36 QObject.Connect(layout.unitTypeList, SIGNAL("itemDoubleClicked(QListWidgetItem*)"), UnitTypeDoubleClicked);
29
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 SetOkayButtonState(false);
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
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 private void UnitTypeSelectionChanged()
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 {
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 SetOkayButtonState(layout.unitTypeList.CurrentRow != -1);
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
31
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
45 private void UnitTypeDoubleClicked()
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
46 {
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
47 QPushButton button = OkayButton;
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
48
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
49 if (button.Enabled)
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
50 {
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
51 button.Click();
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
52 }
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
53 }
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
54
29
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 public UnitType SelectedUnit
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 {
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 get { return units[layout.unitTypeList.CurrentRow]; }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59
31
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
60 private QPushButton OkayButton
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
61 {
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
62 get
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
63 {
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
64 return layout.buttonBox.Button(QDialogButtonBox.StandardButton.Ok);
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
65 }
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
66 }
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
67
29
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 private void SetOkayButtonState(bool boolValue)
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 {
31
d586244177ff Fixes #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents: 29
diff changeset
70 OkayButton.Enabled = boolValue;
29
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 }
246237c88b9b Re #244: Create "New Unit" dialog in Qt# app
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74