changeset 140:2b9fabd65309

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
author IBBoard <dev@ibboard.co.uk>
date Sat, 15 Oct 2011 16:07:13 +0100
parents d4b726cec12c
children 1ce4fe9ae3c1
files FrmMainWindow.cs gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.cs gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewArmy.cs gtk-gui/gui.stetic
diffstat 5 files changed, 133 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- 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<string> 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);
 			}
 		}
 
--- 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;
--- 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 ("<ui><menubar name='menubar1'><menu name='menuFile' action='menuFile'><menuitem name='miNewArmy' action='miNewArmy'/><menuitem name='miOpenArmy' action='miOpenArmy'/><menuitem name='miSaveArmy' action='miSaveArmy'/><menuitem name='miSaveArmyAs' action='miSaveArmyAs'/><menu name='miExportArmyAs' action='miExportArmyAs'><menuitem name='miExportArmyAsBasicHTML' action='miExportArmyAsBasicHTML'/><menuitem name='miExportArmyAsTransformedXml' action='miExportArmyAsTransformedXml'/></menu><menuitem name='miCloseArmy' action='miCloseArmy'/><separator/><menuitem name='miReloadFiles' action='miReloadFiles'/><separator/><menuitem name='miExit' action='miExit'/></menu><menu name='menuEdit' action='menuEdit'><menuitem name='miUndo' action='miUndo'/><menuitem name='miRedo' action='miRedo'/><separator/><menuitem name='miEditArmy' action='miEditArmy'/><separator/><menuitem name='miPreferences' action='miPreferences'/></menu><menu name='menuHelp' action='menuHelp'><menuitem name='miAbout' action='miAbout'/></menu></menubar></ui>");
 			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);
--- 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;
--- 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 @@
     <child>
       <widget class="Gtk.VBox" id="vbox1">
         <property name="MemberName" />
+        <property name="Spacing">0</property>
         <child>
           <widget class="Gtk.MenuBar" id="menubar1">
             <property name="MemberName" />
@@ -250,14 +251,40 @@
           </packing>
         </child>
         <child>
-          <widget class="Gtk.HPaned" id="hpaned2">
+          <widget class="Gtk.Statusbar" id="statusbar">
             <property name="MemberName" />
-            <property name="Visible">False</property>
+            <property name="Spacing">6</property>
+            <property name="BorderWidth">1</property>
+            <child>
+              <widget class="Gtk.Label" id="lblValidationWarning">
+                <property name="MemberName" />
+              </widget>
+              <packing>
+                <property name="PackType">End</property>
+                <property name="Position">1</property>
+                <property name="AutoSize">True</property>
+                <property name="Expand">False</property>
+                <property name="Fill">False</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="PackType">End</property>
+            <property name="Position">2</property>
+            <property name="AutoSize">True</property>
+            <property name="Expand">False</property>
+            <property name="Fill">False</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="Gtk.HPaned" id="mainContent">
+            <property name="MemberName" />
             <property name="CanFocus">True</property>
-            <property name="Position">178</property>
+            <property name="Position">180</property>
             <child>
               <widget class="Gtk.TreeView" id="treeUnits">
                 <property name="MemberName" />
+                <property name="Visible">False</property>
                 <property name="CanFocus">True</property>
                 <signal name="RowActivated" handler="ArmyRowActivated" />
                 <signal name="PopupMenu" handler="OnTreeUnitsPopupMenu" />
@@ -281,34 +308,9 @@
             </child>
           </widget>
           <packing>
-            <property name="Position">2</property>
-            <property name="AutoSize">True</property>
-          </packing>
-        </child>
-        <child>
-          <widget class="Gtk.Statusbar" id="statusbar1">
-            <property name="MemberName" />
-            <property name="Spacing">2</property>
-            <child>
-              <placeholder />
-            </child>
-            <child>
-              <widget class="Gtk.Label" id="lblTotalPoints">
-                <property name="MemberName" />
-              </widget>
-              <packing>
-                <property name="Position">2</property>
-                <property name="AutoSize">True</property>
-                <property name="Expand">False</property>
-                <property name="Fill">False</property>
-              </packing>
-            </child>
-          </widget>
-          <packing>
+            <property name="PackType">End</property>
             <property name="Position">3</property>
-            <property name="AutoSize">True</property>
-            <property name="Expand">False</property>
-            <property name="Fill">False</property>
+            <property name="AutoSize">False</property>
           </packing>
         </child>
       </widget>
@@ -371,6 +373,7 @@
             <child>
               <widget class="Gtk.HBox" id="hbox2">
                 <property name="MemberName" />
+                <property name="Spacing">0</property>
                 <child>
                   <widget class="Gtk.SpinButton" id="sbPointsValue">
                     <property name="MemberName" />
@@ -2639,6 +2642,7 @@
             <child>
               <widget class="Gtk.HBox" id="hbox2">
                 <property name="MemberName" />
+                <property name="Spacing">0</property>
                 <child>
                   <widget class="Gtk.SpinButton" id="sbPointsValue">
                     <property name="MemberName" />