diff FrmNewUnit.cs @ 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 b4416ca69153
children f23e5b40ca9d
line wrap: on
line diff
--- 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