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 diff
     1.1 --- a/FrmMainWindow.cs	Wed Oct 12 20:36:02 2011 +0100
     1.2 +++ b/FrmMainWindow.cs	Sat Oct 15 16:07:13 2011 +0100
     1.3 @@ -29,6 +29,7 @@
     1.4  using log4net;
     1.5  using WFObjects = IBBoard.WarFoundry.API.Objects;
     1.6  using IBBoard.WarFoundry.API.Savers.Xml;
     1.7 +using IBBoard.WarFoundry.API.Objects.Requirement;
     1.8  
     1.9  namespace IBBoard.WarFoundry.GUI.GTK
    1.10  {
    1.11 @@ -396,7 +397,7 @@
    1.12  
    1.13  		private void OnPointsValueChanged(WarFoundryObject obj, double before, double after)
    1.14  		{
    1.15 -			SetPointsPanelText();
    1.16 +			SetStatusBarText();
    1.17  		}
    1.18  
    1.19  		public Preferences Preferences
    1.20 @@ -522,6 +523,7 @@
    1.21  				oldArmy.PointsValueChanged -= PointsValueChangedMethod;
    1.22  				oldArmy.NameChanged -= OnArmyNameChanged;
    1.23  				oldArmy.MaxPointsValueChanged -= OnMaxPointsValueChanged;
    1.24 +				oldArmy.ArmyCompositionChanged -= HandleArmyCompositionChanged;
    1.25  			}
    1.26  
    1.27  			unitToWidgetMap.Clear();
    1.28 @@ -542,6 +544,7 @@
    1.29  				newArmy.PointsValueChanged += PointsValueChangedMethod;
    1.30  				newArmy.NameChanged += OnArmyNameChanged;
    1.31  				newArmy.MaxPointsValueChanged += OnMaxPointsValueChanged;
    1.32 +				newArmy.ArmyCompositionChanged += HandleArmyCompositionChanged;
    1.33  				//TODO: Clear all buttons
    1.34  				EnableCategoryButtons();
    1.35  
    1.36 @@ -557,14 +560,14 @@
    1.37  			miSaveArmyAs.Sensitive = nonNullNewArmy;
    1.38  			miExportArmyAs.Sensitive = nonNullNewArmy;
    1.39  			miEditArmy.Sensitive = nonNullNewArmy;
    1.40 -			hpaned2.Visible = nonNullNewArmy;
    1.41 +			treeUnits.Visible = nonNullNewArmy;
    1.42  			loadedArmyPath = null;
    1.43  			//New army has no changes, so we can't save it
    1.44  			miSaveArmy.Sensitive = false;
    1.45  			bttnSaveArmy.Sensitive = false;
    1.46  
    1.47  			CommandStack.Reset();
    1.48 -			SetPointsPanelText();
    1.49 +			SetStatusBarText();
    1.50  		}
    1.51  
    1.52  		private void OnArmyNameChanged (WarFoundryObject obj, string oldValue, string newValue)
    1.53 @@ -574,7 +577,12 @@
    1.54  
    1.55  		private void OnMaxPointsValueChanged (WarFoundryObject obj, int oldValue, int newValue)
    1.56  		{
    1.57 -			SetPointsPanelText();
    1.58 +			SetStatusBarText();
    1.59 +		}
    1.60 +
    1.61 +		private void HandleArmyCompositionChanged()
    1.62 +		{
    1.63 +			SetStatusBarText();
    1.64  		}
    1.65  
    1.66  		private void SetArmyTree(Army army)
    1.67 @@ -657,15 +665,57 @@
    1.68  			toolbar.ShowAll();
    1.69  		}
    1.70  
    1.71 -		private void SetPointsPanelText()
    1.72 +		private void SetStatusBarText()
    1.73  		{
    1.74  			if (WarFoundryCore.CurrentArmy != null)
    1.75  			{
    1.76 -				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));
    1.77 +				statusbar.Push(1, GetPointsText());
    1.78 +				SetValidationText();
    1.79  			}
    1.80  			else
    1.81  			{
    1.82 -				lblTotalPoints.Text = "";
    1.83 +				statusbar.Push(1, "");
    1.84 +				lblValidationWarning.Text = "";
    1.85 +			}
    1.86 +		}
    1.87 +
    1.88 +		private string GetPointsText()
    1.89 +		{
    1.90 +			int maxPts = WarFoundryCore.CurrentArmy.MaxPoints;
    1.91 +			string maxPtsAbbrev = WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(WarFoundryCore.CurrentArmy.MaxPoints);
    1.92 +			double points = WarFoundryCore.CurrentArmy.Points;
    1.93 +			string ptsAbbrev = WarFoundryCore.CurrentGameSystem.GetPointsAbbrev(WarFoundryCore.CurrentArmy.Points);
    1.94 +			return Translation.GetTranslation("statusPanelPoints", "{0}{2} of {1}{3}", points, maxPts, ptsAbbrev, maxPtsAbbrev);
    1.95 +		}
    1.96 +
    1.97 +		private void SetValidationText()
    1.98 +		{
    1.99 +			if (WarFoundryCore.CurrentGameSystem != null && WarFoundryCore.CurrentGameSystem.WarnOnError)
   1.100 +			{
   1.101 +				SetValidationTextAndColour();
   1.102 +			}
   1.103 +			else
   1.104 +			{
   1.105 +				lblValidationWarning.Text = "";
   1.106 +			}
   1.107 +		}
   1.108 +
   1.109 +		private void SetValidationTextAndColour()
   1.110 +		{
   1.111 +			ICollection<string> failureMessages;
   1.112 +			Validation result = RequirementHandler.ValidateArmy(WarFoundryCore.CurrentArmy, out failureMessages);
   1.113 +			string pluralHack = (failureMessages.Count == 1 ? "" : "s");
   1.114 +			lblValidationWarning.Text = String.Format("{0} validation warning{1}", failureMessages.Count, pluralHack);
   1.115 +			
   1.116 +			if (Validates.AsOkay(result))
   1.117 +			{
   1.118 +				lblValidationWarning.ModifyFg(StateType.Normal, Gdk.Color.Zero);
   1.119 +			}
   1.120 +			else
   1.121 +			{
   1.122 +				Gdk.Color red;
   1.123 +				Gdk.Color.Parse("#cc0000", ref red);
   1.124 +				lblValidationWarning.ModifyFg(StateType.Normal, red);
   1.125  			}
   1.126  		}
   1.127  
     2.1 --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.cs	Wed Oct 12 20:36:02 2011 +0100
     2.2 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.cs	Sat Oct 15 16:07:13 2011 +0100
     2.3 @@ -31,6 +31,7 @@
     2.4  			// Container child table1.Gtk.Table+TableChild
     2.5  			this.hbox2 = new global::Gtk.HBox ();
     2.6  			this.hbox2.Name = "hbox2";
     2.7 +			this.hbox2.Spacing = 0;
     2.8  			// Container child hbox2.Gtk.Box+BoxChild
     2.9  			this.sbPointsValue = new global::Gtk.SpinButton (0, 2000000000, 100);
    2.10  			this.sbPointsValue.WidthRequest = 150;
     3.1 --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs	Wed Oct 12 20:36:02 2011 +0100
     3.2 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs	Sat Oct 15 16:07:13 2011 +0100
     3.3 @@ -34,11 +34,11 @@
     3.4  		private global::Gtk.VBox vbox1;
     3.5  		private global::Gtk.MenuBar menubar1;
     3.6  		private global::Gtk.Toolbar toolbar;
     3.7 -		private global::Gtk.HPaned hpaned2;
     3.8 +		private global::Gtk.Statusbar statusbar;
     3.9 +		private global::Gtk.Label lblValidationWarning;
    3.10 +		private global::Gtk.HPaned mainContent;
    3.11  		private global::Gtk.TreeView treeUnits;
    3.12  		private global::Gtk.Notebook unitsNotebook;
    3.13 -		private global::Gtk.Statusbar statusbar1;
    3.14 -		private global::Gtk.Label lblTotalPoints;
    3.15  		
    3.16  		protected virtual void Build ()
    3.17  		{
    3.18 @@ -135,6 +135,7 @@
    3.19  			// Container child IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.Gtk.Container+ContainerChild
    3.20  			this.vbox1 = new global::Gtk.VBox ();
    3.21  			this.vbox1.Name = "vbox1";
    3.22 +			this.vbox1.Spacing = 0;
    3.23  			// Container child vbox1.Gtk.Box+BoxChild
    3.24  			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>");
    3.25  			this.menubar1 = ((global::Gtk.MenuBar)(this.UIManager.GetWidget ("/menubar1")));
    3.26 @@ -158,53 +159,57 @@
    3.27  			w3.Expand = false;
    3.28  			w3.Fill = false;
    3.29  			// Container child vbox1.Gtk.Box+BoxChild
    3.30 -			this.hpaned2 = new global::Gtk.HPaned ();
    3.31 -			this.hpaned2.CanFocus = true;
    3.32 -			this.hpaned2.Name = "hpaned2";
    3.33 -			this.hpaned2.Position = 178;
    3.34 -			// Container child hpaned2.Gtk.Paned+PanedChild
    3.35 +			this.statusbar = new global::Gtk.Statusbar ();
    3.36 +			this.statusbar.Name = "statusbar";
    3.37 +			this.statusbar.Spacing = 6;
    3.38 +			this.statusbar.BorderWidth = ((uint)(1));
    3.39 +			// Container child statusbar.Gtk.Box+BoxChild
    3.40 +			this.lblValidationWarning = new global::Gtk.Label ();
    3.41 +			this.lblValidationWarning.Name = "lblValidationWarning";
    3.42 +			this.statusbar.Add (this.lblValidationWarning);
    3.43 +			global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(this.statusbar [this.lblValidationWarning]));
    3.44 +			w4.PackType = ((global::Gtk.PackType)(1));
    3.45 +			w4.Position = 1;
    3.46 +			w4.Expand = false;
    3.47 +			w4.Fill = false;
    3.48 +			this.vbox1.Add (this.statusbar);
    3.49 +			global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.statusbar]));
    3.50 +			w5.PackType = ((global::Gtk.PackType)(1));
    3.51 +			w5.Position = 2;
    3.52 +			w5.Expand = false;
    3.53 +			w5.Fill = false;
    3.54 +			// Container child vbox1.Gtk.Box+BoxChild
    3.55 +			this.mainContent = new global::Gtk.HPaned ();
    3.56 +			this.mainContent.CanFocus = true;
    3.57 +			this.mainContent.Name = "mainContent";
    3.58 +			this.mainContent.Position = 180;
    3.59 +			// Container child mainContent.Gtk.Paned+PanedChild
    3.60  			this.treeUnits = new global::Gtk.TreeView ();
    3.61  			this.treeUnits.CanFocus = true;
    3.62  			this.treeUnits.Name = "treeUnits";
    3.63 -			this.hpaned2.Add (this.treeUnits);
    3.64 -			global::Gtk.Paned.PanedChild w4 = ((global::Gtk.Paned.PanedChild)(this.hpaned2 [this.treeUnits]));
    3.65 -			w4.Resize = false;
    3.66 -			// Container child hpaned2.Gtk.Paned+PanedChild
    3.67 +			this.mainContent.Add (this.treeUnits);
    3.68 +			global::Gtk.Paned.PanedChild w6 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.treeUnits]));
    3.69 +			w6.Resize = false;
    3.70 +			// Container child mainContent.Gtk.Paned+PanedChild
    3.71  			this.unitsNotebook = new global::Gtk.Notebook ();
    3.72  			this.unitsNotebook.CanFocus = true;
    3.73  			this.unitsNotebook.Name = "unitsNotebook";
    3.74  			this.unitsNotebook.CurrentPage = -1;
    3.75  			this.unitsNotebook.Scrollable = true;
    3.76 -			this.hpaned2.Add (this.unitsNotebook);
    3.77 -			global::Gtk.Paned.PanedChild w5 = ((global::Gtk.Paned.PanedChild)(this.hpaned2 [this.unitsNotebook]));
    3.78 -			w5.Shrink = false;
    3.79 -			this.vbox1.Add (this.hpaned2);
    3.80 -			global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.hpaned2]));
    3.81 -			w6.Position = 2;
    3.82 -			// Container child vbox1.Gtk.Box+BoxChild
    3.83 -			this.statusbar1 = new global::Gtk.Statusbar ();
    3.84 -			this.statusbar1.Name = "statusbar1";
    3.85 -			this.statusbar1.Spacing = 2;
    3.86 -			// Container child statusbar1.Gtk.Box+BoxChild
    3.87 -			this.lblTotalPoints = new global::Gtk.Label ();
    3.88 -			this.lblTotalPoints.Name = "lblTotalPoints";
    3.89 -			this.statusbar1.Add (this.lblTotalPoints);
    3.90 -			global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(this.statusbar1 [this.lblTotalPoints]));
    3.91 -			w7.Position = 2;
    3.92 -			w7.Expand = false;
    3.93 -			w7.Fill = false;
    3.94 -			this.vbox1.Add (this.statusbar1);
    3.95 -			global::Gtk.Box.BoxChild w8 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.statusbar1]));
    3.96 +			this.mainContent.Add (this.unitsNotebook);
    3.97 +			global::Gtk.Paned.PanedChild w7 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.unitsNotebook]));
    3.98 +			w7.Shrink = false;
    3.99 +			this.vbox1.Add (this.mainContent);
   3.100 +			global::Gtk.Box.BoxChild w8 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.mainContent]));
   3.101 +			w8.PackType = ((global::Gtk.PackType)(1));
   3.102  			w8.Position = 3;
   3.103 -			w8.Expand = false;
   3.104 -			w8.Fill = false;
   3.105  			this.Add (this.vbox1);
   3.106  			if ((this.Child != null)) {
   3.107  				this.Child.ShowAll ();
   3.108  			}
   3.109  			this.DefaultWidth = 832;
   3.110  			this.DefaultHeight = 659;
   3.111 -			this.hpaned2.Hide ();
   3.112 +			this.treeUnits.Hide ();
   3.113  			this.Show ();
   3.114  			this.miNewArmy.Activated += new global::System.EventHandler (this.OnCreateArmyActivated);
   3.115  			this.miOpenArmy.Activated += new global::System.EventHandler (this.OnOpenArmyActivated);
     4.1 --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewArmy.cs	Wed Oct 12 20:36:02 2011 +0100
     4.2 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewArmy.cs	Sat Oct 15 16:07:13 2011 +0100
     4.3 @@ -63,6 +63,7 @@
     4.4  			// Container child table1.Gtk.Table+TableChild
     4.5  			this.hbox2 = new global::Gtk.HBox ();
     4.6  			this.hbox2.Name = "hbox2";
     4.7 +			this.hbox2.Spacing = 0;
     4.8  			// Container child hbox2.Gtk.Box+BoxChild
     4.9  			this.sbPointsValue = new global::Gtk.SpinButton (0, 2000000000, 100);
    4.10  			this.sbPointsValue.WidthRequest = 150;
     5.1 --- a/gtk-gui/gui.stetic	Wed Oct 12 20:36:02 2011 +0100
     5.2 +++ b/gtk-gui/gui.stetic	Sat Oct 15 16:07:13 2011 +0100
     5.3 @@ -186,6 +186,7 @@
     5.4      <child>
     5.5        <widget class="Gtk.VBox" id="vbox1">
     5.6          <property name="MemberName" />
     5.7 +        <property name="Spacing">0</property>
     5.8          <child>
     5.9            <widget class="Gtk.MenuBar" id="menubar1">
    5.10              <property name="MemberName" />
    5.11 @@ -250,14 +251,40 @@
    5.12            </packing>
    5.13          </child>
    5.14          <child>
    5.15 -          <widget class="Gtk.HPaned" id="hpaned2">
    5.16 +          <widget class="Gtk.Statusbar" id="statusbar">
    5.17              <property name="MemberName" />
    5.18 -            <property name="Visible">False</property>
    5.19 +            <property name="Spacing">6</property>
    5.20 +            <property name="BorderWidth">1</property>
    5.21 +            <child>
    5.22 +              <widget class="Gtk.Label" id="lblValidationWarning">
    5.23 +                <property name="MemberName" />
    5.24 +              </widget>
    5.25 +              <packing>
    5.26 +                <property name="PackType">End</property>
    5.27 +                <property name="Position">1</property>
    5.28 +                <property name="AutoSize">True</property>
    5.29 +                <property name="Expand">False</property>
    5.30 +                <property name="Fill">False</property>
    5.31 +              </packing>
    5.32 +            </child>
    5.33 +          </widget>
    5.34 +          <packing>
    5.35 +            <property name="PackType">End</property>
    5.36 +            <property name="Position">2</property>
    5.37 +            <property name="AutoSize">True</property>
    5.38 +            <property name="Expand">False</property>
    5.39 +            <property name="Fill">False</property>
    5.40 +          </packing>
    5.41 +        </child>
    5.42 +        <child>
    5.43 +          <widget class="Gtk.HPaned" id="mainContent">
    5.44 +            <property name="MemberName" />
    5.45              <property name="CanFocus">True</property>
    5.46 -            <property name="Position">178</property>
    5.47 +            <property name="Position">180</property>
    5.48              <child>
    5.49                <widget class="Gtk.TreeView" id="treeUnits">
    5.50                  <property name="MemberName" />
    5.51 +                <property name="Visible">False</property>
    5.52                  <property name="CanFocus">True</property>
    5.53                  <signal name="RowActivated" handler="ArmyRowActivated" />
    5.54                  <signal name="PopupMenu" handler="OnTreeUnitsPopupMenu" />
    5.55 @@ -281,34 +308,9 @@
    5.56              </child>
    5.57            </widget>
    5.58            <packing>
    5.59 -            <property name="Position">2</property>
    5.60 -            <property name="AutoSize">True</property>
    5.61 -          </packing>
    5.62 -        </child>
    5.63 -        <child>
    5.64 -          <widget class="Gtk.Statusbar" id="statusbar1">
    5.65 -            <property name="MemberName" />
    5.66 -            <property name="Spacing">2</property>
    5.67 -            <child>
    5.68 -              <placeholder />
    5.69 -            </child>
    5.70 -            <child>
    5.71 -              <widget class="Gtk.Label" id="lblTotalPoints">
    5.72 -                <property name="MemberName" />
    5.73 -              </widget>
    5.74 -              <packing>
    5.75 -                <property name="Position">2</property>
    5.76 -                <property name="AutoSize">True</property>
    5.77 -                <property name="Expand">False</property>
    5.78 -                <property name="Fill">False</property>
    5.79 -              </packing>
    5.80 -            </child>
    5.81 -          </widget>
    5.82 -          <packing>
    5.83 +            <property name="PackType">End</property>
    5.84              <property name="Position">3</property>
    5.85 -            <property name="AutoSize">True</property>
    5.86 -            <property name="Expand">False</property>
    5.87 -            <property name="Fill">False</property>
    5.88 +            <property name="AutoSize">False</property>
    5.89            </packing>
    5.90          </child>
    5.91        </widget>
    5.92 @@ -371,6 +373,7 @@
    5.93              <child>
    5.94                <widget class="Gtk.HBox" id="hbox2">
    5.95                  <property name="MemberName" />
    5.96 +                <property name="Spacing">0</property>
    5.97                  <child>
    5.98                    <widget class="Gtk.SpinButton" id="sbPointsValue">
    5.99                      <property name="MemberName" />
   5.100 @@ -2639,6 +2642,7 @@
   5.101              <child>
   5.102                <widget class="Gtk.HBox" id="hbox2">
   5.103                  <property name="MemberName" />
   5.104 +                <property name="Spacing">0</property>
   5.105                  <child>
   5.106                    <widget class="Gtk.SpinButton" id="sbPointsValue">
   5.107                      <property name="MemberName" />