corrade-vassal – Diff between revs 2 and 3
?pathlinks?
Rev 2 | Rev 3 | |||
---|---|---|---|---|
Line 40... | Line 40... | |||
40 | mainForm.StatusText.Text = @"loading regions..."; |
40 | mainForm.StatusText.Text = @"loading regions..."; |
|
41 | mainForm.StatusProgress.Value = 0; |
41 | mainForm.StatusProgress.Value = 0; |
|
Line 42... | Line 42... | |||
42 | |
42 | |
|
43 | // import CSV regions |
43 | // import CSV regions |
|
44 | Vector3 localPosition; |
44 | Vector3 localPosition; |
|
45 | Vassal.ConfiguredRegions = |
45 | List<KeyValuePair<string, Vector3>> ConfiguredRegions = new List<KeyValuePair<string, Vector3>>( |
|
46 | File.ReadAllLines(file) |
46 | File.ReadAllLines(file) |
|
47 | .AsParallel() |
47 | .AsParallel() |
|
48 | .Select(o => new List<string>(Vassal.wasCSVToEnumerable(o))) |
48 | .Select(o => new List<string>(Vassal.wasCSVToEnumerable(o))) |
|
49 | .Where(o => o.Count == 2) |
49 | .Where(o => o.Count == 2) |
|
50 | .ToDictionary(o => o.First(), |
50 | .ToDictionary(o => o.First(), |
|
51 | p => |
51 | p => |
|
52 | Vector3.TryParse(p.Last(), out localPosition) |
52 | Vector3.TryParse(p.Last(), out localPosition) |
|
53 | ? localPosition |
53 | ? localPosition |
|
Line 54... | Line 54... | |||
54 | : Vector3.Zero); |
54 | : Vector3.Zero)); |
|
55 | |
55 | |
|
56 | Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => |
56 | Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => |
|
57 | { |
57 | { |
|
58 | Vassal.vassalForm.LoadedRegions.Items.Clear(); |
58 | Vassal.vassalForm.LoadedRegions.Items.Clear(); |
|
59 | Vassal.vassalForm.LoadedRegions.Items.AddRange( |
59 | Vassal.vassalForm.LoadedRegions.Items.AddRange( |
|
60 | Vassal.ConfiguredRegions.Select( |
60 | ConfiguredRegions.Select( |
|
- | 61 | o => (object) new ListViewItem {Text = o.Key, Tag = o.Value}) |
||
- | 62 | .ToArray()); |
||
- | 63 | // Update batch restart grid view. |
||
- | 64 | Vassal.vassalForm.BatchRestartGridView.Rows.Clear(); |
||
- | 65 | foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions) |
||
- | 66 | { |
||
61 | o => (object) new ListViewItem {Text = o.Key, Tag = o.Value}) |
67 | Vassal.vassalForm.BatchRestartGridView.Rows.Add(data.Key, data.Value); |
|
Line 62... | Line 68... | |||
62 | .ToArray()); |
68 | } |
|
63 | })); |
69 | })); |
|
64 | |
70 | |
|
65 | Regions.Items.Clear(); |
71 | Regions.Items.Clear(); |
|
Line 66... | Line 72... | |||
66 | Regions.Items.AddRange( |
72 | Regions.Items.AddRange( |
|
67 | Vassal.ConfiguredRegions.Select(o => (object)new ListViewItem { Text = o.Key + @" " + @"(" + o.Value.ToString() + @")", Tag = o }) |
73 | ConfiguredRegions.Select(o => (object)new ListViewItem { Text = o.Key + @" " + @"(" + o.Value.ToString() + @")", Tag = o }) |
|
68 | .ToArray()); |
74 | .ToArray()); |
|
Line 103... | Line 109... | |||
103 | using ( |
109 | using ( |
|
104 | StreamWriter streamWriter = |
110 | StreamWriter streamWriter = |
|
105 | new StreamWriter(file, false, |
111 | new StreamWriter(file, false, |
|
106 | Encoding.UTF8)) |
112 | Encoding.UTF8)) |
|
107 | { |
113 | { |
|
- | 114 | foreach ( |
||
108 | foreach (KeyValuePair<string, Vector3> region in Vassal.ConfiguredRegions) |
115 | KeyValuePair<string, Vector3> region in |
|
- | 116 | Regions.Items.Cast<ListViewItem>() |
||
- | 117 | .Select(o => (KeyValuePair<string, Vector3>) o.Tag)) |
||
109 | { |
118 | { |
|
110 | streamWriter.Write( |
119 | streamWriter.Write( |
|
111 | Vassal.wasEnumerableToCSV(new[] {region.Key, region.Value.ToString()})); |
120 | Vassal.wasEnumerableToCSV(new[] {region.Key, region.Value.ToString()})); |
|
112 | streamWriter.Write(Environment.NewLine); |
121 | streamWriter.Write(Environment.NewLine); |
|
113 | } |
122 | } |
|
Line 130... | Line 139... | |||
130 | |
139 | |
|
131 | |
140 | |
|
132 | private void RegionEditShown(object sender, EventArgs e) |
141 | private void RegionEditShown(object sender, EventArgs e) |
|
- | 142 | { |
||
- | 143 | Regions.Items.Clear(); |
||
- | 144 | // Get all the regions if they exist. |
||
- | 145 | if (File.Exists(Vassal.VASSAL_CONSTANTS.VASSAL_REGIONS)) |
||
- | 146 | { |
||
- | 147 | Vector3 localPosition; |
||
- | 148 | List<KeyValuePair<string, Vector3>> ConfiguredRegions = new List<KeyValuePair<string, Vector3>>( |
||
- | 149 | File.ReadAllLines(Vassal.VASSAL_CONSTANTS.VASSAL_REGIONS) |
||
- | 150 | .Select(o => new List<string>(Vassal.wasCSVToEnumerable(o))) |
||
- | 151 | .Where(o => o.Count == 2) |
||
- | 152 | .ToDictionary(o => o.First(), |
||
- | 153 | p => |
||
- | 154 | Vector3.TryParse(p.Last(), out localPosition) |
||
133 | { |
155 | ? localPosition |
|
- | 156 | : Vector3.Zero).OrderBy(o => o.Key).ToDictionary(o => o.Key, o => o.Value)); |
||
134 | Regions.Items.Clear(); |
157 | Regions.Items.AddRange( |
|
135 | Regions.Items.AddRange( |
158 | ConfiguredRegions.Select( |
|
- | 159 | o => (object) new ListViewItem {Text = o.Key + @" " + @"(" + o.Value.ToString() + @")", Tag = o}) |
||
136 | Vassal.ConfiguredRegions.Select(o => (object)new ListViewItem { Text = o.Key + @" " + @"(" + o.Value.ToString() + @")", Tag = o }) |
160 | .ToArray()); |
|
Line 137... | Line 161... | |||
137 | .ToArray()); |
161 | } |
|
138 | } |
162 | } |
|
139 | |
163 | |
|
Line 157... | Line 181... | |||
157 | Regions.Items.Add(new ListViewItem |
181 | Regions.Items.Add(new ListViewItem |
|
158 | { |
182 | { |
|
159 | Text = RegionName.Text + @" " + @"(" + position + @")", |
183 | Text = RegionName.Text + @" " + @"(" + position + @")", |
|
160 | Tag = new KeyValuePair<string, Vector3>(RegionName.Text, position) |
184 | Tag = new KeyValuePair<string, Vector3>(RegionName.Text, position) |
|
161 | }); |
185 | }); |
|
- | 186 | |
||
162 | Vassal.ConfiguredRegions.Add(RegionName.Text, position); |
187 | // Update drop down box. |
|
163 | Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => |
188 | Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => |
|
164 | { |
189 | { |
|
165 | Vassal.vassalForm.LoadedRegions.Items.Add(new ListViewItem |
190 | Vassal.vassalForm.LoadedRegions.Items.Add(new ListViewItem |
|
166 | { |
191 | { |
|
167 | Text = RegionName.Text, |
192 | Text = RegionName.Text, |
|
168 | Tag = position |
193 | Tag = position |
|
169 | }); |
194 | }); |
|
- | 195 | // Add the row to the batch restart grid view. |
||
- | 196 | Vassal.vassalForm.BatchRestartGridView.Rows.Add(RegionName.Text, position.ToString()); |
||
170 | })); |
197 | })); |
|
171 | })); |
198 | })); |
|
172 | } |
199 | } |
|
Line 173... | Line 200... | |||
173 | |
200 | |
|
Line 179... | Line 206... | |||
179 | if (listViewItem == null) |
206 | if (listViewItem == null) |
|
180 | { |
207 | { |
|
181 | Regions.BackColor = Color.MistyRose; |
208 | Regions.BackColor = Color.MistyRose; |
|
182 | return; |
209 | return; |
|
183 | } |
210 | } |
|
184 | Regions.BackColor = Color.Empty; |
- | ||
- | 211 | |
||
185 | int selectedItemIndex = Regions.SelectedIndex; |
212 | int selectedItemIndex = Regions.SelectedIndex; |
|
- | 213 | if (selectedItemIndex == -1) |
||
- | 214 | return; |
||
Line 186... | Line 215... | |||
186 | |
215 | |
|
Line 187... | Line 216... | |||
187 | Vassal.ConfiguredRegions.Remove(RegionName.Text); |
216 | Regions.BackColor = Color.Empty; |
|
188 | |
217 | |
|
189 | Vassal.vassalForm.BeginInvoke((MethodInvoker)(() => |
218 | Vassal.vassalForm.BeginInvoke((MethodInvoker)(() => |
|
- | 219 | { |
||
- | 220 | Vassal.vassalForm.LoadedRegions.Items.RemoveAt(selectedItemIndex); |
||
190 | { |
221 | // Update the batch restart grid view. |
|
Line 191... | Line 222... | |||
191 | Vassal.vassalForm.LoadedRegions.Items.RemoveAt(selectedItemIndex); |
222 | Vassal.vassalForm.BatchRestartGridView.Rows.RemoveAt(selectedItemIndex); |
|
Line 192... | Line 223... | |||
192 | })); |
223 | })); |
|
Line 202... | Line 233... | |||
202 | { |
233 | { |
|
203 | ListViewItem listViewItem = Regions.SelectedItem as ListViewItem; |
234 | ListViewItem listViewItem = Regions.SelectedItem as ListViewItem; |
|
204 | if (listViewItem == null) |
235 | if (listViewItem == null) |
|
205 | return; |
236 | return; |
|
Line -... | Line 237... | |||
- | 237 | |
||
- | 238 | int selectedItemIndex = Regions.SelectedIndex; |
||
- | 239 | if (selectedItemIndex == -1) |
||
- | 240 | return; |
||
206 | |
241 | |
|
207 | if (string.IsNullOrEmpty(RegionName.Text)) |
242 | if (string.IsNullOrEmpty(RegionName.Text)) |
|
208 | { |
243 | { |
|
209 | RegionName.BackColor = Color.MistyRose; |
244 | RegionName.BackColor = Color.MistyRose; |
|
210 | RegionPosition.BackColor = Color.MistyRose; |
245 | RegionPosition.BackColor = Color.MistyRose; |
|
Line 218... | Line 253... | |||
218 | return; |
253 | return; |
|
219 | } |
254 | } |
|
Line 220... | Line 255... | |||
220 | |
255 | |
|
221 | RegionName.BackColor = Color.Empty; |
256 | RegionName.BackColor = Color.Empty; |
|
222 | RegionPosition.BackColor = Color.Empty; |
- | ||
- | 257 | RegionPosition.BackColor = Color.Empty; |
||
Line 223... | Line -... | |||
223 | int selectedItemIndex = Regions.SelectedIndex; |
- | ||
224 | |
- | ||
225 | Vassal.ConfiguredRegions.Remove(RegionName.Text); |
258 | |
|
226 | Vassal.ConfiguredRegions.Add(RegionName.Text, position); |
259 | |
|
227 | Vassal.vassalForm.BeginInvoke((MethodInvoker)(() => |
260 | Vassal.vassalForm.BeginInvoke((MethodInvoker)(() => |
|
228 | { |
261 | { |
|
- | 262 | if (Vassal.vassalForm.LoadedRegions.Items.Count > selectedItemIndex) |
||
- | 263 | { |
||
229 | Vassal.vassalForm.LoadedRegions.Items[selectedItemIndex] = new ListViewItem |
264 | Vassal.vassalForm.LoadedRegions.Items[selectedItemIndex] = new ListViewItem |
|
230 | { |
265 | { |
|
- | 266 | Text = RegionName.Text, |
||
- | 267 | Tag = position |
||
- | 268 | }; |
||
- | 269 | } |
||
- | 270 | // Update the batch restart grid view. |
||
- | 271 | if (Vassal.vassalForm.BatchRestartGridView.Rows.Count > selectedItemIndex) |
||
- | 272 | { |
||
- | 273 | Vassal.vassalForm.BatchRestartGridView.Rows[selectedItemIndex].Cells["BatchRestartRegionName"] |
||
- | 274 | .Value |
||
- | 275 | = RegionName.Text; |
||
- | 276 | Vassal.vassalForm.BatchRestartGridView.Rows[selectedItemIndex].Cells["BatchRestartPosition"] |
||
231 | Text = RegionName.Text, |
277 | .Value |
|
232 | Tag = position |
278 | = position.ToString(); |
|
Line 233... | Line 279... | |||
233 | }; |
279 | } |
|
234 | })); |
280 | })); |
|
235 | |
281 | |
|
Line 247... | Line 293... | |||
247 | mainForm.BeginInvoke((MethodInvoker)(() => |
293 | mainForm.BeginInvoke((MethodInvoker)(() => |
|
248 | { |
294 | { |
|
249 | ListViewItem listViewItem = Regions.SelectedItem as ListViewItem; |
295 | ListViewItem listViewItem = Regions.SelectedItem as ListViewItem; |
|
250 | if (listViewItem == null) |
296 | if (listViewItem == null) |
|
251 | return; |
297 | return; |
|
- | 298 | |
||
- | 299 | int selectedItemIndex = Regions.SelectedIndex; |
||
- | 300 | if (selectedItemIndex == -1) |
||
- | 301 | return; |
||
- | 302 | |
||
252 | KeyValuePair<string, Vector3> region = (KeyValuePair<string, Vector3>) listViewItem.Tag; |
303 | KeyValuePair<string, Vector3> region = (KeyValuePair<string, Vector3>) listViewItem.Tag; |
|
253 | RegionName.Text = region.Key; |
304 | RegionName.Text = region.Key; |
|
254 | RegionPosition.Text = region.Value.ToString(); |
305 | RegionPosition.Text = region.Value.ToString(); |
|
255 | })); |
306 | })); |
|
256 | } |
307 | } |