changeset 134:57f7b80757ea

Re #68: Export army to another format * Add styling to table * Add in text for equipment * Add method to Unit to get equipment amount strings * Refactor unit equipment handling to reduce duplication
author IBBoard <dev@ibboard.co.uk>
date Tue, 01 Sep 2009 18:56:38 +0000
parents a6d1cc17ec33
children a37cdcbcad14
files api/Exporters/WarFoundryHtmlExporter.cs api/Objects/Unit.cs
diffstat 2 files changed, 56 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/api/Exporters/WarFoundryHtmlExporter.cs	Tue Sep 01 18:21:27 2009 +0000
+++ b/api/Exporters/WarFoundryHtmlExporter.cs	Tue Sep 01 18:56:38 2009 +0000
@@ -5,6 +5,7 @@
 using System;
 using System.Collections.Generic;
 using System.IO;
+using System.Text;
 using System.Xml;
 using System.Xml.Schema;
 using IBBoard.Lang;
@@ -43,8 +44,11 @@
 			XmlElement head = doc.CreateElement("head");
 			html.AppendChild(head);
 			XmlElement title = doc.CreateElement("title");
+			title.InnerXml = army.Name;
 			head.AppendChild(title);
-			title.InnerXml = army.Name;
+			XmlElement style = doc.CreateElement("style");
+			style.InnerText = "table, th, td { border: 1px solid #000 }";
+			head.AppendChild(style);
 			XmlElement body = doc.CreateElement("body");
 			html.AppendChild(body);
 			XmlElement header = doc.CreateElement("h1");
@@ -125,9 +129,26 @@
 				statCell.InnerText = stat.SlotValueString;
 				row.AppendChild(statCell);
 			}
+
+			StringBuilder sb = new StringBuilder();
+			bool addSeparator = false;
+
+			foreach (UnitEquipmentItem equip in unit.GetEquipment())
+			{
+				if (!addSeparator)
+				{
+					addSeparator = true;
+				}
+				else
+				{
+					sb.Append(", ");
+				}
+
+				sb.Append(Translation.GetTranslation("armyHtmlExportEquipAmountRatio", "{0} for {1}", equip.Name, unit.GetEquipmentAmountString(equip)));
+			}
 						
 			XmlElement notes = doc.CreateElement("td");
-			notes.InnerText = "TODO: Notes here (equipment etc)";
+			notes.InnerText = sb.ToString();
 			row.AppendChild(notes);
 			
 			XmlElement points = doc.CreateElement("td");
--- a/api/Objects/Unit.cs	Tue Sep 01 18:21:27 2009 +0000
+++ b/api/Objects/Unit.cs	Tue Sep 01 18:56:38 2009 +0000
@@ -269,13 +269,45 @@
 
 		public bool GetEquipmentAmountIsRatio(UnitEquipmentItem item)
 		{
-			return (DictionaryUtils.GetValue(equipment, item) is UnitEquipmentRatioSelection);
+			return IsEquipmentAmountRatio(GetEquipmentSelection(item));
+		}
+
+		private AbstractUnitEquipmentItemSelection GetEquipmentSelection(UnitEquipmentItem item)
+		{
+			return DictionaryUtils.GetValue(equipment, item);
+		}
+
+		private bool IsEquipmentAmountRatio(AbstractUnitEquipmentItemSelection selection)
+		{
+			return (selection is UnitEquipmentRatioSelection);
 		}
 
 		public bool GetEquipmentAmountIsRatio(string itemID)
 		{
 			return GetEquipmentAmountIsRatio(UnitType.GetEquipmentItem(itemID));
 		}
+
+		public string GetEquipmentAmountString(string equipID)
+		{
+			return GetEquipmentAmountString(UnitType.GetEquipmentItem(equipID));
+		}
+
+		public string GetEquipmentAmountString(UnitEquipmentItem item)
+		{
+			String amountString = "";
+			AbstractUnitEquipmentItemSelection selection = GetEquipmentSelection(item);
+				
+			if (IsEquipmentAmountRatio(selection))
+			{
+				amountString = UnitEquipmentRatioSelection.GetEquipmentAmountString(GetEquipmentAmount(item));
+			}
+			else
+			{
+				amountString = UnitEquipmentNumericSelection.GetEquipmentAmountString(GetEquipmentAmount(item));
+			}
+
+			return amountString;
+		}
 		
 		public void SetEquipmentAmount(UnitEquipmentItem equip, int amount)
 		{