# HG changeset patch # User IBBoard # Date 1282420803 0 # Node ID dafbd432ca235d570dcbc6792febdc9ee453d3f9 # Parent d2f4fcc282542162084529974267b2587496b691 Re #60: Add UI to add/remove/edit weapons in GTK * Start to implement Add functionality using a new abstraction concept that keeps the UI dumb and keeps the logic in a cross-toolkit controller diff -r d2f4fcc28254 -r dafbd432ca23 FrmAddEquipment.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FrmAddEquipment.cs Sat Aug 21 20:00:03 2010 +0000 @@ -0,0 +1,39 @@ +// This file (FrmAddEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.GTK 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 IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces; +using IBBoard.WarFoundry.API.Objects; +namespace IBBoard.WarFoundry.GUI.GTK +{ + public partial class FrmAddEquipment : Gtk.Dialog, IAddEquipmentUI + { + public FrmAddEquipment() + { + this.Build(); + } + + public event SingleArgMethodInvoker UnitEquipmentItemChoiceChanged; + + public void SetUnitEquipmentItems(UnitEquipmentItem[] items) + { + throw new NotImplementedException(); + } + + public void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber) + { + throw new NotImplementedException(); + } + + public void SetUnitEquipmentLimitsEnabled(bool isEnabled) + { + throw new NotImplementedException(); + } + + public void ShowControl() + { + throw new NotImplementedException(); + } + } +} + diff -r d2f4fcc28254 -r dafbd432ca23 IBBoard.WarFoundry.GUI.GTK.csproj --- a/IBBoard.WarFoundry.GUI.GTK.csproj Sun Aug 15 16:02:49 2010 +0000 +++ b/IBBoard.WarFoundry.GUI.GTK.csproj Sat Aug 21 20:00:03 2010 +0000 @@ -50,6 +50,10 @@ + + + + @@ -103,4 +107,8 @@ App.ico + + + + \ No newline at end of file diff -r d2f4fcc28254 -r dafbd432ca23 IBBoard.WarFoundry.GUI.GTK.sln --- a/IBBoard.WarFoundry.GUI.GTK.sln Sun Aug 15 16:02:49 2010 +0000 +++ b/IBBoard.WarFoundry.GUI.GTK.sln Sat Aug 21 20:00:03 2010 +0000 @@ -19,6 +19,10 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IBBoard.Tests", "..\IBBoard.Tests\IBBoard.Tests.csproj", "{4160F7B6-4CFA-41FC-B5D7-5C9AE06FEBA7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IBBoard.NUnit", "..\IBBoard.NUnit\IBBoard.NUnit.csproj", "{C52AFD32-B869-4E14-AACE-2846AD2CC742}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IBBoard.NUnit.Tests", "..\IBBoard.NUnit.Tests\IBBoard.NUnit.Tests.csproj", "{2025A316-8377-4454-807C-3C4ED02DF4D5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -33,6 +37,10 @@ {182E4A7C-7CFB-4337-A9AD-AB2DCA054A53}.Debug|x86.Build.0 = Debug|Any CPU {182E4A7C-7CFB-4337-A9AD-AB2DCA054A53}.Release|x86.ActiveCfg = Release|Any CPU {182E4A7C-7CFB-4337-A9AD-AB2DCA054A53}.Release|x86.Build.0 = Release|Any CPU + {2025A316-8377-4454-807C-3C4ED02DF4D5}.Debug|x86.ActiveCfg = Debug|Any CPU + {2025A316-8377-4454-807C-3C4ED02DF4D5}.Debug|x86.Build.0 = Debug|Any CPU + {2025A316-8377-4454-807C-3C4ED02DF4D5}.Release|x86.ActiveCfg = Release|Any CPU + {2025A316-8377-4454-807C-3C4ED02DF4D5}.Release|x86.Build.0 = Release|Any CPU {3BBDF326-7128-406C-85DF-EF049633E602}.Debug|x86.ActiveCfg = Debug|Any CPU {3BBDF326-7128-406C-85DF-EF049633E602}.Debug|x86.Build.0 = Debug|Any CPU {3BBDF326-7128-406C-85DF-EF049633E602}.Release|x86.ActiveCfg = Release|Any CPU @@ -61,6 +69,10 @@ {B20E808D-878E-4F6D-B1E3-84A9A49905CB}.Debug|x86.Build.0 = Debug|Any CPU {B20E808D-878E-4F6D-B1E3-84A9A49905CB}.Release|x86.ActiveCfg = Release|Any CPU {B20E808D-878E-4F6D-B1E3-84A9A49905CB}.Release|x86.Build.0 = Release|Any CPU + {C52AFD32-B869-4E14-AACE-2846AD2CC742}.Debug|x86.ActiveCfg = Debug|x86 + {C52AFD32-B869-4E14-AACE-2846AD2CC742}.Debug|x86.Build.0 = Debug|x86 + {C52AFD32-B869-4E14-AACE-2846AD2CC742}.Release|x86.ActiveCfg = Release|x86 + {C52AFD32-B869-4E14-AACE-2846AD2CC742}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution StartupItem = IBBoard.WarFoundry.GUI.GTK.csproj diff -r d2f4fcc28254 -r dafbd432ca23 UIControl/AddEquipmentUIControl.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UIControl/AddEquipmentUIControl.cs Sat Aug 21 20:00:03 2010 +0000 @@ -0,0 +1,64 @@ +// This file (AddEquipmentUI.cs) is a part of the IBBoard.WarFoundry.GUI.GTK 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 IBBoard.Commands; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.WarFoundry.API.Util; +using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces; +namespace IBBoard.WarFoundry.GUI.GTK.UIControl +{ + public class AddEquipmentUIControl + { + private Unit unit; + private CommandStack commandStack; + private IAddEquipmentUI ui; + + public AddEquipmentUIControl(Unit unit, CommandStack commandStack) + { + this.unit = unit; + this.commandStack = commandStack; + SetupUI(); + } + + private void SetupUI() + { + CreateEquipmentUI(); + UnitEquipmentItem[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment()); + ui.SetUnitEquipmentItems(items); + ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged; + } + + //TODO Make abstract + protected void CreateEquipmentUI() + { + ui = new FrmAddEquipment(); + } + + private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip) + { + bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); + double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + maxPercent = Math.Max(0, maxPercent); + double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + minPercent = Math.Max(0, minPercent); + int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); + maxNumber = Math.Max(0, maxNumber); + int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); + minNumber = Math.Max(0, minNumber); + + } + + private double RoundPercentage(double percent) + { + return Math.Round(percent, 1); + } + + //TODO Make abstract + public void Show() + { + ((FrmAddEquipment)ui).ShowNow(); + } + } +} + diff -r d2f4fcc28254 -r dafbd432ca23 UIControl/Interfaces/IAddEquipmentUI.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UIControl/Interfaces/IAddEquipmentUI.cs Sat Aug 21 20:00:03 2010 +0000 @@ -0,0 +1,62 @@ +// This file (IAddEquipmentUI.cs) is a part of the IBBoard.WarFoundry.GUI.GTK 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 IBBoard.WarFoundry.API.Objects; +namespace IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces +{ + /// + /// The interface that UI components should implement to represent "Add Equipment" dialogs or system equivalents (e.g. console areas or HTML fragments) + /// + public interface IAddEquipmentUI + { + /// + /// Should be fired when unit equipment item choice changes. + /// + event SingleArgMethodInvoker UnitEquipmentItemChoiceChanged; + + + + /// + /// Sets the equipment items that should be displayed on the form + /// + /// + /// The equipment items that should be displayed on the form + /// + void SetUnitEquipmentItems(UnitEquipmentItem[] items); + + /// + /// Sets the limits for the currently selected equipment item + /// + /// + /// True if the current limit is a ratio limit, else false for absolute limits + /// + /// + /// The minimum limit as a percentage + /// + /// + /// The maximum limit as a percentage + /// + /// + /// The minimum number as an absolute figure + /// + /// + /// The maximum number as an absolute figure + /// + void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber); + + /// + /// Sets whether the unit equipment limit UI components should be enabled and able to accept input. + /// + /// + /// True if the UI components should accept input, else false + /// + void SetUnitEquipmentLimitsEnabled(bool isEnabled); + + /// + /// Shows the control and awaits a user action (close or okay) + /// + void ShowControl(); + } +} + diff -r d2f4fcc28254 -r dafbd432ca23 Widgets/UnitDisplayWidget.cs --- a/Widgets/UnitDisplayWidget.cs Sun Aug 15 16:02:49 2010 +0000 +++ b/Widgets/UnitDisplayWidget.cs Sat Aug 21 20:00:03 2010 +0000 @@ -9,6 +9,7 @@ using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Commands; +using IBBoard.WarFoundry.GUI.GTK.UIControl; namespace IBBoard.WarFoundry.GTK.Widgets { @@ -107,7 +108,7 @@ [GLib.ConnectBefore ()] protected virtual void OnUnitSizeKeyPress (object o, Gtk.KeyPressEventArgs args) { - if (args.Event.Key == Gdk.Key.Return) + if (args.Event.Key == Gdk.Key.Return || args.Event.Key == Gdk.Key.KP_Enter) { SetNewUnitSize(); } @@ -138,11 +139,23 @@ private void SetNewUnitName() { - if (unitName.Text!=unit.Name) + if (unitName.Text != unit.Name) { SetNameCommand cmd = new SetNameCommand(unit, unitName.Text); stack.Execute(cmd); } } + + private void OnBttnAddEquipmentActivated(object sender, System.EventArgs e) + { + Console.WriteLine("Add button clicked"); + AddEquipment(); + } + + private void AddEquipment() + { + AddEquipmentUIControl addEquipment = new AddEquipmentUIControl(unit, stack); + addEquipment.Show(); + } } } diff -r d2f4fcc28254 -r dafbd432ca23 gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs --- a/gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs Sun Aug 15 16:02:49 2010 +0000 +++ b/gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs Sat Aug 21 20:00:03 2010 +0000 @@ -34,13 +34,13 @@ private global::Gtk.VBox vbox3; - private global::Gtk.Button bttnAddOptional; + private global::Gtk.Button bttnAddEquipment; - private global::Gtk.Button bttnEditOptional; + private global::Gtk.Button bttnEditEquipment; - private global::Gtk.Button bttnReplace; + private global::Gtk.Button bttnReplaceEquipment; - private global::Gtk.Button bttnRemove; + private global::Gtk.Button bttnRemoveEquipment; protected virtual void Build() { @@ -162,46 +162,46 @@ this.vbox3.Name = "vbox3"; this.vbox3.Spacing = 6; // Container child vbox3.Gtk.Box+BoxChild - this.bttnAddOptional = new global::Gtk.Button(); - this.bttnAddOptional.CanFocus = true; - this.bttnAddOptional.Name = "bttnAddOptional"; - this.bttnAddOptional.UseUnderline = true; - this.bttnAddOptional.Label = global::Mono.Unix.Catalog.GetString("Add"); - this.vbox3.Add(this.bttnAddOptional); - global::Gtk.Box.BoxChild w13 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnAddOptional])); + this.bttnAddEquipment = new global::Gtk.Button(); + this.bttnAddEquipment.CanFocus = true; + this.bttnAddEquipment.Name = "bttnAddEquipment"; + this.bttnAddEquipment.UseUnderline = true; + this.bttnAddEquipment.Label = global::Mono.Unix.Catalog.GetString("Add"); + this.vbox3.Add(this.bttnAddEquipment); + global::Gtk.Box.BoxChild w13 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnAddEquipment])); w13.Position = 0; w13.Expand = false; w13.Fill = false; // Container child vbox3.Gtk.Box+BoxChild - this.bttnEditOptional = new global::Gtk.Button(); - this.bttnEditOptional.CanFocus = true; - this.bttnEditOptional.Name = "bttnEditOptional"; - this.bttnEditOptional.UseUnderline = true; - this.bttnEditOptional.Label = global::Mono.Unix.Catalog.GetString("Edit"); - this.vbox3.Add(this.bttnEditOptional); - global::Gtk.Box.BoxChild w14 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnEditOptional])); + this.bttnEditEquipment = new global::Gtk.Button(); + this.bttnEditEquipment.CanFocus = true; + this.bttnEditEquipment.Name = "bttnEditEquipment"; + this.bttnEditEquipment.UseUnderline = true; + this.bttnEditEquipment.Label = global::Mono.Unix.Catalog.GetString("Edit"); + this.vbox3.Add(this.bttnEditEquipment); + global::Gtk.Box.BoxChild w14 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnEditEquipment])); w14.Position = 1; w14.Expand = false; w14.Fill = false; // Container child vbox3.Gtk.Box+BoxChild - this.bttnReplace = new global::Gtk.Button(); - this.bttnReplace.CanFocus = true; - this.bttnReplace.Name = "bttnReplace"; - this.bttnReplace.UseUnderline = true; - this.bttnReplace.Label = global::Mono.Unix.Catalog.GetString("Replace"); - this.vbox3.Add(this.bttnReplace); - global::Gtk.Box.BoxChild w15 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnReplace])); + this.bttnReplaceEquipment = new global::Gtk.Button(); + this.bttnReplaceEquipment.CanFocus = true; + this.bttnReplaceEquipment.Name = "bttnReplaceEquipment"; + this.bttnReplaceEquipment.UseUnderline = true; + this.bttnReplaceEquipment.Label = global::Mono.Unix.Catalog.GetString("Replace"); + this.vbox3.Add(this.bttnReplaceEquipment); + global::Gtk.Box.BoxChild w15 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnReplaceEquipment])); w15.Position = 2; w15.Expand = false; w15.Fill = false; // Container child vbox3.Gtk.Box+BoxChild - this.bttnRemove = new global::Gtk.Button(); - this.bttnRemove.CanFocus = true; - this.bttnRemove.Name = "bttnRemove"; - this.bttnRemove.UseUnderline = true; - this.bttnRemove.Label = global::Mono.Unix.Catalog.GetString("Remove"); - this.vbox3.Add(this.bttnRemove); - global::Gtk.Box.BoxChild w16 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnRemove])); + this.bttnRemoveEquipment = new global::Gtk.Button(); + this.bttnRemoveEquipment.CanFocus = true; + this.bttnRemoveEquipment.Name = "bttnRemoveEquipment"; + this.bttnRemoveEquipment.UseUnderline = true; + this.bttnRemoveEquipment.Label = global::Mono.Unix.Catalog.GetString("Remove"); + this.vbox3.Add(this.bttnRemoveEquipment); + global::Gtk.Box.BoxChild w16 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnRemoveEquipment])); w16.Position = 3; w16.Expand = false; w16.Fill = false; @@ -226,6 +226,7 @@ this.unitName.KeyPressEvent += new global::Gtk.KeyPressEventHandler(this.OnUnitNameKeyPress); this.unitSize.FocusOutEvent += new global::Gtk.FocusOutEventHandler(this.OnUnitSizeFocusOut); this.unitSize.KeyPressEvent += new global::Gtk.KeyPressEventHandler(this.OnUnitSizeKeyPress); + this.bttnAddEquipment.Activated += new global::System.EventHandler(this.OnBttnAddEquipmentActivated); } } } diff -r d2f4fcc28254 -r dafbd432ca23 gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs Sat Aug 21 20:00:03 2010 +0000 @@ -0,0 +1,61 @@ + +// This file has been generated by the GUI designer. Do not modify. +namespace IBBoard.WarFoundry.GUI.GTK +{ + public partial class FrmAddEquipment + { + private global::Gtk.Button buttonCancel; + + private global::Gtk.Button buttonOk; + + protected virtual void Build() + { + global::Stetic.Gui.Initialize(this); + // Widget IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment + this.Name = "IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment"; + this.WindowPosition = ((global::Gtk.WindowPosition)(4)); + // Internal child IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.VBox + global::Gtk.VBox w1 = this.VBox; + w1.Name = "dialog1_VBox"; + w1.BorderWidth = ((uint)(2)); + // Internal child IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.ActionArea + global::Gtk.HButtonBox w2 = this.ActionArea; + w2.Name = "dialog1_ActionArea"; + w2.Spacing = 10; + w2.BorderWidth = ((uint)(5)); + w2.LayoutStyle = ((global::Gtk.ButtonBoxStyle)(4)); + // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild + this.buttonCancel = new global::Gtk.Button(); + this.buttonCancel.CanDefault = true; + this.buttonCancel.CanFocus = true; + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.UseStock = true; + this.buttonCancel.UseUnderline = true; + this.buttonCancel.Label = "gtk-cancel"; + this.AddActionWidget(this.buttonCancel, -6); + global::Gtk.ButtonBox.ButtonBoxChild w3 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w2[this.buttonCancel])); + w3.Expand = false; + w3.Fill = false; + // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild + this.buttonOk = new global::Gtk.Button(); + this.buttonOk.CanDefault = true; + this.buttonOk.CanFocus = true; + this.buttonOk.Name = "buttonOk"; + this.buttonOk.UseStock = true; + this.buttonOk.UseUnderline = true; + this.buttonOk.Label = "gtk-ok"; + this.AddActionWidget(this.buttonOk, -5); + global::Gtk.ButtonBox.ButtonBoxChild w4 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w2[this.buttonOk])); + w4.Position = 1; + w4.Expand = false; + w4.Fill = false; + if ((this.Child != null)) + { + this.Child.ShowAll(); + } + this.DefaultWidth = 400; + this.DefaultHeight = 300; + this.Show(); + } + } +} diff -r d2f4fcc28254 -r dafbd432ca23 gtk-gui/gui.stetic --- a/gtk-gui/gui.stetic Sun Aug 15 16:02:49 2010 +0000 +++ b/gtk-gui/gui.stetic Sat Aug 21 20:00:03 2010 +0000 @@ -868,12 +868,13 @@ 6 - + True TextOnly Add True + 0 @@ -883,7 +884,7 @@ - + True TextOnly @@ -898,7 +899,7 @@ - + True TextOnly @@ -913,7 +914,7 @@ - + True TextOnly @@ -956,4 +957,61 @@ + + + CenterOnParent + 2 + False + + + + 2 + + + + + + + + + 10 + 5 + 2 + End + + + + True + True + True + StockItem + gtk-cancel + -6 + gtk-cancel + + + False + False + + + + + + True + True + True + StockItem + gtk-ok + -5 + gtk-ok + + + 1 + False + False + + + + + \ No newline at end of file