changeset 90:63ca28bd8ada

Re #179: Translations throughout GUI * Add translation for "equip all" radio button on equipment editing
author IBBoard <dev@ibboard.co.uk>
date Mon, 02 Nov 2009 20:26:37 +0000
parents 971f7801f984
children e1e3957db129
files IBBoard.WarFoundry.GUI.WinForms.csproj UI/EquipmentAmountControl.cs translations/en.translation
diffstat 3 files changed, 258 insertions(+), 255 deletions(-) [+]
line wrap: on
line diff
--- a/IBBoard.WarFoundry.GUI.WinForms.csproj	Mon Nov 02 20:11:18 2009 +0000
+++ b/IBBoard.WarFoundry.GUI.WinForms.csproj	Mon Nov 02 20:26:37 2009 +0000
@@ -165,6 +165,7 @@
     </EmbeddedResource>
     <EmbeddedResource Include="FrmEditUnitEquipment.resx">
       <DependentUpon>FrmEditUnitEquipment.cs</DependentUpon>
+      <SubType>Designer</SubType>
     </EmbeddedResource>
     <EmbeddedResource Include="FrmMain.resx">
       <DependentUpon>FrmMain.cs</DependentUpon>
--- a/UI/EquipmentAmountControl.cs	Mon Nov 02 20:11:18 2009 +0000
+++ b/UI/EquipmentAmountControl.cs	Mon Nov 02 20:26:37 2009 +0000
@@ -1,267 +1,268 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Drawing;
-using System.Data;
-using System.Text;
-using System.Windows.Forms;
-using IBBoard.CustomMath;
-using IBBoard.Lang;
-using IBBoard.Limits;
-using IBBoard.WarFoundry.API;
-using IBBoard.WarFoundry.API.Objects;
-using IBBoard.WarFoundry.API.Util;
-
-namespace IBBoard.WarFoundry.GUI.WinForms.UI
-{
-	public partial class EquipmentAmountControl : UserControl
-	{
-		private Unit unit;
-		private UnitEquipmentItem equip;
-		public event EventHandler ValueChanged;
-
-		public EquipmentAmountControl()
-		{
-			InitializeComponent();
-		}
-
-		public void SetUnit(Unit equipUnit)
-		{
-			unit = equipUnit;
-		}
-
-		public void SetUnitEquipmentItem(UnitEquipmentItem unitEquipment)
-		{
-			equip = unitEquipment;
-			SetWidgetValues();
-			SetUnitEquipmentItemAmount();
-		}
-
-		private void OnValueChanged()
-		{
-			if (ValueChanged != null)
-			{
-				ValueChanged(this, new EventArgs());
-			}
-		}
-
-		private void SetWidgetValues()
-		{
-			if (equip != null)
-			{
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Text;
+using System.Windows.Forms;
+using IBBoard.CustomMath;
+using IBBoard.Lang;
+using IBBoard.Limits;
+using IBBoard.WarFoundry.API;
+using IBBoard.WarFoundry.API.Objects;
+using IBBoard.WarFoundry.API.Util;
+
+namespace IBBoard.WarFoundry.GUI.WinForms.UI
+{
+	public partial class EquipmentAmountControl : UserControl
+	{
+		private Unit unit;
+		private UnitEquipmentItem equip;
+		public event EventHandler ValueChanged;
+
+		public EquipmentAmountControl()
+		{
+			InitializeComponent();
+			rbEquipAll.Text = Translation.GetTranslation("rbEquipAll", "equip all");
+		}
+
+		public void SetUnit(Unit equipUnit)
+		{
+			unit = equipUnit;
+		}
+
+		public void SetUnitEquipmentItem(UnitEquipmentItem unitEquipment)
+		{
+			equip = unitEquipment;
+			SetWidgetValues();
+			SetUnitEquipmentItemAmount();
+		}
+
+		private void OnValueChanged()
+		{
+			if (ValueChanged != null)
+			{
+				ValueChanged(this, new EventArgs());
+			}
+		}
+
+		private void SetWidgetValues()
+		{
+			if (equip != null)
+			{
 				bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip);
 				double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
-				double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
-				int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
-				int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
-
-				SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber);
-
-				if (equipIsRatioLimit)
-				{
-					SetEquipmentAmountsFromPercentage(minPercent);
-				}
-				else
-				{
-					SetEquipmentAmountsFromNumber(minNumber);
-				}
-
-				rbEquipAll.Enabled = equipIsRatioLimit && maxPercent == 100;
-				rbEquipAll.Checked = equipIsRatioLimit && minPercent == 100;
-				percentage.Enabled = equipIsRatioLimit && minPercent != 100;
-				rbPercentage.Enabled = percentage.Enabled;
-				rbPercentage.Checked = equipIsRatioLimit && !rbEquipAll.Checked;
-				numeric.Enabled = !equipIsRatioLimit || minPercent != 100;
-				rbNumeric.Enabled = numeric.Enabled;
-				rbNumeric.Checked = !equipIsRatioLimit;
-			}
-			else
-			{
-				Enabled = false;
-			}
-		}
-
-		private void SetUpDownControlMinMaxes(double minPercent, double maxPercent, int minNumber, int maxNumber)
-		{
-			percentage.ValueChanged -= percentage_ValueChanged;
-			numeric.ValueChanged -= numeric_ValueChanged;
-			SetUpDownControlMinMax(percentage, minPercent, maxPercent);
-			SetUpDownControlMinMax(numeric, (decimal) minNumber, (decimal) maxNumber);
-			percentage.ValueChanged += percentage_ValueChanged;
-			numeric.ValueChanged += numeric_ValueChanged;
-		}
-
-		private void SetUpDownControlMinMax(NumericUpDown upDownControl, double min, double max)
-		{
-			SetUpDownControlMinMax(upDownControl, (decimal)min, (decimal)max);
-		}
-
-		private void SetUpDownControlMinMax(NumericUpDown upDownControl, decimal min, decimal max)
-		{
-			upDownControl.Minimum = min;
-			upDownControl.Maximum = max;
-		}
-
-		private void rbEquipAll_CheckedChanged(object sender, EventArgs e)
-		{
-			bool equipAll = rbEquipAll.Checked;
-			numeric.Enabled = !equipAll;
-			percentage.Enabled = !equipAll;
-
-			if (equipAll)
-			{
-				numeric.Value = unit.Size;
-				percentage.Value = 100;
-			}
-
-			radioCheckedChanged(sender, e);
-		}
-
-		private void percentage_ValueChanged(object sender, EventArgs e)
-		{
-			SetNumericValueFromPercentage();
-			rbEquipAll.Checked = (percentage.Value == 100 && !rbNumeric.Checked);
-			OnValueChanged();
-		}
-
-		private void SetNumericValueFromPercentage()
+				double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
+				int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
+				int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
+
+				SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber);
+
+				if (equipIsRatioLimit)
+				{
+					SetEquipmentAmountsFromPercentage(minPercent);
+				}
+				else
+				{
+					SetEquipmentAmountsFromNumber(minNumber);
+				}
+
+				rbEquipAll.Enabled = equipIsRatioLimit && maxPercent == 100;
+				rbEquipAll.Checked = equipIsRatioLimit && minPercent == 100;
+				percentage.Enabled = equipIsRatioLimit && minPercent != 100;
+				rbPercentage.Enabled = percentage.Enabled;
+				rbPercentage.Checked = equipIsRatioLimit && !rbEquipAll.Checked;
+				numeric.Enabled = !equipIsRatioLimit || minPercent != 100;
+				rbNumeric.Enabled = numeric.Enabled;
+				rbNumeric.Checked = !equipIsRatioLimit;
+			}
+			else
+			{
+				Enabled = false;
+			}
+		}
+
+		private void SetUpDownControlMinMaxes(double minPercent, double maxPercent, int minNumber, int maxNumber)
+		{
+			percentage.ValueChanged -= percentage_ValueChanged;
+			numeric.ValueChanged -= numeric_ValueChanged;
+			SetUpDownControlMinMax(percentage, minPercent, maxPercent);
+			SetUpDownControlMinMax(numeric, (decimal) minNumber, (decimal) maxNumber);
+			percentage.ValueChanged += percentage_ValueChanged;
+			numeric.ValueChanged += numeric_ValueChanged;
+		}
+
+		private void SetUpDownControlMinMax(NumericUpDown upDownControl, double min, double max)
+		{
+			SetUpDownControlMinMax(upDownControl, (decimal)min, (decimal)max);
+		}
+
+		private void SetUpDownControlMinMax(NumericUpDown upDownControl, decimal min, decimal max)
 		{
-			numeric.ValueChanged -= numeric_ValueChanged;
+			upDownControl.Minimum = min;
+			upDownControl.Maximum = max;
+		}
+
+		private void rbEquipAll_CheckedChanged(object sender, EventArgs e)
+		{
+			bool equipAll = rbEquipAll.Checked;
+			numeric.Enabled = !equipAll;
+			percentage.Enabled = !equipAll;
+
+			if (equipAll)
+			{
+				numeric.Value = unit.Size;
+				percentage.Value = 100;
+			}
+
+			radioCheckedChanged(sender, e);
+		}
+
+		private void percentage_ValueChanged(object sender, EventArgs e)
+		{
+			SetNumericValueFromPercentage();
+			rbEquipAll.Checked = (percentage.Value == 100 && !rbNumeric.Checked);
+			OnValueChanged();
+		}
+
+		private void SetNumericValueFromPercentage()
+		{
+			numeric.ValueChanged -= numeric_ValueChanged;
 			numeric.Value = CalculateNumericValueFromPercentage(percentage.Value);
-			numeric.ValueChanged += numeric_ValueChanged;
-		}
-
-		private decimal CalculateNumericValueFromPercentage(decimal percent)
-		{
-			return (decimal) IBBoard.CustomMath.IBBMath.Round((double)(unit.Size * (percent / 100)), equip.RoundNumberUp);
-		}
-
-		private void numeric_ValueChanged(object sender, EventArgs e)
-		{
-			SetPercentageValueFromNumeric();
-			OnValueChanged();
-		}
-
-		private void SetPercentageValueFromNumeric()
-		{
+			numeric.ValueChanged += numeric_ValueChanged;
+		}
+
+		private decimal CalculateNumericValueFromPercentage(decimal percent)
+		{
+			return (decimal) IBBoard.CustomMath.IBBMath.Round((double)(unit.Size * (percent / 100)), equip.RoundNumberUp);
+		}
+
+		private void numeric_ValueChanged(object sender, EventArgs e)
+		{
+			SetPercentageValueFromNumeric();
+			OnValueChanged();
+		}
+
+		private void SetPercentageValueFromNumeric()
+		{
 			int number = (int)numeric.Value;
-			percentage.ValueChanged -= percentage_ValueChanged;
+			percentage.ValueChanged -= percentage_ValueChanged;
 			percentage.Value = CalcualtePercentageValueFromNumber(number);
-			percentage.ValueChanged += percentage_ValueChanged;
-		}
-
-		private decimal CalcualtePercentageValueFromNumber(int number)
+			percentage.ValueChanged += percentage_ValueChanged;
+		}
+
+		private decimal CalcualtePercentageValueFromNumber(int number)
 		{
-			return (decimal) RoundPercentage((number / (unit.Size * 1.0)) * 100);
+			return (decimal) RoundPercentage((number / (unit.Size * 1.0)) * 100);
 		}
 
 		private double RoundPercentage(double percent)
 		{
 			return Math.Round(percent, 1);
-		}
-
-		public double EquipmentAmount
-		{
-			get
-			{
-				double val = 0;
-
-				if (rbNumeric.Checked)
-				{
-					val = (double) numeric.Value;
-				}
-				else if (rbPercentage.Checked)
-				{
-					val = (double) percentage.Value;
-				}
-				else if (rbEquipAll.Checked)
-				{
-					val = 100;
-				}
-				else
-				{
-					val = 0;
-				}
-
-				return val;
-			}
-		}
-
-		public bool IsRatioEquipmentAmount
-		{
-			get
-			{
-				return !rbNumeric.Checked;
-			}
-		}
-
-		private void SetUnitEquipmentItemAmount()
-		{
-			double equipAmountNum = unit.GetEquipmentAmount(equip);
-
-			if (equipAmountNum > 0)
-			{
-				bool isRatio = unit.GetEquipmentAmountIsRatio(equip);
-
-				if (isRatio)
-				{
-					SetEquipmentAmountsFromPercentage(equipAmountNum);
-				}
-				else
-				{
-					int equipAmount = (int) equipAmountNum;
-					SetEquipmentAmountsFromNumber(equipAmount);
-				}
-			}
-		}
-
-		private void SetEquipmentAmountsFromPercentage(double equipAmountNum)
-		{
-			decimal decEquipAmount = (decimal) equipAmountNum;
-
-			if (decEquipAmount > percentage.Maximum)
-			{
-				string percentageTooLarge = Translation.GetTranslation("equipPercentageTooLarge", "The current percentage ({0}%) was larger than the maximum for the equipment item ({1}%). The maximum value will be used instead.", equipAmountNum, percentage.Maximum);
-				string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "Equipment percentage too large");
-				MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle);
-				decEquipAmount = percentage.Maximum;
-			}
-			else if (decEquipAmount < percentage.Minimum)
-			{
-				string percentageTooSmall = Translation.GetTranslation("equipPercentageTooSmall", "The current percentage ({0}%) was smaller than the minimum for the equipment item ({1}%). The minimum value will be used instead.", equipAmountNum, percentage.Minimum);
-				string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "Equipment percentage too small");
-				MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle);
-				decEquipAmount = percentage.Minimum;
-			}
-
-			numeric.Value = CalculateNumericValueFromPercentage(decEquipAmount);
-			percentage.Value = decEquipAmount;
-		}
-
-		private void SetEquipmentAmountsFromNumber(int equipAmount)
-		{
-			if (equipAmount > numeric.Maximum)
-			{
-				string amountTooLarge = Translation.GetTranslation("equipNumberTooLarge", "The current amount ({0}) was larger than the maximum for the equipment item ({1}). The maximum value will be used instead.", equipAmount, numeric.Maximum);
-				string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "Equipment amount too large");
-				MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle);
-				equipAmount = (int)numeric.Maximum;
-			}
-			else if (equipAmount < numeric.Minimum)
-			{
-				string amountTooSmall = Translation.GetTranslation("equipNumberTooSmall", "The current amount ({0}) was smaller than the minimum for the equipment item ({1}). The minimum value will be used instead.", equipAmount, numeric.Minimum);
-				string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "Equipment amount too small");
-				MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle);
-				equipAmount = (int) numeric.Minimum;
-			}
-
-			percentage.Value = CalcualtePercentageValueFromNumber(equipAmount);
-			numeric.Value = equipAmount;
-		}
-
-		private void radioCheckedChanged(object sender, EventArgs e)
-		{
-			OnValueChanged();
-		}
-	}
-}
+		}
+
+		public double EquipmentAmount
+		{
+			get
+			{
+				double val = 0;
+
+				if (rbNumeric.Checked)
+				{
+					val = (double) numeric.Value;
+				}
+				else if (rbPercentage.Checked)
+				{
+					val = (double) percentage.Value;
+				}
+				else if (rbEquipAll.Checked)
+				{
+					val = 100;
+				}
+				else
+				{
+					val = 0;
+				}
+
+				return val;
+			}
+		}
+
+		public bool IsRatioEquipmentAmount
+		{
+			get
+			{
+				return !rbNumeric.Checked;
+			}
+		}
+
+		private void SetUnitEquipmentItemAmount()
+		{
+			double equipAmountNum = unit.GetEquipmentAmount(equip);
+
+			if (equipAmountNum > 0)
+			{
+				bool isRatio = unit.GetEquipmentAmountIsRatio(equip);
+
+				if (isRatio)
+				{
+					SetEquipmentAmountsFromPercentage(equipAmountNum);
+				}
+				else
+				{
+					int equipAmount = (int) equipAmountNum;
+					SetEquipmentAmountsFromNumber(equipAmount);
+				}
+			}
+		}
+
+		private void SetEquipmentAmountsFromPercentage(double equipAmountNum)
+		{
+			decimal decEquipAmount = (decimal) equipAmountNum;
+
+			if (decEquipAmount > percentage.Maximum)
+			{
+				string percentageTooLarge = Translation.GetTranslation("equipPercentageTooLarge", "The current percentage ({0}%) was larger than the maximum for the equipment item ({1}%). The maximum value will be used instead.", equipAmountNum, percentage.Maximum);
+				string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "Equipment percentage too large");
+				MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle);
+				decEquipAmount = percentage.Maximum;
+			}
+			else if (decEquipAmount < percentage.Minimum)
+			{
+				string percentageTooSmall = Translation.GetTranslation("equipPercentageTooSmall", "The current percentage ({0}%) was smaller than the minimum for the equipment item ({1}%). The minimum value will be used instead.", equipAmountNum, percentage.Minimum);
+				string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "Equipment percentage too small");
+				MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle);
+				decEquipAmount = percentage.Minimum;
+			}
+
+			numeric.Value = CalculateNumericValueFromPercentage(decEquipAmount);
+			percentage.Value = decEquipAmount;
+		}
+
+		private void SetEquipmentAmountsFromNumber(int equipAmount)
+		{
+			if (equipAmount > numeric.Maximum)
+			{
+				string amountTooLarge = Translation.GetTranslation("equipNumberTooLarge", "The current amount ({0}) was larger than the maximum for the equipment item ({1}). The maximum value will be used instead.", equipAmount, numeric.Maximum);
+				string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "Equipment amount too large");
+				MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle);
+				equipAmount = (int)numeric.Maximum;
+			}
+			else if (equipAmount < numeric.Minimum)
+			{
+				string amountTooSmall = Translation.GetTranslation("equipNumberTooSmall", "The current amount ({0}) was smaller than the minimum for the equipment item ({1}). The minimum value will be used instead.", equipAmount, numeric.Minimum);
+				string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "Equipment amount too small");
+				MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle);
+				equipAmount = (int) numeric.Minimum;
+			}
+
+			percentage.Value = CalcualtePercentageValueFromNumber(equipAmount);
+			numeric.Value = equipAmount;
+		}
+
+		private void radioCheckedChanged(object sender, EventArgs e)
+		{
+			OnValueChanged();
+		}
+	}
+}
--- a/translations/en.translation	Mon Nov 02 20:11:18 2009 +0000
+++ b/translations/en.translation	Mon Nov 02 20:26:37 2009 +0000
@@ -40,6 +40,7 @@
 	<translation id="FrmNewUnitEquipment">New equipment for {0}</translation>
 	<translation id="lblAmount">Amount:</translation>
 	<translation id="lblItem">Equipment Item:</translation>
+	<translation id="rbEquipAll">Equip All</translation>
 	<translation id="equipPercentageTooLarge">The current percentage ({0}%) was larger than the maximum for the equipment item ({1}%). The maximum value will be used instead.</translation>
 	<translation id="equipPercentageTooLargeTitle">Equipment percentage too large</translation>
 	<translation id="equipPercentageTooSmall">The current percentage ({0}%) was smaller than the minimum for the equipment item ({1}%). The minimum value will be used instead.</translation>