# HG changeset patch # User IBBoard # Date 1318691233 -3600 # Node ID 2b9fabd653094998594c605d47adb784bb47ca4c # Parent d4b726cec12c83040acce45464ffc395ef9f0a18 Re #344: Show unit requirement failures * Use status bar properly * Add initial validation label * Make use of new event from Army to see when things changed Also: * Commit some automated changes diff -r d4b726cec12c -r 2b9fabd65309 FrmMainWindow.cs --- a/FrmMainWindow.cs Wed Oct 12 20:36:02 2011 +0100 +++ b/FrmMainWindow.cs Sat Oct 15 16:07:13 2011 +0100 @@ -29,6 +29,7 @@ using log4net; using WFObjects = IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Savers.Xml; +using IBBoard.WarFoundry.API.Objects.Requirement; namespace IBBoard.WarFoundry.GUI.GTK { @@ -396,7 +397,7 @@ private void OnPointsValueChanged(WarFoundryObject obj, double before, double after) { - SetPointsPanelText(); + SetStatusBarText(); } public Preferences Preferences @@ -522,6 +523,7 @@ oldArmy.PointsValueChanged -= PointsValueChangedMethod; oldArmy.NameChanged -= OnArmyNameChanged; oldArmy.MaxPointsValueChanged -= OnMaxPointsValueChanged; + oldArmy.ArmyCompositionChanged -= HandleArmyCompositionChanged; } unitToWidgetMap.Clear(); @@ -542,6 +544,7 @@ newArmy.PointsValueChanged += PointsValueChangedMethod; newArmy.NameChanged += OnArmyNameChanged; newArmy.MaxPointsValueChanged += OnMaxPointsValueChanged; + newArmy.ArmyCompositionChanged += HandleArmyCompositionChanged; //TODO: Clear all buttons EnableCategoryButtons(); @@ -557,14 +560,14 @@ miSaveArmyAs.Sensitive = nonNullNewArmy; miExportArmyAs.Sensitive = nonNullNewArmy; miEditArmy.Sensitive = nonNullNewArmy; - hpaned2.Visible = nonNullNewArmy; + treeUnits.Visible = nonNullNewArmy; loadedArmyPath = null; //New army has no changes, so we can't save it miSaveArmy.Sensitive = false; bttnSaveArmy.Sensitive = false; CommandStack.Reset(); - SetPointsPanelText(); + SetStatusBarText(); } private void OnArmyNameChanged (WarFoundryObject obj, string oldValue, string newValue) @@ -574,7 +577,12 @@ private void OnMaxPointsValueChanged (WarFoundryObject obj, int oldValue, int newValue) { - SetPointsPanelText(); + SetStatusBarText(); + } + + private void HandleArmyCompositionChanged() + { + SetStatusBarText(); } private void SetArmyTree(Army army) @@ -657,15 +665,57 @@ toolbar.ShowAll(); } - private void SetPointsPanelText() + private void SetStatusBarText() { if (WarFoundryCore.CurrentArmy != null) { - lblTotalPoints.Text = Translation.GetTranslation("statusPanelPoints", "{0}{2} of {1}{3}", WarFoundryCore.CurrentArmy.Points, WarFoundryCore.CurrentArmy.MaxPoints, WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(WarFoundryCore.CurrentArmy.Points), WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(WarFoundryCore.CurrentArmy.MaxPoints)); + statusbar.Push(1, GetPointsText()); + SetValidationText(); } else { - lblTotalPoints.Text = ""; + statusbar.Push(1, ""); + lblValidationWarning.Text = ""; + } + } + + private string GetPointsText() + { + int maxPts = WarFoundryCore.CurrentArmy.MaxPoints; + string maxPtsAbbrev = WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(WarFoundryCore.CurrentArmy.MaxPoints); + double points = WarFoundryCore.CurrentArmy.Points; + string ptsAbbrev = WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(WarFoundryCore.CurrentArmy.Points); + return Translation.GetTranslation("statusPanelPoints", "{0}{2} of {1}{3}", points, maxPts, ptsAbbrev, maxPtsAbbrev); + } + + private void SetValidationText() + { + if (WarFoundryCore.CurrentGameSystem != null && WarFoundryCore.CurrentGameSystem.WarnOnError) + { + SetValidationTextAndColour(); + } + else + { + lblValidationWarning.Text = ""; + } + } + + private void SetValidationTextAndColour() + { + ICollection failureMessages; + Validation result = RequirementHandler.ValidateArmy(WarFoundryCore.CurrentArmy, out failureMessages); + string pluralHack = (failureMessages.Count == 1 ? "" : "s"); + lblValidationWarning.Text = String.Format("{0} validation warning{1}", failureMessages.Count, pluralHack); + + if (Validates.AsOkay(result)) + { + lblValidationWarning.ModifyFg(StateType.Normal, Gdk.Color.Zero); + } + else + { + Gdk.Color red; + Gdk.Color.Parse("#cc0000", ref red); + lblValidationWarning.ModifyFg(StateType.Normal, red); } } diff -r d4b726cec12c -r 2b9fabd65309 gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.cs --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.cs Wed Oct 12 20:36:02 2011 +0100 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.cs Sat Oct 15 16:07:13 2011 +0100 @@ -31,6 +31,7 @@ // Container child table1.Gtk.Table+TableChild this.hbox2 = new global::Gtk.HBox (); this.hbox2.Name = "hbox2"; + this.hbox2.Spacing = 0; // Container child hbox2.Gtk.Box+BoxChild this.sbPointsValue = new global::Gtk.SpinButton (0, 2000000000, 100); this.sbPointsValue.WidthRequest = 150; diff -r d4b726cec12c -r 2b9fabd65309 gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs Wed Oct 12 20:36:02 2011 +0100 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs Sat Oct 15 16:07:13 2011 +0100 @@ -34,11 +34,11 @@ private global::Gtk.VBox vbox1; private global::Gtk.MenuBar menubar1; private global::Gtk.Toolbar toolbar; - private global::Gtk.HPaned hpaned2; + private global::Gtk.Statusbar statusbar; + private global::Gtk.Label lblValidationWarning; + private global::Gtk.HPaned mainContent; private global::Gtk.TreeView treeUnits; private global::Gtk.Notebook unitsNotebook; - private global::Gtk.Statusbar statusbar1; - private global::Gtk.Label lblTotalPoints; protected virtual void Build () { @@ -135,6 +135,7 @@ // Container child IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.Gtk.Container+ContainerChild this.vbox1 = new global::Gtk.VBox (); this.vbox1.Name = "vbox1"; + this.vbox1.Spacing = 0; // Container child vbox1.Gtk.Box+BoxChild this.UIManager.AddUiFromString (""); this.menubar1 = ((global::Gtk.MenuBar)(this.UIManager.GetWidget ("/menubar1"))); @@ -158,53 +159,57 @@ w3.Expand = false; w3.Fill = false; // Container child vbox1.Gtk.Box+BoxChild - this.hpaned2 = new global::Gtk.HPaned (); - this.hpaned2.CanFocus = true; - this.hpaned2.Name = "hpaned2"; - this.hpaned2.Position = 178; - // Container child hpaned2.Gtk.Paned+PanedChild + this.statusbar = new global::Gtk.Statusbar (); + this.statusbar.Name = "statusbar"; + this.statusbar.Spacing = 6; + this.statusbar.BorderWidth = ((uint)(1)); + // Container child statusbar.Gtk.Box+BoxChild + this.lblValidationWarning = new global::Gtk.Label (); + this.lblValidationWarning.Name = "lblValidationWarning"; + this.statusbar.Add (this.lblValidationWarning); + global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(this.statusbar [this.lblValidationWarning])); + w4.PackType = ((global::Gtk.PackType)(1)); + w4.Position = 1; + w4.Expand = false; + w4.Fill = false; + this.vbox1.Add (this.statusbar); + global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.statusbar])); + w5.PackType = ((global::Gtk.PackType)(1)); + w5.Position = 2; + w5.Expand = false; + w5.Fill = false; + // Container child vbox1.Gtk.Box+BoxChild + this.mainContent = new global::Gtk.HPaned (); + this.mainContent.CanFocus = true; + this.mainContent.Name = "mainContent"; + this.mainContent.Position = 180; + // Container child mainContent.Gtk.Paned+PanedChild this.treeUnits = new global::Gtk.TreeView (); this.treeUnits.CanFocus = true; this.treeUnits.Name = "treeUnits"; - this.hpaned2.Add (this.treeUnits); - global::Gtk.Paned.PanedChild w4 = ((global::Gtk.Paned.PanedChild)(this.hpaned2 [this.treeUnits])); - w4.Resize = false; - // Container child hpaned2.Gtk.Paned+PanedChild + this.mainContent.Add (this.treeUnits); + global::Gtk.Paned.PanedChild w6 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.treeUnits])); + w6.Resize = false; + // Container child mainContent.Gtk.Paned+PanedChild this.unitsNotebook = new global::Gtk.Notebook (); this.unitsNotebook.CanFocus = true; this.unitsNotebook.Name = "unitsNotebook"; this.unitsNotebook.CurrentPage = -1; this.unitsNotebook.Scrollable = true; - this.hpaned2.Add (this.unitsNotebook); - global::Gtk.Paned.PanedChild w5 = ((global::Gtk.Paned.PanedChild)(this.hpaned2 [this.unitsNotebook])); - w5.Shrink = false; - this.vbox1.Add (this.hpaned2); - global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.hpaned2])); - w6.Position = 2; - // Container child vbox1.Gtk.Box+BoxChild - this.statusbar1 = new global::Gtk.Statusbar (); - this.statusbar1.Name = "statusbar1"; - this.statusbar1.Spacing = 2; - // Container child statusbar1.Gtk.Box+BoxChild - this.lblTotalPoints = new global::Gtk.Label (); - this.lblTotalPoints.Name = "lblTotalPoints"; - this.statusbar1.Add (this.lblTotalPoints); - global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(this.statusbar1 [this.lblTotalPoints])); - w7.Position = 2; - w7.Expand = false; - w7.Fill = false; - this.vbox1.Add (this.statusbar1); - global::Gtk.Box.BoxChild w8 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.statusbar1])); + this.mainContent.Add (this.unitsNotebook); + global::Gtk.Paned.PanedChild w7 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.unitsNotebook])); + w7.Shrink = false; + this.vbox1.Add (this.mainContent); + global::Gtk.Box.BoxChild w8 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.mainContent])); + w8.PackType = ((global::Gtk.PackType)(1)); w8.Position = 3; - w8.Expand = false; - w8.Fill = false; this.Add (this.vbox1); if ((this.Child != null)) { this.Child.ShowAll (); } this.DefaultWidth = 832; this.DefaultHeight = 659; - this.hpaned2.Hide (); + this.treeUnits.Hide (); this.Show (); this.miNewArmy.Activated += new global::System.EventHandler (this.OnCreateArmyActivated); this.miOpenArmy.Activated += new global::System.EventHandler (this.OnOpenArmyActivated); diff -r d4b726cec12c -r 2b9fabd65309 gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewArmy.cs --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewArmy.cs Wed Oct 12 20:36:02 2011 +0100 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewArmy.cs Sat Oct 15 16:07:13 2011 +0100 @@ -63,6 +63,7 @@ // Container child table1.Gtk.Table+TableChild this.hbox2 = new global::Gtk.HBox (); this.hbox2.Name = "hbox2"; + this.hbox2.Spacing = 0; // Container child hbox2.Gtk.Box+BoxChild this.sbPointsValue = new global::Gtk.SpinButton (0, 2000000000, 100); this.sbPointsValue.WidthRequest = 150; diff -r d4b726cec12c -r 2b9fabd65309 gtk-gui/gui.stetic --- a/gtk-gui/gui.stetic Wed Oct 12 20:36:02 2011 +0100 +++ b/gtk-gui/gui.stetic Sat Oct 15 16:07:13 2011 +0100 @@ -186,6 +186,7 @@ + 0 @@ -250,14 +251,40 @@ - + - False + 6 + 1 + + + + + + End + 1 + True + False + False + + + + + End + 2 + True + False + False + + + + + True - 178 + 180 + False True @@ -281,34 +308,9 @@ - 2 - True - - - - - - 2 - - - - - - - - - 2 - True - False - False - - - - + End 3 - True - False - False + False @@ -371,6 +373,7 @@ + 0 @@ -2639,6 +2642,7 @@ + 0