Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
changeset 57:293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
* Make enabling/disabling fit the values passed (copied from existing WinForms checks)
* Add extra interface methods and properties to get necessary values from UI to use in command
* Implement new interface methods
* Implement command execution
* Make use of IDisposable interface instead of defining Dispose ourselves
Also:
* Use existing method of printing exception stack traces in main window
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 26 Aug 2010 19:30:22 +0000 |
parents | 0c5fbb54bfb0 |
children | 7bba99c368c8 |
files | FrmAddEquipment.cs FrmMainWindow.cs UIControl/AddEquipmentUIControl.cs UIControl/Interfaces/IAddEquipmentUI.cs |
diffstat | 4 files changed, 121 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmAddEquipment.cs Wed Aug 25 20:04:27 2010 +0000 +++ b/FrmAddEquipment.cs Thu Aug 26 19:30:22 2010 +0000 @@ -36,7 +36,7 @@ { if (UnitEquipmentItemChoiceChanged!=null) { - UnitEquipmentItemChoiceChanged((UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment)); + UnitEquipmentItemChoiceChanged(SelectedUnitEquipmentItem); } } @@ -69,12 +69,28 @@ private void SetEnabledState() { - rbEquipNumeric.Sensitive = (limitsEnabled && ratioLimited); - numericAmount.Sensitive = (limitsEnabled && ratioLimited); - rbEquipPercent.Sensitive = limitsEnabled; - percentageAmount.Sensitive = limitsEnabled; - rbEquipAll.Sensitive = limitsEnabled; - lblEquipAll.Sensitive = limitsEnabled; + rbEquipNumeric.Sensitive = (limitsEnabled && !ratioLimited); + numericAmount.Sensitive = (limitsEnabled && !ratioLimited); + double minPercentage = GetMinPercentage(); + rbEquipPercent.Sensitive = limitsEnabled && minPercentage != 100; + percentageAmount.Sensitive = limitsEnabled && minPercentage != 100; + double maxPercentage = GetMaxPercentage(); + rbEquipAll.Sensitive = limitsEnabled && maxPercentage == 100; + lblEquipAll.Sensitive = limitsEnabled && maxPercentage == 100; + } + + private double GetMaxPercentage() + { + double min, max; + percentageAmount.GetRange(out min, out max); + return max; + } + + private double GetMinPercentage() + { + double min, max; + percentageAmount.GetRange(out min, out max); + return min; } public bool ShowControl() @@ -96,6 +112,52 @@ log.Debug("Okay clicked"); Respond(ResponseType.Ok); } + + public UnitEquipmentItem SelectedUnitEquipmentItem + { + get + { + return (UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment); + } + } + + + public bool IsRatioEquipmentAmount + { + get + { + return !rbEquipNumeric.Active; + } + } + + + public int EquipmentNumericAmount + { + get + { + return (int)numericAmount.Value; + } + } + + + public double EquipmentPercentageAmount + { + get + { + double percent; + + if (rbEquipAll.Active) + { + percent = 100; + } + else + { + percent = percentageAmount.Value; + } + + return percent; + } + } } }
--- a/FrmMainWindow.cs Wed Aug 25 20:04:27 2010 +0000 +++ b/FrmMainWindow.cs Thu Aug 26 19:30:22 2010 +0000 @@ -90,9 +90,10 @@ private static void HandleUnhandledException(Exception ex) { - LogManager.GetLogger(typeof(FrmMainWindow)).FatalFormat("({0}) {1} {2} {3}", ex.GetType().FullName, ex.Message, Environment.NewLine, GetStackTrace(ex)); + string msg = String.Format("({0}) {1}", ex.GetType().FullName, ex.Message); + LogManager.GetLogger(typeof(FrmMainWindow)).Fatal(msg, ex); MessageDialog dialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "An unhandled exception occurred. Please check the log for more details."); - dialog.Show(); + dialog.Run(); } private static string GetStackTrace(Exception ex) @@ -101,7 +102,7 @@ if (ex != null) { - message = "Caused by: " + ex.GetType().FullName + Environment.NewLine + ex.StackTrace + Environment.NewLine + GetStackTrace(ex.InnerException); + message = "Caused by: " + ex.GetType().FullName + Environment.NewLine + ex.StackTrace + Environment.NewLine ; } return message;
--- a/UIControl/AddEquipmentUIControl.cs Wed Aug 25 20:04:27 2010 +0000 +++ b/UIControl/AddEquipmentUIControl.cs Thu Aug 26 19:30:22 2010 +0000 @@ -6,6 +6,7 @@ using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Util; using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces; +using IBBoard.WarFoundry.API.Commands; namespace IBBoard.WarFoundry.GUI.GTK.UIControl { public class AddEquipmentUIControl @@ -67,8 +68,22 @@ public void Show() { - ui.ShowControl(); - //Do command stuff here + bool okayed = ui.ShowControl(); + + if (okayed) + { + UnitEquipmentItem equipItem = ui.SelectedUnitEquipmentItem; + + if (ui.IsRatioEquipmentAmount) + { + commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, ui.EquipmentPercentageAmount)); + } + else + { + commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, ui.EquipmentNumericAmount)); + } + } + ui.Dispose(); } }
--- a/UIControl/Interfaces/IAddEquipmentUI.cs Wed Aug 25 20:04:27 2010 +0000 +++ b/UIControl/Interfaces/IAddEquipmentUI.cs Thu Aug 26 19:30:22 2010 +0000 @@ -8,7 +8,7 @@ /// <summary> /// The interface that UI components should implement to represent "Add Equipment" dialogs or system equivalents (e.g. console areas or HTML fragments) /// </summary> - public interface IAddEquipmentUI + public interface IAddEquipmentUI : IDisposable { /// <summary> /// Should be fired when unit equipment item choice changes. @@ -58,19 +58,38 @@ /// <code>true</code> if the control was closed with "Okay", else <code>false</code> /// </returns> bool ShowControl(); - + /// <summary> - /// Releases all resource used by the <see cref="IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces.IAddEquipmentUI"/> object. + /// Gets the selected equipment item. + /// </summary> + /// <value> + /// The selected equipment item. + /// </value> + UnitEquipmentItem SelectedUnitEquipmentItem { get; } + + /// <summary> + /// Gets a value indicating whether the equipment amount is a ratio or an absolute number. /// </summary> - /// <remarks> - /// Call <see cref="Dispose"/> when you are finished using the - /// <see cref="IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces.IAddEquipmentUI"/>. The <see cref="Dispose"/> method - /// leaves the <see cref="IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces.IAddEquipmentUI"/> in an unusable state. - /// After calling <see cref="Dispose"/>, you must release all references to the - /// <see cref="IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces.IAddEquipmentUI"/> so the garbage collector can reclaim - /// the memory that the <see cref="IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces.IAddEquipmentUI"/> was occupying. - /// </remarks> - void Dispose(); + /// <value> + /// <c>true</c> if the selected amount is a ratio type (percentage or "all"); otherwise, <c>false</c>. + /// </value> + bool IsRatioEquipmentAmount { get; } + + /// <summary> + /// Gets the numeric amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>true</code> + /// </summary> + /// <value> + /// The absolue number of items taken. + /// </value> + int EquipmentNumericAmount { get; } + + /// <summary> + /// Gets the percentage amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>false</code> + /// </summary> + /// <value> + /// The number of items taken as a percentage of the unit size. + /// </value> + double EquipmentPercentageAmount { get; } } }