Mercurial > repos > IBBoard.WarFoundry.GUI.QtSharp
view NewArmyDialog.cs @ 8:8a8735679d55
Re #243: Create "New Army" dialog in Qt# app
* Disable "OK" button on army creation form
* Add event hooks and methods to enable OK Button when all values are completed
* Set properties on spinbox
Still need to work out how to stop dialog showing up in task bar.
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 30 Jan 2010 20:57:36 +0000 |
parents | bbf40d66dfe4 |
children | 3d0c9cf1b924 |
line wrap: on
line source
// This file (NewArmyDialog.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 System.Collections.Generic; using Qyoto; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry.GUI.QtSharp { public class NewArmyDialog : QDialog { private Ui_CreateNewArmyLayout layout; //TODO: Replace local cached arrays with some kind of storing as user data on controls, if possible //Qt doesn't seem to support it by default, but there should be a better alternative private GameSystem[] gameSystems; private Race[] races; public NewArmyDialog () { layout = new Ui_CreateNewArmyLayout(); layout.SetupUi(this); PopulateControls(); layout.gameSystems.CurrentIndex = -1; QObject.Connect(layout.gameSystems, SIGNAL("currentIndexChanged(int)"), GameSystemSelectionChanged); QObject.Connect(layout.armyName, SIGNAL("textChanged(QString)"), ArmyNameChanged); QObject.Connect(layout.armySize, SIGNAL("valueChanged(int)"), ArmySizeChanged); SetOkayButtonState(false); } private void SetOkayButtonState (bool boolValue) { layout.buttonBox.Button(QDialogButtonBox.StandardButton.Ok).Enabled = boolValue; } private void PopulateControls() { gameSystems = WarFoundryLoader.GetDefault().GetGameSystems(); foreach (GameSystem system in gameSystems) { layout.gameSystems.AddItem(system.Name); } } private void GameSystemSelectionChanged() { ValidateForm(); layout.raceList.Clear(); if (layout.gameSystems.CurrentIndex != -1) { races = WarFoundryLoader.GetDefault().GetRaces(GetSelectedSystem()); foreach (Race race in races) { layout.raceList.AddItem(race.Name); } } } private void ValidateForm() { bool complete = (layout.gameSystems.CurrentIndex != -1); complete &= (layout.raceList.CurrentRow != -1); complete &= (layout.armyName.Text != ""); complete &= (layout.armySize.Value > 0); SetOkayButtonState(complete); } private GameSystem GetSelectedSystem() { GameSystem system = null; int selectedIndex = layout.gameSystems.CurrentIndex; if (selectedIndex != -1) { system = gameSystems[selectedIndex]; } return system; } private void ArmyNameChanged() { ValidateForm(); } private void ArmySizeChanged() { ValidateForm(); } } }