# HG changeset patch # User IBBoard # Date 1282487536 0 # Node ID 4bad8cb3f889e449250341418349c7e2cb730455 # Parent dafbd432ca235d570dcbc6792febdc9ee453d3f9 Re #60: Add UI to add/remove/edit weapons in GTK * Remove "not implemented" exceptions and add first implementation of setting equipment list * Add widgets to add equipment form * Subscribe to Clicked instead of Activated to hook on to correct event * Extract tree rendering method into helper class Also: * Improve exception handling of unhandled exceptions (print full stack trace with "caused by" hierarchy) diff -r dafbd432ca23 -r 4bad8cb3f889 FrmAddEquipment.cs --- a/FrmAddEquipment.cs Sat Aug 21 20:00:03 2010 +0000 +++ b/FrmAddEquipment.cs Sun Aug 22 14:32:16 2010 +0000 @@ -4,6 +4,8 @@ using System; using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces; using IBBoard.WarFoundry.API.Objects; +using Gtk; +using IBBoard.WarFoundry.GUI.GTK.Util; namespace IBBoard.WarFoundry.GUI.GTK { public partial class FrmAddEquipment : Gtk.Dialog, IAddEquipmentUI @@ -11,28 +13,42 @@ public FrmAddEquipment() { this.Build(); + + TreeViewColumn equipColumn = new TreeViewColumn(); + equipColumn.Title = "Equipment"; + CellRendererText equipCell = new CellRendererText(); + equipColumn.PackStart(equipCell, true); + equipColumn.SetCellDataFunc(equipCell, GtkWarFoundryUtil.RenderWarFoundryObjectName); + lstEquipment.AppendColumn(equipColumn); } public event SingleArgMethodInvoker UnitEquipmentItemChoiceChanged; public void SetUnitEquipmentItems(UnitEquipmentItem[] items) { - throw new NotImplementedException(); + ListStore store = new ListStore(typeof(UnitEquipmentItem)); + + foreach (UnitEquipmentItem equipItem in items) + { + store.AppendValues(equipItem); + } + + lstEquipment.Model = store; } 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 dafbd432ca23 -r 4bad8cb3f889 FrmMainWindow.cs --- a/FrmMainWindow.cs Sat Aug 21 20:00:03 2010 +0000 +++ b/FrmMainWindow.cs Sun Aug 22 14:32:16 2010 +0000 @@ -90,10 +90,22 @@ private static void HandleUnhandledException(Exception ex) { - LogManager.GetLogger(typeof(FrmMainWindow)).Fatal("(" + ex.GetType().Name + ") " + ex.Message + Environment.NewLine + ex.StackTrace); + LogManager.GetLogger(typeof(FrmMainWindow)).FatalFormat("({0}) {1} {2} {3}", ex.GetType().FullName, ex.Message, Environment.NewLine, GetStackTrace(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(); } + + private static string GetStackTrace(Exception ex) + { + string message = ""; + + if (ex != null) + { + message = "Caused by: " + ex.GetType().FullName + Environment.NewLine + ex.StackTrace + Environment.NewLine + GetStackTrace(ex.InnerException); + } + + return message; + } public FrmMainWindow() : this(new string[0]) { diff -r dafbd432ca23 -r 4bad8cb3f889 FrmNewArmy.cs --- a/FrmNewArmy.cs Sat Aug 21 20:00:03 2010 +0000 +++ b/FrmNewArmy.cs Sun Aug 22 14:32:16 2010 +0000 @@ -9,6 +9,7 @@ using IBBoard.WarFoundry.API.Objects; using IBBoard.GtkSharp; using log4net; +using IBBoard.WarFoundry.GUI.GTK.Util; namespace IBBoard.WarFoundry.GTK { @@ -42,7 +43,7 @@ CellRendererText raceCell = new CellRendererText (); raceColumn.PackStart (raceCell, true); lstRaces.AppendColumn(raceColumn); - raceColumn.SetCellDataFunc(raceCell, new TreeCellDataFunc(RenderRaceName)); + raceColumn.SetCellDataFunc(raceCell, GtkWarFoundryUtil.RenderWarFoundryObjectName); if (gameSystem!=null) @@ -56,12 +57,6 @@ get { return Title; } set { Title = value; } } - - private void RenderRaceName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) - { - Race r = (Race)model.GetValue(iter, 0); - (cell as CellRendererText).Text = r.Name; - } protected virtual void OnSelectionChanged(object o, EventArgs e) { diff -r dafbd432ca23 -r 4bad8cb3f889 IBBoard.WarFoundry.GUI.GTK.csproj --- a/IBBoard.WarFoundry.GUI.GTK.csproj Sat Aug 21 20:00:03 2010 +0000 +++ b/IBBoard.WarFoundry.GUI.GTK.csproj Sun Aug 22 14:32:16 2010 +0000 @@ -54,6 +54,7 @@ + @@ -110,5 +111,6 @@ + \ No newline at end of file diff -r dafbd432ca23 -r 4bad8cb3f889 Util/GtkWarFoundryUtil.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Util/GtkWarFoundryUtil.cs Sun Aug 22 14:32:16 2010 +0000 @@ -0,0 +1,18 @@ +// This file (GtkWarFoundryUtil.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; +using Gtk; +namespace IBBoard.WarFoundry.GUI.GTK.Util +{ + public class GtkWarFoundryUtil + { + public static void RenderWarFoundryObjectName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) + { + WarFoundryObject equip = (WarFoundryObject)model.GetValue(iter, 0); + (cell as CellRendererText).Text = equip.Name; + } + } +} + diff -r dafbd432ca23 -r 4bad8cb3f889 Widgets/UnitDisplayWidget.cs --- a/Widgets/UnitDisplayWidget.cs Sat Aug 21 20:00:03 2010 +0000 +++ b/Widgets/UnitDisplayWidget.cs Sun Aug 22 14:32:16 2010 +0000 @@ -146,9 +146,8 @@ } } - private void OnBttnAddEquipmentActivated(object sender, System.EventArgs e) + private void OnBttnAddEquipmentClicked(object sender, System.EventArgs e) { - Console.WriteLine("Add button clicked"); AddEquipment(); } diff -r dafbd432ca23 -r 4bad8cb3f889 gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs --- a/gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs Sat Aug 21 20:00:03 2010 +0000 +++ b/gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs Sun Aug 22 14:32:16 2010 +0000 @@ -226,7 +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); + this.bttnAddEquipment.Clicked += new global::System.EventHandler(this.OnBttnAddEquipmentClicked); } } } diff -r dafbd432ca23 -r 4bad8cb3f889 gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs Sat Aug 21 20:00:03 2010 +0000 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs Sun Aug 22 14:32:16 2010 +0000 @@ -4,6 +4,34 @@ { public partial class FrmAddEquipment { + private global::Gtk.Table table1; + + private global::Gtk.ScrolledWindow GtkScrolledWindow; + + private global::Gtk.TreeView lstEquipment; + + private global::Gtk.HBox hbox2; + + private global::Gtk.Table table2; + + private global::Gtk.Label lblEquipAll; + + private global::Gtk.Label lblPercent; + + private global::Gtk.RadioButton rbEquipAll; + + private global::Gtk.RadioButton rbEquipNumeric; + + private global::Gtk.RadioButton rbEquipPercent; + + private global::Gtk.SpinButton spinbutton1; + + private global::Gtk.SpinButton spinbutton2; + + private global::Gtk.Label lblEquipAmount; + + private global::Gtk.Label lblEquipment; + private global::Gtk.Button buttonCancel; private global::Gtk.Button buttonOk; @@ -18,12 +46,164 @@ global::Gtk.VBox w1 = this.VBox; w1.Name = "dialog1_VBox"; w1.BorderWidth = ((uint)(2)); + // Container child dialog1_VBox.Gtk.Box+BoxChild + this.table1 = new global::Gtk.Table(((uint)(2)), ((uint)(2)), false); + this.table1.Name = "table1"; + this.table1.RowSpacing = ((uint)(6)); + this.table1.ColumnSpacing = ((uint)(6)); + // Container child table1.Gtk.Table+TableChild + this.GtkScrolledWindow = new global::Gtk.ScrolledWindow(); + this.GtkScrolledWindow.Name = "GtkScrolledWindow"; + this.GtkScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1)); + // Container child GtkScrolledWindow.Gtk.Container+ContainerChild + this.lstEquipment = new global::Gtk.TreeView(); + this.lstEquipment.CanFocus = true; + this.lstEquipment.Name = "lstEquipment"; + this.GtkScrolledWindow.Add(this.lstEquipment); + this.table1.Add(this.GtkScrolledWindow); + global::Gtk.Table.TableChild w3 = ((global::Gtk.Table.TableChild)(this.table1[this.GtkScrolledWindow])); + w3.LeftAttach = ((uint)(1)); + w3.RightAttach = ((uint)(2)); + w3.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table1.Gtk.Table+TableChild + this.hbox2 = new global::Gtk.HBox(); + this.hbox2.Name = "hbox2"; + this.hbox2.Spacing = 6; + // Container child hbox2.Gtk.Box+BoxChild + this.table2 = new global::Gtk.Table(((uint)(3)), ((uint)(3)), false); + this.table2.Name = "table2"; + this.table2.RowSpacing = ((uint)(6)); + this.table2.ColumnSpacing = ((uint)(6)); + // Container child table2.Gtk.Table+TableChild + this.lblEquipAll = new global::Gtk.Label(); + this.lblEquipAll.Name = "lblEquipAll"; + this.lblEquipAll.LabelProp = global::Mono.Unix.Catalog.GetString("equip all"); + this.table2.Add(this.lblEquipAll); + global::Gtk.Table.TableChild w4 = ((global::Gtk.Table.TableChild)(this.table2[this.lblEquipAll])); + w4.TopAttach = ((uint)(2)); + w4.BottomAttach = ((uint)(3)); + w4.LeftAttach = ((uint)(1)); + w4.RightAttach = ((uint)(2)); + w4.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild + this.lblPercent = new global::Gtk.Label(); + this.lblPercent.Name = "lblPercent"; + this.lblPercent.LabelProp = global::Mono.Unix.Catalog.GetString("%"); + this.table2.Add(this.lblPercent); + global::Gtk.Table.TableChild w5 = ((global::Gtk.Table.TableChild)(this.table2[this.lblPercent])); + w5.TopAttach = ((uint)(1)); + w5.BottomAttach = ((uint)(2)); + w5.LeftAttach = ((uint)(2)); + w5.RightAttach = ((uint)(3)); + w5.XOptions = ((global::Gtk.AttachOptions)(4)); + w5.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild + this.rbEquipAll = new global::Gtk.RadioButton(""); + this.rbEquipAll.CanFocus = true; + this.rbEquipAll.Name = "rbEquipAll"; + this.rbEquipAll.DrawIndicator = true; + this.rbEquipAll.UseUnderline = true; + this.rbEquipAll.Group = new global::GLib.SList(global::System.IntPtr.Zero); + this.table2.Add(this.rbEquipAll); + global::Gtk.Table.TableChild w6 = ((global::Gtk.Table.TableChild)(this.table2[this.rbEquipAll])); + w6.TopAttach = ((uint)(2)); + w6.BottomAttach = ((uint)(3)); + w6.XOptions = ((global::Gtk.AttachOptions)(4)); + w6.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild + this.rbEquipNumeric = new global::Gtk.RadioButton(""); + this.rbEquipNumeric.CanFocus = true; + this.rbEquipNumeric.Name = "rbEquipNumeric"; + this.rbEquipNumeric.DrawIndicator = true; + this.rbEquipNumeric.UseUnderline = true; + this.rbEquipNumeric.Group = this.rbEquipAll.Group; + this.table2.Add(this.rbEquipNumeric); + global::Gtk.Table.TableChild w7 = ((global::Gtk.Table.TableChild)(this.table2[this.rbEquipNumeric])); + w7.XOptions = ((global::Gtk.AttachOptions)(4)); + w7.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild + this.rbEquipPercent = new global::Gtk.RadioButton(""); + this.rbEquipPercent.CanFocus = true; + this.rbEquipPercent.Name = "rbEquipPercent"; + this.rbEquipPercent.DrawIndicator = true; + this.rbEquipPercent.UseUnderline = true; + this.rbEquipPercent.Group = this.rbEquipAll.Group; + this.table2.Add(this.rbEquipPercent); + global::Gtk.Table.TableChild w8 = ((global::Gtk.Table.TableChild)(this.table2[this.rbEquipPercent])); + w8.TopAttach = ((uint)(1)); + w8.BottomAttach = ((uint)(2)); + w8.XOptions = ((global::Gtk.AttachOptions)(4)); + w8.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild + this.spinbutton1 = new global::Gtk.SpinButton(0, 100, 1); + this.spinbutton1.CanFocus = true; + this.spinbutton1.Name = "spinbutton1"; + this.spinbutton1.Adjustment.PageIncrement = 10; + this.spinbutton1.ClimbRate = 1; + this.spinbutton1.Numeric = true; + this.table2.Add(this.spinbutton1); + global::Gtk.Table.TableChild w9 = ((global::Gtk.Table.TableChild)(this.table2[this.spinbutton1])); + w9.LeftAttach = ((uint)(1)); + w9.RightAttach = ((uint)(2)); + w9.XOptions = ((global::Gtk.AttachOptions)(0)); + w9.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild + this.spinbutton2 = new global::Gtk.SpinButton(0, 100, 1); + this.spinbutton2.CanFocus = true; + this.spinbutton2.Name = "spinbutton2"; + this.spinbutton2.Adjustment.PageIncrement = 10; + this.spinbutton2.ClimbRate = 1; + this.spinbutton2.Digits = ((uint)(1)); + this.spinbutton2.Numeric = true; + this.table2.Add(this.spinbutton2); + global::Gtk.Table.TableChild w10 = ((global::Gtk.Table.TableChild)(this.table2[this.spinbutton2])); + w10.TopAttach = ((uint)(1)); + w10.BottomAttach = ((uint)(2)); + w10.LeftAttach = ((uint)(1)); + w10.RightAttach = ((uint)(2)); + w10.XOptions = ((global::Gtk.AttachOptions)(0)); + w10.YOptions = ((global::Gtk.AttachOptions)(4)); + this.hbox2.Add(this.table2); + global::Gtk.Box.BoxChild w11 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.table2])); + w11.Position = 0; + w11.Expand = false; + w11.Fill = false; + this.table1.Add(this.hbox2); + global::Gtk.Table.TableChild w12 = ((global::Gtk.Table.TableChild)(this.table1[this.hbox2])); + w12.TopAttach = ((uint)(1)); + w12.BottomAttach = ((uint)(2)); + w12.LeftAttach = ((uint)(1)); + w12.RightAttach = ((uint)(2)); + w12.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table1.Gtk.Table+TableChild + this.lblEquipAmount = new global::Gtk.Label(); + this.lblEquipAmount.Name = "lblEquipAmount"; + this.lblEquipAmount.LabelProp = global::Mono.Unix.Catalog.GetString("amount:"); + this.table1.Add(this.lblEquipAmount); + global::Gtk.Table.TableChild w13 = ((global::Gtk.Table.TableChild)(this.table1[this.lblEquipAmount])); + w13.TopAttach = ((uint)(1)); + w13.BottomAttach = ((uint)(2)); + w13.XOptions = ((global::Gtk.AttachOptions)(4)); + w13.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table1.Gtk.Table+TableChild + this.lblEquipment = new global::Gtk.Label(); + this.lblEquipment.Name = "lblEquipment"; + this.lblEquipment.LabelProp = global::Mono.Unix.Catalog.GetString("equipment"); + this.table1.Add(this.lblEquipment); + global::Gtk.Table.TableChild w14 = ((global::Gtk.Table.TableChild)(this.table1[this.lblEquipment])); + w14.XOptions = ((global::Gtk.AttachOptions)(4)); + w14.YOptions = ((global::Gtk.AttachOptions)(4)); + w1.Add(this.table1); + global::Gtk.Box.BoxChild w15 = ((global::Gtk.Box.BoxChild)(w1[this.table1])); + w15.Position = 0; + w15.Expand = false; + w15.Fill = false; // 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)); + global::Gtk.HButtonBox w16 = this.ActionArea; + w16.Name = "dialog1_ActionArea"; + w16.Spacing = 10; + w16.BorderWidth = ((uint)(5)); + w16.LayoutStyle = ((global::Gtk.ButtonBoxStyle)(4)); // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild this.buttonCancel = new global::Gtk.Button(); this.buttonCancel.CanDefault = true; @@ -33,9 +213,9 @@ 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; + global::Gtk.ButtonBox.ButtonBoxChild w17 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w16[this.buttonCancel])); + w17.Expand = false; + w17.Fill = false; // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild this.buttonOk = new global::Gtk.Button(); this.buttonOk.CanDefault = true; @@ -45,10 +225,10 @@ 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; + global::Gtk.ButtonBox.ButtonBoxChild w18 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w16[this.buttonOk])); + w18.Position = 1; + w18.Expand = false; + w18.Fill = false; if ((this.Child != null)) { this.Child.ShowAll(); diff -r dafbd432ca23 -r 4bad8cb3f889 gtk-gui/gui.stetic --- a/gtk-gui/gui.stetic Sat Aug 21 20:00:03 2010 +0000 +++ b/gtk-gui/gui.stetic Sun Aug 22 14:32:16 2010 +0000 @@ -874,7 +874,7 @@ TextOnly Add True - + 0 @@ -967,7 +967,288 @@ 2 - + + + 2 + 2 + 6 + 6 + + + + In + + + + True + True + False + + + + + 1 + 2 + True + Fill + True + True + False + False + True + False + + + + + + 6 + + + + 3 + 3 + 6 + 6 + + + + + + + + + + equip all + + + 2 + 3 + 1 + 2 + False + Fill + True + True + False + False + True + False + + + + + + % + + + 1 + 2 + 2 + 3 + True + Fill + Fill + False + True + False + False + True + False + + + + + + True + + True + True + True + True + group1 + + + 2 + 3 + True + Fill + Fill + False + True + False + False + True + False + + + + + + True + + True + True + True + group1 + + + False + Fill + Fill + False + True + False + False + True + False + + + + + + True + + True + True + True + group1 + + + 1 + 2 + True + Fill + Fill + False + True + False + False + True + False + + + + + + True + 100 + 10 + 1 + 1 + True + + + 1 + 2 + False + 0 + Fill + False + False + False + False + True + False + + + + + + True + 100 + 10 + 1 + 1 + 1 + True + + + 1 + 2 + 1 + 2 + False + 0 + Fill + False + False + False + False + True + False + + + + + 0 + True + False + False + + + + + + + + 1 + 2 + 1 + 2 + True + Fill + True + True + False + False + True + False + + + + + + amount: + + + 1 + 2 + True + Fill + Fill + False + True + False + False + True + False + + + + + + equipment + + + True + Fill + Fill + False + True + False + False + True + False + + + + + 0 + True + False + False +