# HG changeset patch # User IBBoard # Date 1280864209 0 # Node ID 246237c88b9baff6f41d12e5d31fa16b3a88af79 # Parent 5ee15def17e7a8719f914c6c1ac9d376c14362ab 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 diff -r 5ee15def17e7 -r 246237c88b9b IBBoard.WarFoundry.GUI.QtSharp.csproj --- a/IBBoard.WarFoundry.GUI.QtSharp.csproj Sat Jul 31 20:32:01 2010 +0000 +++ b/IBBoard.WarFoundry.GUI.QtSharp.csproj Tue Aug 03 19:36:49 2010 +0000 @@ -41,6 +41,7 @@ + diff -r 5ee15def17e7 -r 246237c88b9b MainWindow.cs --- a/MainWindow.cs Sat Jul 31 20:32:01 2010 +0000 +++ b/MainWindow.cs Tue Aug 03 19:36:49 2010 +0000 @@ -15,6 +15,7 @@ using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Savers; using IBBoard.WarFoundry.GUI.QtSharp.Handler; +using IBBoard.WarFoundry.API.Commands; namespace IBBoard.WarFoundry.GUI.QtSharp { @@ -110,7 +111,7 @@ if (CloseCurrentArmy()) { NewArmyDialog dialog = new NewArmyDialog(this); - int result = dialog.Exec (); + int result = dialog.Exec(); if (result == (int)QDialog.DialogCode.Accepted) { @@ -522,7 +523,7 @@ { QAction action = new QAction(this); action.icon = new QIcon("icons/ui/add.png"); - NewUnitEventHandler handler = new NewUnitEventHandler(category, AddUnit); + NewUnitEventHandler handler = new NewUnitEventHandler(category, AddUnitFromCategory); ConnectMenuAction(action, handler.CreateNewUnit); categoryActions[i] = action; layout.toolBar.AddAction(action); @@ -531,9 +532,22 @@ } } - private void AddUnit(Category cat) + private void AddUnitFromCategory(Category cat) { - QMessageBox.Information(this, "Add unit", cat.Name); + NewUnitDialog newUnit = new NewUnitDialog(this, CurrentArmy.Race, cat, CurrentArmy); + int result = newUnit.Exec(); + + if (result == (int)QDialog.DialogCode.Accepted) + { + CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, CurrentArmy.GetCategory(cat)); + CommandStack.Execute(cmd); + OpenUnitDialog(cmd.Unit); + } + } + + private void OpenUnitDialog(Unit unit) + { + } void EnableCategoryButtons () diff -r 5ee15def17e7 -r 246237c88b9b NewUnitDialog.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NewUnitDialog.cs Tue Aug 03 19:36:49 2010 +0000 @@ -0,0 +1,55 @@ +// This file (NewUnitDialog.cs) is a part of the IBBoard.WarFoundry.GUI.QtSharp project and is copyright 2010 IBBoard +// +// // 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. +using System; +using Qyoto; +using IBBoard.WarFoundry.API; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.GUI.QtSharp +{ + public class NewUnitDialog : QDialog + { + private Ui_CreateNewUnitLayout layout; + + private Army army; + private UnitType[] units; + private bool[] allowed; + + public NewUnitDialog(QWidget parent, Race race, Category cat, Army army) : base(parent) + { + layout = new Ui_CreateNewUnitLayout(); + layout.SetupUi(this); + + units = race.GetUnitTypes(cat); + allowed = new bool[units.Length]; + this.army = army; + + for (int i = 0; i < units.Length; i++) + { + UnitType unit = units[i]; + allowed[i] = army.CanAddUnitType(unit).Count == 0; + layout.unitTypeList.AddItem(unit.Name); + } + + QObject.Connect(layout.unitTypeList, SIGNAL("currentRowChanged(int)"), UnitTypeSelectionChanged); + SetOkayButtonState(false); + } + + private void UnitTypeSelectionChanged() + { + SetOkayButtonState(layout.unitTypeList.CurrentRow != -1); + } + + public UnitType SelectedUnit + { + get { return units[layout.unitTypeList.CurrentRow]; } + } + + private void SetOkayButtonState(bool boolValue) + { + layout.buttonBox.Button(QDialogButtonBox.StandardButton.Ok).Enabled = boolValue; + } + } +} + diff -r 5ee15def17e7 -r 246237c88b9b qt-gui/CreateNewUnitLayout.cs --- a/qt-gui/CreateNewUnitLayout.cs Sat Jul 31 20:32:01 2010 +0000 +++ b/qt-gui/CreateNewUnitLayout.cs Tue Aug 03 19:36:49 2010 +0000 @@ -1,7 +1,7 @@ /******************************************************************************** ** Form generated from reading ui file 'CreateNewUnitLayout.ui' ** -** Created: Sat Jul 31 21:11:26 2010 +** Created: Tue Aug 3 20:32:59 2010 ** by: Qt User Interface Compiler for C# version 4.6.3 ** ** WARNING! All changes made in this file will be lost when recompiling ui file! @@ -10,59 +10,59 @@ using Qyoto; -public class Ui_CreateNewArmyLayout +public class Ui_CreateNewUnitLayout { public QGridLayout gridLayout; public QDialogButtonBox buttonBox; public QLabel lblUnitType; public QListWidget unitTypeList; - public void SetupUi(QDialog CreateNewArmyLayout) + public void SetupUi(QDialog CreateNewUnitLayout) { - if (CreateNewArmyLayout.ObjectName == "") - CreateNewArmyLayout.ObjectName = "CreateNewArmyLayout"; - CreateNewArmyLayout.WindowModality = Qt.WindowModality.WindowModal; + if (CreateNewUnitLayout.ObjectName == "") + CreateNewUnitLayout.ObjectName = "CreateNewUnitLayout"; + CreateNewUnitLayout.WindowModality = Qt.WindowModality.WindowModal; QSize Size = new QSize(400, 214); - Size = Size.ExpandedTo(CreateNewArmyLayout.MinimumSizeHint()); - CreateNewArmyLayout.Size = Size; - gridLayout = new QGridLayout(CreateNewArmyLayout); + Size = Size.ExpandedTo(CreateNewUnitLayout.MinimumSizeHint()); + CreateNewUnitLayout.Size = Size; + gridLayout = new QGridLayout(CreateNewUnitLayout); gridLayout.ObjectName = "gridLayout"; - buttonBox = new QDialogButtonBox(CreateNewArmyLayout); + buttonBox = new QDialogButtonBox(CreateNewUnitLayout); buttonBox.ObjectName = "buttonBox"; buttonBox.Orientation = Qt.Orientation.Horizontal; buttonBox.StandardButtons = Qyoto.Qyoto.GetCPPEnumValue("QDialogButtonBox", "Cancel") | Qyoto.Qyoto.GetCPPEnumValue("QDialogButtonBox", "Ok"); gridLayout.AddWidget(buttonBox, 1, 2, 1, 1); - lblUnitType = new QLabel(CreateNewArmyLayout); + lblUnitType = new QLabel(CreateNewUnitLayout); lblUnitType.ObjectName = "lblUnitType"; lblUnitType.Alignment = Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignRight") | Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignTop") | Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignTrailing"); gridLayout.AddWidget(lblUnitType, 0, 0, 1, 1); - unitTypeList = new QListWidget(CreateNewArmyLayout); + unitTypeList = new QListWidget(CreateNewUnitLayout); unitTypeList.ObjectName = "unitTypeList"; - unitTypeList.Enabled = false; + unitTypeList.Enabled = true; gridLayout.AddWidget(unitTypeList, 0, 2, 1, 1); - RetranslateUi(CreateNewArmyLayout); - QObject.Connect(buttonBox, Qt.SIGNAL("accepted()"), CreateNewArmyLayout, Qt.SLOT("accept()")); - QObject.Connect(buttonBox, Qt.SIGNAL("rejected()"), CreateNewArmyLayout, Qt.SLOT("reject()")); + RetranslateUi(CreateNewUnitLayout); + QObject.Connect(buttonBox, Qt.SIGNAL("accepted()"), CreateNewUnitLayout, Qt.SLOT("accept()")); + QObject.Connect(buttonBox, Qt.SIGNAL("rejected()"), CreateNewUnitLayout, Qt.SLOT("reject()")); - QMetaObject.ConnectSlotsByName(CreateNewArmyLayout); + QMetaObject.ConnectSlotsByName(CreateNewUnitLayout); } // SetupUi - public void RetranslateUi(QDialog CreateNewArmyLayout) + public void RetranslateUi(QDialog CreateNewUnitLayout) { - CreateNewArmyLayout.WindowTitle = QApplication.Translate("CreateNewArmyLayout", "Dialog", null, QApplication.Encoding.UnicodeUTF8); - lblUnitType.Text = QApplication.Translate("CreateNewArmyLayout", "unit type:", null, QApplication.Encoding.UnicodeUTF8); + CreateNewUnitLayout.WindowTitle = QApplication.Translate("CreateNewUnitLayout", "Dialog", null, QApplication.Encoding.UnicodeUTF8); + lblUnitType.Text = QApplication.Translate("CreateNewUnitLayout", "unit type:", null, QApplication.Encoding.UnicodeUTF8); } // RetranslateUi } namespace Ui { - public class CreateNewArmyLayout : Ui_CreateNewArmyLayout {} + public class CreateNewUnitLayout : Ui_CreateNewUnitLayout {} } // namespace Ui diff -r 5ee15def17e7 -r 246237c88b9b qt-gui/CreateNewUnitLayout.ui --- a/qt-gui/CreateNewUnitLayout.ui Sat Jul 31 20:32:01 2010 +0000 +++ b/qt-gui/CreateNewUnitLayout.ui Tue Aug 03 19:36:49 2010 +0000 @@ -1,7 +1,7 @@ - CreateNewArmyLayout - + CreateNewUnitLayout + Qt::WindowModal @@ -40,7 +40,7 @@ - false + true @@ -51,7 +51,7 @@ buttonBox accepted() - CreateNewArmyLayout + CreateNewUnitLayout accept() @@ -67,7 +67,7 @@ buttonBox rejected() - CreateNewArmyLayout + CreateNewUnitLayout reject()