annotate api/Exporters/WarFoundryHtmlExporter.cs @ 261:b9b8b0e60c31

Re #281: Export multiple stat lines in HTML * Add initial version of multiple stat lines per unit - still needs some work Also: * Line ending cleanup
author IBBoard <dev@ibboard.co.uk>
date Sat, 29 May 2010 20:03:17 +0000
parents 22509bd03ca2
children 900adf96a915
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");
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
60 style.InnerText = "table, th, td { border: 1px solid #000; border-spacing: 0 }" +
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
61 "table table { width: 100% }";
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
62 head.AppendChild(style);
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
63 XmlElement body = doc.CreateElement("body");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
64 html.AppendChild(body);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
65 XmlElement header = doc.CreateElement("h1");
143
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 134
diff changeset
66 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
67 body.AppendChild(header);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
68
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
69 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
70 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
71 if (!IsTableOnlyHeader(table))
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
72 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
73 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
74 }
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
75 }
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 StreamWriter writer = new StreamWriter(path, false);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
78
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
79 try
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
80 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
81 writer.Write(doc.OuterXml);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
82 }
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
83 finally
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
84 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
85 writer.Close();
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
86 }
154
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
87 }
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 private bool IsTableOnlyHeader(XmlElement table)
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
90 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 153
diff changeset
91 return table.ChildNodes.Count == 1;
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
92 }
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 private XmlElement[] CreateTables(Army army, XmlDocument doc)
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
95 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
96 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
97
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
98 foreach (SystemStats statSets in army.GameSystem.SystemStats)
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
99 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
100 tables[statSets.ID] = CreateTable(statSets, doc);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
101 }
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 foreach (Unit unit in army.GetUnits())
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
104 {
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
105 tables[GetFirstStatType(unit)].AppendChild(CreateUnitRow(unit, doc));
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
106 }
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 return DictionaryUtils.ToArray(tables);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
109 }
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
110
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
111 private static string GetFirstStatType(Unit unit)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
112 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
113 string[] unitStatIDs = unit.UnitStatsArrayIDs;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
114 return GetFirstStatType(unitStatIDs);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
115 }
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 public static string GetFirstStatType(string[] unitStatIDs)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
118 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
119 return unitStatIDs[0];
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
120 }
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
121
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
122 private XmlElement CreateTable(SystemStats stats, XmlDocument doc)
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
123 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
124 XmlElement table = doc.CreateElement("table");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
125 XmlElement headerRow = doc.CreateElement("tr");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
126 table.AppendChild(headerRow);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
127 XmlElement name = doc.CreateElement("th");
228
ece26f6a62f3 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 227
diff changeset
128 name.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitName", "name");
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
129 headerRow.AppendChild(name);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
130
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
131 XmlElement unitTypeName = doc.CreateElement("th");
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
132 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
133 headerRow.AppendChild(unitTypeName);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
134
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
135 foreach (StatSlot stat in stats.StatSlots)
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
136 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
137 XmlElement statHeader = doc.CreateElement("th");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
138 statHeader.InnerText = stat.Name;
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
139 headerRow.AppendChild(statHeader);
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
140 }
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 XmlElement notes = doc.CreateElement("th");
228
ece26f6a62f3 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 227
diff changeset
143 notes.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitNotes", "name");;
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
144 headerRow.AppendChild(notes);
132
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
145
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
146 XmlElement points = doc.CreateElement("th");
228
ece26f6a62f3 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 227
diff changeset
147 points.InnerText = Translation.GetTranslation("armyHtmlOutputTableHeaderUnitPoints", "name");;
132
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
148 headerRow.AppendChild(points);
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
149
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
150 return table;
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
151 }
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 private XmlElement CreateUnitRow(Unit unit, XmlDocument doc)
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
154 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
155 XmlElement row = doc.CreateElement("tr");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
156 XmlElement name = doc.CreateElement("td");
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
157 name.InnerText = unit.Name;
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
158 row.AppendChild(name);
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
159 CreateStatsBlock(unit, row);
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
160
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
161 StringBuilder sb = new StringBuilder();
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
162 UnitEquipmentItem[] unitEquipment = unit.GetEquipment ();
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
163
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
164 if (unitEquipment.Length > 0)
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
165 {
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
166 bool addSeparator = false;
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
167
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
168 foreach (UnitEquipmentItem equip in unitEquipment)
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
169 {
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
170 if (!addSeparator)
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
171 {
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
172 addSeparator = true;
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
173 }
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
174 else
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
175 {
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
176 sb.Append(", ");
216
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
177 }
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
178
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
179 string amountString;
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
180 double amount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip);
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
181
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
182 if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip))
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
183 {
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
184
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
185 if (amount == 100)
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
186 {
237
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
187 amountString = GetEquipmentAmountAllTranslation(unit);
216
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
188 }
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
189 else
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
190 {
237
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
191 int number = UnitEquipmentUtil.GetEquipmentAmountTaken(unit, equip);
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
192 amountString = GetEquipmentAmountRatioTranslation (amount, number);
216
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
193 }
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
194 }
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
195 else
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
196 {
237
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
197 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
198 {
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
199 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
200 }
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
201 else
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
202 {
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
203 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
204 }
216
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
205 }
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 214
diff changeset
206
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 208
diff changeset
207 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
208 }
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
209
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
210 sb.Append(". ");
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
211 }
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
212
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
213 ICollection<Ability> abilities = unit.Abilities;
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
214
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
215 if (abilities.Count > 0)
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
216 {
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
217 bool addSeparator = false;
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
218
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
219 foreach (Ability ability in abilities)
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
220 {
208
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
221 if (!addSeparator)
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
222 {
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
223 addSeparator = true;
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
224 }
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
225 else
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
226 {
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
227 sb.Append(", ");
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
228 }
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
229
e8e9026dd4ea Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents: 164
diff changeset
230 sb.Append(ability.Name);
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(". ");
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
234 }
132
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
235
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
236 XmlElement notes = doc.CreateElement("td");
134
57f7b80757ea Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents: 132
diff changeset
237 notes.InnerText = sb.ToString();
132
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
238 row.AppendChild(notes);
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
239
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
240 XmlElement points = doc.CreateElement("td");
143
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 134
diff changeset
241 points.InnerText = unit.Points.ToString();
132
e9c415839462 Re #68: Add "export" of army
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
242 row.AppendChild(points);
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
243
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 130
diff changeset
244 return row;
130
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
245 }
237
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
246
261
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
247 private void CreateStatsBlock(Unit unit, XmlElement unitRow)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
248 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
249 XmlDocument doc = unitRow.OwnerDocument;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
250 XmlElement statsWrapperCell = doc.CreateElement("td");
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
251 unitRow.AppendChild(statsWrapperCell);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
252 Stat[][] memberStats = unit.UnitStatsArraysWithName;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
253 statsWrapperCell.SetAttribute("colspan", memberStats[0].Length.ToString());
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
254 string[] statTypeIDs = unit.UnitStatsArrayIDs;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
255 string defaultStatType = GetFirstStatType(statTypeIDs);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
256 Dictionary<string, XmlElement> statTables = CreateEmptyStatsTables(statTypeIDs, statsWrapperCell);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
257
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
258 int statCount = statTypeIDs.Length;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
259
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
260 for (int i = 0; i < statCount; i++)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
261 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
262 Stat[] statLine = memberStats[i];
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
263 string statTypeID = statTypeIDs[i];
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
264 XmlElement tableElement = DictionaryUtils.GetValue(statTables, statTypeID);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
265 int statLineCount = statLine.Length;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
266 XmlElement statRow = doc.CreateElement("tr");
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
267 tableElement.AppendChild(statRow);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
268 GetStatCellTextDelegate statCellTextDelegate = (statTypeID.Equals(defaultStatType) ? new GetStatCellTextDelegate(GetDefaultStatCellText) : new GetStatCellTextDelegate(GetOtherStatCellText));
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
269 AddStatCell(statLine[0].SlotValueString, statRow);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
270
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
271 for (int j = 1; j < statLineCount; j++)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
272 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
273 string statText = statCellTextDelegate(statLine[j]);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
274 AddStatCell(statText, statRow);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
275 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
276 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
277 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
278
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
279 private Dictionary<string, XmlElement> CreateEmptyStatsTables(string[] statTypeIDs, XmlElement containerCell)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
280 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
281 Dictionary<string, XmlElement> statTables = new Dictionary<string, XmlElement>();
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
282 XmlDocument doc = containerCell.OwnerDocument;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
283
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
284 foreach (string statTypeID in statTypeIDs)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
285 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
286 if (!statTables.ContainsKey(statTypeID))
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
287 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
288 XmlElement tableElement = doc.CreateElement("table");
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
289 containerCell.AppendChild(tableElement);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
290 statTables[statTypeID] = tableElement;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
291 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
292 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
293
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
294 return statTables;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
295 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
296
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
297 private string GetDefaultStatCellText(Stat stat)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
298 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
299 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
300 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
301
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
302 private string GetOtherStatCellText(Stat stat)
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
303 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
304 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
305 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
306
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
307 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
308 {
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
309 XmlElement statCell = row.OwnerDocument.CreateElement("td");
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
310 statCell.InnerText = statValue;
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
311 row.AppendChild(statCell);
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
312 }
b9b8b0e60c31 Re #281: Export multiple stat lines in HTML
IBBoard <dev@ibboard.co.uk>
parents: 251
diff changeset
313
237
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
314 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
315 {
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
316 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
317 }
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
318
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
319 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
320 {
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
321 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
322 }
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
323
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
324 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
325 {
ec7fe85116cf Fixes #254: Basic HTML export outputs "-1" for equipment amounts instead of "all"
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
326 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
327 }
130
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
328 }
e147a1e9399b Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
329 }