Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
changeset 24:7c366fe55635
* Fix line terminators
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 27 Jun 2009 19:01:59 +0000 |
parents | b8de17271084 |
children | 041f05e56496 |
files | AssemblyInfo.cs FrmArmyTree.cs FrmDebugOutput.cs FrmEditUnitEquipment.cs FrmNewArmy.cs FrmNewUnit.cs FrmNewUnitEquipment.cs FrmReplaceUnitEquipment.cs FrmSelectSystem.cs FrmUnit.cs Util/UnitEquipmentChoice.cs |
diffstat | 11 files changed, 2384 insertions(+), 2387 deletions(-) [+] |
line wrap: on
line diff
--- a/AssemblyInfo.cs Sat Jun 27 18:20:22 2009 +0000 +++ b/AssemblyInfo.cs Sat Jun 27 19:01:59 2009 +0000 @@ -1,58 +1,58 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -// -[assembly: AssemblyTitle("WarFoundry Army Builder")] -[assembly: AssemblyDescription("WarFoundry is an army creator/designer/builder designed to cover a wide range of war game systems")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("WarFoundry")] -[assembly: AssemblyCopyright("IBBoard, 2007-2009")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: - -[assembly: AssemblyVersion("1.0.0.*")] - -// -// In order to sign your assembly you must specify a key to use. Refer to the -// Microsoft .NET Framework documentation for more information on assembly signing. -// -// Use the attributes below to control which key is used for signing. -// -// Notes: -// (*) If no key is specified, the assembly is not signed. -// (*) KeyName refers to a key that has been installed in the Crypto Service -// Provider (CSP) on your machine. KeyFile refers to a file which contains -// a key. -// (*) If the KeyFile and the KeyName values are both specified, the -// following processing occurs: -// (1) If the KeyName can be found in the CSP, that key is used. -// (2) If the KeyName does not exist and the KeyFile does exist, the key -// in the KeyFile is installed into the CSP and used. -// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. -// When specifying the KeyFile, the location of the KeyFile should be -// relative to the project output directory which is -// %Project Directory%\obj\<configuration>. For example, if your KeyFile is -// located in the project directory, you would specify the AssemblyKeyFile -// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] -// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework -// documentation for more information on this. -// -[assembly: AssemblyDelaySign(false)] -[assembly: AssemblyKeyFile("")] -[assembly: AssemblyKeyName("")] +using System.Reflection; +using System.Runtime.CompilerServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly: AssemblyTitle("WarFoundry Army Builder")] +[assembly: AssemblyDescription("WarFoundry is an army creator/designer/builder designed to cover a wide range of war game systems")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WarFoundry")] +[assembly: AssemblyCopyright("IBBoard, 2007-2009")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("1.0.0.*")] + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project output directory which is +// %Project Directory%\obj\<configuration>. For example, if your KeyFile is +// located in the project directory, you would specify the AssemblyKeyFile +// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly: AssemblyDelaySign(false)] +[assembly: AssemblyKeyFile("")] +[assembly: AssemblyKeyName("")]
--- a/FrmArmyTree.cs Sat Jun 27 18:20:22 2009 +0000 +++ b/FrmArmyTree.cs Sat Jun 27 19:01:59 2009 +0000 @@ -140,9 +140,7 @@ htNodes.Clear(); treeView.Nodes.Clear(); - ArrayList list = new ArrayList(htUnitWindows.Values); - - foreach (FrmUnit window in list) + foreach (FrmUnit window in htUnitWindows.Values) { window.Close(); } @@ -152,20 +150,22 @@ private void SetArmy(Army army) { - if (army!=null) + ClearArmy(); + + if (army != null) { ArmyCategory[] cats = army.Categories; TreeNode[] catNodes = new TreeNode[cats.Length]; Unit[] units; - for (int i = 0; i<cats.Length; i++) + for (int i = 0; i < cats.Length; i++) { units = army.GetUnits(cats[i]); cats[i].NameChanged += TreeNameChangedMethod; TreeNode[] unitNodes = new TreeNode[units.Length]; TreeNode temp; - for (int j = 0; j<units.Length; j++) + for (int j = 0; j < units.Length; j++) { unitNodes[j] = createTreeNode(units[j]); } @@ -213,12 +213,9 @@ { newArmy.UnitAdded += UnitAddedMethod; newArmy.UnitRemoved += UnitRemovedMethod; - SetArmy(newArmy); } - else - { - ClearArmy(); - } + + SetArmy(newArmy); } private void AddUnit(object obj)
--- a/FrmDebugOutput.cs Sat Jun 27 18:20:22 2009 +0000 +++ b/FrmDebugOutput.cs Sat Jun 27 19:01:59 2009 +0000 @@ -1,309 +1,309 @@ -// This file (FrmDebugOutput.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. -// -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. - -using System; -using System.Drawing; -using System.Collections; -using System.ComponentModel; -using System.Text; -using System.Windows.Forms; -using IBBoard.Lang; -using IBBoard.Logging; -using IBBoard.Windows.Forms; - -namespace IBBoard.WarFoundry -{ - /// <summary> - /// Summary description for FrmDebugOutput. - /// </summary> - public class FrmDebugOutput : IBBForm - { - private System.Windows.Forms.ListBox lstDebugItems; - private System.Windows.Forms.ComboBox cmbDebugLevel; - private System.Windows.Forms.Label lblDebugLevel; - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.Container components = null; - private System.Windows.Forms.ContextMenu contextMenu; - private System.Windows.Forms.MenuItem miCopy; - private System.Windows.Forms.TextBox txtDetail; - private System.Windows.Forms.Splitter splitter1; - private System.Windows.Forms.Panel panel1; - //private int MAX_LIST_LENGTH = 50; - - public FrmDebugOutput() - { - //this.logger = logger; - //logger.LogUpdatedEvent+=new IBBoard.Logging.Logger.LogUpdatedDelegate(logger_LogUpdatedEvent); - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - /*if (LogLevels.Debug >= logger.LogLevel) - { - cmbDebugLevel.Items.Add(LogLevels.Debug); - } - - if (LogLevels.Info >= logger.LogLevel) - { - cmbDebugLevel.Items.Add(LogLevels.Info); - } - - if (LogLevels.Warning >= logger.LogLevel) - { - cmbDebugLevel.Items.Add(LogLevels.Warning); - } - - if (LogLevels.Error >= logger.LogLevel) - { - cmbDebugLevel.Items.Add(LogLevels.Error); - } - - if (LogLevels.Critical >= logger.LogLevel) - { - cmbDebugLevel.Items.Add(LogLevels.Critical); - }*/ - - this.Name = "DebugOutputForm"; - - //cmbDebugLevel.SelectedItem = logger.LogLevel; - - Translation.Translate(this, true); - - fillDebugList(); - } - - /// <summary> - /// Clean up any resources being used. - /// </summary> - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if(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.lstDebugItems = new System.Windows.Forms.ListBox(); - this.contextMenu = new System.Windows.Forms.ContextMenu(); - this.miCopy = new System.Windows.Forms.MenuItem(); - this.cmbDebugLevel = new System.Windows.Forms.ComboBox(); - this.lblDebugLevel = new System.Windows.Forms.Label(); - this.txtDetail = new System.Windows.Forms.TextBox(); - this.splitter1 = new System.Windows.Forms.Splitter(); - this.panel1 = new System.Windows.Forms.Panel(); - this.SuspendLayout(); - // - // lstDebugItems - // - this.lstDebugItems.ContextMenu = this.contextMenu; - this.lstDebugItems.Dock = System.Windows.Forms.DockStyle.Fill; - this.lstDebugItems.IntegralHeight = false; - this.lstDebugItems.Location = new System.Drawing.Point(0, 24); - this.lstDebugItems.Name = "lstDebugItems"; - this.lstDebugItems.ScrollAlwaysVisible = true; - this.lstDebugItems.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; - this.lstDebugItems.Size = new System.Drawing.Size(656, 144); - this.lstDebugItems.TabIndex = 0; - this.lstDebugItems.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstDebugItems_MouseDown); - this.lstDebugItems.SelectedIndexChanged += new System.EventHandler(this.lstDebugItems_SelectedIndexChanged); - // - // contextMenu - // - this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { - this.miCopy}); - this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup); - // - // miCopy - // - this.miCopy.Index = 0; - this.miCopy.Text = "&Copy"; - this.miCopy.Click += new System.EventHandler(this.miCopy_Click); - // - // cmbDebugLevel - // - this.cmbDebugLevel.Location = new System.Drawing.Point(190, 2); - this.cmbDebugLevel.Name = "cmbDebugLevel"; - this.cmbDebugLevel.Size = new System.Drawing.Size(464, 21); - this.cmbDebugLevel.TabIndex = 1; - this.cmbDebugLevel.SelectedIndexChanged += new System.EventHandler(this.cmbDebugLevel_SelectedIndexChanged); - // - // lblDebugLevel - // - this.lblDebugLevel.Location = new System.Drawing.Point(16, 0); - this.lblDebugLevel.Name = "lblDebugLevel"; - this.lblDebugLevel.Size = new System.Drawing.Size(168, 21); - this.lblDebugLevel.TabIndex = 2; - this.lblDebugLevel.Text = "debug level:"; - this.lblDebugLevel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - // - // txtDetail - // - this.txtDetail.Dock = System.Windows.Forms.DockStyle.Bottom; - this.txtDetail.Location = new System.Drawing.Point(0, 172); - this.txtDetail.Multiline = true; - this.txtDetail.Name = "txtDetail"; - this.txtDetail.ReadOnly = true; - this.txtDetail.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.txtDetail.Size = new System.Drawing.Size(656, 64); - this.txtDetail.TabIndex = 3; - this.txtDetail.TabStop = false; - this.txtDetail.Text = ""; - this.txtDetail.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDetail_KeyDown); - // - // splitter1 - // - this.splitter1.Cursor = System.Windows.Forms.Cursors.HSplit; - this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom; - this.splitter1.Location = new System.Drawing.Point(0, 168); - this.splitter1.MinExtra = 50; - this.splitter1.MinSize = 50; - this.splitter1.Name = "splitter1"; - this.splitter1.Size = new System.Drawing.Size(656, 4); - this.splitter1.TabIndex = 4; - this.splitter1.TabStop = false; - // - // panel1 - // - this.panel1.Dock = System.Windows.Forms.DockStyle.Top; - this.panel1.Location = new System.Drawing.Point(0, 0); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(656, 24); - this.panel1.TabIndex = 5; - // - // FrmDebugOutput - // - this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); - this.ClientSize = new System.Drawing.Size(656, 236); - this.Controls.Add(this.lblDebugLevel); - this.Controls.Add(this.cmbDebugLevel); - this.Controls.Add(this.lstDebugItems); - this.Controls.Add(this.splitter1); - this.Controls.Add(this.panel1); - this.Controls.Add(this.txtDetail); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Name = "FrmDebugOutput"; - this.ShowInTaskbar = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "FrmDebugOutput"; - this.ResumeLayout(false); - - } - #endregion - - private void cmbDebugLevel_SelectedIndexChanged(object sender, System.EventArgs e) - { - fillDebugList(); - } - - private void fillDebugList() - { - lstDebugItems.Items.Clear(); - /*LogItem[] items = logger.GetLogItems((LogLevels)cmbDebugLevel.SelectedItem); - int last = items.Length - 1; - int stop = last - MAX_LIST_LENGTH; - - if (stop < 0) - { - stop = 0; - } - - //reverse fill the list so that we can have newest items at the top - for (int i = last; i >= stop; i--) - { - lstDebugItems.Items.Add(items[i]); - }*/ - } - - private void logger_LogUpdatedEvent(LogItem item) - { - /*if (item.Level >= (LogLevels)cmbDebugLevel.SelectedItem) - { - lock (lstDebugItems) - { - lstDebugItems.Items.Insert(0, item); - - if (lstDebugItems.Items.Count > MAX_LIST_LENGTH) - { - lstDebugItems.Items.RemoveAt(lstDebugItems.Items.Count - 1); - } - } - }*/ - } - - private void miCopy_Click(object sender, System.EventArgs e) - { - if (lstDebugItems.SelectedIndices.Count==1) - { - Clipboard.SetDataObject(lstDebugItems.SelectedItem.ToString()); - } - else if (lstDebugItems.SelectedIndices.Count > 1) - { - StringBuilder sb = new StringBuilder(); - - foreach (int idx in lstDebugItems.SelectedIndices) - { - sb.Append(lstDebugItems.Items[idx].ToString()+Environment.NewLine); - } - - Clipboard.SetDataObject(sb.ToString().Trim()); - } - } - - private void contextMenu_Popup(object sender, System.EventArgs e) - { - foreach (MenuItem mi in contextMenu.MenuItems) - { - mi.Visible = lstDebugItems.SelectedIndex > -1; - } - } - - private void lstDebugItems_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) - { - if (e.Button == MouseButtons.Right) - { - int idx = lstDebugItems.IndexFromPoint(e.X, e.Y); - - if (lstDebugItems.SelectedIndices.Contains(idx)) - { - lstDebugItems.SelectedIndex = idx; - } - } - } - - private void lstDebugItems_SelectedIndexChanged(object sender, System.EventArgs e) - { - if (lstDebugItems.SelectedIndex > -1) - { - LogItem item = (LogItem)lstDebugItems.SelectedItem; - txtDetail.Text = item.ToString() + Environment.NewLine + Environment.NewLine + "Stack Trace: "+ item.StackTrace; - } - else - { - txtDetail.Text = ""; - } - } - - private void txtDetail_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) - { - if(e.KeyData == (Keys.Control|Keys.A) && e.Control) - { - txtDetail.SelectAll(); - } - } - } -} +// This file (FrmDebugOutput.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. +// +// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. + +using System; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Text; +using System.Windows.Forms; +using IBBoard.Lang; +using IBBoard.Logging; +using IBBoard.Windows.Forms; + +namespace IBBoard.WarFoundry +{ + /// <summary> + /// Summary description for FrmDebugOutput. + /// </summary> + public class FrmDebugOutput : IBBForm + { + private System.Windows.Forms.ListBox lstDebugItems; + private System.Windows.Forms.ComboBox cmbDebugLevel; + private System.Windows.Forms.Label lblDebugLevel; + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.Container components = null; + private System.Windows.Forms.ContextMenu contextMenu; + private System.Windows.Forms.MenuItem miCopy; + private System.Windows.Forms.TextBox txtDetail; + private System.Windows.Forms.Splitter splitter1; + private System.Windows.Forms.Panel panel1; + //private int MAX_LIST_LENGTH = 50; + + public FrmDebugOutput() + { + //this.logger = logger; + //logger.LogUpdatedEvent+=new IBBoard.Logging.Logger.LogUpdatedDelegate(logger_LogUpdatedEvent); + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + /*if (LogLevels.Debug >= logger.LogLevel) + { + cmbDebugLevel.Items.Add(LogLevels.Debug); + } + + if (LogLevels.Info >= logger.LogLevel) + { + cmbDebugLevel.Items.Add(LogLevels.Info); + } + + if (LogLevels.Warning >= logger.LogLevel) + { + cmbDebugLevel.Items.Add(LogLevels.Warning); + } + + if (LogLevels.Error >= logger.LogLevel) + { + cmbDebugLevel.Items.Add(LogLevels.Error); + } + + if (LogLevels.Critical >= logger.LogLevel) + { + cmbDebugLevel.Items.Add(LogLevels.Critical); + }*/ + + this.Name = "DebugOutputForm"; + + //cmbDebugLevel.SelectedItem = logger.LogLevel; + + Translation.Translate(this, true); + + fillDebugList(); + } + + /// <summary> + /// Clean up any resources being used. + /// </summary> + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if(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.lstDebugItems = new System.Windows.Forms.ListBox(); + this.contextMenu = new System.Windows.Forms.ContextMenu(); + this.miCopy = new System.Windows.Forms.MenuItem(); + this.cmbDebugLevel = new System.Windows.Forms.ComboBox(); + this.lblDebugLevel = new System.Windows.Forms.Label(); + this.txtDetail = new System.Windows.Forms.TextBox(); + this.splitter1 = new System.Windows.Forms.Splitter(); + this.panel1 = new System.Windows.Forms.Panel(); + this.SuspendLayout(); + // + // lstDebugItems + // + this.lstDebugItems.ContextMenu = this.contextMenu; + this.lstDebugItems.Dock = System.Windows.Forms.DockStyle.Fill; + this.lstDebugItems.IntegralHeight = false; + this.lstDebugItems.Location = new System.Drawing.Point(0, 24); + this.lstDebugItems.Name = "lstDebugItems"; + this.lstDebugItems.ScrollAlwaysVisible = true; + this.lstDebugItems.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; + this.lstDebugItems.Size = new System.Drawing.Size(656, 144); + this.lstDebugItems.TabIndex = 0; + this.lstDebugItems.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstDebugItems_MouseDown); + this.lstDebugItems.SelectedIndexChanged += new System.EventHandler(this.lstDebugItems_SelectedIndexChanged); + // + // contextMenu + // + this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { + this.miCopy}); + this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup); + // + // miCopy + // + this.miCopy.Index = 0; + this.miCopy.Text = "&Copy"; + this.miCopy.Click += new System.EventHandler(this.miCopy_Click); + // + // cmbDebugLevel + // + this.cmbDebugLevel.Location = new System.Drawing.Point(190, 2); + this.cmbDebugLevel.Name = "cmbDebugLevel"; + this.cmbDebugLevel.Size = new System.Drawing.Size(464, 21); + this.cmbDebugLevel.TabIndex = 1; + this.cmbDebugLevel.SelectedIndexChanged += new System.EventHandler(this.cmbDebugLevel_SelectedIndexChanged); + // + // lblDebugLevel + // + this.lblDebugLevel.Location = new System.Drawing.Point(16, 0); + this.lblDebugLevel.Name = "lblDebugLevel"; + this.lblDebugLevel.Size = new System.Drawing.Size(168, 21); + this.lblDebugLevel.TabIndex = 2; + this.lblDebugLevel.Text = "debug level:"; + this.lblDebugLevel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // txtDetail + // + this.txtDetail.Dock = System.Windows.Forms.DockStyle.Bottom; + this.txtDetail.Location = new System.Drawing.Point(0, 172); + this.txtDetail.Multiline = true; + this.txtDetail.Name = "txtDetail"; + this.txtDetail.ReadOnly = true; + this.txtDetail.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.txtDetail.Size = new System.Drawing.Size(656, 64); + this.txtDetail.TabIndex = 3; + this.txtDetail.TabStop = false; + this.txtDetail.Text = ""; + this.txtDetail.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDetail_KeyDown); + // + // splitter1 + // + this.splitter1.Cursor = System.Windows.Forms.Cursors.HSplit; + this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.splitter1.Location = new System.Drawing.Point(0, 168); + this.splitter1.MinExtra = 50; + this.splitter1.MinSize = 50; + this.splitter1.Name = "splitter1"; + this.splitter1.Size = new System.Drawing.Size(656, 4); + this.splitter1.TabIndex = 4; + this.splitter1.TabStop = false; + // + // panel1 + // + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(656, 24); + this.panel1.TabIndex = 5; + // + // FrmDebugOutput + // + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.ClientSize = new System.Drawing.Size(656, 236); + this.Controls.Add(this.lblDebugLevel); + this.Controls.Add(this.cmbDebugLevel); + this.Controls.Add(this.lstDebugItems); + this.Controls.Add(this.splitter1); + this.Controls.Add(this.panel1); + this.Controls.Add(this.txtDetail); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Name = "FrmDebugOutput"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "FrmDebugOutput"; + this.ResumeLayout(false); + + } + #endregion + + private void cmbDebugLevel_SelectedIndexChanged(object sender, System.EventArgs e) + { + fillDebugList(); + } + + private void fillDebugList() + { + lstDebugItems.Items.Clear(); + /*LogItem[] items = logger.GetLogItems((LogLevels)cmbDebugLevel.SelectedItem); + int last = items.Length - 1; + int stop = last - MAX_LIST_LENGTH; + + if (stop < 0) + { + stop = 0; + } + + //reverse fill the list so that we can have newest items at the top + for (int i = last; i >= stop; i--) + { + lstDebugItems.Items.Add(items[i]); + }*/ + } + + private void logger_LogUpdatedEvent(LogItem item) + { + /*if (item.Level >= (LogLevels)cmbDebugLevel.SelectedItem) + { + lock (lstDebugItems) + { + lstDebugItems.Items.Insert(0, item); + + if (lstDebugItems.Items.Count > MAX_LIST_LENGTH) + { + lstDebugItems.Items.RemoveAt(lstDebugItems.Items.Count - 1); + } + } + }*/ + } + + private void miCopy_Click(object sender, System.EventArgs e) + { + if (lstDebugItems.SelectedIndices.Count==1) + { + Clipboard.SetDataObject(lstDebugItems.SelectedItem.ToString()); + } + else if (lstDebugItems.SelectedIndices.Count > 1) + { + StringBuilder sb = new StringBuilder(); + + foreach (int idx in lstDebugItems.SelectedIndices) + { + sb.Append(lstDebugItems.Items[idx].ToString()+Environment.NewLine); + } + + Clipboard.SetDataObject(sb.ToString().Trim()); + } + } + + private void contextMenu_Popup(object sender, System.EventArgs e) + { + foreach (MenuItem mi in contextMenu.MenuItems) + { + mi.Visible = lstDebugItems.SelectedIndex > -1; + } + } + + private void lstDebugItems_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) + { + if (e.Button == MouseButtons.Right) + { + int idx = lstDebugItems.IndexFromPoint(e.X, e.Y); + + if (lstDebugItems.SelectedIndices.Contains(idx)) + { + lstDebugItems.SelectedIndex = idx; + } + } + } + + private void lstDebugItems_SelectedIndexChanged(object sender, System.EventArgs e) + { + if (lstDebugItems.SelectedIndex > -1) + { + LogItem item = (LogItem)lstDebugItems.SelectedItem; + txtDetail.Text = item.ToString() + Environment.NewLine + Environment.NewLine + "Stack Trace: "+ item.StackTrace; + } + else + { + txtDetail.Text = ""; + } + } + + private void txtDetail_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) + { + if(e.KeyData == (Keys.Control|Keys.A) && e.Control) + { + txtDetail.SelectAll(); + } + } + } +}
--- a/FrmEditUnitEquipment.cs Sat Jun 27 18:20:22 2009 +0000 +++ b/FrmEditUnitEquipment.cs Sat Jun 27 19:01:59 2009 +0000 @@ -1,252 +1,252 @@ -// This file (FrmEditUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. -// -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. - -using System; -using System.Drawing; -using System.Collections; -using System.ComponentModel; -using System.Windows.Forms; -using IBBoard.Commands; -using IBBoard.WarFoundry.API; -using IBBoard.WarFoundry.API.Commands; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry -{ - /// <summary> - /// Summary description for FrmEditUnitEquipment. - /// </summary> - public class FrmEditUnitEquipment : System.Windows.Forms.Form - { - private Unit unit; - private UnitEquipmentItem equipItem; - private double equipAmount; - private CommandStack commandStack; - - private System.Windows.Forms.NumericUpDown numEquipAmount; - private System.Windows.Forms.Label lblPercent; - private System.Windows.Forms.Label lblAmount; - private System.Windows.Forms.Button bttnCancel; - private System.Windows.Forms.Button bttnOkay; - private System.Windows.Forms.CheckBox cbEquipAll; - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.Container components = null; - - public FrmEditUnitEquipment(Unit unit, UnitEquipmentItem equipItem, CommandStack stack) - { - commandStack = stack; - this.unit = unit; - this.equipItem = equipItem; - InitializeComponent(); - this.Text = equipItem.Name + " for " + unit.Name; - equipAmount = unit.GetEquipmentAmount(equipItem); - - if (equipItem.IsRatioLimit) - { - numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2); - numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2); - numEquipAmount.Value = (decimal)Math.Round(equipAmount * 100, 2); - cbEquipAll.Enabled = false; - lblPercent.Visible = true; - numEquipAmount.Width = 120; - } - else - { - numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? equipItem.MinNumber : unit.Size); - numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? equipItem.MaxNumber : unit.Size); - numEquipAmount.Value = (decimal)(equipAmount == WarFoundryCore.INFINITY ? unit.Size : equipAmount); - cbEquipAll.Checked = (equipAmount == WarFoundryCore.INFINITY); - cbEquipAll.Enabled = (equipItem.MaxNumber == WarFoundryCore.INFINITY && equipItem.MinNumber != WarFoundryCore.INFINITY); - numEquipAmount.Enabled = !cbEquipAll.Checked && equipItem.MinNumber != WarFoundryCore.INFINITY; - numEquipAmount.Width = 144; - } - - bttnOkay.Enabled = false; - } - - /// <summary> - /// Clean up any resources being used. - /// </summary> - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if(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.numEquipAmount = new System.Windows.Forms.NumericUpDown(); - this.lblPercent = new System.Windows.Forms.Label(); - this.lblAmount = new System.Windows.Forms.Label(); - this.bttnCancel = new System.Windows.Forms.Button(); - this.bttnOkay = new System.Windows.Forms.Button(); - this.cbEquipAll = new System.Windows.Forms.CheckBox(); - ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); - this.SuspendLayout(); - // - // numEquipAmount - // - this.numEquipAmount.Location = new System.Drawing.Point(88, 8); - this.numEquipAmount.Name = "numEquipAmount"; - this.numEquipAmount.Size = new System.Drawing.Size(144, 20); - this.numEquipAmount.TabIndex = 0; - this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged); - // - // lblPercent - // - this.lblPercent.Location = new System.Drawing.Point(208, 8); - this.lblPercent.Name = "lblPercent"; - this.lblPercent.Size = new System.Drawing.Size(16, 16); - this.lblPercent.TabIndex = 1; - this.lblPercent.Text = "%"; - this.lblPercent.Visible = false; - // - // lblAmount - // - this.lblAmount.Location = new System.Drawing.Point(8, 8); - this.lblAmount.Name = "lblAmount"; - this.lblAmount.Size = new System.Drawing.Size(72, 23); - this.lblAmount.TabIndex = 2; - this.lblAmount.Text = "amount"; - this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // bttnCancel - // - this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnCancel.Location = new System.Drawing.Point(160, 64); - this.bttnCancel.Name = "bttnCancel"; - this.bttnCancel.TabIndex = 3; - this.bttnCancel.Text = "cancel"; - this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); - // - // bttnOkay - // - this.bttnOkay.Enabled = false; - this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnOkay.Location = new System.Drawing.Point(8, 64); - this.bttnOkay.Name = "bttnOkay"; - this.bttnOkay.TabIndex = 4; - this.bttnOkay.Text = "okay"; - this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); - // - // cbEquipAll - // - this.cbEquipAll.Enabled = false; - this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.cbEquipAll.Location = new System.Drawing.Point(88, 32); - this.cbEquipAll.Name = "cbEquipAll"; - this.cbEquipAll.TabIndex = 5; - this.cbEquipAll.Text = "equip all"; - this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged); - // - // FrmEditUnitEquipment - // - this.AcceptButton = this.bttnOkay; - this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); - this.CancelButton = this.bttnCancel; - this.ClientSize = new System.Drawing.Size(240, 92); - this.ControlBox = false; - this.Controls.Add(this.cbEquipAll); - this.Controls.Add(this.bttnOkay); - this.Controls.Add(this.bttnCancel); - this.Controls.Add(this.lblAmount); - this.Controls.Add(this.numEquipAmount); - this.Controls.Add(this.lblPercent); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Name = "FrmEditUnitEquipment"; - this.ShowInTaskbar = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "FrmEditUnitEquipment"; - ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit(); - this.ResumeLayout(false); - - } - #endregion - - private void bttnOkay_Click(object sender, System.EventArgs e) - { - if (setValue()) - { - this.Close(); - } - } - - private bool setValue() - { - if ((!numEquipAmount.Enabled || numEquipAmount.Value == 0) && !cbEquipAll.Checked && unit.GetEquipmentAmount(equipItem) != 0) - { - if (equipItem.IsRequired) - { - MessageBox.Show(this, "This item is required and cannot be removed. It must have a quantity of at least one or be replaced by an alternative.", "Required item", MessageBoxButtons.OK, MessageBoxIcon.Warning); - return false; - } - else - { - DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); - - if (dr!=DialogResult.Yes) - { - return false; - } - } - } - - if (cbEquipAll.Checked) - { - if (equipAmount != WarFoundryCore.INFINITY) - { - commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, WarFoundryCore.INFINITY)); - } - } - else if (numEquipAmount.Value != (decimal)equipAmount) - { - if (equipItem.IsRatioLimit) - { - commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, ((double)numEquipAmount.Value / 100.0))); - } - else - { - commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value)); - } - } - - return true; - } - - private void bttnCancel_Click(object sender, System.EventArgs e) - { - this.Close(); - } - - private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) - { - numEquipAmount.Enabled = !cbEquipAll.Checked && equipItem.MinNumber != WarFoundryCore.INFINITY; - setOkayButton(); - } - - private void setOkayButton() - { - bttnOkay.Enabled = (cbEquipAll.Checked || (numEquipAmount.Enabled && (numEquipAmount.Value > 0 || !equipItem.IsRequired))); - } - - private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) - { - setOkayButton(); - } - } -} +// This file (FrmEditUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. +// +// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. + +using System; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms; +using IBBoard.Commands; +using IBBoard.WarFoundry.API; +using IBBoard.WarFoundry.API.Commands; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry +{ + /// <summary> + /// Summary description for FrmEditUnitEquipment. + /// </summary> + public class FrmEditUnitEquipment : System.Windows.Forms.Form + { + private Unit unit; + private UnitEquipmentItem equipItem; + private double equipAmount; + private CommandStack commandStack; + + private System.Windows.Forms.NumericUpDown numEquipAmount; + private System.Windows.Forms.Label lblPercent; + private System.Windows.Forms.Label lblAmount; + private System.Windows.Forms.Button bttnCancel; + private System.Windows.Forms.Button bttnOkay; + private System.Windows.Forms.CheckBox cbEquipAll; + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.Container components = null; + + public FrmEditUnitEquipment(Unit unit, UnitEquipmentItem equipItem, CommandStack stack) + { + commandStack = stack; + this.unit = unit; + this.equipItem = equipItem; + InitializeComponent(); + this.Text = equipItem.Name + " for " + unit.Name; + equipAmount = unit.GetEquipmentAmount(equipItem); + + if (equipItem.IsRatioLimit) + { + numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2); + numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2); + numEquipAmount.Value = (decimal)Math.Round(equipAmount * 100, 2); + cbEquipAll.Enabled = false; + lblPercent.Visible = true; + numEquipAmount.Width = 120; + } + else + { + numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? equipItem.MinNumber : unit.Size); + numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? equipItem.MaxNumber : unit.Size); + numEquipAmount.Value = (decimal)(equipAmount == WarFoundryCore.INFINITY ? unit.Size : equipAmount); + cbEquipAll.Checked = (equipAmount == WarFoundryCore.INFINITY); + cbEquipAll.Enabled = (equipItem.MaxNumber == WarFoundryCore.INFINITY && equipItem.MinNumber != WarFoundryCore.INFINITY); + numEquipAmount.Enabled = !cbEquipAll.Checked && equipItem.MinNumber != WarFoundryCore.INFINITY; + numEquipAmount.Width = 144; + } + + bttnOkay.Enabled = false; + } + + /// <summary> + /// Clean up any resources being used. + /// </summary> + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if(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.numEquipAmount = new System.Windows.Forms.NumericUpDown(); + this.lblPercent = new System.Windows.Forms.Label(); + this.lblAmount = new System.Windows.Forms.Label(); + this.bttnCancel = new System.Windows.Forms.Button(); + this.bttnOkay = new System.Windows.Forms.Button(); + this.cbEquipAll = new System.Windows.Forms.CheckBox(); + ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); + this.SuspendLayout(); + // + // numEquipAmount + // + this.numEquipAmount.Location = new System.Drawing.Point(88, 8); + this.numEquipAmount.Name = "numEquipAmount"; + this.numEquipAmount.Size = new System.Drawing.Size(144, 20); + this.numEquipAmount.TabIndex = 0; + this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged); + // + // lblPercent + // + this.lblPercent.Location = new System.Drawing.Point(208, 8); + this.lblPercent.Name = "lblPercent"; + this.lblPercent.Size = new System.Drawing.Size(16, 16); + this.lblPercent.TabIndex = 1; + this.lblPercent.Text = "%"; + this.lblPercent.Visible = false; + // + // lblAmount + // + this.lblAmount.Location = new System.Drawing.Point(8, 8); + this.lblAmount.Name = "lblAmount"; + this.lblAmount.Size = new System.Drawing.Size(72, 23); + this.lblAmount.TabIndex = 2; + this.lblAmount.Text = "amount"; + this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // bttnCancel + // + this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnCancel.Location = new System.Drawing.Point(160, 64); + this.bttnCancel.Name = "bttnCancel"; + this.bttnCancel.TabIndex = 3; + this.bttnCancel.Text = "cancel"; + this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); + // + // bttnOkay + // + this.bttnOkay.Enabled = false; + this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnOkay.Location = new System.Drawing.Point(8, 64); + this.bttnOkay.Name = "bttnOkay"; + this.bttnOkay.TabIndex = 4; + this.bttnOkay.Text = "okay"; + this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); + // + // cbEquipAll + // + this.cbEquipAll.Enabled = false; + this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.cbEquipAll.Location = new System.Drawing.Point(88, 32); + this.cbEquipAll.Name = "cbEquipAll"; + this.cbEquipAll.TabIndex = 5; + this.cbEquipAll.Text = "equip all"; + this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged); + // + // FrmEditUnitEquipment + // + this.AcceptButton = this.bttnOkay; + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.CancelButton = this.bttnCancel; + this.ClientSize = new System.Drawing.Size(240, 92); + this.ControlBox = false; + this.Controls.Add(this.cbEquipAll); + this.Controls.Add(this.bttnOkay); + this.Controls.Add(this.bttnCancel); + this.Controls.Add(this.lblAmount); + this.Controls.Add(this.numEquipAmount); + this.Controls.Add(this.lblPercent); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Name = "FrmEditUnitEquipment"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "FrmEditUnitEquipment"; + ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit(); + this.ResumeLayout(false); + + } + #endregion + + private void bttnOkay_Click(object sender, System.EventArgs e) + { + if (setValue()) + { + this.Close(); + } + } + + private bool setValue() + { + if ((!numEquipAmount.Enabled || numEquipAmount.Value == 0) && !cbEquipAll.Checked && unit.GetEquipmentAmount(equipItem) != 0) + { + if (equipItem.IsRequired) + { + MessageBox.Show(this, "This item is required and cannot be removed. It must have a quantity of at least one or be replaced by an alternative.", "Required item", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return false; + } + else + { + DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); + + if (dr!=DialogResult.Yes) + { + return false; + } + } + } + + if (cbEquipAll.Checked) + { + if (equipAmount != WarFoundryCore.INFINITY) + { + commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, WarFoundryCore.INFINITY)); + } + } + else if (numEquipAmount.Value != (decimal)equipAmount) + { + if (equipItem.IsRatioLimit) + { + commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, ((double)numEquipAmount.Value / 100.0))); + } + else + { + commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value)); + } + } + + return true; + } + + private void bttnCancel_Click(object sender, System.EventArgs e) + { + this.Close(); + } + + private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) + { + numEquipAmount.Enabled = !cbEquipAll.Checked && equipItem.MinNumber != WarFoundryCore.INFINITY; + setOkayButton(); + } + + private void setOkayButton() + { + bttnOkay.Enabled = (cbEquipAll.Checked || (numEquipAmount.Enabled && (numEquipAmount.Value > 0 || !equipItem.IsRequired))); + } + + private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) + { + setOkayButton(); + } + } +}
--- a/FrmNewArmy.cs Sat Jun 27 18:20:22 2009 +0000 +++ b/FrmNewArmy.cs Sat Jun 27 19:01:59 2009 +0000 @@ -1,244 +1,244 @@ -// This file (FrmNewArmy.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. -// -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. - -using System; -using System.Drawing; -using System.Collections; -using System.ComponentModel; -using System.Windows.Forms; -using IBBoard; -using IBBoard.Lang; -using IBBoard.Windows.Forms; -using IBBoard.WarFoundry.API; -using IBBoard.WarFoundry.API.Objects; -using IBBoard.Windows.Forms.I18N; - -namespace IBBoard.WarFoundry -{ - /// <summary> - /// Summary description for FrmNewArmy. - /// </summary> - public class FrmNewArmy : IBBForm - { - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.Container components = null; - private IBBoard.Windows.Forms.IBBButton bttnCancel; - private IBBoard.Windows.Forms.IBBLabel lblRaceList; - private IBBoard.Windows.Forms.IBBButton bttnSelectRace; - private System.Windows.Forms.ListBox lstRaces; - private Race[] races; - private IBBoard.Windows.Forms.IBBLabel lblArmyName; - private IBBoard.Windows.Forms.IBBLabel lblArmySize; - private System.Windows.Forms.NumericUpDown armySize; - private System.Windows.Forms.TextBox txtArmyName; - - public FrmNewArmy(GameSystem system) - { - InitializeComponent(); - - ControlTranslator.TranslateControl(this); - - races = WarFoundryLoader.GetDefault().GetRaces(system); - - for (int i = 0; i<races.Length; i++) - { - lstRaces.Items.Add(races[i].Name); - } - } - - /// <summary> - /// Clean up any resources being used. - /// </summary> - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if(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() - { - System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmNewArmy)); - this.lstRaces = new System.Windows.Forms.ListBox(); - this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); - this.lblRaceList = new IBBoard.Windows.Forms.IBBLabel(); - this.bttnSelectRace = new IBBoard.Windows.Forms.IBBButton(); - this.lblArmyName = new IBBoard.Windows.Forms.IBBLabel(); - this.txtArmyName = new System.Windows.Forms.TextBox(); - this.lblArmySize = new IBBoard.Windows.Forms.IBBLabel(); - this.armySize = new System.Windows.Forms.NumericUpDown(); - ((System.ComponentModel.ISupportInitialize)(this.armySize)).BeginInit(); - this.SuspendLayout(); - // - // lstRaces - // - this.lstRaces.Location = new System.Drawing.Point(88, 8); - this.lstRaces.Name = "lstRaces"; - this.lstRaces.Size = new System.Drawing.Size(272, 121); - this.lstRaces.TabIndex = 7; - this.lstRaces.SelectedIndexChanged += new System.EventHandler(this.lstRaces_SelectedIndexChanged); - // - // bttnCancel - // - this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnCancel.Location = new System.Drawing.Point(8, 200); - this.bttnCancel.Name = "bttnCancel"; - this.bttnCancel.Size = new System.Drawing.Size(80, 24); - this.bttnCancel.TabIndex = 6; - this.bttnCancel.Text = "Cancel"; - this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); - // - // lblRaceList - // - this.lblRaceList.Location = new System.Drawing.Point(0, 8); - this.lblRaceList.Name = "lblRaceList"; - this.lblRaceList.Size = new System.Drawing.Size(88, 80); - this.lblRaceList.TabIndex = 5; - this.lblRaceList.Text = "race list"; - this.lblRaceList.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // bttnSelectRace - // - this.bttnSelectRace.Enabled = false; - this.bttnSelectRace.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnSelectRace.Location = new System.Drawing.Point(256, 200); - this.bttnSelectRace.Name = "bttnSelectRace"; - this.bttnSelectRace.Size = new System.Drawing.Size(104, 24); - this.bttnSelectRace.TabIndex = 4; - this.bttnSelectRace.Text = "create race"; - this.bttnSelectRace.Click += new System.EventHandler(this.bttnSelectRace_Click); - // - // lblArmyName - // - this.lblArmyName.Location = new System.Drawing.Point(0, 136); - this.lblArmyName.Name = "lblArmyName"; - this.lblArmyName.Size = new System.Drawing.Size(88, 32); - this.lblArmyName.TabIndex = 8; - this.lblArmyName.Text = "army name"; - this.lblArmyName.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // txtArmyName - // - this.txtArmyName.Location = new System.Drawing.Point(88, 136); - this.txtArmyName.Name = "txtArmyName"; - this.txtArmyName.Size = new System.Drawing.Size(272, 20); - this.txtArmyName.TabIndex = 9; - this.txtArmyName.Text = ""; - this.txtArmyName.TextChanged += new System.EventHandler(this.txtArmyName_TextChanged); - // - // lblArmySize - // - this.lblArmySize.Location = new System.Drawing.Point(0, 168); - this.lblArmySize.Name = "lblArmySize"; - this.lblArmySize.Size = new System.Drawing.Size(88, 32); - this.lblArmySize.TabIndex = 10; - this.lblArmySize.Text = "army size"; - this.lblArmySize.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // armySize - // - this.armySize.Increment = new System.Decimal(new int[] { - 50, - 0, - 0, - 0}); - this.armySize.Location = new System.Drawing.Point(88, 168); - this.armySize.Maximum = new System.Decimal(new int[] { - 1000000, - 0, - 0, - 0}); - this.armySize.Name = "armySize"; - this.armySize.TabIndex = 11; - this.armySize.ThousandsSeparator = true; - this.armySize.Value = new System.Decimal(new int[] { - 2000, - 0, - 0, - 0}); - // - // FrmNewArmy - // - this.AcceptButton = this.bttnSelectRace; - this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); - this.CancelButton = this.bttnCancel; - this.ClientSize = new System.Drawing.Size(370, 228); - this.Controls.Add(this.armySize); - this.Controls.Add(this.lblArmySize); - this.Controls.Add(this.txtArmyName); - this.Controls.Add(this.lblArmyName); - this.Controls.Add(this.bttnCancel); - this.Controls.Add(this.lblRaceList); - this.Controls.Add(this.bttnSelectRace); - this.Controls.Add(this.lstRaces); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "FrmNewArmy"; - this.ShowInTaskbar = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "FrmNewArmy"; - ((System.ComponentModel.ISupportInitialize)(this.armySize)).EndInit(); - this.ResumeLayout(false); - - } - #endregion - - public Race SelectedRace - { - get { return races[lstRaces.SelectedIndex]; } - } - - public string ArmyName - { - get { return txtArmyName.Text; } - } - - public int ArmySize - { - get { return (int)armySize.Value; } - } - - private void bttnCancel_Click(object sender, System.EventArgs e) - { - DialogResult = DialogResult.Cancel; - this.Close(); - } - - private void bttnSelectRace_Click(object sender, System.EventArgs e) - { - DialogResult = DialogResult.OK; - this.Close(); - } - - private void txtArmyName_TextChanged(object sender, System.EventArgs e) - { - setSelectRaceEnabledVal(); - } - - private void setSelectRaceEnabledVal() - { - bttnSelectRace.Enabled = (lstRaces.SelectedIndex>-1 && txtArmyName.Text.Trim()!="" && armySize.Value > 0); - } - - private void lstRaces_SelectedIndexChanged(object sender, System.EventArgs e) - { - setSelectRaceEnabledVal(); - } - } -} +// This file (FrmNewArmy.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. +// +// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. + +using System; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms; +using IBBoard; +using IBBoard.Lang; +using IBBoard.Windows.Forms; +using IBBoard.WarFoundry.API; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.Windows.Forms.I18N; + +namespace IBBoard.WarFoundry +{ + /// <summary> + /// Summary description for FrmNewArmy. + /// </summary> + public class FrmNewArmy : IBBForm + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.Container components = null; + private IBBoard.Windows.Forms.IBBButton bttnCancel; + private IBBoard.Windows.Forms.IBBLabel lblRaceList; + private IBBoard.Windows.Forms.IBBButton bttnSelectRace; + private System.Windows.Forms.ListBox lstRaces; + private Race[] races; + private IBBoard.Windows.Forms.IBBLabel lblArmyName; + private IBBoard.Windows.Forms.IBBLabel lblArmySize; + private System.Windows.Forms.NumericUpDown armySize; + private System.Windows.Forms.TextBox txtArmyName; + + public FrmNewArmy(GameSystem system) + { + InitializeComponent(); + + ControlTranslator.TranslateControl(this); + + races = WarFoundryLoader.GetDefault().GetRaces(system); + + for (int i = 0; i<races.Length; i++) + { + lstRaces.Items.Add(races[i].Name); + } + } + + /// <summary> + /// Clean up any resources being used. + /// </summary> + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if(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() + { + System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmNewArmy)); + this.lstRaces = new System.Windows.Forms.ListBox(); + this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); + this.lblRaceList = new IBBoard.Windows.Forms.IBBLabel(); + this.bttnSelectRace = new IBBoard.Windows.Forms.IBBButton(); + this.lblArmyName = new IBBoard.Windows.Forms.IBBLabel(); + this.txtArmyName = new System.Windows.Forms.TextBox(); + this.lblArmySize = new IBBoard.Windows.Forms.IBBLabel(); + this.armySize = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.armySize)).BeginInit(); + this.SuspendLayout(); + // + // lstRaces + // + this.lstRaces.Location = new System.Drawing.Point(88, 8); + this.lstRaces.Name = "lstRaces"; + this.lstRaces.Size = new System.Drawing.Size(272, 121); + this.lstRaces.TabIndex = 7; + this.lstRaces.SelectedIndexChanged += new System.EventHandler(this.lstRaces_SelectedIndexChanged); + // + // bttnCancel + // + this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnCancel.Location = new System.Drawing.Point(8, 200); + this.bttnCancel.Name = "bttnCancel"; + this.bttnCancel.Size = new System.Drawing.Size(80, 24); + this.bttnCancel.TabIndex = 6; + this.bttnCancel.Text = "Cancel"; + this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); + // + // lblRaceList + // + this.lblRaceList.Location = new System.Drawing.Point(0, 8); + this.lblRaceList.Name = "lblRaceList"; + this.lblRaceList.Size = new System.Drawing.Size(88, 80); + this.lblRaceList.TabIndex = 5; + this.lblRaceList.Text = "race list"; + this.lblRaceList.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // bttnSelectRace + // + this.bttnSelectRace.Enabled = false; + this.bttnSelectRace.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnSelectRace.Location = new System.Drawing.Point(256, 200); + this.bttnSelectRace.Name = "bttnSelectRace"; + this.bttnSelectRace.Size = new System.Drawing.Size(104, 24); + this.bttnSelectRace.TabIndex = 4; + this.bttnSelectRace.Text = "create race"; + this.bttnSelectRace.Click += new System.EventHandler(this.bttnSelectRace_Click); + // + // lblArmyName + // + this.lblArmyName.Location = new System.Drawing.Point(0, 136); + this.lblArmyName.Name = "lblArmyName"; + this.lblArmyName.Size = new System.Drawing.Size(88, 32); + this.lblArmyName.TabIndex = 8; + this.lblArmyName.Text = "army name"; + this.lblArmyName.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // txtArmyName + // + this.txtArmyName.Location = new System.Drawing.Point(88, 136); + this.txtArmyName.Name = "txtArmyName"; + this.txtArmyName.Size = new System.Drawing.Size(272, 20); + this.txtArmyName.TabIndex = 9; + this.txtArmyName.Text = ""; + this.txtArmyName.TextChanged += new System.EventHandler(this.txtArmyName_TextChanged); + // + // lblArmySize + // + this.lblArmySize.Location = new System.Drawing.Point(0, 168); + this.lblArmySize.Name = "lblArmySize"; + this.lblArmySize.Size = new System.Drawing.Size(88, 32); + this.lblArmySize.TabIndex = 10; + this.lblArmySize.Text = "army size"; + this.lblArmySize.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // armySize + // + this.armySize.Increment = new System.Decimal(new int[] { + 50, + 0, + 0, + 0}); + this.armySize.Location = new System.Drawing.Point(88, 168); + this.armySize.Maximum = new System.Decimal(new int[] { + 1000000, + 0, + 0, + 0}); + this.armySize.Name = "armySize"; + this.armySize.TabIndex = 11; + this.armySize.ThousandsSeparator = true; + this.armySize.Value = new System.Decimal(new int[] { + 2000, + 0, + 0, + 0}); + // + // FrmNewArmy + // + this.AcceptButton = this.bttnSelectRace; + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.CancelButton = this.bttnCancel; + this.ClientSize = new System.Drawing.Size(370, 228); + this.Controls.Add(this.armySize); + this.Controls.Add(this.lblArmySize); + this.Controls.Add(this.txtArmyName); + this.Controls.Add(this.lblArmyName); + this.Controls.Add(this.bttnCancel); + this.Controls.Add(this.lblRaceList); + this.Controls.Add(this.bttnSelectRace); + this.Controls.Add(this.lstRaces); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "FrmNewArmy"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "FrmNewArmy"; + ((System.ComponentModel.ISupportInitialize)(this.armySize)).EndInit(); + this.ResumeLayout(false); + + } + #endregion + + public Race SelectedRace + { + get { return races[lstRaces.SelectedIndex]; } + } + + public string ArmyName + { + get { return txtArmyName.Text; } + } + + public int ArmySize + { + get { return (int)armySize.Value; } + } + + private void bttnCancel_Click(object sender, System.EventArgs e) + { + DialogResult = DialogResult.Cancel; + this.Close(); + } + + private void bttnSelectRace_Click(object sender, System.EventArgs e) + { + DialogResult = DialogResult.OK; + this.Close(); + } + + private void txtArmyName_TextChanged(object sender, System.EventArgs e) + { + setSelectRaceEnabledVal(); + } + + private void setSelectRaceEnabledVal() + { + bttnSelectRace.Enabled = (lstRaces.SelectedIndex>-1 && txtArmyName.Text.Trim()!="" && armySize.Value > 0); + } + + private void lstRaces_SelectedIndexChanged(object sender, System.EventArgs e) + { + setSelectRaceEnabledVal(); + } + } +}
--- a/FrmNewUnit.cs Sat Jun 27 18:20:22 2009 +0000 +++ b/FrmNewUnit.cs Sat Jun 27 19:01:59 2009 +0000 @@ -1,242 +1,242 @@ -// This file (FrmNewUnit.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. -// -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. - -using System; -using System.Drawing; -using System.Collections; -using System.ComponentModel; -using System.Windows.Forms; -using IBBoard; -using IBBoard.Lang; -using IBBoard.Windows.Forms; -using IBBoard.WarFoundry.API; -using IBBoard.WarFoundry.API.Objects; -using IBBoard.Windows.Forms.I18N; - -namespace IBBoard.WarFoundry -{ - /// <summary> - /// Summary description for FrmNewUnit. - /// </summary> - public class FrmNewUnit : IBBForm - { - private System.ComponentModel.IContainer components; - private IBBoard.Windows.Forms.IBBButton bttnCancel; - private IBBoard.Windows.Forms.IBBLabel lblUnitList; - private IBBoard.Windows.Forms.IBBButton bttnSelectUnit; - private System.Windows.Forms.ListBox lstUnits; - private UnitType[] units; - private Army army; - private System.Windows.Forms.ImageList imageList; - private System.Windows.Forms.Label lblNewUnitWarning; - private System.Windows.Forms.Label lblWarningIcon; - private bool[] allowed; - - public FrmNewUnit(Race race, Category cat, Army army) - { - InitializeComponent(); - - ControlTranslator.TranslateControl(this, cat.Name); - units = race.GetUnitTypes(cat); - allowed = new bool[units.Length]; - this.army = army; - - for (int i = 0; i<units.Length; i++) - { - allowed[i] = army.CanAddUnitType(units[i]).Count == 0; - lstUnits.Items.Add(units[i].Name); - } - } - - /// <summary> - /// Clean up any resources being used. - /// </summary> - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if(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.components = new System.ComponentModel.Container(); - System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmNewUnit)); - this.lstUnits = new System.Windows.Forms.ListBox(); - this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); - this.lblUnitList = new IBBoard.Windows.Forms.IBBLabel(); - this.bttnSelectUnit = new IBBoard.Windows.Forms.IBBButton(); - this.lblNewUnitWarning = new System.Windows.Forms.Label(); - this.imageList = new System.Windows.Forms.ImageList(this.components); - this.lblWarningIcon = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // lstUnits - // - this.lstUnits.Location = new System.Drawing.Point(88, 8); - this.lstUnits.Name = "lstUnits"; - this.lstUnits.Size = new System.Drawing.Size(272, 121); - this.lstUnits.TabIndex = 7; - this.lstUnits.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstUnits_MouseDown); - this.lstUnits.DoubleClick += new System.EventHandler(this.lstUnits_DoubleClick); - this.lstUnits.SelectedIndexChanged += new System.EventHandler(this.lstUnits_SelectedIndexChanged); - // - // bttnCancel - // - this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnCancel.Location = new System.Drawing.Point(8, 168); - this.bttnCancel.Name = "bttnCancel"; - this.bttnCancel.Size = new System.Drawing.Size(80, 24); - this.bttnCancel.TabIndex = 6; - this.bttnCancel.Text = "Cancel"; - this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); - // - // lblUnitList - // - this.lblUnitList.Location = new System.Drawing.Point(0, 8); - this.lblUnitList.Name = "lblUnitList"; - this.lblUnitList.Size = new System.Drawing.Size(88, 80); - this.lblUnitList.TabIndex = 5; - this.lblUnitList.Text = "unit list"; - this.lblUnitList.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // bttnSelectUnit - // - this.bttnSelectUnit.Enabled = false; - this.bttnSelectUnit.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnSelectUnit.Location = new System.Drawing.Point(256, 168); - this.bttnSelectUnit.Name = "bttnSelectUnit"; - this.bttnSelectUnit.Size = new System.Drawing.Size(104, 24); - this.bttnSelectUnit.TabIndex = 4; - this.bttnSelectUnit.Text = "create unit"; - this.bttnSelectUnit.Click += new System.EventHandler(this.bttnSelectUnit_Click); - // - // lblNewUnitWarning - // - this.lblNewUnitWarning.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.lblNewUnitWarning.ImageList = this.imageList; - this.lblNewUnitWarning.Location = new System.Drawing.Point(48, 136); - this.lblNewUnitWarning.Name = "lblNewUnitWarning"; - this.lblNewUnitWarning.Size = new System.Drawing.Size(312, 32); - this.lblNewUnitWarning.TabIndex = 9; - this.lblNewUnitWarning.Text = "label1"; - this.lblNewUnitWarning.TextAlign = System.Drawing.ContentAlignment.TopRight; - this.lblNewUnitWarning.Visible = false; - // - // imageList - // - this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit; - this.imageList.ImageSize = new System.Drawing.Size(32, 32); - this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream"))); - this.imageList.TransparentColor = System.Drawing.Color.Transparent; - // - // lblWarningIcon - // - this.lblWarningIcon.ImageIndex = 0; - this.lblWarningIcon.ImageList = this.imageList; - this.lblWarningIcon.Location = new System.Drawing.Point(8, 136); - this.lblWarningIcon.Name = "lblWarningIcon"; - this.lblWarningIcon.Size = new System.Drawing.Size(40, 32); - this.lblWarningIcon.TabIndex = 10; - this.lblWarningIcon.Visible = false; - // - // FrmNewUnit - // - this.AcceptButton = this.bttnSelectUnit; - this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); - this.CancelButton = this.bttnCancel; - this.ClientSize = new System.Drawing.Size(370, 196); - this.Controls.Add(this.lblWarningIcon); - this.Controls.Add(this.lblNewUnitWarning); - this.Controls.Add(this.bttnCancel); - this.Controls.Add(this.lblUnitList); - this.Controls.Add(this.bttnSelectUnit); - this.Controls.Add(this.lstUnits); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "FrmNewUnit"; - this.ShowInTaskbar = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "FrmNewUni"; - this.ResumeLayout(false); - - } - #endregion - - public UnitType SelectedUnit - { - get { return units[lstUnits.SelectedIndex]; } - } - - private void bttnCancel_Click(object sender, System.EventArgs e) - { - DialogResult = DialogResult.Cancel; - this.Close(); - } - - private void bttnSelectUnit_Click(object sender, System.EventArgs e) - { - selectUnit(); - } - - private void selectUnit() - { - DialogResult = DialogResult.OK; - this.Close(); - } - - private void setSelectUnitEnabledVal() - { - if (lstUnits.SelectedIndex>-1) - { - bttnSelectUnit.Enabled = true; - lblNewUnitWarning.Visible = !allowed[lstUnits.SelectedIndex]; - lblWarningIcon.Visible = lblNewUnitWarning.Visible; - - if (lblNewUnitWarning.Visible) - { - //lblNewUnitWarning.Text = army.GetFailedAddRequirement(units[lstUnits.SelectedIndex]).Description; - //FIXME: Add failed requirement text - } - } - else - { - bttnSelectUnit.Enabled = false; - } - } - - private void lstUnits_SelectedIndexChanged(object sender, System.EventArgs e) - { - setSelectUnitEnabledVal(); - } - - private void lstUnits_DoubleClick(object sender, EventArgs e) - { - if (lstUnits.SelectedIndex>-1) - { - selectUnit(); - } - } - - private void lstUnits_MouseDown(object sender, MouseEventArgs e) - { - //make sure no item is selected when a click is made outside a unit - int index = lstUnits.IndexFromPoint(e.X, e.Y); - lstUnits.SelectedIndex = index; - } - } -} +// This file (FrmNewUnit.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. +// +// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. + +using System; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms; +using IBBoard; +using IBBoard.Lang; +using IBBoard.Windows.Forms; +using IBBoard.WarFoundry.API; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.Windows.Forms.I18N; + +namespace IBBoard.WarFoundry +{ + /// <summary> + /// Summary description for FrmNewUnit. + /// </summary> + public class FrmNewUnit : IBBForm + { + private System.ComponentModel.IContainer components; + private IBBoard.Windows.Forms.IBBButton bttnCancel; + private IBBoard.Windows.Forms.IBBLabel lblUnitList; + private IBBoard.Windows.Forms.IBBButton bttnSelectUnit; + private System.Windows.Forms.ListBox lstUnits; + private UnitType[] units; + private Army army; + private System.Windows.Forms.ImageList imageList; + private System.Windows.Forms.Label lblNewUnitWarning; + private System.Windows.Forms.Label lblWarningIcon; + private bool[] allowed; + + public FrmNewUnit(Race race, Category cat, Army army) + { + InitializeComponent(); + + ControlTranslator.TranslateControl(this, cat.Name); + units = race.GetUnitTypes(cat); + allowed = new bool[units.Length]; + this.army = army; + + for (int i = 0; i<units.Length; i++) + { + allowed[i] = army.CanAddUnitType(units[i]).Count == 0; + lstUnits.Items.Add(units[i].Name); + } + } + + /// <summary> + /// Clean up any resources being used. + /// </summary> + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if(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.components = new System.ComponentModel.Container(); + System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmNewUnit)); + this.lstUnits = new System.Windows.Forms.ListBox(); + this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); + this.lblUnitList = new IBBoard.Windows.Forms.IBBLabel(); + this.bttnSelectUnit = new IBBoard.Windows.Forms.IBBButton(); + this.lblNewUnitWarning = new System.Windows.Forms.Label(); + this.imageList = new System.Windows.Forms.ImageList(this.components); + this.lblWarningIcon = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // lstUnits + // + this.lstUnits.Location = new System.Drawing.Point(88, 8); + this.lstUnits.Name = "lstUnits"; + this.lstUnits.Size = new System.Drawing.Size(272, 121); + this.lstUnits.TabIndex = 7; + this.lstUnits.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstUnits_MouseDown); + this.lstUnits.DoubleClick += new System.EventHandler(this.lstUnits_DoubleClick); + this.lstUnits.SelectedIndexChanged += new System.EventHandler(this.lstUnits_SelectedIndexChanged); + // + // bttnCancel + // + this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnCancel.Location = new System.Drawing.Point(8, 168); + this.bttnCancel.Name = "bttnCancel"; + this.bttnCancel.Size = new System.Drawing.Size(80, 24); + this.bttnCancel.TabIndex = 6; + this.bttnCancel.Text = "Cancel"; + this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); + // + // lblUnitList + // + this.lblUnitList.Location = new System.Drawing.Point(0, 8); + this.lblUnitList.Name = "lblUnitList"; + this.lblUnitList.Size = new System.Drawing.Size(88, 80); + this.lblUnitList.TabIndex = 5; + this.lblUnitList.Text = "unit list"; + this.lblUnitList.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // bttnSelectUnit + // + this.bttnSelectUnit.Enabled = false; + this.bttnSelectUnit.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnSelectUnit.Location = new System.Drawing.Point(256, 168); + this.bttnSelectUnit.Name = "bttnSelectUnit"; + this.bttnSelectUnit.Size = new System.Drawing.Size(104, 24); + this.bttnSelectUnit.TabIndex = 4; + this.bttnSelectUnit.Text = "create unit"; + this.bttnSelectUnit.Click += new System.EventHandler(this.bttnSelectUnit_Click); + // + // lblNewUnitWarning + // + this.lblNewUnitWarning.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.lblNewUnitWarning.ImageList = this.imageList; + this.lblNewUnitWarning.Location = new System.Drawing.Point(48, 136); + this.lblNewUnitWarning.Name = "lblNewUnitWarning"; + this.lblNewUnitWarning.Size = new System.Drawing.Size(312, 32); + this.lblNewUnitWarning.TabIndex = 9; + this.lblNewUnitWarning.Text = "label1"; + this.lblNewUnitWarning.TextAlign = System.Drawing.ContentAlignment.TopRight; + this.lblNewUnitWarning.Visible = false; + // + // imageList + // + this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit; + this.imageList.ImageSize = new System.Drawing.Size(32, 32); + this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream"))); + this.imageList.TransparentColor = System.Drawing.Color.Transparent; + // + // lblWarningIcon + // + this.lblWarningIcon.ImageIndex = 0; + this.lblWarningIcon.ImageList = this.imageList; + this.lblWarningIcon.Location = new System.Drawing.Point(8, 136); + this.lblWarningIcon.Name = "lblWarningIcon"; + this.lblWarningIcon.Size = new System.Drawing.Size(40, 32); + this.lblWarningIcon.TabIndex = 10; + this.lblWarningIcon.Visible = false; + // + // FrmNewUnit + // + this.AcceptButton = this.bttnSelectUnit; + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.CancelButton = this.bttnCancel; + this.ClientSize = new System.Drawing.Size(370, 196); + this.Controls.Add(this.lblWarningIcon); + this.Controls.Add(this.lblNewUnitWarning); + this.Controls.Add(this.bttnCancel); + this.Controls.Add(this.lblUnitList); + this.Controls.Add(this.bttnSelectUnit); + this.Controls.Add(this.lstUnits); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "FrmNewUnit"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "FrmNewUni"; + this.ResumeLayout(false); + + } + #endregion + + public UnitType SelectedUnit + { + get { return units[lstUnits.SelectedIndex]; } + } + + private void bttnCancel_Click(object sender, System.EventArgs e) + { + DialogResult = DialogResult.Cancel; + this.Close(); + } + + private void bttnSelectUnit_Click(object sender, System.EventArgs e) + { + selectUnit(); + } + + private void selectUnit() + { + DialogResult = DialogResult.OK; + this.Close(); + } + + private void setSelectUnitEnabledVal() + { + if (lstUnits.SelectedIndex>-1) + { + bttnSelectUnit.Enabled = true; + lblNewUnitWarning.Visible = !allowed[lstUnits.SelectedIndex]; + lblWarningIcon.Visible = lblNewUnitWarning.Visible; + + if (lblNewUnitWarning.Visible) + { + //lblNewUnitWarning.Text = army.GetFailedAddRequirement(units[lstUnits.SelectedIndex]).Description; + //FIXME: Add failed requirement text + } + } + else + { + bttnSelectUnit.Enabled = false; + } + } + + private void lstUnits_SelectedIndexChanged(object sender, System.EventArgs e) + { + setSelectUnitEnabledVal(); + } + + private void lstUnits_DoubleClick(object sender, EventArgs e) + { + if (lstUnits.SelectedIndex>-1) + { + selectUnit(); + } + } + + private void lstUnits_MouseDown(object sender, MouseEventArgs e) + { + //make sure no item is selected when a click is made outside a unit + int index = lstUnits.IndexFromPoint(e.X, e.Y); + lstUnits.SelectedIndex = index; + } + } +}
--- a/FrmNewUnitEquipment.cs Sat Jun 27 18:20:22 2009 +0000 +++ b/FrmNewUnitEquipment.cs Sat Jun 27 19:01:59 2009 +0000 @@ -1,272 +1,272 @@ -// This file (FrmNewUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. -// -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. - -using System; -using System.Drawing; -using System.Collections; -using System.ComponentModel; -using System.Windows.Forms; -using IBBoard; -using IBBoard.Commands; -using IBBoard.WarFoundry.API; -using IBBoard.WarFoundry.API.Commands; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry -{ - /// <summary> - /// Summary description for FrmNewUnitEquipment. - /// </summary> - public class FrmNewUnitEquipment : System.Windows.Forms.Form - { - private Unit unit; - private bool required; - private CommandStack commandStack; - - private System.Windows.Forms.NumericUpDown numEquipAmount; - private System.Windows.Forms.Label lblPercent; - private System.Windows.Forms.Label lblAmount; - private System.Windows.Forms.Button bttnCancel; - private System.Windows.Forms.Button bttnOkay; - private System.Windows.Forms.CheckBox cbEquipAll; - private System.Windows.Forms.Label lblItem; - private System.Windows.Forms.ListBox listItems; - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.Container components = null; - - public FrmNewUnitEquipment(Unit unit, CommandStack stack) - { - commandStack = stack; - this.unit = unit; - InitializeComponent(); - this.Text = "New equipment for " + unit.Name; - object[] items = Arrays.Subtract(unit.GetAllowedOptionalEquipment(), unit.GetEquipment()); - listItems.Items.AddRange(items); - } - - /// <summary> - /// Clean up any resources being used. - /// </summary> - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if(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.numEquipAmount = new System.Windows.Forms.NumericUpDown(); - this.lblPercent = new System.Windows.Forms.Label(); - this.lblAmount = new System.Windows.Forms.Label(); - this.bttnCancel = new System.Windows.Forms.Button(); - this.bttnOkay = new System.Windows.Forms.Button(); - this.cbEquipAll = new System.Windows.Forms.CheckBox(); - this.lblItem = new System.Windows.Forms.Label(); - this.listItems = new System.Windows.Forms.ListBox(); - ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); - this.SuspendLayout(); - // - // numEquipAmount - // - this.numEquipAmount.Enabled = false; - this.numEquipAmount.Location = new System.Drawing.Point(88, 80); - this.numEquipAmount.Name = "numEquipAmount"; - this.numEquipAmount.Size = new System.Drawing.Size(144, 20); - this.numEquipAmount.TabIndex = 0; - this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged); - // - // lblPercent - // - this.lblPercent.Location = new System.Drawing.Point(208, 80); - this.lblPercent.Name = "lblPercent"; - this.lblPercent.Size = new System.Drawing.Size(16, 16); - this.lblPercent.TabIndex = 1; - this.lblPercent.Text = "%"; - this.lblPercent.Visible = false; - // - // lblAmount - // - this.lblAmount.Location = new System.Drawing.Point(8, 80); - this.lblAmount.Name = "lblAmount"; - this.lblAmount.Size = new System.Drawing.Size(72, 23); - this.lblAmount.TabIndex = 2; - this.lblAmount.Text = "amount"; - this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // bttnCancel - // - this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnCancel.Location = new System.Drawing.Point(160, 136); - this.bttnCancel.Name = "bttnCancel"; - this.bttnCancel.TabIndex = 3; - this.bttnCancel.Text = "cancel"; - this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); - // - // bttnOkay - // - this.bttnOkay.Enabled = false; - this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnOkay.Location = new System.Drawing.Point(8, 136); - this.bttnOkay.Name = "bttnOkay"; - this.bttnOkay.TabIndex = 4; - this.bttnOkay.Text = "okay"; - this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); - // - // cbEquipAll - // - this.cbEquipAll.Enabled = false; - this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.cbEquipAll.Location = new System.Drawing.Point(88, 104); - this.cbEquipAll.Name = "cbEquipAll"; - this.cbEquipAll.TabIndex = 5; - this.cbEquipAll.Text = "equip all"; - this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged); - // - // lblItem - // - this.lblItem.Location = new System.Drawing.Point(0, 8); - this.lblItem.Name = "lblItem"; - this.lblItem.Size = new System.Drawing.Size(80, 23); - this.lblItem.TabIndex = 6; - this.lblItem.Text = "item"; - this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // listItems - // - this.listItems.Location = new System.Drawing.Point(88, 8); - this.listItems.Name = "listItems"; - this.listItems.Size = new System.Drawing.Size(144, 69); - this.listItems.TabIndex = 7; - this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged); - // - // FrmNewUnitEquipment - // - this.AcceptButton = this.bttnOkay; - this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); - this.CancelButton = this.bttnCancel; - this.ClientSize = new System.Drawing.Size(240, 164); - this.ControlBox = false; - this.Controls.Add(this.listItems); - this.Controls.Add(this.lblItem); - this.Controls.Add(this.cbEquipAll); - this.Controls.Add(this.bttnOkay); - this.Controls.Add(this.bttnCancel); - this.Controls.Add(this.lblAmount); - this.Controls.Add(this.numEquipAmount); - this.Controls.Add(this.lblPercent); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Name = "FrmNewUnitEquipment"; - this.ShowInTaskbar = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "FrmEditUnitEquipment"; - ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit(); - this.ResumeLayout(false); - - } - #endregion - - private void bttnOkay_Click(object sender, System.EventArgs e) - { - setValue(); - this.Close(); - } - - private void setValue() - { - UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; - - if (cbEquipAll.Checked) - { - commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, WarFoundryCore.INFINITY)); - } - else - { - if (equipItem.IsRatioLimit) - { - commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value / 100.0)); - } - else - { - commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value)); - } - } - } - - private void bttnCancel_Click(object sender, System.EventArgs e) - { - this.Close(); - } - - private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) - { - numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked; - setOkayButton(); - } - - private void listItems_SelectedIndexChanged(object sender, System.EventArgs e) - { - refreshNumber(); - setOkayButton(); - } - - private void refreshNumber() - { - if (listItems.SelectedIndex > -1) - { - UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; - required = equipItem.IsRequired; - - if (equipItem.IsRatioLimit) - { - numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2); - numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2); - numEquipAmount.Value = numEquipAmount.Minimum; - cbEquipAll.Enabled = false; - lblPercent.Visible = true; - numEquipAmount.Width = 120; - } - else - { - numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? equipItem.MinNumber : unit.Size); - numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? equipItem.MaxNumber : unit.Size); - numEquipAmount.Value = numEquipAmount.Minimum; - cbEquipAll.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY; - cbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY; - numEquipAmount.Width = 144; - } - } - else - { - numEquipAmount.Minimum = 0; - numEquipAmount.Value = 0; - numEquipAmount.Enabled = false; - cbEquipAll.Enabled = false; - } - } - - private void setOkayButton() - { - bttnOkay.Enabled = listItems.SelectedIndex > -1 && (cbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0)); - } - - private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) - { - setOkayButton(); - } - } -} +// This file (FrmNewUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. +// +// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. + +using System; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms; +using IBBoard; +using IBBoard.Commands; +using IBBoard.WarFoundry.API; +using IBBoard.WarFoundry.API.Commands; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry +{ + /// <summary> + /// Summary description for FrmNewUnitEquipment. + /// </summary> + public class FrmNewUnitEquipment : System.Windows.Forms.Form + { + private Unit unit; + private bool required; + private CommandStack commandStack; + + private System.Windows.Forms.NumericUpDown numEquipAmount; + private System.Windows.Forms.Label lblPercent; + private System.Windows.Forms.Label lblAmount; + private System.Windows.Forms.Button bttnCancel; + private System.Windows.Forms.Button bttnOkay; + private System.Windows.Forms.CheckBox cbEquipAll; + private System.Windows.Forms.Label lblItem; + private System.Windows.Forms.ListBox listItems; + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.Container components = null; + + public FrmNewUnitEquipment(Unit unit, CommandStack stack) + { + commandStack = stack; + this.unit = unit; + InitializeComponent(); + this.Text = "New equipment for " + unit.Name; + object[] items = Arrays.Subtract(unit.GetAllowedOptionalEquipment(), unit.GetEquipment()); + listItems.Items.AddRange(items); + } + + /// <summary> + /// Clean up any resources being used. + /// </summary> + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if(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.numEquipAmount = new System.Windows.Forms.NumericUpDown(); + this.lblPercent = new System.Windows.Forms.Label(); + this.lblAmount = new System.Windows.Forms.Label(); + this.bttnCancel = new System.Windows.Forms.Button(); + this.bttnOkay = new System.Windows.Forms.Button(); + this.cbEquipAll = new System.Windows.Forms.CheckBox(); + this.lblItem = new System.Windows.Forms.Label(); + this.listItems = new System.Windows.Forms.ListBox(); + ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); + this.SuspendLayout(); + // + // numEquipAmount + // + this.numEquipAmount.Enabled = false; + this.numEquipAmount.Location = new System.Drawing.Point(88, 80); + this.numEquipAmount.Name = "numEquipAmount"; + this.numEquipAmount.Size = new System.Drawing.Size(144, 20); + this.numEquipAmount.TabIndex = 0; + this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged); + // + // lblPercent + // + this.lblPercent.Location = new System.Drawing.Point(208, 80); + this.lblPercent.Name = "lblPercent"; + this.lblPercent.Size = new System.Drawing.Size(16, 16); + this.lblPercent.TabIndex = 1; + this.lblPercent.Text = "%"; + this.lblPercent.Visible = false; + // + // lblAmount + // + this.lblAmount.Location = new System.Drawing.Point(8, 80); + this.lblAmount.Name = "lblAmount"; + this.lblAmount.Size = new System.Drawing.Size(72, 23); + this.lblAmount.TabIndex = 2; + this.lblAmount.Text = "amount"; + this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // bttnCancel + // + this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnCancel.Location = new System.Drawing.Point(160, 136); + this.bttnCancel.Name = "bttnCancel"; + this.bttnCancel.TabIndex = 3; + this.bttnCancel.Text = "cancel"; + this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); + // + // bttnOkay + // + this.bttnOkay.Enabled = false; + this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnOkay.Location = new System.Drawing.Point(8, 136); + this.bttnOkay.Name = "bttnOkay"; + this.bttnOkay.TabIndex = 4; + this.bttnOkay.Text = "okay"; + this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); + // + // cbEquipAll + // + this.cbEquipAll.Enabled = false; + this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.cbEquipAll.Location = new System.Drawing.Point(88, 104); + this.cbEquipAll.Name = "cbEquipAll"; + this.cbEquipAll.TabIndex = 5; + this.cbEquipAll.Text = "equip all"; + this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged); + // + // lblItem + // + this.lblItem.Location = new System.Drawing.Point(0, 8); + this.lblItem.Name = "lblItem"; + this.lblItem.Size = new System.Drawing.Size(80, 23); + this.lblItem.TabIndex = 6; + this.lblItem.Text = "item"; + this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // listItems + // + this.listItems.Location = new System.Drawing.Point(88, 8); + this.listItems.Name = "listItems"; + this.listItems.Size = new System.Drawing.Size(144, 69); + this.listItems.TabIndex = 7; + this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged); + // + // FrmNewUnitEquipment + // + this.AcceptButton = this.bttnOkay; + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.CancelButton = this.bttnCancel; + this.ClientSize = new System.Drawing.Size(240, 164); + this.ControlBox = false; + this.Controls.Add(this.listItems); + this.Controls.Add(this.lblItem); + this.Controls.Add(this.cbEquipAll); + this.Controls.Add(this.bttnOkay); + this.Controls.Add(this.bttnCancel); + this.Controls.Add(this.lblAmount); + this.Controls.Add(this.numEquipAmount); + this.Controls.Add(this.lblPercent); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Name = "FrmNewUnitEquipment"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "FrmEditUnitEquipment"; + ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit(); + this.ResumeLayout(false); + + } + #endregion + + private void bttnOkay_Click(object sender, System.EventArgs e) + { + setValue(); + this.Close(); + } + + private void setValue() + { + UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; + + if (cbEquipAll.Checked) + { + commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, WarFoundryCore.INFINITY)); + } + else + { + if (equipItem.IsRatioLimit) + { + commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value / 100.0)); + } + else + { + commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value)); + } + } + } + + private void bttnCancel_Click(object sender, System.EventArgs e) + { + this.Close(); + } + + private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) + { + numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked; + setOkayButton(); + } + + private void listItems_SelectedIndexChanged(object sender, System.EventArgs e) + { + refreshNumber(); + setOkayButton(); + } + + private void refreshNumber() + { + if (listItems.SelectedIndex > -1) + { + UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; + required = equipItem.IsRequired; + + if (equipItem.IsRatioLimit) + { + numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2); + numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2); + numEquipAmount.Value = numEquipAmount.Minimum; + cbEquipAll.Enabled = false; + lblPercent.Visible = true; + numEquipAmount.Width = 120; + } + else + { + numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? equipItem.MinNumber : unit.Size); + numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? equipItem.MaxNumber : unit.Size); + numEquipAmount.Value = numEquipAmount.Minimum; + cbEquipAll.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY; + cbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY; + numEquipAmount.Width = 144; + } + } + else + { + numEquipAmount.Minimum = 0; + numEquipAmount.Value = 0; + numEquipAmount.Enabled = false; + cbEquipAll.Enabled = false; + } + } + + private void setOkayButton() + { + bttnOkay.Enabled = listItems.SelectedIndex > -1 && (cbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0)); + } + + private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) + { + setOkayButton(); + } + } +}
--- a/FrmReplaceUnitEquipment.cs Sat Jun 27 18:20:22 2009 +0000 +++ b/FrmReplaceUnitEquipment.cs Sat Jun 27 19:01:59 2009 +0000 @@ -1,274 +1,274 @@ -// This file (FrmReplaceUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. -// -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. - -using System; -using System.Drawing; -using System.Collections; -using System.ComponentModel; -using System.Windows.Forms; -using IBBoard; -using IBBoard.Commands; -using IBBoard.WarFoundry.API; -using IBBoard.WarFoundry.API.Commands; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry -{ - /// <summary> - /// Summary description for FrmNewUnitEquipment. - /// </summary> - public class FrmReplaceUnitEquipment : System.Windows.Forms.Form - { - private Unit unit; - private UnitEquipmentItem oldItem; - private bool required; - private CommandStack commandStack; - - private System.Windows.Forms.NumericUpDown numEquipAmount; - private System.Windows.Forms.Label lblPercent; - private System.Windows.Forms.Label lblAmount; - private System.Windows.Forms.Button bttnCancel; - private System.Windows.Forms.Button bttnOkay; - private System.Windows.Forms.CheckBox cbEquipAll; - private System.Windows.Forms.Label lblItem; - private System.Windows.Forms.ListBox listItems; - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.Container components = null; - - public FrmReplaceUnitEquipment(Unit unit, UnitEquipmentItem item, CommandStack stack) - { - commandStack = stack; - this.unit = unit; - oldItem = item; - InitializeComponent(); - this.Text = "Replace " + item.EquipmentItem.Name + " with new equipment"; - object[] items = Arrays.Subtract(unit.UnitType.GetEquipmentItemsByExclusionGroup(item.MutexGroup), unit.GetEquipment()); - listItems.Items.AddRange(items); - } - - /// <summary> - /// Clean up any resources being used. - /// </summary> - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if(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.numEquipAmount = new System.Windows.Forms.NumericUpDown(); - this.lblPercent = new System.Windows.Forms.Label(); - this.lblAmount = new System.Windows.Forms.Label(); - this.bttnCancel = new System.Windows.Forms.Button(); - this.bttnOkay = new System.Windows.Forms.Button(); - this.cbEquipAll = new System.Windows.Forms.CheckBox(); - this.lblItem = new System.Windows.Forms.Label(); - this.listItems = new System.Windows.Forms.ListBox(); - ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); - this.SuspendLayout(); - // - // numEquipAmount - // - this.numEquipAmount.Enabled = false; - this.numEquipAmount.Location = new System.Drawing.Point(88, 80); - this.numEquipAmount.Name = "numEquipAmount"; - this.numEquipAmount.Size = new System.Drawing.Size(144, 20); - this.numEquipAmount.TabIndex = 0; - this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged); - // - // lblPercent - // - this.lblPercent.Location = new System.Drawing.Point(208, 80); - this.lblPercent.Name = "lblPercent"; - this.lblPercent.Size = new System.Drawing.Size(16, 16); - this.lblPercent.TabIndex = 1; - this.lblPercent.Text = "%"; - this.lblPercent.Visible = false; - // - // lblAmount - // - this.lblAmount.Location = new System.Drawing.Point(8, 80); - this.lblAmount.Name = "lblAmount"; - this.lblAmount.Size = new System.Drawing.Size(72, 23); - this.lblAmount.TabIndex = 2; - this.lblAmount.Text = "amount"; - this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // bttnCancel - // - this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnCancel.Location = new System.Drawing.Point(160, 136); - this.bttnCancel.Name = "bttnCancel"; - this.bttnCancel.TabIndex = 3; - this.bttnCancel.Text = "cancel"; - this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); - // - // bttnOkay - // - this.bttnOkay.Enabled = false; - this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnOkay.Location = new System.Drawing.Point(8, 136); - this.bttnOkay.Name = "bttnOkay"; - this.bttnOkay.TabIndex = 4; - this.bttnOkay.Text = "okay"; - this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); - // - // cbEquipAll - // - this.cbEquipAll.Enabled = false; - this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.cbEquipAll.Location = new System.Drawing.Point(88, 104); - this.cbEquipAll.Name = "cbEquipAll"; - this.cbEquipAll.TabIndex = 5; - this.cbEquipAll.Text = "equip all"; - this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged); - // - // lblItem - // - this.lblItem.Location = new System.Drawing.Point(0, 8); - this.lblItem.Name = "lblItem"; - this.lblItem.Size = new System.Drawing.Size(80, 23); - this.lblItem.TabIndex = 6; - this.lblItem.Text = "item"; - this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // listItems - // - this.listItems.Location = new System.Drawing.Point(88, 8); - this.listItems.Name = "listItems"; - this.listItems.Size = new System.Drawing.Size(144, 69); - this.listItems.TabIndex = 7; - this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged); - // - // FrmReplaceUnitEquipment - // - this.AcceptButton = this.bttnOkay; - this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); - this.CancelButton = this.bttnCancel; - this.ClientSize = new System.Drawing.Size(240, 164); - this.ControlBox = false; - this.Controls.Add(this.listItems); - this.Controls.Add(this.lblItem); - this.Controls.Add(this.cbEquipAll); - this.Controls.Add(this.bttnOkay); - this.Controls.Add(this.bttnCancel); - this.Controls.Add(this.lblAmount); - this.Controls.Add(this.numEquipAmount); - this.Controls.Add(this.lblPercent); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Name = "FrmReplaceUnitEquipment"; - this.ShowInTaskbar = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "FrmEditUnitEquipment"; - ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit(); - this.ResumeLayout(false); - - } - #endregion - - private void bttnOkay_Click(object sender, System.EventArgs e) - { - setValue(); - this.Close(); - } - - private void setValue() - { - UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; - - if (cbEquipAll.Checked) - { - commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, WarFoundryCore.INFINITY)); - } - else - { - if (equipItem.IsRatioLimit) - { - commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value / 100.0)); - } - else - { - commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value)); - } - } - } - - private void bttnCancel_Click(object sender, System.EventArgs e) - { - this.Close(); - } - - private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) - { - numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked; - setOkayButton(); - } - - private void listItems_SelectedIndexChanged(object sender, System.EventArgs e) - { - refreshNumber(); - setOkayButton(); - } - - private void refreshNumber() - { - if (listItems.SelectedIndex > -1) - { - UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; - required = equipItem.IsRequired; - - if (equipItem.IsRatioLimit) - { - numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2); - numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2); - numEquipAmount.Value = numEquipAmount.Minimum; - cbEquipAll.Enabled = false; - lblPercent.Visible = true; - numEquipAmount.Width = 120; - } - else - { - numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? equipItem.MinNumber : unit.Size); - numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? equipItem.MaxNumber : unit.Size); - numEquipAmount.Value = numEquipAmount.Minimum; - cbEquipAll.Enabled = (equipItem.MaxNumber == WarFoundryCore.INFINITY && equipItem.MinNumber != WarFoundryCore.INFINITY); - cbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY; - numEquipAmount.Width = 144; - } - } - else - { - numEquipAmount.Minimum = 0; - numEquipAmount.Value = 0; - numEquipAmount.Enabled = false; - cbEquipAll.Enabled = false; - } - } - - private void setOkayButton() - { - bttnOkay.Enabled = listItems.SelectedIndex > -1 && (cbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0)); - } - - private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) - { - setOkayButton(); - } - } -} +// This file (FrmReplaceUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. +// +// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. + +using System; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms; +using IBBoard; +using IBBoard.Commands; +using IBBoard.WarFoundry.API; +using IBBoard.WarFoundry.API.Commands; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry +{ + /// <summary> + /// Summary description for FrmNewUnitEquipment. + /// </summary> + public class FrmReplaceUnitEquipment : System.Windows.Forms.Form + { + private Unit unit; + private UnitEquipmentItem oldItem; + private bool required; + private CommandStack commandStack; + + private System.Windows.Forms.NumericUpDown numEquipAmount; + private System.Windows.Forms.Label lblPercent; + private System.Windows.Forms.Label lblAmount; + private System.Windows.Forms.Button bttnCancel; + private System.Windows.Forms.Button bttnOkay; + private System.Windows.Forms.CheckBox cbEquipAll; + private System.Windows.Forms.Label lblItem; + private System.Windows.Forms.ListBox listItems; + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.Container components = null; + + public FrmReplaceUnitEquipment(Unit unit, UnitEquipmentItem item, CommandStack stack) + { + commandStack = stack; + this.unit = unit; + oldItem = item; + InitializeComponent(); + this.Text = "Replace " + item.EquipmentItem.Name + " with new equipment"; + object[] items = Arrays.Subtract(unit.UnitType.GetEquipmentItemsByExclusionGroup(item.MutexGroup), unit.GetEquipment()); + listItems.Items.AddRange(items); + } + + /// <summary> + /// Clean up any resources being used. + /// </summary> + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if(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.numEquipAmount = new System.Windows.Forms.NumericUpDown(); + this.lblPercent = new System.Windows.Forms.Label(); + this.lblAmount = new System.Windows.Forms.Label(); + this.bttnCancel = new System.Windows.Forms.Button(); + this.bttnOkay = new System.Windows.Forms.Button(); + this.cbEquipAll = new System.Windows.Forms.CheckBox(); + this.lblItem = new System.Windows.Forms.Label(); + this.listItems = new System.Windows.Forms.ListBox(); + ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); + this.SuspendLayout(); + // + // numEquipAmount + // + this.numEquipAmount.Enabled = false; + this.numEquipAmount.Location = new System.Drawing.Point(88, 80); + this.numEquipAmount.Name = "numEquipAmount"; + this.numEquipAmount.Size = new System.Drawing.Size(144, 20); + this.numEquipAmount.TabIndex = 0; + this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged); + // + // lblPercent + // + this.lblPercent.Location = new System.Drawing.Point(208, 80); + this.lblPercent.Name = "lblPercent"; + this.lblPercent.Size = new System.Drawing.Size(16, 16); + this.lblPercent.TabIndex = 1; + this.lblPercent.Text = "%"; + this.lblPercent.Visible = false; + // + // lblAmount + // + this.lblAmount.Location = new System.Drawing.Point(8, 80); + this.lblAmount.Name = "lblAmount"; + this.lblAmount.Size = new System.Drawing.Size(72, 23); + this.lblAmount.TabIndex = 2; + this.lblAmount.Text = "amount"; + this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // bttnCancel + // + this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnCancel.Location = new System.Drawing.Point(160, 136); + this.bttnCancel.Name = "bttnCancel"; + this.bttnCancel.TabIndex = 3; + this.bttnCancel.Text = "cancel"; + this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); + // + // bttnOkay + // + this.bttnOkay.Enabled = false; + this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnOkay.Location = new System.Drawing.Point(8, 136); + this.bttnOkay.Name = "bttnOkay"; + this.bttnOkay.TabIndex = 4; + this.bttnOkay.Text = "okay"; + this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); + // + // cbEquipAll + // + this.cbEquipAll.Enabled = false; + this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.cbEquipAll.Location = new System.Drawing.Point(88, 104); + this.cbEquipAll.Name = "cbEquipAll"; + this.cbEquipAll.TabIndex = 5; + this.cbEquipAll.Text = "equip all"; + this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged); + // + // lblItem + // + this.lblItem.Location = new System.Drawing.Point(0, 8); + this.lblItem.Name = "lblItem"; + this.lblItem.Size = new System.Drawing.Size(80, 23); + this.lblItem.TabIndex = 6; + this.lblItem.Text = "item"; + this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // listItems + // + this.listItems.Location = new System.Drawing.Point(88, 8); + this.listItems.Name = "listItems"; + this.listItems.Size = new System.Drawing.Size(144, 69); + this.listItems.TabIndex = 7; + this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged); + // + // FrmReplaceUnitEquipment + // + this.AcceptButton = this.bttnOkay; + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.CancelButton = this.bttnCancel; + this.ClientSize = new System.Drawing.Size(240, 164); + this.ControlBox = false; + this.Controls.Add(this.listItems); + this.Controls.Add(this.lblItem); + this.Controls.Add(this.cbEquipAll); + this.Controls.Add(this.bttnOkay); + this.Controls.Add(this.bttnCancel); + this.Controls.Add(this.lblAmount); + this.Controls.Add(this.numEquipAmount); + this.Controls.Add(this.lblPercent); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Name = "FrmReplaceUnitEquipment"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "FrmEditUnitEquipment"; + ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit(); + this.ResumeLayout(false); + + } + #endregion + + private void bttnOkay_Click(object sender, System.EventArgs e) + { + setValue(); + this.Close(); + } + + private void setValue() + { + UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; + + if (cbEquipAll.Checked) + { + commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, WarFoundryCore.INFINITY)); + } + else + { + if (equipItem.IsRatioLimit) + { + commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value / 100.0)); + } + else + { + commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value)); + } + } + } + + private void bttnCancel_Click(object sender, System.EventArgs e) + { + this.Close(); + } + + private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) + { + numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked; + setOkayButton(); + } + + private void listItems_SelectedIndexChanged(object sender, System.EventArgs e) + { + refreshNumber(); + setOkayButton(); + } + + private void refreshNumber() + { + if (listItems.SelectedIndex > -1) + { + UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; + required = equipItem.IsRequired; + + if (equipItem.IsRatioLimit) + { + numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2); + numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2); + numEquipAmount.Value = numEquipAmount.Minimum; + cbEquipAll.Enabled = false; + lblPercent.Visible = true; + numEquipAmount.Width = 120; + } + else + { + numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? equipItem.MinNumber : unit.Size); + numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? equipItem.MaxNumber : unit.Size); + numEquipAmount.Value = numEquipAmount.Minimum; + cbEquipAll.Enabled = (equipItem.MaxNumber == WarFoundryCore.INFINITY && equipItem.MinNumber != WarFoundryCore.INFINITY); + cbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY; + numEquipAmount.Width = 144; + } + } + else + { + numEquipAmount.Minimum = 0; + numEquipAmount.Value = 0; + numEquipAmount.Enabled = false; + cbEquipAll.Enabled = false; + } + } + + private void setOkayButton() + { + bttnOkay.Enabled = listItems.SelectedIndex > -1 && (cbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0)); + } + + private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) + { + setOkayButton(); + } + } +}
--- a/FrmSelectSystem.cs Sat Jun 27 18:20:22 2009 +0000 +++ b/FrmSelectSystem.cs Sat Jun 27 19:01:59 2009 +0000 @@ -1,162 +1,162 @@ -// This file (FrmSelectSystem.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. -// -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. - -using System; -using System.IO; -using System.Drawing; -using System.Collections; -using System.ComponentModel; -using System.Windows.Forms; -using IBBoard; -using IBBoard.Lang; -using IBBoard.WarFoundry.API; -using IBBoard.Windows.Forms; -using IBBoard.WarFoundry.API.Objects; -using IBBoard.Windows.Forms.I18N; - -namespace IBBoard.WarFoundry -{ - /// <summary> - /// Summary description for FrmSelectSystem. - /// </summary> - public class FrmSelectSystem : IBBoard.Windows.Forms.IBBForm - { - private System.Windows.Forms.ListBox lstSystems; - private IBBoard.Windows.Forms.IBBLabel lblSystemList; - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.Container components = null; - private IBBoard.Windows.Forms.IBBButton bttnCancel; - private IBBoard.Windows.Forms.IBBButton bttnSelectSystem; - private GameSystem selectedSystem; - - - public FrmSelectSystem() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - ControlTranslator.TranslateControl(this); - - lstSystems.Items.Clear(); - GameSystem[] systems = WarFoundryLoader.GetDefault().GetGameSystems(); - lstSystems.DataSource = systems; - lstSystems.DisplayMember = "Name"; - } - - /// <summary> - /// Clean up any resources being used. - /// </summary> - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if(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.lstSystems = new System.Windows.Forms.ListBox(); - this.bttnSelectSystem = new IBBoard.Windows.Forms.IBBButton(); - this.lblSystemList = new IBBoard.Windows.Forms.IBBLabel(); - this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); - this.SuspendLayout(); - // - // lstSystems - // - this.lstSystems.Location = new System.Drawing.Point(80, 8); - this.lstSystems.Name = "lstSystems"; - this.lstSystems.Size = new System.Drawing.Size(216, 95); - this.lstSystems.TabIndex = 0; - this.lstSystems.SelectedIndexChanged += new System.EventHandler(this.lstSystems_SelectedIndexChanged); - // - // bttnSelectSystem - // - this.bttnSelectSystem.Enabled = false; - this.bttnSelectSystem.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnSelectSystem.Location = new System.Drawing.Point(192, 112); - this.bttnSelectSystem.Name = "bttnSelectSystem"; - this.bttnSelectSystem.Size = new System.Drawing.Size(104, 24); - this.bttnSelectSystem.TabIndex = 1; - this.bttnSelectSystem.Text = "Select system"; - this.bttnSelectSystem.Click += new System.EventHandler(this.bttnSelectSystem_Click); - // - // lblSystemList - // - this.lblSystemList.Location = new System.Drawing.Point(0, 8); - this.lblSystemList.Name = "lblSystemList"; - this.lblSystemList.Size = new System.Drawing.Size(80, 80); - this.lblSystemList.TabIndex = 2; - this.lblSystemList.Text = "system list"; - this.lblSystemList.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // bttnCancel - // - this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnCancel.Location = new System.Drawing.Point(8, 112); - this.bttnCancel.Name = "bttnCancel"; - this.bttnCancel.Size = new System.Drawing.Size(80, 24); - this.bttnCancel.TabIndex = 3; - this.bttnCancel.Text = "Cancel"; - this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); - // - // FrmSelectSystem - // - this.AcceptButton = this.bttnSelectSystem; - this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); - this.CancelButton = this.bttnCancel; - this.ClientSize = new System.Drawing.Size(306, 142); - this.ControlBox = false; - this.Controls.Add(this.bttnCancel); - this.Controls.Add(this.lblSystemList); - this.Controls.Add(this.bttnSelectSystem); - this.Controls.Add(this.lstSystems); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Name = "FrmSelectSystem"; - this.ShowInTaskbar = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "FrmSelectSystem"; - this.ResumeLayout(false); - - } - #endregion - - private void lstSystems_SelectedIndexChanged(object sender, System.EventArgs e) - { - bttnSelectSystem.Enabled = (lstSystems.SelectedIndex>-1); - } - - private void bttnSelectSystem_Click(object sender, System.EventArgs e) - { - selectedSystem = (GameSystem) lstSystems.SelectedItem; - this.DialogResult = DialogResult.OK; - this.Close(); - } - - private void bttnCancel_Click(object sender, System.EventArgs e) - { - this.DialogResult = DialogResult.Cancel; - this.Close(); - } - - public GameSystem GameSystem - { - get { return selectedSystem; } - } - } -} +// This file (FrmSelectSystem.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. +// +// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. + +using System; +using System.IO; +using System.Drawing; +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms; +using IBBoard; +using IBBoard.Lang; +using IBBoard.WarFoundry.API; +using IBBoard.Windows.Forms; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.Windows.Forms.I18N; + +namespace IBBoard.WarFoundry +{ + /// <summary> + /// Summary description for FrmSelectSystem. + /// </summary> + public class FrmSelectSystem : IBBoard.Windows.Forms.IBBForm + { + private System.Windows.Forms.ListBox lstSystems; + private IBBoard.Windows.Forms.IBBLabel lblSystemList; + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.Container components = null; + private IBBoard.Windows.Forms.IBBButton bttnCancel; + private IBBoard.Windows.Forms.IBBButton bttnSelectSystem; + private GameSystem selectedSystem; + + + public FrmSelectSystem() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + ControlTranslator.TranslateControl(this); + + lstSystems.Items.Clear(); + GameSystem[] systems = WarFoundryLoader.GetDefault().GetGameSystems(); + lstSystems.DataSource = systems; + lstSystems.DisplayMember = "Name"; + } + + /// <summary> + /// Clean up any resources being used. + /// </summary> + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if(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.lstSystems = new System.Windows.Forms.ListBox(); + this.bttnSelectSystem = new IBBoard.Windows.Forms.IBBButton(); + this.lblSystemList = new IBBoard.Windows.Forms.IBBLabel(); + this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); + this.SuspendLayout(); + // + // lstSystems + // + this.lstSystems.Location = new System.Drawing.Point(80, 8); + this.lstSystems.Name = "lstSystems"; + this.lstSystems.Size = new System.Drawing.Size(216, 95); + this.lstSystems.TabIndex = 0; + this.lstSystems.SelectedIndexChanged += new System.EventHandler(this.lstSystems_SelectedIndexChanged); + // + // bttnSelectSystem + // + this.bttnSelectSystem.Enabled = false; + this.bttnSelectSystem.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnSelectSystem.Location = new System.Drawing.Point(192, 112); + this.bttnSelectSystem.Name = "bttnSelectSystem"; + this.bttnSelectSystem.Size = new System.Drawing.Size(104, 24); + this.bttnSelectSystem.TabIndex = 1; + this.bttnSelectSystem.Text = "Select system"; + this.bttnSelectSystem.Click += new System.EventHandler(this.bttnSelectSystem_Click); + // + // lblSystemList + // + this.lblSystemList.Location = new System.Drawing.Point(0, 8); + this.lblSystemList.Name = "lblSystemList"; + this.lblSystemList.Size = new System.Drawing.Size(80, 80); + this.lblSystemList.TabIndex = 2; + this.lblSystemList.Text = "system list"; + this.lblSystemList.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // bttnCancel + // + this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnCancel.Location = new System.Drawing.Point(8, 112); + this.bttnCancel.Name = "bttnCancel"; + this.bttnCancel.Size = new System.Drawing.Size(80, 24); + this.bttnCancel.TabIndex = 3; + this.bttnCancel.Text = "Cancel"; + this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); + // + // FrmSelectSystem + // + this.AcceptButton = this.bttnSelectSystem; + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.CancelButton = this.bttnCancel; + this.ClientSize = new System.Drawing.Size(306, 142); + this.ControlBox = false; + this.Controls.Add(this.bttnCancel); + this.Controls.Add(this.lblSystemList); + this.Controls.Add(this.bttnSelectSystem); + this.Controls.Add(this.lstSystems); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Name = "FrmSelectSystem"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "FrmSelectSystem"; + this.ResumeLayout(false); + + } + #endregion + + private void lstSystems_SelectedIndexChanged(object sender, System.EventArgs e) + { + bttnSelectSystem.Enabled = (lstSystems.SelectedIndex>-1); + } + + private void bttnSelectSystem_Click(object sender, System.EventArgs e) + { + selectedSystem = (GameSystem) lstSystems.SelectedItem; + this.DialogResult = DialogResult.OK; + this.Close(); + } + + private void bttnCancel_Click(object sender, System.EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + + public GameSystem GameSystem + { + get { return selectedSystem; } + } + } +}
--- a/FrmUnit.cs Sat Jun 27 18:20:22 2009 +0000 +++ b/FrmUnit.cs Sat Jun 27 19:01:59 2009 +0000 @@ -1,524 +1,524 @@ -// This file (FrmUnit.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. -// -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. - -using System; -using System.Drawing; -using System.Data; -using System.Collections.Generic; -using System.ComponentModel; -using System.Windows.Forms; -using IBBoard.Commands; -using IBBoard.Windows.Forms; -using IBBoard.WarFoundry.API; -using IBBoard.WarFoundry.API.Commands; -using IBBoard.WarFoundry.API.Objects; -using IBBoard.WarFoundry.GUI.WinForms.Util; - -namespace IBBoard.WarFoundry -{ - ///TODO: Separate weapons out into optional and required, where required only has button for replacing - - /// <summary> - /// Summary description for FrmUnit. - /// </summary> - public class FrmUnit : IBBoard.Windows.Forms.IBBForm - { - private Unit unit; - private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>(); - private CommandStack commandStack; - 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.Button bttnEditWeapon; - private System.Windows.Forms.Label lblRequiredEquip; - private System.Windows.Forms.ListBox reqdList; - private System.Windows.Forms.ListBox optList; - private System.Windows.Forms.Label lblOptionalEquip; - private System.Windows.Forms.Button bttnReplaceWeapon; - private System.Windows.Forms.Button bttnEditReqdWeapon; - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.Container components = null; - - public FrmUnit(Unit toDisplay, CommandStack cmdStack) - { - unit = toDisplay; - commandStack = cmdStack; - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - tbUnitName.Text = unit.Name; - Text = unit.Name; - unit.NameChanged+=new StringValChangedDelegate(unit_NameChanged); - unit.UnitSizeChanged+= new IntValChangedDelegate(unit_UnitSizeChanged); - unit.UnitEquipmentAmountChanged+=new DoubleValChangedDelegate(unit_UnitEquipmentAmountChanged); - - if (unit.UnitType.MaxSize==unit.UnitType.MinSize) - { - unitSize.Value = unit.UnitType.MaxSize; - unitSize.Visible = false; - lblUnitSize.Visible = false; - } - else - { - unitSize.Value = unit.Size; - unitSize.Maximum = (unit.UnitType.MaxSize == WarFoundryCore.INFINITY ? int.MaxValue : unit.UnitType.MaxSize); - unitSize.Minimum = unit.UnitType.MinSize; - } - - SetStats(); - SetWeapons(); - } - - private void SetStats() - { - DataTable dt = new DataTable(); - Stat[] stats = unit.UnitStatsArrayWithName; - DataColumn[] dc = new DataColumn[stats.Length+1]; - dc[0] = new DataColumn("name"); - - DataGridTableStyle dgStyle = new DataGridTableStyle(); - dgStyle.RowHeadersVisible = false; - - DataGridTextBoxColumn colStyle = new DataGridTextBoxColumn(); - colStyle.Width = statsGrid.ClientSize.Width - (stats.Length * 40) - 4; - colStyle.MappingName = "name"; - colStyle.HeaderText = "name"; - colStyle.ReadOnly = true; - dgStyle.GridColumnStyles.Add(colStyle); - - DataColumn tempCol; - int i = 1; - - foreach (Stat stat in stats) - { - tempCol = new DataColumn(stat.ParentSlotName); - dc[i] = tempCol; - colStyle = new DataGridTextBoxColumn(); - colStyle.Alignment = HorizontalAlignment.Center; - colStyle.Width = 40; - colStyle.MappingName = stat.ParentSlotName; - colStyle.HeaderText = stat.ParentSlotName; - colStyle.ReadOnly = true; - dgStyle.GridColumnStyles.Add(colStyle); - i++; - } - - dt.Columns.AddRange(dc); - - DataRow dr = dt.NewRow(); - dr.ItemArray = unit.UnitStatsArrayWithName; - dt.Rows.Add(dr); - statsGrid.DataSource = dt; - statsGrid.TableStyles.Add(dgStyle); - } - - private void SetWeapons() - { - foreach(UnitEquipmentItem item in unit.GetEquipment()) - { - if (item.IsRequired) - { - reqdList.Items.Add(GetEquipmentChoice(item)); - } - else - { - optList.Items.Add(GetEquipmentChoice(item)); - } - } - } - - private UnitEquipmentChoice GetEquipmentChoice(UnitEquipmentItem item) - { - UnitEquipmentChoice choice = null; - equipmentChoices.TryGetValue(item, out choice); - - if (choice == null) - { - choice = new UnitEquipmentChoice(Unit, item); - equipmentChoices[item] = choice; - } - - return choice; - } - - /// <summary> - /// Clean up any resources being used. - /// </summary> - protected override void Dispose( bool disposing ) - { - //remove our leave events so that disposing doesn't trigger them - tbUnitName.Leave-= new System.EventHandler(this.tbUnitName_Leave); - unitSize.Leave-= new System.EventHandler(this.unitSize_Leave); - - if( disposing ) - { - if(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.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.lblRequiredEquip = new System.Windows.Forms.Label(); - this.bttnAddWeapon = new System.Windows.Forms.Button(); - this.bttnRemoveWeapon = new System.Windows.Forms.Button(); - this.reqdList = new System.Windows.Forms.ListBox(); - this.bttnEditWeapon = new System.Windows.Forms.Button(); - this.optList = new System.Windows.Forms.ListBox(); - this.lblOptionalEquip = new System.Windows.Forms.Label(); - this.bttnReplaceWeapon = new System.Windows.Forms.Button(); - this.bttnEditReqdWeapon = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.statsGrid)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.unitSize)).BeginInit(); - this.SuspendLayout(); - // - // statsGrid - // - this.statsGrid.AllowNavigation = false; - this.statsGrid.AllowSorting = false; - this.statsGrid.AlternatingBackColor = System.Drawing.SystemColors.Control; - this.statsGrid.BackgroundColor = System.Drawing.SystemColors.Control; - this.statsGrid.CaptionVisible = false; - this.statsGrid.DataMember = ""; - this.statsGrid.GridLineColor = System.Drawing.SystemColors.ControlDarkDark; - this.statsGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText; - this.statsGrid.Location = new System.Drawing.Point(8, 32); - this.statsGrid.Name = "statsGrid"; - this.statsGrid.PreferredColumnWidth = 40; - this.statsGrid.ReadOnly = true; - this.statsGrid.RowHeadersVisible = false; - this.statsGrid.SelectionBackColor = System.Drawing.SystemColors.Control; - this.statsGrid.SelectionForeColor = System.Drawing.SystemColors.WindowText; - this.statsGrid.Size = new System.Drawing.Size(600, 88); - this.statsGrid.TabIndex = 0; - this.statsGrid.TabStop = false; - // - // tbUnitName - // - this.tbUnitName.Location = new System.Drawing.Point(8, 8); - this.tbUnitName.Name = "tbUnitName"; - this.tbUnitName.Size = new System.Drawing.Size(344, 20); - this.tbUnitName.TabIndex = 1; - this.tbUnitName.Text = ""; - this.tbUnitName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbUnitName_KeyDown); - this.tbUnitName.Leave += new System.EventHandler(this.tbUnitName_Leave); - // - // unitSize - // - this.unitSize.Location = new System.Drawing.Point(528, 8); - this.unitSize.Name = "unitSize"; - this.unitSize.Size = new System.Drawing.Size(80, 20); - this.unitSize.TabIndex = 1; - this.unitSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - this.unitSize.Value = new System.Decimal(new int[] { - 1, - 0, - 0, - 0}); - this.unitSize.KeyDown += new System.Windows.Forms.KeyEventHandler(this.unitSize_KeyDown); - this.unitSize.Leave += new System.EventHandler(this.unitSize_Leave); - // - // lblUnitSize - // - this.lblUnitSize.Location = new System.Drawing.Point(424, 8); - this.lblUnitSize.Name = "lblUnitSize"; - this.lblUnitSize.TabIndex = 0; - this.lblUnitSize.Text = "unit size"; - this.lblUnitSize.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // lblRequiredEquip - // - this.lblRequiredEquip.Location = new System.Drawing.Point(8, 128); - this.lblRequiredEquip.Name = "lblRequiredEquip"; - this.lblRequiredEquip.Size = new System.Drawing.Size(88, 32); - this.lblRequiredEquip.TabIndex = 3; - this.lblRequiredEquip.Text = "reqd equipment"; - this.lblRequiredEquip.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // bttnAddWeapon - // - this.bttnAddWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnAddWeapon.Location = new System.Drawing.Point(520, 200); - this.bttnAddWeapon.Name = "bttnAddWeapon"; - this.bttnAddWeapon.Size = new System.Drawing.Size(88, 22); - this.bttnAddWeapon.TabIndex = 4; - this.bttnAddWeapon.Text = "add"; - this.bttnAddWeapon.Click += new System.EventHandler(this.bttnAddWeapon_Click); - // - // bttnRemoveWeapon - // - this.bttnRemoveWeapon.Enabled = false; - this.bttnRemoveWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnRemoveWeapon.Location = new System.Drawing.Point(520, 248); - this.bttnRemoveWeapon.Name = "bttnRemoveWeapon"; - this.bttnRemoveWeapon.Size = new System.Drawing.Size(88, 22); - this.bttnRemoveWeapon.TabIndex = 5; - this.bttnRemoveWeapon.Text = "remove"; - this.bttnRemoveWeapon.Click += new System.EventHandler(this.bttnRemoveWeapon_Click); - // - // reqdList - // - this.reqdList.Location = new System.Drawing.Point(104, 128); - this.reqdList.Name = "reqdList"; - this.reqdList.Size = new System.Drawing.Size(408, 69); - this.reqdList.TabIndex = 6; - this.reqdList.DoubleClick += new System.EventHandler(this.reqdList_DoubleClick); - this.reqdList.SelectedIndexChanged += new System.EventHandler(this.reqdList_SelectedIndexChanged); - // - // bttnEditWeapon - // - this.bttnEditWeapon.Enabled = false; - this.bttnEditWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnEditWeapon.Location = new System.Drawing.Point(520, 224); - this.bttnEditWeapon.Name = "bttnEditWeapon"; - this.bttnEditWeapon.Size = new System.Drawing.Size(88, 22); - this.bttnEditWeapon.TabIndex = 7; - this.bttnEditWeapon.Text = "edit"; - this.bttnEditWeapon.Click += new System.EventHandler(this.bttnEditWeapon_Click); - // - // optList - // - this.optList.Location = new System.Drawing.Point(104, 200); - this.optList.Name = "optList"; - this.optList.Size = new System.Drawing.Size(408, 69); - this.optList.TabIndex = 9; - this.optList.DoubleClick += new System.EventHandler(this.optList_DoubleClick); - this.optList.SelectedIndexChanged += new System.EventHandler(this.optList_SelectedIndexChanged); - // - // lblOptionalEquip - // - this.lblOptionalEquip.Location = new System.Drawing.Point(8, 200); - this.lblOptionalEquip.Name = "lblOptionalEquip"; - this.lblOptionalEquip.Size = new System.Drawing.Size(88, 32); - this.lblOptionalEquip.TabIndex = 8; - this.lblOptionalEquip.Text = "opt equipment"; - this.lblOptionalEquip.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // bttnReplaceWeapon - // - this.bttnReplaceWeapon.Enabled = false; - this.bttnReplaceWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnReplaceWeapon.Location = new System.Drawing.Point(520, 128); - this.bttnReplaceWeapon.Name = "bttnReplaceWeapon"; - this.bttnReplaceWeapon.Size = new System.Drawing.Size(88, 22); - this.bttnReplaceWeapon.TabIndex = 10; - this.bttnReplaceWeapon.Text = "replace"; - this.bttnReplaceWeapon.Click += new System.EventHandler(this.bttnReplaceWeapon_Click); - // - // bttnEditReqdWeapon - // - this.bttnEditReqdWeapon.Enabled = false; - this.bttnEditReqdWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnEditReqdWeapon.Location = new System.Drawing.Point(520, 152); - this.bttnEditReqdWeapon.Name = "bttnEditReqdWeapon"; - this.bttnEditReqdWeapon.Size = new System.Drawing.Size(88, 22); - this.bttnEditReqdWeapon.TabIndex = 11; - this.bttnEditReqdWeapon.Text = "edit"; - this.bttnEditReqdWeapon.Click += new System.EventHandler(this.bttnEditReqdWeapon_Click); - // - // FrmUnit - // - this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); - this.ClientSize = new System.Drawing.Size(616, 314); - this.Controls.Add(this.bttnEditReqdWeapon); - this.Controls.Add(this.bttnReplaceWeapon); - this.Controls.Add(this.optList); - this.Controls.Add(this.lblOptionalEquip); - this.Controls.Add(this.bttnEditWeapon); - this.Controls.Add(this.reqdList); - this.Controls.Add(this.bttnRemoveWeapon); - this.Controls.Add(this.bttnAddWeapon); - this.Controls.Add(this.lblRequiredEquip); - this.Controls.Add(this.lblUnitSize); - this.Controls.Add(this.unitSize); - this.Controls.Add(this.tbUnitName); - this.Controls.Add(this.statsGrid); - this.Name = "FrmUnit"; - this.ShowInTaskbar = false; - this.Text = "FrmUnit"; - ((System.ComponentModel.ISupportInitialize)(this.statsGrid)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.unitSize)).EndInit(); - this.ResumeLayout(false); - - } - #endregion - - public Unit Unit - { - get { return unit; } - } - - private void tbUnitName_Leave(object sender, System.EventArgs e) - { - updateUnitName(); - } - - private void tbUnitName_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) - { - if (e.KeyCode == Keys.Enter) - { - updateUnitName(); - } - } - - private void updateUnitName() - { - if (unit.Name!=tbUnitName.Text) - { - commandStack.Execute(new SetNameCommand(unit, tbUnitName.Text)); - } - } - - private void unitSize_Leave(object sender, System.EventArgs e) - { - updateUnitSize(); - } - - private void unitSize_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) - { - if (e.KeyCode == Keys.Enter) - { - updateUnitSize(); - } - } - - private void updateUnitSize() - { - if (unit.Size!=unitSize.Value) - { - commandStack.Execute(new SetUnitSizeCommand(unit, (int)unitSize.Value)); - } - } - - private void unit_NameChanged(WarFoundryObject obj, string oldValue, string newValue) - { - if (obj is Unit && obj.Equals(unit)) - { - Unit u = (Unit)obj; - tbUnitName.Text = obj.Name; - Text = obj.Name; - } - } - - private void unit_UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue) - { - if (obj is Unit && obj.Equals(unit)) - { - unitSize.Value = newValue; - } - } - - private void reqdList_SelectedIndexChanged(object sender, System.EventArgs e) - { - bttnReplaceWeapon.Enabled = (reqdList.SelectedIndex>-1 && ((UnitEquipmentChoice)reqdList.SelectedItem).Item.HasAlternatives()); - bttnEditReqdWeapon.Enabled = (reqdList.SelectedIndex>-1); - } - - private void optList_SelectedIndexChanged(object sender, System.EventArgs e) - { - bttnEditWeapon.Enabled = optList.SelectedIndex>-1; - bttnRemoveWeapon.Enabled = bttnEditWeapon.Enabled; - } - - private void unit_UnitEquipmentAmountChanged(WarFoundryObject obj, double oldValue, double newValue) - { - if (obj is UnitEquipmentItem) - { - UnitEquipmentItem equip = (UnitEquipmentItem)obj; - ListBox weaponList = (equip.IsRequired ? reqdList : optList); - - if (newValue==0) - { - weaponList.Items.Remove(GetEquipmentChoice(equip)); - } - else - { - UnitEquipmentChoice equipObj = GetEquipmentChoice(equip); - int idx = weaponList.Items.IndexOf(equipObj); - - if (idx>-1) - { - weaponList.Items[idx] = equipObj; - } - else - { - weaponList.Items.Add(equipObj); - } - } - } - } - - private void editWeapon(ListBox list) - { - FrmEditUnitEquipment editEquip = new FrmEditUnitEquipment(Unit, ((UnitEquipmentChoice)list.SelectedItem).Item, commandStack); - editEquip.ShowDialog(this); - } - - private void bttnEditWeapon_Click(object sender, System.EventArgs e) - { - editWeapon(optList); - } - - private void optList_DoubleClick(object sender, System.EventArgs e) - { - editWeapon(optList); - } - - private void reqdList_DoubleClick(object sender, System.EventArgs e) - { - editWeapon(reqdList); - } - - private void addWeapon() - { - FrmNewUnitEquipment newEquip = new FrmNewUnitEquipment(Unit, commandStack); - newEquip.ShowDialog(this); - } - - private void bttnAddWeapon_Click(object sender, System.EventArgs e) - { - addWeapon(); - } - - private void removeWeapon() - { - commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, ((UnitEquipmentChoice)optList.SelectedItem).Item, 0)); - } - - private void bttnRemoveWeapon_Click(object sender, System.EventArgs e) - { - removeWeapon(); - } - - private void bttnEditReqdWeapon_Click(object sender, System.EventArgs e) - { - editWeapon(reqdList); - } - - private void bttnReplaceWeapon_Click(object sender, System.EventArgs e) - { - FrmReplaceUnitEquipment replace = new FrmReplaceUnitEquipment(unit, ((UnitEquipmentChoice)reqdList.SelectedItem).Item, commandStack); - replace.ShowDialog(this); - } - } -} +// This file (FrmUnit.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. +// +// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. + +using System; +using System.Drawing; +using System.Data; +using System.Collections.Generic; +using System.ComponentModel; +using System.Windows.Forms; +using IBBoard.Commands; +using IBBoard.Windows.Forms; +using IBBoard.WarFoundry.API; +using IBBoard.WarFoundry.API.Commands; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.WarFoundry.GUI.WinForms.Util; + +namespace IBBoard.WarFoundry +{ + ///TODO: Separate weapons out into optional and required, where required only has button for replacing + + /// <summary> + /// Summary description for FrmUnit. + /// </summary> + public class FrmUnit : IBBoard.Windows.Forms.IBBForm + { + private Unit unit; + private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>(); + private CommandStack commandStack; + 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.Button bttnEditWeapon; + private System.Windows.Forms.Label lblRequiredEquip; + private System.Windows.Forms.ListBox reqdList; + private System.Windows.Forms.ListBox optList; + private System.Windows.Forms.Label lblOptionalEquip; + private System.Windows.Forms.Button bttnReplaceWeapon; + private System.Windows.Forms.Button bttnEditReqdWeapon; + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.Container components = null; + + public FrmUnit(Unit toDisplay, CommandStack cmdStack) + { + unit = toDisplay; + commandStack = cmdStack; + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + tbUnitName.Text = unit.Name; + Text = unit.Name; + unit.NameChanged+=new StringValChangedDelegate(unit_NameChanged); + unit.UnitSizeChanged+= new IntValChangedDelegate(unit_UnitSizeChanged); + unit.UnitEquipmentAmountChanged+=new DoubleValChangedDelegate(unit_UnitEquipmentAmountChanged); + + if (unit.UnitType.MaxSize==unit.UnitType.MinSize) + { + unitSize.Value = unit.UnitType.MaxSize; + unitSize.Visible = false; + lblUnitSize.Visible = false; + } + else + { + unitSize.Value = unit.Size; + unitSize.Maximum = (unit.UnitType.MaxSize == WarFoundryCore.INFINITY ? int.MaxValue : unit.UnitType.MaxSize); + unitSize.Minimum = unit.UnitType.MinSize; + } + + SetStats(); + SetWeapons(); + } + + private void SetStats() + { + DataTable dt = new DataTable(); + Stat[] stats = unit.UnitStatsArrayWithName; + DataColumn[] dc = new DataColumn[stats.Length+1]; + dc[0] = new DataColumn("name"); + + DataGridTableStyle dgStyle = new DataGridTableStyle(); + dgStyle.RowHeadersVisible = false; + + DataGridTextBoxColumn colStyle = new DataGridTextBoxColumn(); + colStyle.Width = statsGrid.ClientSize.Width - (stats.Length * 40) - 4; + colStyle.MappingName = "name"; + colStyle.HeaderText = "name"; + colStyle.ReadOnly = true; + dgStyle.GridColumnStyles.Add(colStyle); + + DataColumn tempCol; + int i = 1; + + foreach (Stat stat in stats) + { + tempCol = new DataColumn(stat.ParentSlotName); + dc[i] = tempCol; + colStyle = new DataGridTextBoxColumn(); + colStyle.Alignment = HorizontalAlignment.Center; + colStyle.Width = 40; + colStyle.MappingName = stat.ParentSlotName; + colStyle.HeaderText = stat.ParentSlotName; + colStyle.ReadOnly = true; + dgStyle.GridColumnStyles.Add(colStyle); + i++; + } + + dt.Columns.AddRange(dc); + + DataRow dr = dt.NewRow(); + dr.ItemArray = unit.UnitStatsArrayWithName; + dt.Rows.Add(dr); + statsGrid.DataSource = dt; + statsGrid.TableStyles.Add(dgStyle); + } + + private void SetWeapons() + { + foreach(UnitEquipmentItem item in unit.GetEquipment()) + { + if (item.IsRequired) + { + reqdList.Items.Add(GetEquipmentChoice(item)); + } + else + { + optList.Items.Add(GetEquipmentChoice(item)); + } + } + } + + private UnitEquipmentChoice GetEquipmentChoice(UnitEquipmentItem item) + { + UnitEquipmentChoice choice = null; + equipmentChoices.TryGetValue(item, out choice); + + if (choice == null) + { + choice = new UnitEquipmentChoice(Unit, item); + equipmentChoices[item] = choice; + } + + return choice; + } + + /// <summary> + /// Clean up any resources being used. + /// </summary> + protected override void Dispose( bool disposing ) + { + //remove our leave events so that disposing doesn't trigger them + tbUnitName.Leave-= new System.EventHandler(this.tbUnitName_Leave); + unitSize.Leave-= new System.EventHandler(this.unitSize_Leave); + + if( disposing ) + { + if(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.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.lblRequiredEquip = new System.Windows.Forms.Label(); + this.bttnAddWeapon = new System.Windows.Forms.Button(); + this.bttnRemoveWeapon = new System.Windows.Forms.Button(); + this.reqdList = new System.Windows.Forms.ListBox(); + this.bttnEditWeapon = new System.Windows.Forms.Button(); + this.optList = new System.Windows.Forms.ListBox(); + this.lblOptionalEquip = new System.Windows.Forms.Label(); + this.bttnReplaceWeapon = new System.Windows.Forms.Button(); + this.bttnEditReqdWeapon = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.statsGrid)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.unitSize)).BeginInit(); + this.SuspendLayout(); + // + // statsGrid + // + this.statsGrid.AllowNavigation = false; + this.statsGrid.AllowSorting = false; + this.statsGrid.AlternatingBackColor = System.Drawing.SystemColors.Control; + this.statsGrid.BackgroundColor = System.Drawing.SystemColors.Control; + this.statsGrid.CaptionVisible = false; + this.statsGrid.DataMember = ""; + this.statsGrid.GridLineColor = System.Drawing.SystemColors.ControlDarkDark; + this.statsGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText; + this.statsGrid.Location = new System.Drawing.Point(8, 32); + this.statsGrid.Name = "statsGrid"; + this.statsGrid.PreferredColumnWidth = 40; + this.statsGrid.ReadOnly = true; + this.statsGrid.RowHeadersVisible = false; + this.statsGrid.SelectionBackColor = System.Drawing.SystemColors.Control; + this.statsGrid.SelectionForeColor = System.Drawing.SystemColors.WindowText; + this.statsGrid.Size = new System.Drawing.Size(600, 88); + this.statsGrid.TabIndex = 0; + this.statsGrid.TabStop = false; + // + // tbUnitName + // + this.tbUnitName.Location = new System.Drawing.Point(8, 8); + this.tbUnitName.Name = "tbUnitName"; + this.tbUnitName.Size = new System.Drawing.Size(344, 20); + this.tbUnitName.TabIndex = 1; + this.tbUnitName.Text = ""; + this.tbUnitName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbUnitName_KeyDown); + this.tbUnitName.Leave += new System.EventHandler(this.tbUnitName_Leave); + // + // unitSize + // + this.unitSize.Location = new System.Drawing.Point(528, 8); + this.unitSize.Name = "unitSize"; + this.unitSize.Size = new System.Drawing.Size(80, 20); + this.unitSize.TabIndex = 1; + this.unitSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.unitSize.Value = new System.Decimal(new int[] { + 1, + 0, + 0, + 0}); + this.unitSize.KeyDown += new System.Windows.Forms.KeyEventHandler(this.unitSize_KeyDown); + this.unitSize.Leave += new System.EventHandler(this.unitSize_Leave); + // + // lblUnitSize + // + this.lblUnitSize.Location = new System.Drawing.Point(424, 8); + this.lblUnitSize.Name = "lblUnitSize"; + this.lblUnitSize.TabIndex = 0; + this.lblUnitSize.Text = "unit size"; + this.lblUnitSize.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // lblRequiredEquip + // + this.lblRequiredEquip.Location = new System.Drawing.Point(8, 128); + this.lblRequiredEquip.Name = "lblRequiredEquip"; + this.lblRequiredEquip.Size = new System.Drawing.Size(88, 32); + this.lblRequiredEquip.TabIndex = 3; + this.lblRequiredEquip.Text = "reqd equipment"; + this.lblRequiredEquip.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // bttnAddWeapon + // + this.bttnAddWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnAddWeapon.Location = new System.Drawing.Point(520, 200); + this.bttnAddWeapon.Name = "bttnAddWeapon"; + this.bttnAddWeapon.Size = new System.Drawing.Size(88, 22); + this.bttnAddWeapon.TabIndex = 4; + this.bttnAddWeapon.Text = "add"; + this.bttnAddWeapon.Click += new System.EventHandler(this.bttnAddWeapon_Click); + // + // bttnRemoveWeapon + // + this.bttnRemoveWeapon.Enabled = false; + this.bttnRemoveWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnRemoveWeapon.Location = new System.Drawing.Point(520, 248); + this.bttnRemoveWeapon.Name = "bttnRemoveWeapon"; + this.bttnRemoveWeapon.Size = new System.Drawing.Size(88, 22); + this.bttnRemoveWeapon.TabIndex = 5; + this.bttnRemoveWeapon.Text = "remove"; + this.bttnRemoveWeapon.Click += new System.EventHandler(this.bttnRemoveWeapon_Click); + // + // reqdList + // + this.reqdList.Location = new System.Drawing.Point(104, 128); + this.reqdList.Name = "reqdList"; + this.reqdList.Size = new System.Drawing.Size(408, 69); + this.reqdList.TabIndex = 6; + this.reqdList.DoubleClick += new System.EventHandler(this.reqdList_DoubleClick); + this.reqdList.SelectedIndexChanged += new System.EventHandler(this.reqdList_SelectedIndexChanged); + // + // bttnEditWeapon + // + this.bttnEditWeapon.Enabled = false; + this.bttnEditWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnEditWeapon.Location = new System.Drawing.Point(520, 224); + this.bttnEditWeapon.Name = "bttnEditWeapon"; + this.bttnEditWeapon.Size = new System.Drawing.Size(88, 22); + this.bttnEditWeapon.TabIndex = 7; + this.bttnEditWeapon.Text = "edit"; + this.bttnEditWeapon.Click += new System.EventHandler(this.bttnEditWeapon_Click); + // + // optList + // + this.optList.Location = new System.Drawing.Point(104, 200); + this.optList.Name = "optList"; + this.optList.Size = new System.Drawing.Size(408, 69); + this.optList.TabIndex = 9; + this.optList.DoubleClick += new System.EventHandler(this.optList_DoubleClick); + this.optList.SelectedIndexChanged += new System.EventHandler(this.optList_SelectedIndexChanged); + // + // lblOptionalEquip + // + this.lblOptionalEquip.Location = new System.Drawing.Point(8, 200); + this.lblOptionalEquip.Name = "lblOptionalEquip"; + this.lblOptionalEquip.Size = new System.Drawing.Size(88, 32); + this.lblOptionalEquip.TabIndex = 8; + this.lblOptionalEquip.Text = "opt equipment"; + this.lblOptionalEquip.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // bttnReplaceWeapon + // + this.bttnReplaceWeapon.Enabled = false; + this.bttnReplaceWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnReplaceWeapon.Location = new System.Drawing.Point(520, 128); + this.bttnReplaceWeapon.Name = "bttnReplaceWeapon"; + this.bttnReplaceWeapon.Size = new System.Drawing.Size(88, 22); + this.bttnReplaceWeapon.TabIndex = 10; + this.bttnReplaceWeapon.Text = "replace"; + this.bttnReplaceWeapon.Click += new System.EventHandler(this.bttnReplaceWeapon_Click); + // + // bttnEditReqdWeapon + // + this.bttnEditReqdWeapon.Enabled = false; + this.bttnEditReqdWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnEditReqdWeapon.Location = new System.Drawing.Point(520, 152); + this.bttnEditReqdWeapon.Name = "bttnEditReqdWeapon"; + this.bttnEditReqdWeapon.Size = new System.Drawing.Size(88, 22); + this.bttnEditReqdWeapon.TabIndex = 11; + this.bttnEditReqdWeapon.Text = "edit"; + this.bttnEditReqdWeapon.Click += new System.EventHandler(this.bttnEditReqdWeapon_Click); + // + // FrmUnit + // + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.ClientSize = new System.Drawing.Size(616, 314); + this.Controls.Add(this.bttnEditReqdWeapon); + this.Controls.Add(this.bttnReplaceWeapon); + this.Controls.Add(this.optList); + this.Controls.Add(this.lblOptionalEquip); + this.Controls.Add(this.bttnEditWeapon); + this.Controls.Add(this.reqdList); + this.Controls.Add(this.bttnRemoveWeapon); + this.Controls.Add(this.bttnAddWeapon); + this.Controls.Add(this.lblRequiredEquip); + this.Controls.Add(this.lblUnitSize); + this.Controls.Add(this.unitSize); + this.Controls.Add(this.tbUnitName); + this.Controls.Add(this.statsGrid); + this.Name = "FrmUnit"; + this.ShowInTaskbar = false; + this.Text = "FrmUnit"; + ((System.ComponentModel.ISupportInitialize)(this.statsGrid)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.unitSize)).EndInit(); + this.ResumeLayout(false); + + } + #endregion + + public Unit Unit + { + get { return unit; } + } + + private void tbUnitName_Leave(object sender, System.EventArgs e) + { + updateUnitName(); + } + + private void tbUnitName_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + updateUnitName(); + } + } + + private void updateUnitName() + { + if (unit.Name!=tbUnitName.Text) + { + commandStack.Execute(new SetNameCommand(unit, tbUnitName.Text)); + } + } + + private void unitSize_Leave(object sender, System.EventArgs e) + { + updateUnitSize(); + } + + private void unitSize_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + updateUnitSize(); + } + } + + private void updateUnitSize() + { + if (unit.Size!=unitSize.Value) + { + commandStack.Execute(new SetUnitSizeCommand(unit, (int)unitSize.Value)); + } + } + + private void unit_NameChanged(WarFoundryObject obj, string oldValue, string newValue) + { + if (obj is Unit && obj.Equals(unit)) + { + Unit u = (Unit)obj; + tbUnitName.Text = obj.Name; + Text = obj.Name; + } + } + + private void unit_UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue) + { + if (obj is Unit && obj.Equals(unit)) + { + unitSize.Value = newValue; + } + } + + private void reqdList_SelectedIndexChanged(object sender, System.EventArgs e) + { + bttnReplaceWeapon.Enabled = (reqdList.SelectedIndex>-1 && ((UnitEquipmentChoice)reqdList.SelectedItem).Item.HasAlternatives()); + bttnEditReqdWeapon.Enabled = (reqdList.SelectedIndex>-1); + } + + private void optList_SelectedIndexChanged(object sender, System.EventArgs e) + { + bttnEditWeapon.Enabled = optList.SelectedIndex>-1; + bttnRemoveWeapon.Enabled = bttnEditWeapon.Enabled; + } + + private void unit_UnitEquipmentAmountChanged(WarFoundryObject obj, double oldValue, double newValue) + { + if (obj is UnitEquipmentItem) + { + UnitEquipmentItem equip = (UnitEquipmentItem)obj; + ListBox weaponList = (equip.IsRequired ? reqdList : optList); + + if (newValue==0) + { + weaponList.Items.Remove(GetEquipmentChoice(equip)); + } + else + { + UnitEquipmentChoice equipObj = GetEquipmentChoice(equip); + int idx = weaponList.Items.IndexOf(equipObj); + + if (idx>-1) + { + weaponList.Items[idx] = equipObj; + } + else + { + weaponList.Items.Add(equipObj); + } + } + } + } + + private void editWeapon(ListBox list) + { + FrmEditUnitEquipment editEquip = new FrmEditUnitEquipment(Unit, ((UnitEquipmentChoice)list.SelectedItem).Item, commandStack); + editEquip.ShowDialog(this); + } + + private void bttnEditWeapon_Click(object sender, System.EventArgs e) + { + editWeapon(optList); + } + + private void optList_DoubleClick(object sender, System.EventArgs e) + { + editWeapon(optList); + } + + private void reqdList_DoubleClick(object sender, System.EventArgs e) + { + editWeapon(reqdList); + } + + private void addWeapon() + { + FrmNewUnitEquipment newEquip = new FrmNewUnitEquipment(Unit, commandStack); + newEquip.ShowDialog(this); + } + + private void bttnAddWeapon_Click(object sender, System.EventArgs e) + { + addWeapon(); + } + + private void removeWeapon() + { + commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, ((UnitEquipmentChoice)optList.SelectedItem).Item, 0)); + } + + private void bttnRemoveWeapon_Click(object sender, System.EventArgs e) + { + removeWeapon(); + } + + private void bttnEditReqdWeapon_Click(object sender, System.EventArgs e) + { + editWeapon(reqdList); + } + + private void bttnReplaceWeapon_Click(object sender, System.EventArgs e) + { + FrmReplaceUnitEquipment replace = new FrmReplaceUnitEquipment(unit, ((UnitEquipmentChoice)reqdList.SelectedItem).Item, commandStack); + replace.ShowDialog(this); + } + } +}
--- a/Util/UnitEquipmentChoice.cs Sat Jun 27 18:20:22 2009 +0000 +++ b/Util/UnitEquipmentChoice.cs Sat Jun 27 19:01:59 2009 +0000 @@ -1,40 +1,40 @@ -// This file (UnitEquipmentChoice.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. -// -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. - -using System; -using System.Collections; -using IBBoard.WarFoundry.API.Objects; - - - -namespace IBBoard.WarFoundry.GUI.WinForms.Util -{ - /// <summary> - /// A helper object that holds an equipment choice for a unit. - /// </summary> - - public class UnitEquipmentChoice - { - private Unit unit; - private UnitEquipmentItem item; - - private static Hashtable equipObjs = new Hashtable(); - - public UnitEquipmentChoice(Unit unit, UnitEquipmentItem unitItem) - { - this.unit = unit; - item = unitItem; - } - - public override string ToString() - { - return String.Format("{0} (For {1} at {2}pts each)", item.Name, UnitEquipmentItem.FormatEquipmentAmount(item, unit.GetEquipmentAmount(item)), item.Cost); - } - - public UnitEquipmentItem Item - { - get { return item; } - } - } +// This file (UnitEquipmentChoice.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. +// +// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. + +using System; +using System.Collections; +using IBBoard.WarFoundry.API.Objects; + + + +namespace IBBoard.WarFoundry.GUI.WinForms.Util +{ + /// <summary> + /// A helper object that holds an equipment choice for a unit. + /// </summary> + + public class UnitEquipmentChoice + { + private Unit unit; + private UnitEquipmentItem item; + + private static Hashtable equipObjs = new Hashtable(); + + public UnitEquipmentChoice(Unit unit, UnitEquipmentItem unitItem) + { + this.unit = unit; + item = unitItem; + } + + public override string ToString() + { + return String.Format("{0} (For {1} at {2}pts each)", item.Name, UnitEquipmentItem.FormatEquipmentAmount(item, unit.GetEquipmentAmount(item)), item.Cost); + } + + public UnitEquipmentItem Item + { + get { return item; } + } + } } \ No newline at end of file