Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
changeset 85:0bb9f40d44eb
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
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 31 Oct 2009 20:54:42 +0000 |
parents | 1e85a0687e4d |
children | a9d80b4984bc |
files | FrmAbout.Designer.cs FrmAbout.cs FrmAbout.resx FrmEditUnitEquipment.cs FrmMain.cs FrmNewUnitEquipment.cs FrmUnit.cs IBBoard.WarFoundry.GUI.WinForms.csproj UI/EquipmentAmountControl.cs translations/en.translation |
diffstat | 10 files changed, 620 insertions(+), 280 deletions(-) [+] |
line wrap: on
line diff
--- /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 + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + 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
--- /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
--- /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 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root> \ No newline at end of file
--- 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> /// Summary description for FrmEditUnitEquipment. /// </summary> - 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 @@ /// </summary> 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;
--- 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); + } } }
--- 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> /// Summary description for FrmNewUnitEquipment. /// </summary> - 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; /// <summary> @@ -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 @@ /// </summary> 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;
--- 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; /// <summary> /// 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();
--- 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 @@ <Compile Include="AssemblyInfo.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="FrmAbout.cs"> + <SubType>Form</SubType> + </Compile> + <Compile Include="FrmAbout.Designer.cs"> + <DependentUpon>FrmAbout.cs</DependentUpon> + </Compile> <Compile Include="FrmArmyTree.cs"> <SubType>Form</SubType> </Compile> @@ -149,6 +155,10 @@ <SubType>Component</SubType> </Compile> <Compile Include="Util\UnitEquipmentChoice.cs" /> + <EmbeddedResource Include="FrmAbout.resx"> + <SubType>Designer</SubType> + <DependentUpon>FrmAbout.cs</DependentUpon> + </EmbeddedResource> <EmbeddedResource Include="FrmArmyTree.resx"> <DependentUpon>FrmArmyTree.cs</DependentUpon> <SubType>Designer</SubType>
--- 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(); + } + } +}
--- 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 @@ <translation id="menuHelp">&Help</translation> <translation id="miNewArmy">&Create army</translation> <translation id="miOpenArmy">&Open army</translation> - <translation id="miExit">E&xit</translation> - <translation id="miAbout">&About</translation> <translation id="miSaveArmy">&Save army</translation> <translation id="miSaveArmyAs">Save army &as...</translation> <translation id="miExportArmyAs">&Export army</translation> <translation id="miExportArmyAsBasicHTML">Basic HTML</translation> <translation id="miCloseArmy">&Close army</translation> + <translation id="miReloadFiles">&Reload files</translation> + <translation id="miExit">E&xit</translation> <translation id="miUndo">&Undo</translation> <translation id="miRedo">&Redo</translation> - <translation id="armyFileFilter">WarFoundry Army Files (*.army)</translation> - <translation id="bttnSelectRace">Create army</translation> + <translation id="miAbout">&About</translation> <translation id="bttnOkay">OK</translation> <translation id="bttnCancel">Cancel</translation> - <translation id="bttnSelectUnit">Create unit</translation> - <translation id="lblUnitList">Unit types:</translation> - <translation id="lblRaceList">Races:</translation> - <translation id="lblArmyName">Army name:</translation> - <translation id="lblGameSystem">Game systems:</translation> - <translation id="ArmyTree">Army Tree</translation> - <translation id="FrmNewArmy">Create new army</translation> - <translation id="openArmyDialog">Open Army</translation> - <translation id="saveArmyDialog">Save army</translation> - <translation id="lblArmySize">Army size:</translation> - <translation id="defaultUnitName">Unit of {0} {1}</translation> <translation id="bttnNewArmy">Create army</translation> <translation id="bttnOpenArmy">Open army</translation> <translation id="bttnSaveArmy">Save army</translation> + <translation id="ArmyTree">Army Tree</translation> + <translation id="openArmyDialog">Open Army</translation> + <translation id="saveArmyDialog">Save Army</translation> + <translation id="armyFileFilter">WarFoundry Army Files (*.army)</translation> <translation id="statusPanelPoints">{0} pts / {1} pts</translation> - <translation id="miReloadFiles">&Reload files</translation> + <translation id="defaultUnitName">Unit of {0} {1}</translation> + <translation id="FrmNewArmy">Create new army</translation> + <translation id="lblGameSystem">Game systems:</translation> + <translation id="lblRaceList">Races:</translation> + <translation id="lblArmyName">Army name:</translation> + <translation id="lblArmySize">Army size:</translation> + <translation id="bttnSelectRace">Create army</translation> <translation id="FrmNewUnit">Add New {0} Choice</translation> + <translation id="lblUnitList">Unit types:</translation> + <translation id="bttnSelectUnit">Create unit</translation> + <translation id="FrmNewUnitEquipment">New equipment for {0}</translation> <translation id="lblAmount">Amount:</translation> + <translation id="lblItem">Equipment Item:</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> + <translation id="equipPercentageTooSmallTitle">Equipment percentage too small</translation> + <translation id="FrmEditUnitEquipment">Edit {0} for {1}</translation> + <translation id="FrmAbout">About WarFoundry</translation> + <translation id="lblVersion">Version: {0}</translation> + <translation id="lblDevelopers">Developers:</translation> + <translation id="lblThanks">Thanks to:</translation> + <translation id="FrmUnit">{0}</translation> + <translation id="lblUnitSize">Unit size:</translation> + <translation id="lblEquip">Equipment:</translation> + <translation id="bttnAddWeapon">Add</translation> + <translation id="bttnRemoveWeapon">Remove</translation> + <translation id="bttnReplaceWeapon">Replace</translation> + <translation id="bttnEditWeapon">Edit</translation> </translations> \ No newline at end of file