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 wrap: on
line diff
--- a/FrmMainWindow.cs	Sun May 01 13:07:15 2011 +0000
+++ b/FrmMainWindow.cs	Mon Aug 01 20:22:48 2011 +0000
@@ -23,7 +23,6 @@
 using IBBoard.WarFoundry.API.Factories;
 using IBBoard.WarFoundry.API.Factories.Xml;
 using IBBoard.WarFoundry.API.Objects;
-using IBBoard.WarFoundry.API.Requirements;
 using IBBoard.WarFoundry.API.Savers;
 using IBBoard.WarFoundry.GUI.GTK.Widgets;
 using IBBoard.Xml;
@@ -44,7 +43,6 @@
 		private ObjectAddDelegate UnitAddedMethod;
 		private ObjectRemoveDelegate UnitRemovedMethod;
 		private DoubleValChangedDelegate PointsValueChangedMethod;
-		private FailedUnitRequirementDelegate FailedUnitRequirementMethod;
 		private StringValChangedDelegate UnitNameChangedMethod;
 		private GameSystem system;
 		private string loadedArmyPath;
@@ -152,7 +150,6 @@
 			UnitAddedMethod = new ObjectAddDelegate(OnUnitAdded);
 			UnitRemovedMethod = new ObjectRemoveDelegate(OnUnitRemoved);
 			PointsValueChangedMethod = new DoubleValChangedDelegate(OnPointsValueChanged);
-			FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(OnFailedUnitRequirement);
 			UnitNameChangedMethod = new StringValChangedDelegate(OnUnitNameChanged);
 
 			//FIXME: Temporary hack to add paths and factories before we get preferences and plugins
@@ -402,11 +399,6 @@
 			SetPointsPanelText();
 		}
 
-		private void OnFailedUnitRequirement(List<FailedUnitRequirement> failedRequirement)
-		{
-			//Show error message in panel
-		}
-
 		public Preferences Preferences
 		{
 			get { return preferences; }
@@ -528,7 +520,6 @@
 				oldArmy.UnitAdded -= UnitAddedMethod;
 				oldArmy.UnitRemoved -= UnitRemovedMethod;
 				oldArmy.PointsValueChanged -= PointsValueChangedMethod;
-				oldArmy.FailedRequirement -= FailedUnitRequirementMethod;
 			}
 
 			unitToWidgetMap.Clear();
@@ -547,7 +538,6 @@
 				newArmy.UnitAdded += UnitAddedMethod;
 				newArmy.UnitRemoved += UnitRemovedMethod;
 				newArmy.PointsValueChanged += PointsValueChangedMethod;
-				newArmy.FailedRequirement += FailedUnitRequirementMethod;
 				//TODO: Clear all buttons
 				EnableCategoryButtons();
 
--- a/FrmNewUnit.cs	Sun May 01 13:07:15 2011 +0000
+++ b/FrmNewUnit.cs	Mon Aug 01 20:22:48 2011 +0000
@@ -7,9 +7,10 @@
 using Gtk;
 using IBBoard.GtkSharp.Translatable;
 using IBBoard.WarFoundry.API.Objects;
-using IBBoard.WarFoundry.API.Requirements;
 using log4net;
 using IBBoard.Lang;
+using IBBoard.WarFoundry.API.Objects.Requirement;
+using System.Text;
 
 namespace IBBoard.WarFoundry.GUI.GTK
 {
@@ -104,13 +105,21 @@
 			if (type != null)
 			{
 				bttnCreate.Sensitive = true;
-				List<FailedUnitRequirement> fails = unitArmy.CanAddUnitType(type);
-				lblNewUnitWarning.Visible = (fails != null);
+				ICollection<string> failureMessages;
+				Validation result = RequirementHandler.AllowsAdding(type, unitArmy, out failureMessages);
+				bool validationFailed = !Validates.AsOkay(result);
+				lblNewUnitWarning.Visible = validationFailed;
 
-				if (fails.Count > 0)
+				if (validationFailed)
 				{
-					//FIXME: currently only show the first error
-					lblNewUnitWarning.Text = fails[0].Description;
+					StringBuilder sb = new StringBuilder();
+
+					foreach (string msg in failureMessages)
+					{
+						sb.AppendLine(msg);
+					}
+
+					lblNewUnitWarning.Text = sb.ToString();
 				}
 			}
 			else
--- a/IBBoard.WarFoundry.GUI.GTK.sln	Sun May 01 13:07:15 2011 +0000
+++ b/IBBoard.WarFoundry.GUI.GTK.sln	Mon Aug 01 20:22:48 2011 +0000
@@ -107,7 +107,7 @@
 		$3.inheritsScope = text/plain
 		$3.scope = text/plain
 		$0.StandardHeader = $4
-		$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.
+		$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.
 		$4.IncludeInNewFiles = True
 	EndGlobalSection
 EndGlobal
--- a/gtk-gui/gui.stetic	Sun May 01 13:07:15 2011 +0000
+++ b/gtk-gui/gui.stetic	Mon Aug 01 20:22:48 2011 +0000
@@ -635,12 +635,11 @@
               <widget class="IBBoard.GtkSharp.Translatable.TranslatableLabel" id="lblNewUnitWarning">
                 <property name="MemberName" />
                 <property name="Visible">False</property>
+                <property name="Xalign">0</property>
               </widget>
               <packing>
                 <property name="Position">1</property>
-                <property name="AutoSize">True</property>
-                <property name="Expand">False</property>
-                <property name="Fill">False</property>
+                <property name="AutoSize">False</property>
               </packing>
             </child>
           </widget>