Mercurial > repos > snowblizz-super-API-ideas
annotate api/Exporters/WarFoundryHtmlExporter.cs @ 216:65553d2c8612
* Line-ending fix
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 22 Nov 2009 20:14:51 +0000 |
parents | 1b718b67f7f6 |
children | bf4f04f385d0 |
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 | 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 | 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; |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 public static WarFoundryHtmlExporter GetDefault() |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 { |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 if (exporter == null) |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 { |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 exporter = new WarFoundryHtmlExporter(); |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 } |
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 return exporter; |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 } |
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 private WarFoundryHtmlExporter() |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 { |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 //Hide constructor |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 } |
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 public void ExportArmy(Army army, string path) |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 { |
164 | 42 XmlDocument doc = new XmlDocument(); |
43 CustomXmlResolver resolver = new CustomXmlResolver(); | |
44 resolver.AddMapping("-//W3C//DTD XHTML 1.0 Strict//EN", new Uri("file://" + IBBoard.Constants.ExecutablePath + "/dtds/xhtml1-strict.dtd")); | |
163
395c8042dc03
Fixes #144: HTML generation may need network connection
IBBoard <dev@ibboard.co.uk>
parents:
154
diff
changeset
|
45 doc.XmlResolver = resolver; |
131
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
46 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
|
47 XmlElement html = doc.CreateElement("html"); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
48 doc.AppendChild(html); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
49 XmlElement head = doc.CreateElement("head"); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
50 html.AppendChild(head); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
51 XmlElement title = doc.CreateElement("title"); |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
52 title.InnerXml = army.Name; |
131
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
53 head.AppendChild(title); |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
54 XmlElement style = doc.CreateElement("style"); |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
55 style.InnerText = "table, th, td { border: 1px solid #000 }"; |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
56 head.AppendChild(style); |
131
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
57 XmlElement body = doc.CreateElement("body"); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
58 html.AppendChild(body); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
59 XmlElement header = doc.CreateElement("h1"); |
143
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
60 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
|
61 body.AppendChild(header); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
62 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
63 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
|
64 { |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
153
diff
changeset
|
65 if (!IsTableOnlyHeader(table)) |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
153
diff
changeset
|
66 { |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
153
diff
changeset
|
67 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
|
68 } |
131
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 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
71 StreamWriter writer = new StreamWriter(path, false); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
72 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
73 try |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
74 { |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
75 writer.Write(doc.OuterXml); |
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 finally |
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 writer.Close(); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
80 } |
154
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
153
diff
changeset
|
81 } |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
153
diff
changeset
|
82 |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
153
diff
changeset
|
83 private bool IsTableOnlyHeader(XmlElement table) |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
153
diff
changeset
|
84 { |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
153
diff
changeset
|
85 return table.ChildNodes.Count == 1; |
131
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
86 } |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
87 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
88 private XmlElement[] CreateTables(Army army, XmlDocument doc) |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
89 { |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
90 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
|
91 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
92 foreach (SystemStats statSets in army.GameSystem.SystemStats) |
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 tables[statSets.ID] = CreateTable(statSets, 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 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
97 foreach (Unit unit in army.GetUnits()) |
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 tables[unit.UnitType.StatsID].AppendChild(CreateUnitRow(unit, doc)); |
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 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
102 return DictionaryUtils.ToArray(tables); |
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 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
105 private XmlElement CreateTable(SystemStats stats, XmlDocument doc) |
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 XmlElement table = doc.CreateElement("table"); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
108 XmlElement headerRow = doc.CreateElement("tr"); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
109 table.AppendChild(headerRow); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
110 XmlElement name = doc.CreateElement("th"); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
111 name.InnerText = "Name"; |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
112 headerRow.AppendChild(name); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
113 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
114 foreach (StatSlot stat in stats.StatSlots) |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
115 { |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
116 XmlElement statHeader = doc.CreateElement("th"); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
117 statHeader.InnerText = stat.Name; |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
118 headerRow.AppendChild(statHeader); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
119 } |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
120 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
121 XmlElement notes = doc.CreateElement("th"); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
122 notes.InnerText = "Notes"; |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
123 headerRow.AppendChild(notes); |
132 | 124 |
125 XmlElement points = doc.CreateElement("th"); | |
126 points.InnerText = "Points"; | |
127 headerRow.AppendChild(points); | |
128 | |
131
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
129 return table; |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
130 } |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
131 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
132 private XmlElement CreateUnitRow(Unit unit, XmlDocument doc) |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
133 { |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
134 XmlElement row = doc.CreateElement("tr"); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
135 XmlElement name = doc.CreateElement("td"); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
136 name.InnerText = unit.Name; |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
137 row.AppendChild(name); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
138 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
139 foreach (Stat stat in unit.UnitStatsArray) |
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 XmlElement statCell = doc.CreateElement("td"); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
142 statCell.InnerText = stat.SlotValueString; |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
143 row.AppendChild(statCell); |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
144 } |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
145 |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
146 StringBuilder sb = new StringBuilder(); |
208
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
147 UnitEquipmentItem[] unitEquipment = unit.GetEquipment (); |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
148 |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
149 if (unitEquipment.Length > 0) |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
150 { |
208
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
151 bool addSeparator = false; |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
152 |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
153 foreach (UnitEquipmentItem equip in unitEquipment) |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
154 { |
208
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
155 if (!addSeparator) |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
156 { |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
157 addSeparator = true; |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
158 } |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
159 else |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
160 { |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
161 sb.Append(", "); |
216 | 162 } |
163 | |
164 string amountString; | |
165 double amount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip); | |
166 | |
167 if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip)) | |
168 { | |
169 int number = UnitEquipmentUtil.GetEquipmentAmountTaken(unit, equip); | |
170 | |
171 if (amount == 100) | |
172 { | |
173 amountString = Translation.GetTranslation("armyHtmlExportEquipAmountAll", "all ({1})", amount, number); | |
174 } | |
175 else | |
176 { | |
177 amountString = Translation.GetTranslation("armyHtmlExportEquipAmountPercentage", "{0}% ({1})", amount, number); | |
178 } | |
179 } | |
180 else | |
181 { | |
182 amountString = amount.ToString(); | |
183 } | |
184 | |
214
1b718b67f7f6
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
185 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
|
186 } |
208
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
187 |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
188 sb.Append(". "); |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
189 } |
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 ICollection<Ability> abilities = unit.Abilities; |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
192 |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
193 if (abilities.Count > 0) |
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 bool addSeparator = false; |
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 foreach (Ability ability in abilities) |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
198 { |
208
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
199 if (!addSeparator) |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
200 { |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
201 addSeparator = true; |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
202 } |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
203 else |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
204 { |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
205 sb.Append(", "); |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
206 } |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
207 |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
208 sb.Append(ability.Name); |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
209 } |
208
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
210 |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
211 sb.Append(". "); |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
212 } |
132 | 213 |
214 XmlElement notes = doc.CreateElement("td"); | |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
215 notes.InnerText = sb.ToString(); |
132 | 216 row.AppendChild(notes); |
217 | |
218 XmlElement points = doc.CreateElement("td"); | |
143
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
219 points.InnerText = unit.Points.ToString(); |
132 | 220 row.AppendChild(points); |
131
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
221 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
130
diff
changeset
|
222 return row; |
130
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
223 } |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
224 } |
e147a1e9399b
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
225 } |