# HG changeset patch # User IBBoard # Date 1312230168 0 # Node ID 76b73f15d07e3c65602d482908ec8d272ed5a75b # Parent 4ae69806bb2d8eab7af03c531be28ae168d2c2c0 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 diff -r 4ae69806bb2d -r 76b73f15d07e FrmMainWindow.cs --- 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 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(); diff -r 4ae69806bb2d -r 76b73f15d07e FrmNewUnit.cs --- 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 fails = unitArmy.CanAddUnitType(type); - lblNewUnitWarning.Visible = (fails != null); + ICollection 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 diff -r 4ae69806bb2d -r 76b73f15d07e IBBoard.WarFoundry.GUI.GTK.sln --- 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 diff -r 4ae69806bb2d -r 76b73f15d07e gtk-gui/gui.stetic --- 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 @@ False + 0 1 - True - False - False + False