changeset 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 5ee15def17e7
children 56771b8efdaf
files IBBoard.WarFoundry.GUI.QtSharp.csproj MainWindow.cs NewUnitDialog.cs qt-gui/CreateNewUnitLayout.cs qt-gui/CreateNewUnitLayout.ui
diffstat 5 files changed, 100 insertions(+), 30 deletions(-) [+]
line diff
     1.1 --- a/IBBoard.WarFoundry.GUI.QtSharp.csproj	Sat Jul 31 20:32:01 2010 +0000
     1.2 +++ b/IBBoard.WarFoundry.GUI.QtSharp.csproj	Tue Aug 03 19:36:49 2010 +0000
     1.3 @@ -41,6 +41,7 @@
     1.4      <Compile Include="NewArmyDialog.cs" />
     1.5      <Compile Include="Handler\NewUnitEventHandler.cs" />
     1.6      <Compile Include="qt-gui\CreateNewUnitLayout.cs" />
     1.7 +    <Compile Include="NewUnitDialog.cs" />
     1.8    </ItemGroup>
     1.9    <ItemGroup>
    1.10      <None Include="compile-ui.sh" />
     2.1 --- a/MainWindow.cs	Sat Jul 31 20:32:01 2010 +0000
     2.2 +++ b/MainWindow.cs	Tue Aug 03 19:36:49 2010 +0000
     2.3 @@ -15,6 +15,7 @@
     2.4  using IBBoard.WarFoundry.API.Objects;
     2.5  using IBBoard.WarFoundry.API.Savers;
     2.6  using IBBoard.WarFoundry.GUI.QtSharp.Handler;
     2.7 +using IBBoard.WarFoundry.API.Commands;
     2.8  
     2.9  namespace IBBoard.WarFoundry.GUI.QtSharp
    2.10  {
    2.11 @@ -110,7 +111,7 @@
    2.12  			if (CloseCurrentArmy())
    2.13  			{
    2.14  				NewArmyDialog dialog = new NewArmyDialog(this);
    2.15 -				int result = dialog.Exec ();
    2.16 +				int result = dialog.Exec();
    2.17  				
    2.18  				if (result == (int)QDialog.DialogCode.Accepted)
    2.19  				{
    2.20 @@ -522,7 +523,7 @@
    2.21  				{
    2.22  					QAction action = new QAction(this);
    2.23  					action.icon = new QIcon("icons/ui/add.png");
    2.24 -					NewUnitEventHandler handler = new NewUnitEventHandler(category, AddUnit);
    2.25 +					NewUnitEventHandler handler = new NewUnitEventHandler(category, AddUnitFromCategory);
    2.26  					ConnectMenuAction(action, handler.CreateNewUnit);
    2.27  					categoryActions[i] = action;
    2.28  					layout.toolBar.AddAction(action);
    2.29 @@ -531,9 +532,22 @@
    2.30  			}
    2.31  		}
    2.32  
    2.33 -		private void AddUnit(Category cat)
    2.34 +		private void AddUnitFromCategory(Category cat)
    2.35  		{
    2.36 -			QMessageBox.Information(this, "Add unit", cat.Name);
    2.37 +			NewUnitDialog newUnit = new NewUnitDialog(this, CurrentArmy.Race, cat, CurrentArmy);
    2.38 +			int result = newUnit.Exec();
    2.39 +			
    2.40 +			if (result == (int)QDialog.DialogCode.Accepted)
    2.41 +			{				
    2.42 +				CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, CurrentArmy.GetCategory(cat));
    2.43 +				CommandStack.Execute(cmd);
    2.44 +				OpenUnitDialog(cmd.Unit);
    2.45 +			}
    2.46 +		}
    2.47 +
    2.48 +		private void OpenUnitDialog(Unit unit)
    2.49 +		{
    2.50 +			
    2.51  		}
    2.52  
    2.53  		void EnableCategoryButtons ()
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/NewUnitDialog.cs	Tue Aug 03 19:36:49 2010 +0000
     3.3 @@ -0,0 +1,55 @@
     3.4 +//  This file (NewUnitDialog.cs) is a part of the IBBoard.WarFoundry.GUI.QtSharp project and is copyright 2010 IBBoard
     3.5 +// 
     3.6 +//  // 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.
     3.7 +using System;
     3.8 +using Qyoto;
     3.9 +using IBBoard.WarFoundry.API;
    3.10 +using IBBoard.WarFoundry.API.Objects;
    3.11 +
    3.12 +namespace IBBoard.WarFoundry.GUI.QtSharp
    3.13 +{
    3.14 +	public class NewUnitDialog : QDialog
    3.15 +	{
    3.16 +		private Ui_CreateNewUnitLayout layout;
    3.17 +		
    3.18 +		private Army army;
    3.19 +		private UnitType[] units;
    3.20 +		private bool[] allowed;
    3.21 +		
    3.22 +		public NewUnitDialog(QWidget parent, Race race, Category cat, Army army) : base(parent)
    3.23 +		{
    3.24 +			layout = new Ui_CreateNewUnitLayout();
    3.25 +			layout.SetupUi(this);
    3.26 +			
    3.27 +			units = race.GetUnitTypes(cat);
    3.28 +			allowed = new bool[units.Length];
    3.29 +			this.army = army;
    3.30 +			
    3.31 +			for (int i = 0; i < units.Length; i++)
    3.32 +			{
    3.33 +				UnitType unit = units[i];
    3.34 +				allowed[i] = army.CanAddUnitType(unit).Count == 0;
    3.35 +				layout.unitTypeList.AddItem(unit.Name);
    3.36 +			}
    3.37 +			
    3.38 +			QObject.Connect(layout.unitTypeList, SIGNAL("currentRowChanged(int)"), UnitTypeSelectionChanged);
    3.39 +			SetOkayButtonState(false);
    3.40 +		}
    3.41 +
    3.42 +		private void UnitTypeSelectionChanged()
    3.43 +		{
    3.44 +			SetOkayButtonState(layout.unitTypeList.CurrentRow != -1);
    3.45 +		}
    3.46 +		
    3.47 +		public UnitType SelectedUnit
    3.48 +		{
    3.49 +			get { return units[layout.unitTypeList.CurrentRow]; }
    3.50 +		}
    3.51 +
    3.52 +		private void SetOkayButtonState(bool boolValue)
    3.53 +		{
    3.54 +			layout.buttonBox.Button(QDialogButtonBox.StandardButton.Ok).Enabled = boolValue;
    3.55 +		}
    3.56 +	}
    3.57 +}
    3.58 +
     4.1 --- a/qt-gui/CreateNewUnitLayout.cs	Sat Jul 31 20:32:01 2010 +0000
     4.2 +++ b/qt-gui/CreateNewUnitLayout.cs	Tue Aug 03 19:36:49 2010 +0000
     4.3 @@ -1,7 +1,7 @@
     4.4  /********************************************************************************
     4.5  ** Form generated from reading ui file 'CreateNewUnitLayout.ui'
     4.6  **
     4.7 -** Created: Sat Jul 31 21:11:26 2010
     4.8 +** Created: Tue Aug 3 20:32:59 2010
     4.9  **      by: Qt User Interface Compiler for C# version 4.6.3
    4.10  **
    4.11  ** WARNING! All changes made in this file will be lost when recompiling ui file!
    4.12 @@ -10,59 +10,59 @@
    4.13  
    4.14  using Qyoto;
    4.15  
    4.16 -public class Ui_CreateNewArmyLayout
    4.17 +public class Ui_CreateNewUnitLayout
    4.18  {
    4.19      public QGridLayout gridLayout;
    4.20      public QDialogButtonBox buttonBox;
    4.21      public QLabel lblUnitType;
    4.22      public QListWidget unitTypeList;
    4.23  
    4.24 -    public void SetupUi(QDialog CreateNewArmyLayout)
    4.25 +    public void SetupUi(QDialog CreateNewUnitLayout)
    4.26      {
    4.27 -    if (CreateNewArmyLayout.ObjectName == "")
    4.28 -        CreateNewArmyLayout.ObjectName = "CreateNewArmyLayout";
    4.29 -    CreateNewArmyLayout.WindowModality = Qt.WindowModality.WindowModal;
    4.30 +    if (CreateNewUnitLayout.ObjectName == "")
    4.31 +        CreateNewUnitLayout.ObjectName = "CreateNewUnitLayout";
    4.32 +    CreateNewUnitLayout.WindowModality = Qt.WindowModality.WindowModal;
    4.33      QSize Size = new QSize(400, 214);
    4.34 -    Size = Size.ExpandedTo(CreateNewArmyLayout.MinimumSizeHint());
    4.35 -    CreateNewArmyLayout.Size = Size;
    4.36 -    gridLayout = new QGridLayout(CreateNewArmyLayout);
    4.37 +    Size = Size.ExpandedTo(CreateNewUnitLayout.MinimumSizeHint());
    4.38 +    CreateNewUnitLayout.Size = Size;
    4.39 +    gridLayout = new QGridLayout(CreateNewUnitLayout);
    4.40      gridLayout.ObjectName = "gridLayout";
    4.41 -    buttonBox = new QDialogButtonBox(CreateNewArmyLayout);
    4.42 +    buttonBox = new QDialogButtonBox(CreateNewUnitLayout);
    4.43      buttonBox.ObjectName = "buttonBox";
    4.44      buttonBox.Orientation = Qt.Orientation.Horizontal;
    4.45      buttonBox.StandardButtons = Qyoto.Qyoto.GetCPPEnumValue("QDialogButtonBox", "Cancel") | Qyoto.Qyoto.GetCPPEnumValue("QDialogButtonBox", "Ok");
    4.46  
    4.47      gridLayout.AddWidget(buttonBox, 1, 2, 1, 1);
    4.48  
    4.49 -    lblUnitType = new QLabel(CreateNewArmyLayout);
    4.50 +    lblUnitType = new QLabel(CreateNewUnitLayout);
    4.51      lblUnitType.ObjectName = "lblUnitType";
    4.52      lblUnitType.Alignment = Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignRight") | Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignTop") | Qyoto.Qyoto.GetCPPEnumValue("Qt", "AlignTrailing");
    4.53  
    4.54      gridLayout.AddWidget(lblUnitType, 0, 0, 1, 1);
    4.55  
    4.56 -    unitTypeList = new QListWidget(CreateNewArmyLayout);
    4.57 +    unitTypeList = new QListWidget(CreateNewUnitLayout);
    4.58      unitTypeList.ObjectName = "unitTypeList";
    4.59 -    unitTypeList.Enabled = false;
    4.60 +    unitTypeList.Enabled = true;
    4.61  
    4.62      gridLayout.AddWidget(unitTypeList, 0, 2, 1, 1);
    4.63  
    4.64  
    4.65 -    RetranslateUi(CreateNewArmyLayout);
    4.66 -    QObject.Connect(buttonBox, Qt.SIGNAL("accepted()"), CreateNewArmyLayout, Qt.SLOT("accept()"));
    4.67 -    QObject.Connect(buttonBox, Qt.SIGNAL("rejected()"), CreateNewArmyLayout, Qt.SLOT("reject()"));
    4.68 +    RetranslateUi(CreateNewUnitLayout);
    4.69 +    QObject.Connect(buttonBox, Qt.SIGNAL("accepted()"), CreateNewUnitLayout, Qt.SLOT("accept()"));
    4.70 +    QObject.Connect(buttonBox, Qt.SIGNAL("rejected()"), CreateNewUnitLayout, Qt.SLOT("reject()"));
    4.71  
    4.72 -    QMetaObject.ConnectSlotsByName(CreateNewArmyLayout);
    4.73 +    QMetaObject.ConnectSlotsByName(CreateNewUnitLayout);
    4.74      } // SetupUi
    4.75  
    4.76 -    public void RetranslateUi(QDialog CreateNewArmyLayout)
    4.77 +    public void RetranslateUi(QDialog CreateNewUnitLayout)
    4.78      {
    4.79 -    CreateNewArmyLayout.WindowTitle = QApplication.Translate("CreateNewArmyLayout", "Dialog", null, QApplication.Encoding.UnicodeUTF8);
    4.80 -    lblUnitType.Text = QApplication.Translate("CreateNewArmyLayout", "unit type:", null, QApplication.Encoding.UnicodeUTF8);
    4.81 +    CreateNewUnitLayout.WindowTitle = QApplication.Translate("CreateNewUnitLayout", "Dialog", null, QApplication.Encoding.UnicodeUTF8);
    4.82 +    lblUnitType.Text = QApplication.Translate("CreateNewUnitLayout", "unit type:", null, QApplication.Encoding.UnicodeUTF8);
    4.83      } // RetranslateUi
    4.84  
    4.85  }
    4.86  
    4.87  namespace Ui {
    4.88 -    public class CreateNewArmyLayout : Ui_CreateNewArmyLayout {}
    4.89 +    public class CreateNewUnitLayout : Ui_CreateNewUnitLayout {}
    4.90  } // namespace Ui
    4.91  
     5.1 --- a/qt-gui/CreateNewUnitLayout.ui	Sat Jul 31 20:32:01 2010 +0000
     5.2 +++ b/qt-gui/CreateNewUnitLayout.ui	Tue Aug 03 19:36:49 2010 +0000
     5.3 @@ -1,7 +1,7 @@
     5.4  <?xml version="1.0" encoding="UTF-8"?>
     5.5  <ui version="4.0">
     5.6 - <class>CreateNewArmyLayout</class>
     5.7 - <widget class="QDialog" name="CreateNewArmyLayout">
     5.8 + <class>CreateNewUnitLayout</class>
     5.9 + <widget class="QDialog" name="CreateNewUnitLayout">
    5.10    <property name="windowModality">
    5.11     <enum>Qt::WindowModal</enum>
    5.12    </property>
    5.13 @@ -40,7 +40,7 @@
    5.14     <item row="0" column="2">
    5.15      <widget class="QListWidget" name="unitTypeList">
    5.16       <property name="enabled">
    5.17 -      <bool>false</bool>
    5.18 +      <bool>true</bool>
    5.19       </property>
    5.20      </widget>
    5.21     </item>
    5.22 @@ -51,7 +51,7 @@
    5.23    <connection>
    5.24     <sender>buttonBox</sender>
    5.25     <signal>accepted()</signal>
    5.26 -   <receiver>CreateNewArmyLayout</receiver>
    5.27 +   <receiver>CreateNewUnitLayout</receiver>
    5.28     <slot>accept()</slot>
    5.29     <hints>
    5.30      <hint type="sourcelabel">
    5.31 @@ -67,7 +67,7 @@
    5.32    <connection>
    5.33     <sender>buttonBox</sender>
    5.34     <signal>rejected()</signal>
    5.35 -   <receiver>CreateNewArmyLayout</receiver>
    5.36 +   <receiver>CreateNewUnitLayout</receiver>
    5.37     <slot>reject()</slot>
    5.38     <hints>
    5.39      <hint type="sourcelabel">