changeset 166:97fd4b6f823b

Fixes #294: Fix data grid header wrapping problems * Disable wrapping on each column as it is created * Just to make sure, disable header height resizing
author IBBoard <dev@ibboard.co.uk>
date Sat, 24 Jul 2010 10:19:47 +0000
parents 2c17714ad71b
children 7de7890bf079
files FrmUnit.cs
diffstat 1 files changed, 677 insertions(+), 676 deletions(-) [+]
line diff
     1.1 --- a/FrmUnit.cs	Wed Jul 14 20:02:20 2010 +0000
     1.2 +++ b/FrmUnit.cs	Sat Jul 24 10:19:47 2010 +0000
     1.3 @@ -1,677 +1,678 @@
     1.4 -// This file (FrmUnit.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2007, 2008, 2009 IBBoard.
     1.5 -//
     1.6 -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
     1.7 -
     1.8 -using System;
     1.9 -using System.Drawing;
    1.10 -using System.Data;
    1.11 -using System.Collections.Generic;
    1.12 -using System.ComponentModel;
    1.13 -using System.Windows.Forms;
    1.14 -using IBBoard.Commands;
    1.15 -using IBBoard.Lang;
    1.16 -using IBBoard.Windows.Forms;
    1.17 -using IBBoard.Windows.Forms.I18N;
    1.18 -using IBBoard.WarFoundry.API;
    1.19 -using IBBoard.WarFoundry.API.Commands;
    1.20 -using IBBoard.WarFoundry.API.Objects;
    1.21 -using IBBoard.WarFoundry.GUI.WinForms.UI;
    1.22 -using IBBoard.WarFoundry.GUI.WinForms.Util;
    1.23 -using log4net;
    1.24 -
    1.25 -namespace IBBoard.WarFoundry.GUI.WinForms
    1.26 -{
    1.27 -	/// <summary>
    1.28 -	/// Summary description for FrmUnit.
    1.29 -	/// </summary>
    1.30 -	public class FrmUnit : IBBoard.Windows.Forms.IBBForm
    1.31 -	{
    1.32 -		private static readonly ILog log = LogManager.GetLogger(typeof(FrmUnit));
    1.33 -		private static readonly int BORDER_WIDTH = 1;
    1.34 -		private static readonly int NAME_COL_WIDTH_MULTIPLIER = 3;
    1.35 -		private Unit unit;
    1.36 -		private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>();
    1.37 -		private Dictionary<string, DataGridView> DataGridViews = new Dictionary<string, DataGridView>();
    1.38 -		private CommandStack commandStack;
    1.39 -		private System.Windows.Forms.TextBox tbUnitName;
    1.40 -		private System.Windows.Forms.NumericUpDown unitSize;
    1.41 -		private IBBLabel lblUnitSize;
    1.42 -		private IBBButton bttnAddWeapon;
    1.43 -		private IBBButton bttnRemoveWeapon;
    1.44 -		private IBBLabel lblEquip;
    1.45 -		private System.Windows.Forms.ListBox equipmentList;
    1.46 -		private IBBButton bttnReplaceWeapon;
    1.47 -		private IBBButton bttnEditWeapon;
    1.48 -		private Label lblPoints;
    1.49 -		private IBBLabel lblNotes;
    1.50 -		private TextBox notes;
    1.51 -		private ListBox abilitiesList;
    1.52 -		private IBBLabel lblAbilities;
    1.53 -		private FlowLayoutPanel statsPanel;
    1.54 -		/// <summary>
    1.55 -		/// Required designer variable.
    1.56 -		/// </summary>
    1.57 -		private System.ComponentModel.Container components = null;
    1.58 -
    1.59 -		public FrmUnit(Unit toDisplay, CommandStack cmdStack)
    1.60 -		{
    1.61 -			unit = toDisplay;
    1.62 -			commandStack = cmdStack;
    1.63 -			//
    1.64 -			// Required for Windows Form Designer support
    1.65 -			//
    1.66 -			InitializeComponent();
    1.67 -			TranslateForm();
    1.68 -			Translation.TranslationChanged += new MethodInvoker(TranslateForm);
    1.69 -			unit.NameChanged += new StringValChangedDelegate(unit_NameChanged);
    1.70 -			unit.UnitSizeChanged += new IntValChangedDelegate(unit_UnitSizeChanged);
    1.71 -			unit.UnitEquipmentAmountChanged += new DoubleValChangedDelegate(unit_UnitEquipmentAmountChanged);
    1.72 -			unit.PointsValueChanged += new DoubleValChangedDelegate(unit_PointsValueChanged);
    1.73 -
    1.74 -			unitSize.Value = unit.Size;
    1.75 -			unitSize.Maximum = (unit.UnitType.MaxSize == WarFoundryCore.INFINITY ? int.MaxValue : unit.UnitType.MaxSize);
    1.76 -			unitSize.Minimum = unit.UnitType.MinSize;
    1.77 -			unitSize.Enabled = (unitSize.Maximum != unitSize.Minimum);
    1.78 -
    1.79 -			notes.Text = unit.UnitType.Notes;
    1.80 -			abilitiesList.DataSource = new List<Ability>(unit.UnitType.GetRequiredAbilities());
    1.81 -			abilitiesList.DisplayMember = "Name";
    1.82 -			SetPointsValueText();
    1.83 -			SetStats();
    1.84 -			SetWeapons();
    1.85 -		}
    1.86 -
    1.87 -		private void TranslateForm()
    1.88 -		{
    1.89 -			ControlTranslator.TranslateControl(this);
    1.90 -			SetUnitName();
    1.91 -			RefreshUnitEquipment();
    1.92 -		}
    1.93 -
    1.94 -		private void SetUnitName()
    1.95 -		{
    1.96 -			tbUnitName.Text = unit.Name;
    1.97 -			Text = Translation.GetTranslation("FrmUnit", "{0} ({1})", unit.Name, unit.UnitType.Name);
    1.98 -		}
    1.99 -
   1.100 -		void unit_PointsValueChanged(WarFoundryObject obj, double oldValue, double newValue)
   1.101 -		{
   1.102 -			SetPointsValueText();
   1.103 -		}
   1.104 -
   1.105 -		private void SetPointsValueText()
   1.106 -		{
   1.107 -			lblPoints.Text = "(" + unit.Points + " pts)";
   1.108 -		}
   1.109 -
   1.110 -		private void SetStats()
   1.111 -		{
   1.112 -			Stat[][] stats = unit.UnitStatsArraysWithName;
   1.113 -			string[] statsIDs = unit.UnitStatsArrayIDs;
   1.114 -			int statsCount = stats.Length;
   1.115 -			log.DebugFormat("Unit {0} has {1} stats arrays", unit.UnitType.Name, statsCount);
   1.116 -
   1.117 -			for (int i = 0; i < statsCount; i++)
   1.118 -			{
   1.119 -				DataGridView statsGrid = GetDataGridView(statsIDs[i]);
   1.120 -				DataTable dt = (DataTable)statsGrid.DataSource;
   1.121 -				DataRow dr = dt.NewRow();
   1.122 -				dr.ItemArray = stats[i];
   1.123 -				log.DebugFormat("Add row to data table for {0}", statsIDs[i]);
   1.124 -				dt.Rows.Add(dr);
   1.125 -				statsGrid.ClearSelection();
   1.126 -			}
   1.127 -		}
   1.128 -
   1.129 -		private DataGridView GetDataGridView(string statsID)
   1.130 -		{
   1.131 -			DataGridView grid;
   1.132 -
   1.133 -			if (DataGridViews.ContainsKey(statsID))
   1.134 -			{
   1.135 -				grid = DictionaryUtils.GetValue(DataGridViews, statsID);
   1.136 -			}
   1.137 -			else
   1.138 -			{
   1.139 -				grid = CreateDataGridView(statsID);
   1.140 -				DataGridViews[statsID] = grid;
   1.141 -			}
   1.142 -
   1.143 -			return grid;
   1.144 -		}
   1.145 -
   1.146 -		private DataGridView CreateDataGridView(string statsID)
   1.147 -		{
   1.148 -			log.DebugFormat("Create DataGridView for stats ID {0}", statsID);
   1.149 -			SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID);
   1.150 -			StatSlot[] sysStatSlots = sysStats.StatSlots;
   1.151 -			int statsCount = sysStatSlots.Length;
   1.152 -			int statsWithNameCount = statsCount + 1;
   1.153 -			StatSlot[] statsWithName = new StatSlot[statsWithNameCount];
   1.154 -			statsWithName[0] = new StatSlot("Name");
   1.155 -			sysStatSlots.CopyTo(statsWithName, 1);
   1.156 -			DataTable dt = new DataTable();
   1.157 -			DataGridView statsGrid = CreateDataGridView();
   1.158 -			statsGrid.DataSource = dt;
   1.159 -			int columnWidth = statsGrid.Width / (statsCount + NAME_COL_WIDTH_MULTIPLIER);
   1.160 -
   1.161 -			for (int i = 0; i < statsWithNameCount; i++)
   1.162 -			{
   1.163 -				StatSlot stat = statsWithName[i];
   1.164 -				string slotName = stat.Name;
   1.165 -				statsGrid.Columns.Add(CreateStatColumn(slotName, columnWidth));
   1.166 -				dt.Columns.Add(CreateDataColumn(slotName));
   1.167 -			}
   1.168 -
   1.169 -			int otherStatsWidth = statsCount * columnWidth;
   1.170 -			SetNameColumnWidth(statsGrid, otherStatsWidth);
   1.171 -			
   1.172 -			return statsGrid;
   1.173 -		}
   1.174 -
   1.175 -		private static DataGridViewColumn CreateStatColumn(string slotName, int columnWidth)
   1.176 -		{
   1.177 -			DataGridViewColumn col = new DataGridViewTextBoxColumn();
   1.178 -			col.Width = columnWidth;
   1.179 -			col.Name = slotName;
   1.180 -			col.HeaderText = slotName;
   1.181 -			col.DataPropertyName = slotName;
   1.182 -			col.SortMode = DataGridViewColumnSortMode.NotSortable;
   1.183 -			col.CellTemplate = new StatsDataGridViewCell();
   1.184 -			return col;
   1.185 -		}
   1.186 -
   1.187 -		private static void SetNameColumnWidth(DataGridView statsGrid, int otherStatsWidth)
   1.188 -		{
   1.189 -
   1.190 -			DataGridViewColumn nameColumn = statsGrid.Columns[0];
   1.191 -			nameColumn.HeaderText = Translation.GetTranslation("StatLineName", "name");
   1.192 -			nameColumn.Width = statsGrid.Width - otherStatsWidth;
   1.193 -		}
   1.194 -
   1.195 -		private static DataColumn CreateDataColumn(string slotName)
   1.196 -		{
   1.197 -			log.DebugFormat("Create column {0}", slotName);
   1.198 -			DataColumn tempCol = new DataColumn(slotName,  typeof(Stat));
   1.199 -			return tempCol;
   1.200 -		}
   1.201 -
   1.202 -		public DataGridView CreateDataGridView()
   1.203 -		{
   1.204 -			log.Debug("Create DataGridView widget");
   1.205 -			DataGridView statsGrid = new DataGridView();
   1.206 -			statsGrid.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
   1.207 -						| System.Windows.Forms.AnchorStyles.Right)));
   1.208 -			statsGrid.CausesValidation = false;
   1.209 -			statsGrid.ReadOnly = true;
   1.210 -			statsGrid.RowHeadersVisible = false;
   1.211 -			statsGrid.Size = new System.Drawing.Size(600, 88);
   1.212 -			statsGrid.TabStop = false;
   1.213 -			statsGrid.AllowUserToAddRows = false;
   1.214 -			statsGrid.ScrollBars = ScrollBars.None;
   1.215 -			statsGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
   1.216 -			statsGrid.BorderStyle = BorderStyle.None;
   1.217 -			statsGrid.BackgroundColor = SystemColors.Control;
   1.218 -			statsGrid.RowsAdded += new DataGridViewRowsAddedEventHandler(statsGrid_RowsAdded);
   1.219 -			statsPanel.Controls.Add(statsGrid);
   1.220 -			statsGrid.Width = statsPanel.Width - (int)Math.Round(SystemInformation.VerticalScrollBarWidth * 1.4);
   1.221 -			return statsGrid;
   1.222 -		}
   1.223 -
   1.224 -		private void statsGrid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
   1.225 -		{
   1.226 -			if (sender is DataGridView)
   1.227 -			{
   1.228 -				SetGridHeight((DataGridView)sender);
   1.229 -			}
   1.230 -		}
   1.231 -
   1.232 -		private static void SetGridHeight(DataGridView statsGrid)
   1.233 -		{
   1.234 -			DataGridViewRowCollection rows = statsGrid.Rows;
   1.235 -			statsGrid.Height = statsGrid.Columns[0].HeaderCell.Size.Height + (rows.Count * rows[0].Height);
   1.236 -			log.DebugFormat("Set height to {0} for grid of {1} rows", statsGrid.Height, rows.Count);
   1.237 -		}
   1.238 -
   1.239 -		private void SetWeapons()
   1.240 -		{
   1.241 -			foreach (UnitEquipmentItem item in unit.GetEquipment())
   1.242 -			{
   1.243 -				equipmentList.Items.Add(GetEquipmentChoice(item));
   1.244 -			}
   1.245 -		}
   1.246 -
   1.247 -		private UnitEquipmentChoice GetEquipmentChoice(UnitEquipmentItem item)
   1.248 -		{
   1.249 -			UnitEquipmentChoice choice = null;
   1.250 -			equipmentChoices.TryGetValue(item, out choice);
   1.251 -
   1.252 -			if (choice == null)
   1.253 -			{
   1.254 -				choice = new UnitEquipmentChoice(Unit, item);
   1.255 -				equipmentChoices[item] = choice;
   1.256 -			}
   1.257 -
   1.258 -			return choice;
   1.259 -		}
   1.260 -
   1.261 -		/// <summary>
   1.262 -		/// Clean up any resources being used.
   1.263 -		/// </summary>
   1.264 -		protected override void Dispose(bool disposing)
   1.265 -		{
   1.266 -			//remove our leave events so that disposing doesn't trigger them
   1.267 -			tbUnitName.Leave -= new System.EventHandler(this.tbUnitName_Leave);
   1.268 -			unitSize.Leave -= new System.EventHandler(this.unitSize_Leave);
   1.269 -
   1.270 -			if (disposing)
   1.271 -			{
   1.272 -				if (components != null)
   1.273 -				{
   1.274 -					components.Dispose();
   1.275 -				}
   1.276 -			}
   1.277 -			base.Dispose(disposing);
   1.278 -		}
   1.279 -
   1.280 -		#region Windows Form Designer generated code
   1.281 -		/// <summary>
   1.282 -		/// Required method for Designer support - do not modify
   1.283 -		/// the contents of this method with the code editor.
   1.284 -		/// </summary>
   1.285 -		private void InitializeComponent()
   1.286 -		{
   1.287 -			this.tbUnitName = new System.Windows.Forms.TextBox();
   1.288 -			this.unitSize = new System.Windows.Forms.NumericUpDown();
   1.289 -			this.lblUnitSize = new IBBoard.Windows.Forms.IBBLabel();
   1.290 -			this.lblEquip = new IBBoard.Windows.Forms.IBBLabel();
   1.291 -			this.bttnAddWeapon = new IBBoard.Windows.Forms.IBBButton();
   1.292 -			this.bttnRemoveWeapon = new IBBoard.Windows.Forms.IBBButton();
   1.293 -			this.equipmentList = new System.Windows.Forms.ListBox();
   1.294 -			this.bttnReplaceWeapon = new IBBoard.Windows.Forms.IBBButton();
   1.295 -			this.bttnEditWeapon = new IBBoard.Windows.Forms.IBBButton();
   1.296 -			this.lblPoints = new System.Windows.Forms.Label();
   1.297 -			this.lblNotes = new IBBoard.Windows.Forms.IBBLabel();
   1.298 -			this.notes = new System.Windows.Forms.TextBox();
   1.299 -			this.abilitiesList = new System.Windows.Forms.ListBox();
   1.300 -			this.lblAbilities = new IBBoard.Windows.Forms.IBBLabel();
   1.301 -			this.statsPanel = new System.Windows.Forms.FlowLayoutPanel();
   1.302 -			((System.ComponentModel.ISupportInitialize)(this.unitSize)).BeginInit();
   1.303 -			this.SuspendLayout();
   1.304 -			// 
   1.305 -			// tbUnitName
   1.306 -			// 
   1.307 -			this.tbUnitName.Location = new System.Drawing.Point(8, 8);
   1.308 -			this.tbUnitName.Name = "tbUnitName";
   1.309 -			this.tbUnitName.Size = new System.Drawing.Size(344, 20);
   1.310 -			this.tbUnitName.TabIndex = 1;
   1.311 -			this.tbUnitName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbUnitName_KeyDown);
   1.312 -			this.tbUnitName.Leave += new System.EventHandler(this.tbUnitName_Leave);
   1.313 -			// 
   1.314 -			// unitSize
   1.315 -			// 
   1.316 -			this.unitSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.317 -			this.unitSize.Location = new System.Drawing.Point(528, 8);
   1.318 -			this.unitSize.Name = "unitSize";
   1.319 -			this.unitSize.Size = new System.Drawing.Size(80, 20);
   1.320 -			this.unitSize.TabIndex = 1;
   1.321 -			this.unitSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
   1.322 -			this.unitSize.Value = new decimal(new int[] {
   1.323 -            1,
   1.324 -            0,
   1.325 -            0,
   1.326 -            0});
   1.327 -			this.unitSize.Leave += new System.EventHandler(this.unitSize_Leave);
   1.328 -			this.unitSize.KeyDown += new System.Windows.Forms.KeyEventHandler(this.unitSize_KeyDown);
   1.329 -			// 
   1.330 -			// lblUnitSize
   1.331 -			// 
   1.332 -			this.lblUnitSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.333 -			this.lblUnitSize.Location = new System.Drawing.Point(426, 8);
   1.334 -			this.lblUnitSize.Name = "lblUnitSize";
   1.335 -			this.lblUnitSize.Size = new System.Drawing.Size(98, 23);
   1.336 -			this.lblUnitSize.TabIndex = 0;
   1.337 -			this.lblUnitSize.Text = "unit size";
   1.338 -			this.lblUnitSize.TextAlign = System.Drawing.ContentAlignment.TopRight;
   1.339 -			// 
   1.340 -			// lblEquip
   1.341 -			// 
   1.342 -			this.lblEquip.Location = new System.Drawing.Point(15, 126);
   1.343 -			this.lblEquip.Name = "lblEquip";
   1.344 -			this.lblEquip.Size = new System.Drawing.Size(81, 108);
   1.345 -			this.lblEquip.TabIndex = 3;
   1.346 -			this.lblEquip.Text = "equipment";
   1.347 -			this.lblEquip.TextAlign = System.Drawing.ContentAlignment.TopRight;
   1.348 -			// 
   1.349 -			// bttnAddWeapon
   1.350 -			// 
   1.351 -			this.bttnAddWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.352 -			this.bttnAddWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
   1.353 -			this.bttnAddWeapon.Location = new System.Drawing.Point(516, 126);
   1.354 -			this.bttnAddWeapon.Name = "bttnAddWeapon";
   1.355 -			this.bttnAddWeapon.Size = new System.Drawing.Size(88, 22);
   1.356 -			this.bttnAddWeapon.TabIndex = 4;
   1.357 -			this.bttnAddWeapon.Text = "add";
   1.358 -			this.bttnAddWeapon.Click += new System.EventHandler(this.bttnAddWeapon_Click);
   1.359 -			// 
   1.360 -			// bttnRemoveWeapon
   1.361 -			// 
   1.362 -			this.bttnRemoveWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.363 -			this.bttnRemoveWeapon.Enabled = false;
   1.364 -			this.bttnRemoveWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
   1.365 -			this.bttnRemoveWeapon.Location = new System.Drawing.Point(516, 210);
   1.366 -			this.bttnRemoveWeapon.Name = "bttnRemoveWeapon";
   1.367 -			this.bttnRemoveWeapon.Size = new System.Drawing.Size(88, 22);
   1.368 -			this.bttnRemoveWeapon.TabIndex = 5;
   1.369 -			this.bttnRemoveWeapon.Text = "remove";
   1.370 -			this.bttnRemoveWeapon.Click += new System.EventHandler(this.bttnRemoveWeapon_Click);
   1.371 -			// 
   1.372 -			// equipmentList
   1.373 -			// 
   1.374 -			this.equipmentList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
   1.375 -						| System.Windows.Forms.AnchorStyles.Right)));
   1.376 -			this.equipmentList.Location = new System.Drawing.Point(102, 126);
   1.377 -			this.equipmentList.Name = "equipmentList";
   1.378 -			this.equipmentList.Size = new System.Drawing.Size(408, 108);
   1.379 -			this.equipmentList.TabIndex = 6;
   1.380 -			this.equipmentList.SelectedIndexChanged += new System.EventHandler(this.equipmentList_SelectedIndexChanged);
   1.381 -			this.equipmentList.DoubleClick += new System.EventHandler(this.equipmentList_DoubleClick);
   1.382 -			// 
   1.383 -			// bttnReplaceWeapon
   1.384 -			// 
   1.385 -			this.bttnReplaceWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.386 -			this.bttnReplaceWeapon.Enabled = false;
   1.387 -			this.bttnReplaceWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
   1.388 -			this.bttnReplaceWeapon.Location = new System.Drawing.Point(516, 182);
   1.389 -			this.bttnReplaceWeapon.Name = "bttnReplaceWeapon";
   1.390 -			this.bttnReplaceWeapon.Size = new System.Drawing.Size(88, 22);
   1.391 -			this.bttnReplaceWeapon.TabIndex = 10;
   1.392 -			this.bttnReplaceWeapon.Text = "replace";
   1.393 -			this.bttnReplaceWeapon.Click += new System.EventHandler(this.bttnReplaceWeapon_Click);
   1.394 -			// 
   1.395 -			// bttnEditWeapon
   1.396 -			// 
   1.397 -			this.bttnEditWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.398 -			this.bttnEditWeapon.Enabled = false;
   1.399 -			this.bttnEditWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
   1.400 -			this.bttnEditWeapon.Location = new System.Drawing.Point(516, 154);
   1.401 -			this.bttnEditWeapon.Name = "bttnEditWeapon";
   1.402 -			this.bttnEditWeapon.Size = new System.Drawing.Size(88, 22);
   1.403 -			this.bttnEditWeapon.TabIndex = 11;
   1.404 -			this.bttnEditWeapon.Text = "edit";
   1.405 -			this.bttnEditWeapon.Click += new System.EventHandler(this.bttnEditWeapon_Click);
   1.406 -			// 
   1.407 -			// lblPoints
   1.408 -			// 
   1.409 -			this.lblPoints.Location = new System.Drawing.Point(358, 8);
   1.410 -			this.lblPoints.Name = "lblPoints";
   1.411 -			this.lblPoints.Size = new System.Drawing.Size(77, 21);
   1.412 -			this.lblPoints.TabIndex = 12;
   1.413 -			this.lblPoints.Text = "(points)";
   1.414 -			// 
   1.415 -			// lblNotes
   1.416 -			// 
   1.417 -			this.lblNotes.Location = new System.Drawing.Point(13, 317);
   1.418 -			this.lblNotes.Name = "lblNotes";
   1.419 -			this.lblNotes.Size = new System.Drawing.Size(84, 62);
   1.420 -			this.lblNotes.TabIndex = 13;
   1.421 -			this.lblNotes.Text = "notes";
   1.422 -			this.lblNotes.TextAlign = System.Drawing.ContentAlignment.TopRight;
   1.423 -			// 
   1.424 -			// notes
   1.425 -			// 
   1.426 -			this.notes.Location = new System.Drawing.Point(102, 317);
   1.427 -			this.notes.Multiline = true;
   1.428 -			this.notes.Name = "notes";
   1.429 -			this.notes.ReadOnly = true;
   1.430 -			this.notes.Size = new System.Drawing.Size(408, 62);
   1.431 -			this.notes.TabIndex = 14;
   1.432 -			// 
   1.433 -			// abilitiesList
   1.434 -			// 
   1.435 -			this.abilitiesList.FormattingEnabled = true;
   1.436 -			this.abilitiesList.Location = new System.Drawing.Point(102, 240);
   1.437 -			this.abilitiesList.Name = "abilitiesList";
   1.438 -			this.abilitiesList.Size = new System.Drawing.Size(408, 69);
   1.439 -			this.abilitiesList.TabIndex = 15;
   1.440 -			// 
   1.441 -			// lblAbilities
   1.442 -			// 
   1.443 -			this.lblAbilities.Location = new System.Drawing.Point(13, 240);
   1.444 -			this.lblAbilities.Name = "lblAbilities";
   1.445 -			this.lblAbilities.Size = new System.Drawing.Size(84, 62);
   1.446 -			this.lblAbilities.TabIndex = 16;
   1.447 -			this.lblAbilities.Text = "abilities";
   1.448 -			this.lblAbilities.TextAlign = System.Drawing.ContentAlignment.TopRight;
   1.449 -			// 
   1.450 -			// statsPanel
   1.451 -			// 
   1.452 -			this.statsPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
   1.453 -						| System.Windows.Forms.AnchorStyles.Right)));
   1.454 -			this.statsPanel.AutoScroll = true;
   1.455 -			this.statsPanel.Location = new System.Drawing.Point(8, 35);
   1.456 -			this.statsPanel.Name = "statsPanel";
   1.457 -			this.statsPanel.Size = new System.Drawing.Size(600, 85);
   1.458 -			this.statsPanel.TabIndex = 17;
   1.459 -			// 
   1.460 -			// FrmUnit
   1.461 -			// 
   1.462 -			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   1.463 -			this.ClientSize = new System.Drawing.Size(616, 391);
   1.464 -			this.Controls.Add(this.statsPanel);
   1.465 -			this.Controls.Add(this.lblAbilities);
   1.466 -			this.Controls.Add(this.abilitiesList);
   1.467 -			this.Controls.Add(this.notes);
   1.468 -			this.Controls.Add(this.lblNotes);
   1.469 -			this.Controls.Add(this.lblPoints);
   1.470 -			this.Controls.Add(this.bttnEditWeapon);
   1.471 -			this.Controls.Add(this.bttnReplaceWeapon);
   1.472 -			this.Controls.Add(this.equipmentList);
   1.473 -			this.Controls.Add(this.bttnRemoveWeapon);
   1.474 -			this.Controls.Add(this.bttnAddWeapon);
   1.475 -			this.Controls.Add(this.lblEquip);
   1.476 -			this.Controls.Add(this.lblUnitSize);
   1.477 -			this.Controls.Add(this.unitSize);
   1.478 -			this.Controls.Add(this.tbUnitName);
   1.479 -			this.Name = "FrmUnit";
   1.480 -			this.ShowIcon = false;
   1.481 -			this.ShowInTaskbar = false;
   1.482 -			this.Text = "FrmUnit";
   1.483 -			this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmUnit_FormClosing);
   1.484 -			((System.ComponentModel.ISupportInitialize)(this.unitSize)).EndInit();
   1.485 -			this.ResumeLayout(false);
   1.486 -			this.PerformLayout();
   1.487 -
   1.488 -		}
   1.489 -		#endregion
   1.490 -
   1.491 -		public Unit Unit
   1.492 -		{
   1.493 -			get { return unit; }
   1.494 -		}
   1.495 -
   1.496 -		private void tbUnitName_Leave(object sender, System.EventArgs e)
   1.497 -		{
   1.498 -			UpdateUnitName();
   1.499 -		}
   1.500 -
   1.501 -		private void tbUnitName_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
   1.502 -		{
   1.503 -			if (e.KeyCode == Keys.Enter)
   1.504 -			{
   1.505 -				UpdateUnitName();
   1.506 -			}
   1.507 -		}
   1.508 -
   1.509 -		private void UpdateUnitName()
   1.510 -		{
   1.511 -			if (unit.Name != tbUnitName.Text)
   1.512 -			{
   1.513 -				commandStack.Execute(new SetNameCommand(unit, tbUnitName.Text));
   1.514 -			}
   1.515 -		}
   1.516 -
   1.517 -		private void unitSize_Leave(object sender, System.EventArgs e)
   1.518 -		{
   1.519 -			UpdateUnitSize();
   1.520 -		}
   1.521 -
   1.522 -		private void unitSize_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
   1.523 -		{
   1.524 -			if (e.KeyCode == Keys.Enter)
   1.525 -			{
   1.526 -				UpdateUnitSize();
   1.527 -			}
   1.528 -		}
   1.529 -
   1.530 -		private void UpdateUnitSize()
   1.531 -		{
   1.532 -			if (unit.Size != unitSize.Value)
   1.533 -			{
   1.534 -				commandStack.Execute(new SetUnitSizeCommand(unit, (int) unitSize.Value));
   1.535 -			}
   1.536 -		}
   1.537 -
   1.538 -		private void unit_NameChanged(WarFoundryObject obj, string oldValue, string newValue)
   1.539 -		{
   1.540 -			if (obj is Unit && obj.Equals(unit))
   1.541 -			{
   1.542 -				SetUnitName();
   1.543 -			}
   1.544 -		}
   1.545 -
   1.546 -		private void unit_UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue)
   1.547 -		{
   1.548 -			if (obj is Unit && obj.Equals(unit))
   1.549 -			{
   1.550 -				unitSize.Value = newValue;
   1.551 -			}
   1.552 -		}
   1.553 -
   1.554 -		private void RefreshUnitEquipment()
   1.555 -		{
   1.556 -			foreach (UnitEquipmentChoice choice in equipmentChoices.Values)
   1.557 -			{
   1.558 -				SetEquipmentListValue(choice);
   1.559 -			}
   1.560 -		}
   1.561 -
   1.562 -		private void equipmentList_SelectedIndexChanged(object sender, System.EventArgs e)
   1.563 -		{
   1.564 -			SetButtonsEnabledState();
   1.565 -		}
   1.566 -
   1.567 -		private void SetButtonsEnabledState()
   1.568 -		{
   1.569 -
   1.570 -			UnitEquipmentItem equipItem = GetSelectedUnitEquipmentItem();
   1.571 -			bttnReplaceWeapon.Enabled = (equipItem != null && equipItem.HasAlternatives());
   1.572 -			bttnEditWeapon.Enabled = (equipItem != null);
   1.573 -			bttnRemoveWeapon.Enabled = (equipItem != null && !equipItem.IsRequired);
   1.574 -		}
   1.575 -
   1.576 -		private void unit_UnitEquipmentAmountChanged(WarFoundryObject obj, double oldValue, double newValue)
   1.577 -		{
   1.578 -			if (obj is UnitEquipmentItem)
   1.579 -			{
   1.580 -				UnitEquipmentItem equip = (UnitEquipmentItem) obj;
   1.581 -				UnitEquipmentChoice equipChoice = GetEquipmentChoice(equip);
   1.582 -
   1.583 -				if (newValue == 0)
   1.584 -				{
   1.585 -					equipmentList.Items.Remove(equipChoice);
   1.586 -				}
   1.587 -				else
   1.588 -				{
   1.589 -					SetEquipmentListValue(equipChoice);
   1.590 -				}
   1.591 -			}
   1.592 -		}
   1.593 -
   1.594 -		private void SetEquipmentListValue(UnitEquipmentChoice equipChoice)
   1.595 -		{
   1.596 -			int idx = equipmentList.Items.IndexOf(equipChoice);
   1.597 -
   1.598 -			if (idx > -1)
   1.599 -			{
   1.600 -				equipmentList.Items[idx] = equipChoice;
   1.601 -			}
   1.602 -			else
   1.603 -			{
   1.604 -				equipmentList.Items.Add(equipChoice);
   1.605 -			}
   1.606 -		}
   1.607 -
   1.608 -		private void EditWeapon()
   1.609 -		{
   1.610 -			UnitEquipmentItem item = GetSelectedUnitEquipmentItem();
   1.611 -
   1.612 -			if (item != null)
   1.613 -			{
   1.614 -				FrmEditUnitEquipment editEquip = new FrmEditUnitEquipment(Unit, item, commandStack);
   1.615 -				editEquip.ShowDialog(this);
   1.616 -			}
   1.617 -		}
   1.618 -
   1.619 -		private UnitEquipmentItem GetSelectedUnitEquipmentItem()
   1.620 -		{
   1.621 -			UnitEquipmentChoice selectedItem = GetSelectedUnitEquipmentChoice();
   1.622 -			UnitEquipmentItem equipItem = null;
   1.623 -
   1.624 -			if (selectedItem!=null)
   1.625 -			{
   1.626 -				equipItem = selectedItem.Item;
   1.627 -			}
   1.628 -
   1.629 -			return equipItem;
   1.630 -		}
   1.631 -
   1.632 -		private UnitEquipmentChoice GetSelectedUnitEquipmentChoice()
   1.633 -		{
   1.634 -			return (UnitEquipmentChoice) equipmentList.SelectedItem;
   1.635 -		}
   1.636 -
   1.637 -		private void bttnEditWeapon_Click(object sender, System.EventArgs e)
   1.638 -		{
   1.639 -			EditWeapon();
   1.640 -		}
   1.641 -
   1.642 -		private void equipmentList_DoubleClick(object sender, System.EventArgs e)
   1.643 -		{
   1.644 -			EditWeapon();
   1.645 -		}
   1.646 -
   1.647 -		private void AddWeapon()
   1.648 -		{
   1.649 -			FrmNewUnitEquipment newEquip = new FrmNewUnitEquipment(Unit, commandStack);
   1.650 -			newEquip.ShowDialog(this);
   1.651 -		}
   1.652 -
   1.653 -		private void bttnAddWeapon_Click(object sender, System.EventArgs e)
   1.654 -		{
   1.655 -			AddWeapon();
   1.656 -		}
   1.657 -
   1.658 -		private void RemoveWeapon()
   1.659 -		{
   1.660 -			commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, GetSelectedUnitEquipmentItem(), 0));
   1.661 -		}
   1.662 -
   1.663 -		private void bttnRemoveWeapon_Click(object sender, System.EventArgs e)
   1.664 -		{
   1.665 -			RemoveWeapon();
   1.666 -		}
   1.667 -
   1.668 -		private void bttnReplaceWeapon_Click(object sender, System.EventArgs e)
   1.669 -		{
   1.670 -			FrmReplaceUnitEquipment replace = new FrmReplaceUnitEquipment(unit, GetSelectedUnitEquipmentItem(), commandStack);
   1.671 -			replace.ShowDialog(this);
   1.672 -		}
   1.673 -
   1.674 -		private void FrmUnit_FormClosing(object sender, FormClosingEventArgs e)
   1.675 -		{
   1.676 -			UpdateUnitName();
   1.677 -			UpdateUnitSize();
   1.678 -		}
   1.679 -	}
   1.680 +// This file (FrmUnit.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2007, 2008, 2009 IBBoard.
   1.681 +//
   1.682 +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
   1.683 +
   1.684 +using System;
   1.685 +using System.Drawing;
   1.686 +using System.Data;
   1.687 +using System.Collections.Generic;
   1.688 +using System.ComponentModel;
   1.689 +using System.Windows.Forms;
   1.690 +using IBBoard.Commands;
   1.691 +using IBBoard.Lang;
   1.692 +using IBBoard.Windows.Forms;
   1.693 +using IBBoard.Windows.Forms.I18N;
   1.694 +using IBBoard.WarFoundry.API;
   1.695 +using IBBoard.WarFoundry.API.Commands;
   1.696 +using IBBoard.WarFoundry.API.Objects;
   1.697 +using IBBoard.WarFoundry.GUI.WinForms.UI;
   1.698 +using IBBoard.WarFoundry.GUI.WinForms.Util;
   1.699 +using log4net;
   1.700 +
   1.701 +namespace IBBoard.WarFoundry.GUI.WinForms
   1.702 +{
   1.703 +	/// <summary>
   1.704 +	/// Summary description for FrmUnit.
   1.705 +	/// </summary>
   1.706 +	public class FrmUnit : IBBoard.Windows.Forms.IBBForm
   1.707 +	{
   1.708 +		private static readonly ILog log = LogManager.GetLogger(typeof(FrmUnit));
   1.709 +		private static readonly int BORDER_WIDTH = 1;
   1.710 +		private static readonly int NAME_COL_WIDTH_MULTIPLIER = 3;
   1.711 +		private Unit unit;
   1.712 +		private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>();
   1.713 +		private Dictionary<string, DataGridView> DataGridViews = new Dictionary<string, DataGridView>();
   1.714 +		private CommandStack commandStack;
   1.715 +		private System.Windows.Forms.TextBox tbUnitName;
   1.716 +		private System.Windows.Forms.NumericUpDown unitSize;
   1.717 +		private IBBLabel lblUnitSize;
   1.718 +		private IBBButton bttnAddWeapon;
   1.719 +		private IBBButton bttnRemoveWeapon;
   1.720 +		private IBBLabel lblEquip;
   1.721 +		private System.Windows.Forms.ListBox equipmentList;
   1.722 +		private IBBButton bttnReplaceWeapon;
   1.723 +		private IBBButton bttnEditWeapon;
   1.724 +		private Label lblPoints;
   1.725 +		private IBBLabel lblNotes;
   1.726 +		private TextBox notes;
   1.727 +		private ListBox abilitiesList;
   1.728 +		private IBBLabel lblAbilities;
   1.729 +		private FlowLayoutPanel statsPanel;
   1.730 +		/// <summary>
   1.731 +		/// Required designer variable.
   1.732 +		/// </summary>
   1.733 +		private System.ComponentModel.Container components = null;
   1.734 +
   1.735 +		public FrmUnit(Unit toDisplay, CommandStack cmdStack)
   1.736 +		{
   1.737 +			unit = toDisplay;
   1.738 +			commandStack = cmdStack;
   1.739 +			//
   1.740 +			// Required for Windows Form Designer support
   1.741 +			//
   1.742 +			InitializeComponent();
   1.743 +			TranslateForm();
   1.744 +			Translation.TranslationChanged += new MethodInvoker(TranslateForm);
   1.745 +			unit.NameChanged += new StringValChangedDelegate(unit_NameChanged);
   1.746 +			unit.UnitSizeChanged += new IntValChangedDelegate(unit_UnitSizeChanged);
   1.747 +			unit.UnitEquipmentAmountChanged += new DoubleValChangedDelegate(unit_UnitEquipmentAmountChanged);
   1.748 +			unit.PointsValueChanged += new DoubleValChangedDelegate(unit_PointsValueChanged);
   1.749 +
   1.750 +			unitSize.Value = unit.Size;
   1.751 +			unitSize.Maximum = (unit.UnitType.MaxSize == WarFoundryCore.INFINITY ? int.MaxValue : unit.UnitType.MaxSize);
   1.752 +			unitSize.Minimum = unit.UnitType.MinSize;
   1.753 +			unitSize.Enabled = (unitSize.Maximum != unitSize.Minimum);
   1.754 +
   1.755 +			notes.Text = unit.UnitType.Notes;
   1.756 +			abilitiesList.DataSource = new List<Ability>(unit.UnitType.GetRequiredAbilities());
   1.757 +			abilitiesList.DisplayMember = "Name";
   1.758 +			SetPointsValueText();
   1.759 +			SetStats();
   1.760 +			SetWeapons();
   1.761 +		}
   1.762 +
   1.763 +		private void TranslateForm()
   1.764 +		{
   1.765 +			ControlTranslator.TranslateControl(this);
   1.766 +			SetUnitName();
   1.767 +			RefreshUnitEquipment();
   1.768 +		}
   1.769 +
   1.770 +		private void SetUnitName()
   1.771 +		{
   1.772 +			tbUnitName.Text = unit.Name;
   1.773 +			Text = Translation.GetTranslation("FrmUnit", "{0} ({1})", unit.Name, unit.UnitType.Name);
   1.774 +		}
   1.775 +
   1.776 +		void unit_PointsValueChanged(WarFoundryObject obj, double oldValue, double newValue)
   1.777 +		{
   1.778 +			SetPointsValueText();
   1.779 +		}
   1.780 +
   1.781 +		private void SetPointsValueText()
   1.782 +		{
   1.783 +			lblPoints.Text = "(" + unit.Points + " pts)";
   1.784 +		}
   1.785 +
   1.786 +		private void SetStats()
   1.787 +		{
   1.788 +			Stat[][] stats = unit.UnitStatsArraysWithName;
   1.789 +			string[] statsIDs = unit.UnitStatsArrayIDs;
   1.790 +			int statsCount = stats.Length;
   1.791 +			log.DebugFormat("Unit {0} has {1} stats arrays", unit.UnitType.Name, statsCount);
   1.792 +
   1.793 +			for (int i = 0; i < statsCount; i++)
   1.794 +			{
   1.795 +				DataGridView statsGrid = GetDataGridView(statsIDs[i]);
   1.796 +				DataTable dt = (DataTable)statsGrid.DataSource;
   1.797 +				DataRow dr = dt.NewRow();
   1.798 +				dr.ItemArray = stats[i];
   1.799 +				log.DebugFormat("Add row to data table for {0}", statsIDs[i]);
   1.800 +				dt.Rows.Add(dr);
   1.801 +				statsGrid.ClearSelection();
   1.802 +			}
   1.803 +		}
   1.804 +
   1.805 +		private DataGridView GetDataGridView(string statsID)
   1.806 +		{
   1.807 +			DataGridView grid;
   1.808 +
   1.809 +			if (DataGridViews.ContainsKey(statsID))
   1.810 +			{
   1.811 +				grid = DictionaryUtils.GetValue(DataGridViews, statsID);
   1.812 +			}
   1.813 +			else
   1.814 +			{
   1.815 +				grid = CreateDataGridView(statsID);
   1.816 +				DataGridViews[statsID] = grid;
   1.817 +			}
   1.818 +
   1.819 +			return grid;
   1.820 +		}
   1.821 +
   1.822 +		private DataGridView CreateDataGridView(string statsID)
   1.823 +		{
   1.824 +			log.DebugFormat("Create DataGridView for stats ID {0}", statsID);
   1.825 +			SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID);
   1.826 +			StatSlot[] sysStatSlots = sysStats.StatSlots;
   1.827 +			int statsCount = sysStatSlots.Length;
   1.828 +			int statsWithNameCount = statsCount + 1;
   1.829 +			StatSlot[] statsWithName = new StatSlot[statsWithNameCount];
   1.830 +			statsWithName[0] = new StatSlot("Name");
   1.831 +			sysStatSlots.CopyTo(statsWithName, 1);
   1.832 +			DataTable dt = new DataTable();
   1.833 +			DataGridView statsGrid = CreateDataGridView();
   1.834 +			statsGrid.DataSource = dt;
   1.835 +			int columnWidth = statsGrid.Width / (statsCount + NAME_COL_WIDTH_MULTIPLIER);
   1.836 +
   1.837 +			for (int i = 0; i < statsWithNameCount; i++)
   1.838 +			{
   1.839 +				StatSlot stat = statsWithName[i];
   1.840 +				string slotName = stat.Name;
   1.841 +				statsGrid.Columns.Add(CreateStatColumn(slotName, columnWidth));
   1.842 +				dt.Columns.Add(CreateDataColumn(slotName));
   1.843 +			}
   1.844 +
   1.845 +			int otherStatsWidth = statsCount * columnWidth;
   1.846 +			SetNameColumnWidth(statsGrid, otherStatsWidth);
   1.847 +			
   1.848 +			return statsGrid;
   1.849 +		}
   1.850 +
   1.851 +		private static DataGridViewColumn CreateStatColumn(string slotName, int columnWidth)
   1.852 +		{
   1.853 +			DataGridViewColumn col = new DataGridViewTextBoxColumn();
   1.854 +			col.Width = columnWidth;
   1.855 +			col.Name = slotName;
   1.856 +			col.HeaderText = slotName;
   1.857 +			col.DataPropertyName = slotName;
   1.858 +			col.SortMode = DataGridViewColumnSortMode.NotSortable;
   1.859 +			col.CellTemplate = new StatsDataGridViewCell();
   1.860 +			col.HeaderCell.Style.WrapMode = DataGridViewTriState.False;
   1.861 +			return col;
   1.862 +		}
   1.863 +
   1.864 +		private static void SetNameColumnWidth(DataGridView statsGrid, int otherStatsWidth)
   1.865 +		{
   1.866 +
   1.867 +			DataGridViewColumn nameColumn = statsGrid.Columns[0];
   1.868 +			nameColumn.HeaderText = Translation.GetTranslation("StatLineName", "name");
   1.869 +			nameColumn.Width = statsGrid.Width - otherStatsWidth;
   1.870 +		}
   1.871 +
   1.872 +		private static DataColumn CreateDataColumn(string slotName)
   1.873 +		{
   1.874 +			log.DebugFormat("Create column {0}", slotName);
   1.875 +			DataColumn tempCol = new DataColumn(slotName,  typeof(Stat));
   1.876 +			return tempCol;
   1.877 +		}
   1.878 +
   1.879 +		public DataGridView CreateDataGridView()
   1.880 +		{
   1.881 +			log.Debug("Create DataGridView widget");
   1.882 +			DataGridView statsGrid = new DataGridView();
   1.883 +			statsGrid.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
   1.884 +						| System.Windows.Forms.AnchorStyles.Right)));
   1.885 +			statsGrid.CausesValidation = false;
   1.886 +			statsGrid.ReadOnly = true;
   1.887 +			statsGrid.RowHeadersVisible = false;
   1.888 +			statsGrid.Size = new System.Drawing.Size(600, 88);
   1.889 +			statsGrid.TabStop = false;
   1.890 +			statsGrid.AllowUserToAddRows = false;
   1.891 +			statsGrid.ScrollBars = ScrollBars.None;
   1.892 +			statsGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
   1.893 +			statsGrid.BorderStyle = BorderStyle.None;
   1.894 +			statsGrid.BackgroundColor = SystemColors.Control;
   1.895 +			statsGrid.RowsAdded += new DataGridViewRowsAddedEventHandler(statsGrid_RowsAdded);
   1.896 +			statsPanel.Controls.Add(statsGrid);
   1.897 +			statsGrid.Width = statsPanel.Width - (int)Math.Round(SystemInformation.VerticalScrollBarWidth * 1.4);
   1.898 +			return statsGrid;
   1.899 +		}
   1.900 +
   1.901 +		private void statsGrid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
   1.902 +		{
   1.903 +			if (sender is DataGridView)
   1.904 +			{
   1.905 +				SetGridHeight((DataGridView)sender);
   1.906 +			}
   1.907 +		}
   1.908 +
   1.909 +		private static void SetGridHeight(DataGridView statsGrid)
   1.910 +		{
   1.911 +			DataGridViewRowCollection rows = statsGrid.Rows;
   1.912 +			statsGrid.Height = statsGrid.Columns[0].HeaderCell.Size.Height + (rows.Count * rows[0].Height);
   1.913 +			log.DebugFormat("Set height to {0} for grid of {1} rows", statsGrid.Height, rows.Count);
   1.914 +		}
   1.915 +
   1.916 +		private void SetWeapons()
   1.917 +		{
   1.918 +			foreach (UnitEquipmentItem item in unit.GetEquipment())
   1.919 +			{
   1.920 +				equipmentList.Items.Add(GetEquipmentChoice(item));
   1.921 +			}
   1.922 +		}
   1.923 +
   1.924 +		private UnitEquipmentChoice GetEquipmentChoice(UnitEquipmentItem item)
   1.925 +		{
   1.926 +			UnitEquipmentChoice choice = null;
   1.927 +			equipmentChoices.TryGetValue(item, out choice);
   1.928 +
   1.929 +			if (choice == null)
   1.930 +			{
   1.931 +				choice = new UnitEquipmentChoice(Unit, item);
   1.932 +				equipmentChoices[item] = choice;
   1.933 +			}
   1.934 +
   1.935 +			return choice;
   1.936 +		}
   1.937 +
   1.938 +		/// <summary>
   1.939 +		/// Clean up any resources being used.
   1.940 +		/// </summary>
   1.941 +		protected override void Dispose(bool disposing)
   1.942 +		{
   1.943 +			//remove our leave events so that disposing doesn't trigger them
   1.944 +			tbUnitName.Leave -= new System.EventHandler(this.tbUnitName_Leave);
   1.945 +			unitSize.Leave -= new System.EventHandler(this.unitSize_Leave);
   1.946 +
   1.947 +			if (disposing)
   1.948 +			{
   1.949 +				if (components != null)
   1.950 +				{
   1.951 +					components.Dispose();
   1.952 +				}
   1.953 +			}
   1.954 +			base.Dispose(disposing);
   1.955 +		}
   1.956 +
   1.957 +		#region Windows Form Designer generated code
   1.958 +		/// <summary>
   1.959 +		/// Required method for Designer support - do not modify
   1.960 +		/// the contents of this method with the code editor.
   1.961 +		/// </summary>
   1.962 +		private void InitializeComponent()
   1.963 +		{
   1.964 +			this.tbUnitName = new System.Windows.Forms.TextBox();
   1.965 +			this.unitSize = new System.Windows.Forms.NumericUpDown();
   1.966 +			this.lblUnitSize = new IBBoard.Windows.Forms.IBBLabel();
   1.967 +			this.lblEquip = new IBBoard.Windows.Forms.IBBLabel();
   1.968 +			this.bttnAddWeapon = new IBBoard.Windows.Forms.IBBButton();
   1.969 +			this.bttnRemoveWeapon = new IBBoard.Windows.Forms.IBBButton();
   1.970 +			this.equipmentList = new System.Windows.Forms.ListBox();
   1.971 +			this.bttnReplaceWeapon = new IBBoard.Windows.Forms.IBBButton();
   1.972 +			this.bttnEditWeapon = new IBBoard.Windows.Forms.IBBButton();
   1.973 +			this.lblPoints = new System.Windows.Forms.Label();
   1.974 +			this.lblNotes = new IBBoard.Windows.Forms.IBBLabel();
   1.975 +			this.notes = new System.Windows.Forms.TextBox();
   1.976 +			this.abilitiesList = new System.Windows.Forms.ListBox();
   1.977 +			this.lblAbilities = new IBBoard.Windows.Forms.IBBLabel();
   1.978 +			this.statsPanel = new System.Windows.Forms.FlowLayoutPanel();
   1.979 +			((System.ComponentModel.ISupportInitialize)(this.unitSize)).BeginInit();
   1.980 +			this.SuspendLayout();
   1.981 +			// 
   1.982 +			// tbUnitName
   1.983 +			// 
   1.984 +			this.tbUnitName.Location = new System.Drawing.Point(8, 8);
   1.985 +			this.tbUnitName.Name = "tbUnitName";
   1.986 +			this.tbUnitName.Size = new System.Drawing.Size(344, 20);
   1.987 +			this.tbUnitName.TabIndex = 1;
   1.988 +			this.tbUnitName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbUnitName_KeyDown);
   1.989 +			this.tbUnitName.Leave += new System.EventHandler(this.tbUnitName_Leave);
   1.990 +			// 
   1.991 +			// unitSize
   1.992 +			// 
   1.993 +			this.unitSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.994 +			this.unitSize.Location = new System.Drawing.Point(528, 8);
   1.995 +			this.unitSize.Name = "unitSize";
   1.996 +			this.unitSize.Size = new System.Drawing.Size(80, 20);
   1.997 +			this.unitSize.TabIndex = 1;
   1.998 +			this.unitSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
   1.999 +			this.unitSize.Value = new decimal(new int[] {
  1.1000 +            1,
  1.1001 +            0,
  1.1002 +            0,
  1.1003 +            0});
  1.1004 +			this.unitSize.Leave += new System.EventHandler(this.unitSize_Leave);
  1.1005 +			this.unitSize.KeyDown += new System.Windows.Forms.KeyEventHandler(this.unitSize_KeyDown);
  1.1006 +			// 
  1.1007 +			// lblUnitSize
  1.1008 +			// 
  1.1009 +			this.lblUnitSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  1.1010 +			this.lblUnitSize.Location = new System.Drawing.Point(426, 8);
  1.1011 +			this.lblUnitSize.Name = "lblUnitSize";
  1.1012 +			this.lblUnitSize.Size = new System.Drawing.Size(98, 23);
  1.1013 +			this.lblUnitSize.TabIndex = 0;
  1.1014 +			this.lblUnitSize.Text = "unit size";
  1.1015 +			this.lblUnitSize.TextAlign = System.Drawing.ContentAlignment.TopRight;
  1.1016 +			// 
  1.1017 +			// lblEquip
  1.1018 +			// 
  1.1019 +			this.lblEquip.Location = new System.Drawing.Point(15, 126);
  1.1020 +			this.lblEquip.Name = "lblEquip";
  1.1021 +			this.lblEquip.Size = new System.Drawing.Size(81, 108);
  1.1022 +			this.lblEquip.TabIndex = 3;
  1.1023 +			this.lblEquip.Text = "equipment";
  1.1024 +			this.lblEquip.TextAlign = System.Drawing.ContentAlignment.TopRight;
  1.1025 +			// 
  1.1026 +			// bttnAddWeapon
  1.1027 +			// 
  1.1028 +			this.bttnAddWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  1.1029 +			this.bttnAddWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
  1.1030 +			this.bttnAddWeapon.Location = new System.Drawing.Point(516, 126);
  1.1031 +			this.bttnAddWeapon.Name = "bttnAddWeapon";
  1.1032 +			this.bttnAddWeapon.Size = new System.Drawing.Size(88, 22);
  1.1033 +			this.bttnAddWeapon.TabIndex = 4;
  1.1034 +			this.bttnAddWeapon.Text = "add";
  1.1035 +			this.bttnAddWeapon.Click += new System.EventHandler(this.bttnAddWeapon_Click);
  1.1036 +			// 
  1.1037 +			// bttnRemoveWeapon
  1.1038 +			// 
  1.1039 +			this.bttnRemoveWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  1.1040 +			this.bttnRemoveWeapon.Enabled = false;
  1.1041 +			this.bttnRemoveWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
  1.1042 +			this.bttnRemoveWeapon.Location = new System.Drawing.Point(516, 210);
  1.1043 +			this.bttnRemoveWeapon.Name = "bttnRemoveWeapon";
  1.1044 +			this.bttnRemoveWeapon.Size = new System.Drawing.Size(88, 22);
  1.1045 +			this.bttnRemoveWeapon.TabIndex = 5;
  1.1046 +			this.bttnRemoveWeapon.Text = "remove";
  1.1047 +			this.bttnRemoveWeapon.Click += new System.EventHandler(this.bttnRemoveWeapon_Click);
  1.1048 +			// 
  1.1049 +			// equipmentList
  1.1050 +			// 
  1.1051 +			this.equipmentList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  1.1052 +						| System.Windows.Forms.AnchorStyles.Right)));
  1.1053 +			this.equipmentList.Location = new System.Drawing.Point(102, 126);
  1.1054 +			this.equipmentList.Name = "equipmentList";
  1.1055 +			this.equipmentList.Size = new System.Drawing.Size(408, 108);
  1.1056 +			this.equipmentList.TabIndex = 6;
  1.1057 +			this.equipmentList.SelectedIndexChanged += new System.EventHandler(this.equipmentList_SelectedIndexChanged);
  1.1058 +			this.equipmentList.DoubleClick += new System.EventHandler(this.equipmentList_DoubleClick);
  1.1059 +			// 
  1.1060 +			// bttnReplaceWeapon
  1.1061 +			// 
  1.1062 +			this.bttnReplaceWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  1.1063 +			this.bttnReplaceWeapon.Enabled = false;
  1.1064 +			this.bttnReplaceWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
  1.1065 +			this.bttnReplaceWeapon.Location = new System.Drawing.Point(516, 182);
  1.1066 +			this.bttnReplaceWeapon.Name = "bttnReplaceWeapon";
  1.1067 +			this.bttnReplaceWeapon.Size = new System.Drawing.Size(88, 22);
  1.1068 +			this.bttnReplaceWeapon.TabIndex = 10;
  1.1069 +			this.bttnReplaceWeapon.Text = "replace";
  1.1070 +			this.bttnReplaceWeapon.Click += new System.EventHandler(this.bttnReplaceWeapon_Click);
  1.1071 +			// 
  1.1072 +			// bttnEditWeapon
  1.1073 +			// 
  1.1074 +			this.bttnEditWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  1.1075 +			this.bttnEditWeapon.Enabled = false;
  1.1076 +			this.bttnEditWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
  1.1077 +			this.bttnEditWeapon.Location = new System.Drawing.Point(516, 154);
  1.1078 +			this.bttnEditWeapon.Name = "bttnEditWeapon";
  1.1079 +			this.bttnEditWeapon.Size = new System.Drawing.Size(88, 22);
  1.1080 +			this.bttnEditWeapon.TabIndex = 11;
  1.1081 +			this.bttnEditWeapon.Text = "edit";
  1.1082 +			this.bttnEditWeapon.Click += new System.EventHandler(this.bttnEditWeapon_Click);
  1.1083 +			// 
  1.1084 +			// lblPoints
  1.1085 +			// 
  1.1086 +			this.lblPoints.Location = new System.Drawing.Point(358, 8);
  1.1087 +			this.lblPoints.Name = "lblPoints";
  1.1088 +			this.lblPoints.Size = new System.Drawing.Size(77, 21);
  1.1089 +			this.lblPoints.TabIndex = 12;
  1.1090 +			this.lblPoints.Text = "(points)";
  1.1091 +			// 
  1.1092 +			// lblNotes
  1.1093 +			// 
  1.1094 +			this.lblNotes.Location = new System.Drawing.Point(13, 317);
  1.1095 +			this.lblNotes.Name = "lblNotes";
  1.1096 +			this.lblNotes.Size = new System.Drawing.Size(84, 62);
  1.1097 +			this.lblNotes.TabIndex = 13;
  1.1098 +			this.lblNotes.Text = "notes";
  1.1099 +			this.lblNotes.TextAlign = System.Drawing.ContentAlignment.TopRight;
  1.1100 +			// 
  1.1101 +			// notes
  1.1102 +			// 
  1.1103 +			this.notes.Location = new System.Drawing.Point(102, 317);
  1.1104 +			this.notes.Multiline = true;
  1.1105 +			this.notes.Name = "notes";
  1.1106 +			this.notes.ReadOnly = true;
  1.1107 +			this.notes.Size = new System.Drawing.Size(408, 62);
  1.1108 +			this.notes.TabIndex = 14;
  1.1109 +			// 
  1.1110 +			// abilitiesList
  1.1111 +			// 
  1.1112 +			this.abilitiesList.FormattingEnabled = true;
  1.1113 +			this.abilitiesList.Location = new System.Drawing.Point(102, 240);
  1.1114 +			this.abilitiesList.Name = "abilitiesList";
  1.1115 +			this.abilitiesList.Size = new System.Drawing.Size(408, 69);
  1.1116 +			this.abilitiesList.TabIndex = 15;
  1.1117 +			// 
  1.1118 +			// lblAbilities
  1.1119 +			// 
  1.1120 +			this.lblAbilities.Location = new System.Drawing.Point(13, 240);
  1.1121 +			this.lblAbilities.Name = "lblAbilities";
  1.1122 +			this.lblAbilities.Size = new System.Drawing.Size(84, 62);
  1.1123 +			this.lblAbilities.TabIndex = 16;
  1.1124 +			this.lblAbilities.Text = "abilities";
  1.1125 +			this.lblAbilities.TextAlign = System.Drawing.ContentAlignment.TopRight;
  1.1126 +			// 
  1.1127 +			// statsPanel
  1.1128 +			// 
  1.1129 +			this.statsPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  1.1130 +						| System.Windows.Forms.AnchorStyles.Right)));
  1.1131 +			this.statsPanel.AutoScroll = true;
  1.1132 +			this.statsPanel.Location = new System.Drawing.Point(8, 35);
  1.1133 +			this.statsPanel.Name = "statsPanel";
  1.1134 +			this.statsPanel.Size = new System.Drawing.Size(600, 85);
  1.1135 +			this.statsPanel.TabIndex = 17;
  1.1136 +			// 
  1.1137 +			// FrmUnit
  1.1138 +			// 
  1.1139 +			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  1.1140 +			this.ClientSize = new System.Drawing.Size(616, 391);
  1.1141 +			this.Controls.Add(this.statsPanel);
  1.1142 +			this.Controls.Add(this.lblAbilities);
  1.1143 +			this.Controls.Add(this.abilitiesList);
  1.1144 +			this.Controls.Add(this.notes);
  1.1145 +			this.Controls.Add(this.lblNotes);
  1.1146 +			this.Controls.Add(this.lblPoints);
  1.1147 +			this.Controls.Add(this.bttnEditWeapon);
  1.1148 +			this.Controls.Add(this.bttnReplaceWeapon);
  1.1149 +			this.Controls.Add(this.equipmentList);
  1.1150 +			this.Controls.Add(this.bttnRemoveWeapon);
  1.1151 +			this.Controls.Add(this.bttnAddWeapon);
  1.1152 +			this.Controls.Add(this.lblEquip);
  1.1153 +			this.Controls.Add(this.lblUnitSize);
  1.1154 +			this.Controls.Add(this.unitSize);
  1.1155 +			this.Controls.Add(this.tbUnitName);
  1.1156 +			this.Name = "FrmUnit";
  1.1157 +			this.ShowIcon = false;
  1.1158 +			this.ShowInTaskbar = false;
  1.1159 +			this.Text = "FrmUnit";
  1.1160 +			this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmUnit_FormClosing);
  1.1161 +			((System.ComponentModel.ISupportInitialize)(this.unitSize)).EndInit();
  1.1162 +			this.ResumeLayout(false);
  1.1163 +			this.PerformLayout();
  1.1164 +
  1.1165 +		}
  1.1166 +		#endregion
  1.1167 +
  1.1168 +		public Unit Unit
  1.1169 +		{
  1.1170 +			get { return unit; }
  1.1171 +		}
  1.1172 +
  1.1173 +		private void tbUnitName_Leave(object sender, System.EventArgs e)
  1.1174 +		{
  1.1175 +			UpdateUnitName();
  1.1176 +		}
  1.1177 +
  1.1178 +		private void tbUnitName_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
  1.1179 +		{
  1.1180 +			if (e.KeyCode == Keys.Enter)
  1.1181 +			{
  1.1182 +				UpdateUnitName();
  1.1183 +			}
  1.1184 +		}
  1.1185 +
  1.1186 +		private void UpdateUnitName()
  1.1187 +		{
  1.1188 +			if (unit.Name != tbUnitName.Text)
  1.1189 +			{
  1.1190 +				commandStack.Execute(new SetNameCommand(unit, tbUnitName.Text));
  1.1191 +			}
  1.1192 +		}
  1.1193 +
  1.1194 +		private void unitSize_Leave(object sender, System.EventArgs e)
  1.1195 +		{
  1.1196 +			UpdateUnitSize();
  1.1197 +		}
  1.1198 +
  1.1199 +		private void unitSize_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
  1.1200 +		{
  1.1201 +			if (e.KeyCode == Keys.Enter)
  1.1202 +			{
  1.1203 +				UpdateUnitSize();
  1.1204 +			}
  1.1205 +		}
  1.1206 +
  1.1207 +		private void UpdateUnitSize()
  1.1208 +		{
  1.1209 +			if (unit.Size != unitSize.Value)
  1.1210 +			{
  1.1211 +				commandStack.Execute(new SetUnitSizeCommand(unit, (int) unitSize.Value));
  1.1212 +			}
  1.1213 +		}
  1.1214 +
  1.1215 +		private void unit_NameChanged(WarFoundryObject obj, string oldValue, string newValue)
  1.1216 +		{
  1.1217 +			if (obj is Unit && obj.Equals(unit))
  1.1218 +			{
  1.1219 +				SetUnitName();
  1.1220 +			}
  1.1221 +		}
  1.1222 +
  1.1223 +		private void unit_UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue)
  1.1224 +		{
  1.1225 +			if (obj is Unit && obj.Equals(unit))
  1.1226 +			{
  1.1227 +				unitSize.Value = newValue;
  1.1228 +			}
  1.1229 +		}
  1.1230 +
  1.1231 +		private void RefreshUnitEquipment()
  1.1232 +		{
  1.1233 +			foreach (UnitEquipmentChoice choice in equipmentChoices.Values)
  1.1234 +			{
  1.1235 +				SetEquipmentListValue(choice);
  1.1236 +			}
  1.1237 +		}
  1.1238 +
  1.1239 +		private void equipmentList_SelectedIndexChanged(object sender, System.EventArgs e)
  1.1240 +		{
  1.1241 +			SetButtonsEnabledState();
  1.1242 +		}
  1.1243 +
  1.1244 +		private void SetButtonsEnabledState()
  1.1245 +		{
  1.1246 +
  1.1247 +			UnitEquipmentItem equipItem = GetSelectedUnitEquipmentItem();
  1.1248 +			bttnReplaceWeapon.Enabled = (equipItem != null && equipItem.HasAlternatives());
  1.1249 +			bttnEditWeapon.Enabled = (equipItem != null);
  1.1250 +			bttnRemoveWeapon.Enabled = (equipItem != null && !equipItem.IsRequired);
  1.1251 +		}
  1.1252 +
  1.1253 +		private void unit_UnitEquipmentAmountChanged(WarFoundryObject obj, double oldValue, double newValue)
  1.1254 +		{
  1.1255 +			if (obj is UnitEquipmentItem)
  1.1256 +			{
  1.1257 +				UnitEquipmentItem equip = (UnitEquipmentItem) obj;
  1.1258 +				UnitEquipmentChoice equipChoice = GetEquipmentChoice(equip);
  1.1259 +
  1.1260 +				if (newValue == 0)
  1.1261 +				{
  1.1262 +					equipmentList.Items.Remove(equipChoice);
  1.1263 +				}
  1.1264 +				else
  1.1265 +				{
  1.1266 +					SetEquipmentListValue(equipChoice);
  1.1267 +				}
  1.1268 +			}
  1.1269 +		}
  1.1270 +
  1.1271 +		private void SetEquipmentListValue(UnitEquipmentChoice equipChoice)
  1.1272 +		{
  1.1273 +			int idx = equipmentList.Items.IndexOf(equipChoice);
  1.1274 +
  1.1275 +			if (idx > -1)
  1.1276 +			{
  1.1277 +				equipmentList.Items[idx] = equipChoice;
  1.1278 +			}
  1.1279 +			else
  1.1280 +			{
  1.1281 +				equipmentList.Items.Add(equipChoice);
  1.1282 +			}
  1.1283 +		}
  1.1284 +
  1.1285 +		private void EditWeapon()
  1.1286 +		{
  1.1287 +			UnitEquipmentItem item = GetSelectedUnitEquipmentItem();
  1.1288 +
  1.1289 +			if (item != null)
  1.1290 +			{
  1.1291 +				FrmEditUnitEquipment editEquip = new FrmEditUnitEquipment(Unit, item, commandStack);
  1.1292 +				editEquip.ShowDialog(this);
  1.1293 +			}
  1.1294 +		}
  1.1295 +
  1.1296 +		private UnitEquipmentItem GetSelectedUnitEquipmentItem()
  1.1297 +		{
  1.1298 +			UnitEquipmentChoice selectedItem = GetSelectedUnitEquipmentChoice();
  1.1299 +			UnitEquipmentItem equipItem = null;
  1.1300 +
  1.1301 +			if (selectedItem!=null)
  1.1302 +			{
  1.1303 +				equipItem = selectedItem.Item;
  1.1304 +			}
  1.1305 +
  1.1306 +			return equipItem;
  1.1307 +		}
  1.1308 +
  1.1309 +		private UnitEquipmentChoice GetSelectedUnitEquipmentChoice()
  1.1310 +		{
  1.1311 +			return (UnitEquipmentChoice) equipmentList.SelectedItem;
  1.1312 +		}
  1.1313 +
  1.1314 +		private void bttnEditWeapon_Click(object sender, System.EventArgs e)
  1.1315 +		{
  1.1316 +			EditWeapon();
  1.1317 +		}
  1.1318 +
  1.1319 +		private void equipmentList_DoubleClick(object sender, System.EventArgs e)
  1.1320 +		{
  1.1321 +			EditWeapon();
  1.1322 +		}
  1.1323 +
  1.1324 +		private void AddWeapon()
  1.1325 +		{
  1.1326 +			FrmNewUnitEquipment newEquip = new FrmNewUnitEquipment(Unit, commandStack);
  1.1327 +			newEquip.ShowDialog(this);
  1.1328 +		}
  1.1329 +
  1.1330 +		private void bttnAddWeapon_Click(object sender, System.EventArgs e)
  1.1331 +		{
  1.1332 +			AddWeapon();
  1.1333 +		}
  1.1334 +
  1.1335 +		private void RemoveWeapon()
  1.1336 +		{
  1.1337 +			commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, GetSelectedUnitEquipmentItem(), 0));
  1.1338 +		}
  1.1339 +
  1.1340 +		private void bttnRemoveWeapon_Click(object sender, System.EventArgs e)
  1.1341 +		{
  1.1342 +			RemoveWeapon();
  1.1343 +		}
  1.1344 +
  1.1345 +		private void bttnReplaceWeapon_Click(object sender, System.EventArgs e)
  1.1346 +		{
  1.1347 +			FrmReplaceUnitEquipment replace = new FrmReplaceUnitEquipment(unit, GetSelectedUnitEquipmentItem(), commandStack);
  1.1348 +			replace.ShowDialog(this);
  1.1349 +		}
  1.1350 +
  1.1351 +		private void FrmUnit_FormClosing(object sender, FormClosingEventArgs e)
  1.1352 +		{
  1.1353 +			UpdateUnitName();
  1.1354 +			UpdateUnitSize();
  1.1355 +		}
  1.1356 +	}
  1.1357  }
  1.1358 \ No newline at end of file