changeset 110:76b73f15d07e

Re #344: Show unit requirement failures * First pass using new Requirement objects on FrmNewUnit - needs more testing and styling * Remove old references from main window until we get a replacement
author IBBoard <dev@ibboard.co.uk>
date Mon, 01 Aug 2011 20:22:48 +0000
parents 4ae69806bb2d
children a757f41ca0ef
files FrmMainWindow.cs FrmNewUnit.cs IBBoard.WarFoundry.GUI.GTK.sln gtk-gui/gui.stetic
diffstat 4 files changed, 18 insertions(+), 20 deletions(-) [+]
line diff
     1.1 --- a/FrmMainWindow.cs	Sun May 01 13:07:15 2011 +0000
     1.2 +++ b/FrmMainWindow.cs	Mon Aug 01 20:22:48 2011 +0000
     1.3 @@ -23,7 +23,6 @@
     1.4  using IBBoard.WarFoundry.API.Factories;
     1.5  using IBBoard.WarFoundry.API.Factories.Xml;
     1.6  using IBBoard.WarFoundry.API.Objects;
     1.7 -using IBBoard.WarFoundry.API.Requirements;
     1.8  using IBBoard.WarFoundry.API.Savers;
     1.9  using IBBoard.WarFoundry.GUI.GTK.Widgets;
    1.10  using IBBoard.Xml;
    1.11 @@ -44,7 +43,6 @@
    1.12  		private ObjectAddDelegate UnitAddedMethod;
    1.13  		private ObjectRemoveDelegate UnitRemovedMethod;
    1.14  		private DoubleValChangedDelegate PointsValueChangedMethod;
    1.15 -		private FailedUnitRequirementDelegate FailedUnitRequirementMethod;
    1.16  		private StringValChangedDelegate UnitNameChangedMethod;
    1.17  		private GameSystem system;
    1.18  		private string loadedArmyPath;
    1.19 @@ -152,7 +150,6 @@
    1.20  			UnitAddedMethod = new ObjectAddDelegate(OnUnitAdded);
    1.21  			UnitRemovedMethod = new ObjectRemoveDelegate(OnUnitRemoved);
    1.22  			PointsValueChangedMethod = new DoubleValChangedDelegate(OnPointsValueChanged);
    1.23 -			FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(OnFailedUnitRequirement);
    1.24  			UnitNameChangedMethod = new StringValChangedDelegate(OnUnitNameChanged);
    1.25  
    1.26  			//FIXME: Temporary hack to add paths and factories before we get preferences and plugins
    1.27 @@ -402,11 +399,6 @@
    1.28  			SetPointsPanelText();
    1.29  		}
    1.30  
    1.31 -		private void OnFailedUnitRequirement(List<FailedUnitRequirement> failedRequirement)
    1.32 -		{
    1.33 -			//Show error message in panel
    1.34 -		}
    1.35 -
    1.36  		public Preferences Preferences
    1.37  		{
    1.38  			get { return preferences; }
    1.39 @@ -528,7 +520,6 @@
    1.40  				oldArmy.UnitAdded -= UnitAddedMethod;
    1.41  				oldArmy.UnitRemoved -= UnitRemovedMethod;
    1.42  				oldArmy.PointsValueChanged -= PointsValueChangedMethod;
    1.43 -				oldArmy.FailedRequirement -= FailedUnitRequirementMethod;
    1.44  			}
    1.45  
    1.46  			unitToWidgetMap.Clear();
    1.47 @@ -547,7 +538,6 @@
    1.48  				newArmy.UnitAdded += UnitAddedMethod;
    1.49  				newArmy.UnitRemoved += UnitRemovedMethod;
    1.50  				newArmy.PointsValueChanged += PointsValueChangedMethod;
    1.51 -				newArmy.FailedRequirement += FailedUnitRequirementMethod;
    1.52  				//TODO: Clear all buttons
    1.53  				EnableCategoryButtons();
    1.54  
     2.1 --- a/FrmNewUnit.cs	Sun May 01 13:07:15 2011 +0000
     2.2 +++ b/FrmNewUnit.cs	Mon Aug 01 20:22:48 2011 +0000
     2.3 @@ -7,9 +7,10 @@
     2.4  using Gtk;
     2.5  using IBBoard.GtkSharp.Translatable;
     2.6  using IBBoard.WarFoundry.API.Objects;
     2.7 -using IBBoard.WarFoundry.API.Requirements;
     2.8  using log4net;
     2.9  using IBBoard.Lang;
    2.10 +using IBBoard.WarFoundry.API.Objects.Requirement;
    2.11 +using System.Text;
    2.12  
    2.13  namespace IBBoard.WarFoundry.GUI.GTK
    2.14  {
    2.15 @@ -104,13 +105,21 @@
    2.16  			if (type != null)
    2.17  			{
    2.18  				bttnCreate.Sensitive = true;
    2.19 -				List<FailedUnitRequirement> fails = unitArmy.CanAddUnitType(type);
    2.20 -				lblNewUnitWarning.Visible = (fails != null);
    2.21 +				ICollection<string> failureMessages;
    2.22 +				Validation result = RequirementHandler.AllowsAdding(type, unitArmy, out failureMessages);
    2.23 +				bool validationFailed = !Validates.AsOkay(result);
    2.24 +				lblNewUnitWarning.Visible = validationFailed;
    2.25  
    2.26 -				if (fails.Count > 0)
    2.27 +				if (validationFailed)
    2.28  				{
    2.29 -					//FIXME: currently only show the first error
    2.30 -					lblNewUnitWarning.Text = fails[0].Description;
    2.31 +					StringBuilder sb = new StringBuilder();
    2.32 +
    2.33 +					foreach (string msg in failureMessages)
    2.34 +					{
    2.35 +						sb.AppendLine(msg);
    2.36 +					}
    2.37 +
    2.38 +					lblNewUnitWarning.Text = sb.ToString();
    2.39  				}
    2.40  			}
    2.41  			else
     3.1 --- a/IBBoard.WarFoundry.GUI.GTK.sln	Sun May 01 13:07:15 2011 +0000
     3.2 +++ b/IBBoard.WarFoundry.GUI.GTK.sln	Mon Aug 01 20:22:48 2011 +0000
     3.3 @@ -107,7 +107,7 @@
     3.4  		$3.inheritsScope = text/plain
     3.5  		$3.scope = text/plain
     3.6  		$0.StandardHeader = $4
     3.7 -		$4.Text = @This file (${FileName}) is a part of the ${ProjectName} project and is copyright ${Year} ${CopyrightHolder}\r\n\nThe 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.
     3.8 +		$4.Text = @This file (${FileName}) is a part of the ${ProjectName} project and is copyright ${Year} ${CopyrightHolder}\n\nThe 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.
     3.9  		$4.IncludeInNewFiles = True
    3.10  	EndGlobalSection
    3.11  EndGlobal
     4.1 --- a/gtk-gui/gui.stetic	Sun May 01 13:07:15 2011 +0000
     4.2 +++ b/gtk-gui/gui.stetic	Mon Aug 01 20:22:48 2011 +0000
     4.3 @@ -635,12 +635,11 @@
     4.4                <widget class="IBBoard.GtkSharp.Translatable.TranslatableLabel" id="lblNewUnitWarning">
     4.5                  <property name="MemberName" />
     4.6                  <property name="Visible">False</property>
     4.7 +                <property name="Xalign">0</property>
     4.8                </widget>
     4.9                <packing>
    4.10                  <property name="Position">1</property>
    4.11 -                <property name="AutoSize">True</property>
    4.12 -                <property name="Expand">False</property>
    4.13 -                <property name="Fill">False</property>
    4.14 +                <property name="AutoSize">False</property>
    4.15                </packing>
    4.16              </child>
    4.17            </widget>