# HG changeset patch # User IBBoard # Date 1257022482 0 # Node ID 0bb9f40d44ebb4bf9ede77f07e13d3f4f1ba7824 # Parent 1e85a0687e4d4c88240fe677dad0624fc919398a Re #88: Complete initial WinForms UI * Add basic initial "about" box * Translations (below) Re #179: Make sure that translations are used throughout UI * Make all controls translatable * Supply translations for all controls Re #204: Use new limits in WinForms UI * Warn the user and cap the number if we try to go out of range for equipment diff -r 1e85a0687e4d -r 0bb9f40d44eb FrmAbout.Designer.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FrmAbout.Designer.cs Sat Oct 31 20:54:42 2009 +0000 @@ -0,0 +1,126 @@ +namespace IBBoard.WarFoundry.GUI.WinForms +{ + partial class FrmAbout + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lblWarFoundry = new System.Windows.Forms.Label(); + this.lblVersion = new System.Windows.Forms.Label(); + this.lblDevelopers = new IBBoard.Windows.Forms.IBBLabel(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.lblThanks = new IBBoard.Windows.Forms.IBBLabel(); + this.SuspendLayout(); + // + // lblWarFoundry + // + this.lblWarFoundry.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte) (0))); + this.lblWarFoundry.Location = new System.Drawing.Point(12, 9); + this.lblWarFoundry.Name = "lblWarFoundry"; + this.lblWarFoundry.Size = new System.Drawing.Size(268, 45); + this.lblWarFoundry.TabIndex = 0; + this.lblWarFoundry.Text = "WarFoundry"; + this.lblWarFoundry.TextAlign = System.Drawing.ContentAlignment.TopCenter; + // + // lblVersion + // + this.lblVersion.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (0))); + this.lblVersion.Location = new System.Drawing.Point(16, 54); + this.lblVersion.Name = "lblVersion"; + this.lblVersion.Size = new System.Drawing.Size(264, 23); + this.lblVersion.TabIndex = 1; + this.lblVersion.Text = "v0.1b4"; + // + // lblDevelopers + // + this.lblDevelopers.AutoSize = true; + this.lblDevelopers.Location = new System.Drawing.Point(12, 80); + this.lblDevelopers.Name = "lblDevelopers"; + this.lblDevelopers.Size = new System.Drawing.Size(59, 13); + this.lblDevelopers.TabIndex = 2; + this.lblDevelopers.Text = "developers"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(80, 80); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.ReadOnly = true; + this.textBox1.Size = new System.Drawing.Size(200, 89); + this.textBox1.TabIndex = 3; + this.textBox1.Text = "IBBoard (http://ibboard.co.uk/devlog/)"; + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(80, 175); + this.textBox2.Multiline = true; + this.textBox2.Name = "textBox2"; + this.textBox2.ReadOnly = true; + this.textBox2.Size = new System.Drawing.Size(200, 89); + this.textBox2.TabIndex = 5; + this.textBox2.Text = "Snowblizz\r\nFrostlee"; + // + // lblThanks + // + this.lblThanks.AutoSize = true; + this.lblThanks.Location = new System.Drawing.Point(12, 175); + this.lblThanks.Name = "lblThanks"; + this.lblThanks.Size = new System.Drawing.Size(51, 13); + this.lblThanks.TabIndex = 4; + this.lblThanks.Text = "thanks to"; + // + // FrmAbout + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(292, 270); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.lblThanks); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.lblDevelopers); + this.Controls.Add(this.lblVersion); + this.Controls.Add(this.lblWarFoundry); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "FrmAbout"; + this.Text = "FrmAbout"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label lblWarFoundry; + private System.Windows.Forms.Label lblVersion; + private IBBoard.Windows.Forms.IBBLabel lblDevelopers; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + private IBBoard.Windows.Forms.IBBLabel lblThanks; + } +} \ No newline at end of file diff -r 1e85a0687e4d -r 0bb9f40d44eb FrmAbout.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FrmAbout.cs Sat Oct 31 20:54:42 2009 +0000 @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using IBBoard.Lang; +using IBBoard.Windows.Forms; +using IBBoard.Windows.Forms.I18N; + +namespace IBBoard.WarFoundry.GUI.WinForms +{ + public partial class FrmAbout : IBBForm + { + public FrmAbout() + { + InitializeComponent(); + ControlTranslator.TranslateControl(this); + lblVersion.Text = Translation.GetTranslation("lblVersion", "Version: {0}", FrmMain.VERSION); + } + } +} \ No newline at end of file diff -r 1e85a0687e4d -r 0bb9f40d44eb FrmAbout.resx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FrmAbout.resx Sat Oct 31 20:54:42 2009 +0000 @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff -r 1e85a0687e4d -r 0bb9f40d44eb FrmEditUnitEquipment.cs --- a/FrmEditUnitEquipment.cs Sat Oct 31 19:32:48 2009 +0000 +++ b/FrmEditUnitEquipment.cs Sat Oct 31 20:54:42 2009 +0000 @@ -7,6 +7,7 @@ using System.ComponentModel; using System.Windows.Forms; using IBBoard.Commands; +using IBBoard.Lang; using IBBoard.Windows.Forms; using IBBoard.Windows.Forms.I18N; using IBBoard.WarFoundry.API; @@ -18,7 +19,7 @@ /// /// Summary description for FrmEditUnitEquipment. /// - public class FrmEditUnitEquipment : System.Windows.Forms.Form + public class FrmEditUnitEquipment : IBBForm { private Unit unit; private UnitEquipmentItem equipItem; @@ -38,8 +39,8 @@ this.unit = unit; this.equipItem = equipItem; InitializeComponent(); - ControlTranslator.TranslateControls(Controls); - this.Text = equipItem.Name + " for " + unit.Name; + ControlTranslator.TranslateControl(this); + this.Text = Translation.GetTranslation("FrmEditUnitEquipment", "edit {0} for {1}", equipItem.Name, unit.Name); equipmentAmount.SetUnit(unit); equipmentAmount.SetUnitEquipmentItem(equipItem); bttnOkay.Enabled = false; @@ -67,17 +68,17 @@ /// private void InitializeComponent() { - this.lblAmount = new IBBLabel(); - this.bttnCancel = new IBBButton(); - this.bttnOkay = new IBBButton(); + this.lblAmount = new IBBoard.Windows.Forms.IBBLabel(); + this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); + this.bttnOkay = new IBBoard.Windows.Forms.IBBButton(); this.equipmentAmount = new IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl(); this.SuspendLayout(); // // lblAmount // - this.lblAmount.Location = new System.Drawing.Point(8, 8); + this.lblAmount.Location = new System.Drawing.Point(12, 8); this.lblAmount.Name = "lblAmount"; - this.lblAmount.Size = new System.Drawing.Size(72, 23); + this.lblAmount.Size = new System.Drawing.Size(68, 74); this.lblAmount.TabIndex = 2; this.lblAmount.Text = "amount"; this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; diff -r 1e85a0687e4d -r 0bb9f40d44eb FrmMain.cs --- a/FrmMain.cs Sat Oct 31 19:32:48 2009 +0000 +++ b/FrmMain.cs Sat Oct 31 20:54:42 2009 +0000 @@ -36,6 +36,7 @@ public class FrmMain : System.Windows.Forms.Form { private static readonly string AppTitle = "WarFoundry"; + internal static readonly string VERSION = "0.1b4"; const string DefaultDataDir = "data"; private Preferences preferences; @@ -498,10 +499,10 @@ // // miAbout // - this.miAbout.Enabled = false; this.miAbout.Index = 0; this.miAbout.Text = "&about"; this.miAbout.Name = "miAbout"; + this.miAbout.Click += new System.EventHandler(this.miAbout_Click); // // saveArmyDialog // @@ -1308,5 +1309,11 @@ } } } + + private void miAbout_Click(object sender, EventArgs e) + { + FrmAbout about = new FrmAbout(); + about.ShowDialog(this); + } } } diff -r 1e85a0687e4d -r 0bb9f40d44eb FrmNewUnitEquipment.cs --- a/FrmNewUnitEquipment.cs Sat Oct 31 19:32:48 2009 +0000 +++ b/FrmNewUnitEquipment.cs Sat Oct 31 20:54:42 2009 +0000 @@ -14,20 +14,22 @@ using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Util; using IBBoard.WarFoundry.GUI.WinForms.Util; +using IBBoard.Windows.Forms; +using IBBoard.Windows.Forms.I18N; namespace IBBoard.WarFoundry.GUI.WinForms { /// /// Summary description for FrmNewUnitEquipment. /// - public class FrmNewUnitEquipment : System.Windows.Forms.Form + public class FrmNewUnitEquipment : IBBForm { private Unit unit; private CommandStack commandStack; - private System.Windows.Forms.Label lblAmount; - private System.Windows.Forms.Button bttnCancel; - private System.Windows.Forms.Button bttnOkay; - private System.Windows.Forms.Label lblItem; + private IBBLabel lblAmount; + private IBBButton bttnCancel; + private IBBButton bttnOkay; + private IBBLabel lblItem; private System.Windows.Forms.ListBox listItems; private IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl equipmentAmount; /// @@ -40,7 +42,8 @@ commandStack = stack; this.unit = unit; InitializeComponent(); - this.Text = "New equipment for " + unit.Name; + ControlTranslator.TranslateControl(this); + this.Text = Translation.GetTranslation("FrmNewUnitEquipment", "new equipment for {0}", unit.Name); object[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment()); listItems.Items.AddRange(items); equipmentAmount.SetUnit(unit); @@ -68,19 +71,19 @@ /// private void InitializeComponent() { - this.lblAmount = new System.Windows.Forms.Label(); - this.bttnCancel = new System.Windows.Forms.Button(); - this.bttnOkay = new System.Windows.Forms.Button(); - this.lblItem = new System.Windows.Forms.Label(); + this.lblAmount = new IBBoard.Windows.Forms.IBBLabel(); + this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); + this.bttnOkay = new IBBoard.Windows.Forms.IBBButton(); + this.lblItem = new IBBoard.Windows.Forms.IBBLabel(); this.listItems = new System.Windows.Forms.ListBox(); this.equipmentAmount = new IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl(); this.SuspendLayout(); // // lblAmount // - this.lblAmount.Location = new System.Drawing.Point(8, 80); + this.lblAmount.Location = new System.Drawing.Point(12, 80); this.lblAmount.Name = "lblAmount"; - this.lblAmount.Size = new System.Drawing.Size(72, 23); + this.lblAmount.Size = new System.Drawing.Size(68, 77); this.lblAmount.TabIndex = 2; this.lblAmount.Text = "amount"; this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -109,9 +112,9 @@ // // lblItem // - this.lblItem.Location = new System.Drawing.Point(0, 8); + this.lblItem.Location = new System.Drawing.Point(12, 8); this.lblItem.Name = "lblItem"; - this.lblItem.Size = new System.Drawing.Size(80, 23); + this.lblItem.Size = new System.Drawing.Size(68, 69); this.lblItem.TabIndex = 6; this.lblItem.Text = "item"; this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight; diff -r 1e85a0687e4d -r 0bb9f40d44eb FrmUnit.cs --- a/FrmUnit.cs Sat Oct 31 19:32:48 2009 +0000 +++ b/FrmUnit.cs Sat Oct 31 20:54:42 2009 +0000 @@ -11,6 +11,7 @@ using IBBoard.Commands; using IBBoard.Lang; using IBBoard.Windows.Forms; +using IBBoard.Windows.Forms.I18N; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Commands; using IBBoard.WarFoundry.API.Objects; @@ -30,13 +31,13 @@ private System.Windows.Forms.DataGrid statsGrid; private System.Windows.Forms.TextBox tbUnitName; private System.Windows.Forms.NumericUpDown unitSize; - private System.Windows.Forms.Label lblUnitSize; - private System.Windows.Forms.Button bttnAddWeapon; - private System.Windows.Forms.Button bttnRemoveWeapon; - private System.Windows.Forms.Label lblEquip; + private IBBLabel lblUnitSize; + private IBBButton bttnAddWeapon; + private IBBButton bttnRemoveWeapon; + private IBBLabel lblEquip; private System.Windows.Forms.ListBox equipmentList; - private System.Windows.Forms.Button bttnReplaceWeapon; - private System.Windows.Forms.Button bttnEditWeapon; + private IBBButton bttnReplaceWeapon; + private IBBButton bttnEditWeapon; private Label lblPoints; /// /// Required designer variable. @@ -51,9 +52,8 @@ // Required for Windows Form Designer support // InitializeComponent(); - - tbUnitName.Text = unit.Name; - Text = unit.Name; + ControlTranslator.TranslateControl(this); + Text = Translation.GetTranslation("FrmUnit", "{0}", unit.Name); unit.NameChanged += new StringValChangedDelegate(unit_NameChanged); unit.UnitSizeChanged += new IntValChangedDelegate(unit_UnitSizeChanged); unit.UnitEquipmentAmountChanged += new DoubleValChangedDelegate(unit_UnitEquipmentAmountChanged); @@ -181,13 +181,13 @@ this.statsGrid = new System.Windows.Forms.DataGrid(); this.tbUnitName = new System.Windows.Forms.TextBox(); this.unitSize = new System.Windows.Forms.NumericUpDown(); - this.lblUnitSize = new System.Windows.Forms.Label(); - this.lblEquip = new System.Windows.Forms.Label(); - this.bttnAddWeapon = new System.Windows.Forms.Button(); - this.bttnRemoveWeapon = new System.Windows.Forms.Button(); + this.lblUnitSize = new IBBLabel(); + this.lblEquip = new IBBLabel(); + this.bttnAddWeapon = new IBBButton(); + this.bttnRemoveWeapon = new IBBButton(); this.equipmentList = new System.Windows.Forms.ListBox(); - this.bttnReplaceWeapon = new System.Windows.Forms.Button(); - this.bttnEditWeapon = new System.Windows.Forms.Button(); + this.bttnReplaceWeapon = new IBBButton(); + this.bttnEditWeapon = new IBBButton(); this.lblPoints = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize) (this.statsGrid)).BeginInit(); ((System.ComponentModel.ISupportInitialize) (this.unitSize)).BeginInit(); diff -r 1e85a0687e4d -r 0bb9f40d44eb IBBoard.WarFoundry.GUI.WinForms.csproj --- a/IBBoard.WarFoundry.GUI.WinForms.csproj Sat Oct 31 19:32:48 2009 +0000 +++ b/IBBoard.WarFoundry.GUI.WinForms.csproj Sat Oct 31 20:54:42 2009 +0000 @@ -115,6 +115,12 @@ Code + + Form + + + FrmAbout.cs + Form @@ -149,6 +155,10 @@ Component + + Designer + FrmAbout.cs + FrmArmyTree.cs Designer diff -r 1e85a0687e4d -r 0bb9f40d44eb UI/EquipmentAmountControl.cs --- a/UI/EquipmentAmountControl.cs Sat Oct 31 19:32:48 2009 +0000 +++ b/UI/EquipmentAmountControl.cs Sat Oct 31 20:54:42 2009 +0000 @@ -1,226 +1,258 @@ -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.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) - { - bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); - double maxPercent = UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip); - double minPercent = 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 percent = (double)percentage.Value; - numeric.Value = CalculateNumericValueFromPercentage(percent); - } - - private decimal CalculateNumericValueFromPercentage(double percent) - { - return (decimal) IBBMath.Round(unit.Size * (percent / 100.0), equip.RoundNumberUp); - } - - private void numeric_ValueChanged(object sender, EventArgs e) - { - SetPercentageValueFromNumeric(); - OnValueChanged(); - } - - private void SetPercentageValueFromNumeric() - { - int number = (int)numeric.Value; - percentage.Value = CalcualtePercentageValueFromNumber(number); - } - - private decimal CalcualtePercentageValueFromNumber(int number) - { - return (decimal) Math.Round((number / (unit.Size * 1.0)) * 100, 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) - { - numeric.Value = CalculateNumericValueFromPercentage(equipAmountNum); - percentage.Value = (decimal) equipAmountNum; - } - - private void SetEquipmentAmountsFromNumber(int equipAmount) - { - percentage.Value = CalcualtePercentageValueFromNumber(equipAmount); - numeric.Value = equipAmount; - } - - private void radioCheckedChanged(object sender, EventArgs e) - { - OnValueChanged(); - } - } -} +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) + { + bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); + double maxPercent = UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip); + double minPercent = 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() + { + numeric.Value = CalculateNumericValueFromPercentage(percentage.Value); + } + + 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.Value = CalcualtePercentageValueFromNumber(number); + } + + private decimal CalcualtePercentageValueFromNumber(int number) + { + return (decimal) Math.Round((number / (unit.Size * 1.0)) * 100, 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(); + } + } +} diff -r 1e85a0687e4d -r 0bb9f40d44eb translations/en.translation --- a/translations/en.translation Sat Oct 31 19:32:48 2009 +0000 +++ b/translations/en.translation Sat Oct 31 20:54:42 2009 +0000 @@ -5,35 +5,53 @@ &Help &Create army &Open army - E&xit - &About &Save army Save army &as... &Export army Basic HTML &Close army + &Reload files + E&xit &Undo &Redo - WarFoundry Army Files (*.army) - Create army + &About OK Cancel - Create unit - Unit types: - Races: - Army name: - Game systems: - Army Tree - Create new army - Open Army - Save army - Army size: - Unit of {0} {1} Create army Open army Save army + Army Tree + Open Army + Save Army + WarFoundry Army Files (*.army) {0} pts / {1} pts - &Reload files + Unit of {0} {1} + Create new army + Game systems: + Races: + Army name: + Army size: + Create army Add New {0} Choice + Unit types: + Create unit + New equipment for {0} Amount: + Equipment Item: + The current percentage ({0}%) was larger than the maximum for the equipment item ({1}%). The maximum value will be used instead. + Equipment percentage too large + The current percentage ({0}%) was smaller than the minimum for the equipment item ({1}%). The minimum value will be used instead. + Equipment percentage too small + Edit {0} for {1} + About WarFoundry + Version: {0} + Developers: + Thanks to: + {0} + Unit size: + Equipment: + Add + Remove + Replace + Edit \ No newline at end of file