Mercurial > repos > IBBoard.WarFoundry.GUI.QtSharp
diff 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 |
line wrap: on
line diff
--- /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; + } + } +} +