annotate api/Exporters/WarFoundryHtmlExporter.cs @ 389:121d9d1ba53c default-army-name

Re #314: Bugfix of HTML exporter that Frostlee found
author snowblizz
date Sun, 21 Nov 2010 21:53:16 +0000
parents 900adf96a915
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
130
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (WarFoundryHtmlExporter.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // 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.
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
6 using System.Collections.Generic;
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
7 using System.IO;
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
8 using System.Text;
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
9 using System.Xml;
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
10 using System.Xml.Schema;
164
91f7b8da0b53 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 163
diff changeset
11 using IBBoard.Lang;
163
395c8042dc03 Fixes #144: HTML generation may need network connection
IBBoard <dev@ibboard.co.uk>
parents: 154
diff changeset
12 using IBBoard.Xml;
216
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
13 using IBBoard.WarFoundry.API.Objects;
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 208
diff changeset
14 using IBBoard.WarFoundry.API.Util;
130
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 namespace IBBoard.WarFoundry.API.Exporters
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 /// <summary>
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 /// Custom exporter that exports an army as a basic HTML file
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 /// </summary>
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 public class WarFoundryHtmlExporter : IWarFoundryExporter
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 {
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 private static WarFoundryHtmlExporter exporter;
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
24 private delegate string GetStatCellTextDelegate(Stat stat);
130
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 public static WarFoundryHtmlExporter GetDefault()
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 {
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 if (exporter == null)
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 {
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 exporter = new WarFoundryHtmlExporter();
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 }
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 return exporter;
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 }
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 private WarFoundryHtmlExporter()
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 {
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 //Hide constructor
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 }
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 public void ExportArmy(Army army, string path)
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 {
164
91f7b8da0b53 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 163
diff changeset
43 XmlDocument doc = new XmlDocument();
91f7b8da0b53 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 163
diff changeset
44 CustomXmlResolver resolver = new CustomXmlResolver();
227
bf4f04f385d0 * Update exporter to look in "schemas" folder to match r429
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
45 resolver.AddMapping("-//W3C//DTD XHTML 1.0 Strict//EN", new Uri("file://" + IBBoard.Constants.ExecutablePath + "/schemas/xhtml1-strict.dtd"));
163
395c8042dc03 Fixes #144: HTML generation may need network connection
IBBoard <dev@ibboard.co.uk>
parents: 154
diff changeset
46 doc.XmlResolver = resolver;
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
47 doc.AppendChild(doc.CreateDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", null));
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
48 XmlElement html = doc.CreateElement("html");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
49 doc.AppendChild(html);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
50 XmlElement head = doc.CreateElement("head");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
51 html.AppendChild(head);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
52 XmlElement title = doc.CreateElement("title");
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
53 title.InnerXml = army.Name;
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
54 head.AppendChild(title);
251
22509bd03ca2 Re #273: Problems with accented characters and HTML output
IBBoard <dev@ibboard.co.uk>
parents: 237
diff changeset
55 XmlElement metaCharset = doc.CreateElement("meta");
22509bd03ca2 Re #273: Problems with accented characters and HTML output
IBBoard <dev@ibboard.co.uk>
parents: 237
diff changeset
56 metaCharset.SetAttribute("http-equiv", "Content-Type");
22509bd03ca2 Re #273: Problems with accented characters and HTML output
IBBoard <dev@ibboard.co.uk>
parents: 237
diff changeset
57 metaCharset.SetAttribute("content", "text/html;charset=UTF-8");
22509bd03ca2 Re #273: Problems with accented characters and HTML output
IBBoard <dev@ibboard.co.uk>
parents: 237
diff changeset
58 head.AppendChild(metaCharset);
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
59 XmlElement style = doc.CreateElement("style");
389
121d9d1ba53c Re #314: Bugfix of HTML exporter that Frostlee found
snowblizz
parents: 262
diff changeset
60 style.InnerText = "table, th, td { border: 1px solid #000; border-spacing: 0; border-collapse: collapse; margin: 0 }\n"
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
61 +"table table { width: 100%; border-width: 0; margin: -2px }\n"
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
62 +"table table td { border-width:0 1px }";
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
63 head.AppendChild(style);
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
64 XmlElement body = doc.CreateElement("body");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
65 html.AppendChild(body);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
66 XmlElement header = doc.CreateElement("h1");
143
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 134
diff changeset
67 header.InnerText = Translation.GetTranslation("armyHtmlOutputBodyHeader", "{0} - {1}pts", army.Name, army.Points);
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
68 body.AppendChild(header);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
69
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
70 foreach (XmlElement table in CreateTables(army, doc))
154
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
71 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
72 if (!IsTableOnlyHeader(table))
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
73 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
74 body.AppendChild(table);
153
dd892567f054 Fixes #174: HTML output can add empty tables for stat lines
IBBoard <dev@ibboard.co.uk>
parents: 143
diff changeset
75 }
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
76 }
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
77
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
78 StreamWriter writer = new StreamWriter(path, false);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
79
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
80 try
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
81 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
82 writer.Write(doc.OuterXml);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
83 }
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
84 finally
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
85 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
86 writer.Close();
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
87 }
154
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
88 }
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
89
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
90 private bool IsTableOnlyHeader(XmlElement table)
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
91 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
92 return table.ChildNodes.Count == 1;
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
93 }
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
94
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
95 private XmlElement[] CreateTables(Army army, XmlDocument doc)
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
96 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
97 Dictionary<string, XmlElement> tables = new Dictionary<string, XmlElement>();
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
98
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
99 foreach (SystemStats statSets in army.GameSystem.SystemStats)
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
100 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
101 tables[statSets.ID] = CreateTable(statSets, doc);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
102 }
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
103
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
104 foreach (Unit unit in army.GetUnits())
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
105 {
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
106 CreateUnitRow(unit, tables[GetFirstStatType(unit)]);
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
107 }
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
108
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
109 return DictionaryUtils.ToArray(tables);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
110 }
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
111
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
112 private static string GetFirstStatType(Unit unit)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
113 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
114 string[] unitStatIDs = unit.UnitStatsArrayIDs;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
115 return GetFirstStatType(unitStatIDs);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
116 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
117
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
118 public static string GetFirstStatType(string[] unitStatIDs)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
119 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
120 return unitStatIDs[0];
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
121 }
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
122
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
123 private XmlElement CreateTable(SystemStats stats, XmlDocument doc)
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
124 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
125 XmlElement table = doc.CreateElement("table");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
126 XmlElement headerRow = doc.CreateElement("tr");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
127 table.AppendChild(headerRow);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
128 XmlElement name = doc.CreateElement("th");
228
ece26f6a62f3 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 227
diff changeset
129 name.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitName", "name");
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
130 headerRow.AppendChild(name);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
131
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
132 XmlElement unitTypeName = doc.CreateElement("th");
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
133 unitTypeName.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitTypeName", "type name");
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
134 headerRow.AppendChild(unitTypeName);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
135
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
136 foreach (StatSlot stat in stats.StatSlots)
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
137 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
138 XmlElement statHeader = doc.CreateElement("th");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
139 statHeader.InnerText = stat.Name;
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
140 headerRow.AppendChild(statHeader);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
141 }
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
142
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
143 XmlElement notes = doc.CreateElement("th");
228
ece26f6a62f3 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 227
diff changeset
144 notes.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitNotes", "name");;
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
145 headerRow.AppendChild(notes);
132
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
146
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
147 XmlElement points = doc.CreateElement("th");
228
ece26f6a62f3 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 227
diff changeset
148 points.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitPoints", "name");;
132
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
149 headerRow.AppendChild(points);
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
150
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
151 return table;
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
152 }
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
153
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
154 private XmlElement CreateUnitRow(Unit unit, XmlElement tableElem)
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
155 {
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
156 XmlDocument doc = tableElem.OwnerDocument;
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
157 XmlElement row = doc.CreateElement("tr");
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
158 tableElem.AppendChild(row);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
159 Stat[][] memberStats = unit.UnitStatsArraysWithName;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
160 string[] statTypeIDs = unit.UnitStatsArrayIDs;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
161 string defaultStatType = GetFirstStatType(statTypeIDs);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
162 int statRowCount = 0;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
163 bool hasOther = false;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
164
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
165 foreach (string statTypeID in statTypeIDs)
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
166 {
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
167 if (statTypeID.Equals(defaultStatType))
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
168 {
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
169 statRowCount++;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
170 }
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
171 else if (!hasOther)
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
172 {
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
173 statRowCount++;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
174 hasOther = true;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
175 }
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
176 }
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
177
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
178 XmlElement name = doc.CreateElement("td");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
179 name.InnerText = unit.Name;
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
180 SetRowSpan(name, statRowCount);
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
181 row.AppendChild(name);
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
182 CreateStatsBlock(row, memberStats, statTypeIDs);
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
183
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
184 StringBuilder sb = new StringBuilder();
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
185 UnitEquipmentItem[] unitEquipment = unit.GetEquipment();
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
186
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
187 if (unitEquipment.Length > 0)
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
188 {
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
189 bool addSeparator = false;
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
190
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
191 foreach (UnitEquipmentItem equip in unitEquipment)
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
192 {
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
193 if (!addSeparator)
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
194 {
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
195 addSeparator = true;
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
196 }
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
197 else
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
198 {
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
199 sb.Append(", ");
216
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
200 }
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
201
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
202 string amountString;
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
203 double amount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip);
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
204
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
205 if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip))
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
206 {
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
207
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
208 if (amount == 100)
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
209 {
237
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
210 amountString = GetEquipmentAmountAllTranslation(unit);
216
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
211 }
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
212 else
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
213 {
237
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
214 int number = UnitEquipmentUtil.GetEquipmentAmountTaken(unit, equip);
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
215 amountString = GetEquipmentAmountRatioTranslation(amount, number);
216
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
216 }
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
217 }
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
218 else
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
219 {
237
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
220 if (amount == -1)
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
221 {
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
222 amountString = GetEquipmentAmountAllTranslation(unit);
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
223 }
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
224 else
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
225 {
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
226 amountString = GetEquipmentAmountNumberTranslation((int)amount);
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
227 }
216
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
228 }
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
229
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 208
diff changeset
230 sb.Append(Translation.GetTranslation("armyHtmlExportEquipAmountRatio", "{0} for {1}", equip.Name, amountString));
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
231 }
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
232
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
233 sb.Append(". ");
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
234 }
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
235
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
236 ICollection<Ability> abilities = unit.Abilities;
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
237
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
238 if (abilities.Count > 0)
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
239 {
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
240 bool addSeparator = false;
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
241
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
242 foreach (Ability ability in abilities)
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
243 {
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
244 if (!addSeparator)
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
245 {
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
246 addSeparator = true;
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
247 }
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
248 else
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
249 {
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
250 sb.Append(", ");
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
251 }
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
252
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
253 sb.Append(ability.Name);
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
254 }
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
255
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
256 sb.Append(". ");
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
257 }
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
258
132
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
259 XmlElement notes = doc.CreateElement("td");
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
260 notes.InnerText = sb.ToString();
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
261 SetRowSpan(notes, statRowCount);
132
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
262 row.AppendChild(notes);
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
263
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
264 XmlElement points = doc.CreateElement("td");
143
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 134
diff changeset
265 points.InnerText = unit.Points.ToString();
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
266 SetRowSpan(points, statRowCount);
132
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
267 row.AppendChild(points);
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
268
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
269 return row;
130
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
270 }
237
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
271
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
272 private static void SetRowSpan(XmlElement xmlElement, int statRowCount)
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
273 {
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
274 if (statRowCount > 1)
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
275 {
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
276 xmlElement.SetAttribute("rowspan", statRowCount.ToString());
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
277 }
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
278 }
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
279
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
280 private void CreateStatsBlock(XmlElement unitRow, Stat[][] memberStats, string[] statTypeIDs)
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
281 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
282 XmlDocument doc = unitRow.OwnerDocument;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
283 string defaultStatType = GetFirstStatType(statTypeIDs);
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
284
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
285 Stat[] defaultStatLine = memberStats[0];
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
286 int defaultStatLineCount = defaultStatLine.Length;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
287 AddStatCell(defaultStatLine[0].SlotValueString, unitRow);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
288
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
289 for (int i = 1; i < defaultStatLineCount; i++)
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
290 {
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
291 string statText = GetDefaultStatCellText(defaultStatLine[i]);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
292 AddStatCell(statText, unitRow);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
293 }
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
294
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
295 int statCount = statTypeIDs.Length;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
296
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
297 if (statCount > 1)
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
298 {
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
299 XmlElement unitTable = (XmlElement)unitRow.ParentNode;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
300 Dictionary<string, XmlElement> statParents = CreateStatsParentElements(statTypeIDs, unitTable);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
301
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
302 for (int i = 1; i < statCount; i++)
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
303 {
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
304 Stat[] statLine = memberStats[i];
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
305 string statTypeID = statTypeIDs[i];
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
306 XmlElement tableElement = DictionaryUtils.GetValue(statParents, statTypeID);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
307 int statLineCount = statLine.Length;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
308 XmlElement statRow = doc.CreateElement("tr");
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
309 tableElement.AppendChild(statRow);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
310 GetStatCellTextDelegate statCellTextDelegate = (statTypeID.Equals(defaultStatType) ? new GetStatCellTextDelegate(GetDefaultStatCellText) : new GetStatCellTextDelegate(GetOtherStatCellText));
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
311 AddStatCell(statLine[0].SlotValueString, statRow);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
312
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
313 for (int j = 1; j < statLineCount; j++)
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
314 {
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
315 string statText = statCellTextDelegate(statLine[j]);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
316 AddStatCell(statText, statRow);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
317 }
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
318 }
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
319
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
320 if (statParents.Count > 1)
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
321 {
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
322 AddOtherUnitStatTables(statParents, unitTable, defaultStatLineCount);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
323 }
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
324 }
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
325 }
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
326
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
327 private static void AddOtherUnitStatTables(Dictionary<string, XmlElement> statParents, XmlElement unitTable, int defaultStatLineCount)
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
328 {
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
329 XmlDocument doc = unitTable.OwnerDocument;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
330 XmlElement otherStatsRow = doc.CreateElement("tr");
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
331 unitTable.AppendChild(otherStatsRow);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
332 XmlElement otherStatsCell = doc.CreateElement("td");
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
333 otherStatsCell.SetAttribute("colspan", defaultStatLineCount.ToString());
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
334 otherStatsRow.AppendChild(otherStatsCell);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
335
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
336 foreach (XmlElement tableElem in statParents.Values)
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
337 {
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
338 if (tableElem != unitTable)
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
339 {
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
340 otherStatsCell.AppendChild(tableElem);
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
341 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
342 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
343 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
344
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
345 private Dictionary<string, XmlElement> CreateStatsParentElements(string[] statTypeIDs, XmlElement parentTable)
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
346 {
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
347 Dictionary<string, XmlElement> statParents = new Dictionary<string, XmlElement>();
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
348 XmlDocument doc = parentTable.OwnerDocument;
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
349 string defaultStatTypeID = GetFirstStatType(statTypeIDs);
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
350 statParents[defaultStatTypeID] = parentTable;
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
351
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
352 foreach (string statTypeID in statTypeIDs)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
353 {
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
354 if (!statParents.ContainsKey(statTypeID))
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
355 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
356 XmlElement tableElement = doc.CreateElement("table");
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
357 statParents[statTypeID] = tableElement;
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
358 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
359 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
360
262
900adf96a915 Closes #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 261
diff changeset
361 return statParents;
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
362 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
363
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
364 private string GetDefaultStatCellText(Stat stat)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
365 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
366 return Translation.GetTranslation("armyHtmlExportDefaultStatCellText", "{0}", stat.SlotValueString, stat.ParentSlotName);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
367 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
368
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
369 private string GetOtherStatCellText(Stat stat)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
370 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
371 return Translation.GetTranslation("armyHtmlExportOtherStatCellText", "{1}: {0}", stat.SlotValueString, stat.ParentSlotName);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
372 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
373
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
374 private static void AddStatCell(string statValue, XmlElement row)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
375 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
376 XmlElement statCell = row.OwnerDocument.CreateElement("td");
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
377 statCell.InnerText = statValue;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
378 row.AppendChild(statCell);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
379 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
380
237
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
381 private string GetEquipmentAmountRatioTranslation (double amount, int number)
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
382 {
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
383 return Translation.GetTranslation ("armyHtmlExportEquipAmountPercentage", "{0}% ({1})", amount, number);
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
384 }
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
385
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
386 private string GetEquipmentAmountNumberTranslation(int amount)
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
387 {
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
388 return Translation.GetTranslation("armyHtmlExportEquipAmountNumber", "{0}", amount);
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
389 }
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
390
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
391 private string GetEquipmentAmountAllTranslation(Unit unit)
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
392 {
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
393 return Translation.GetTranslation("armyHtmlExportEquipAmountAll", "all ({1})", 100, unit.Size);
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
394 }
130
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
395 }
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
396 }