corrade-vassal – Blame information for rev 8
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
8 | eva | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
||
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
||
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
||
5 | /////////////////////////////////////////////////////////////////////////// |
||
6 | |||
7 | using System; |
||
2 | zed | 8 | using System.Collections.Generic; |
9 | using System.Drawing; |
||
10 | using System.IO; |
||
11 | using System.Linq; |
||
12 | using System.Text; |
||
13 | using System.Threading; |
||
14 | using System.Windows.Forms; |
||
15 | using OpenMetaverse; |
||
16 | |||
17 | namespace Vassal |
||
18 | { |
||
19 | public partial class RegionEditForm : Form |
||
20 | { |
||
21 | private static RegionEditForm mainForm; |
||
22 | |||
23 | public RegionEditForm() |
||
24 | { |
||
25 | InitializeComponent(); |
||
26 | mainForm = this; |
||
27 | } |
||
28 | |||
29 | private void LoadRegionsRequested(object sender, EventArgs e) |
||
30 | { |
||
8 | eva | 31 | mainForm.BeginInvoke((MethodInvoker) (() => |
2 | zed | 32 | { |
33 | switch (mainForm.LoadRegionsDialog.ShowDialog()) |
||
34 | { |
||
35 | case DialogResult.OK: |
||
36 | string file = mainForm.LoadRegionsDialog.FileName; |
||
37 | new Thread(() => |
||
38 | { |
||
8 | eva | 39 | mainForm.BeginInvoke((MethodInvoker) (() => |
2 | zed | 40 | { |
41 | try |
||
42 | { |
||
43 | mainForm.StatusText.Text = @"loading regions..."; |
||
44 | mainForm.StatusProgress.Value = 0; |
||
45 | |||
46 | // import CSV regions |
||
47 | Vector3 localPosition; |
||
8 | eva | 48 | List<KeyValuePair<string, Vector3>> ConfiguredRegions = new List |
49 | <KeyValuePair<string, Vector3>>( |
||
2 | zed | 50 | File.ReadAllLines(file) |
51 | .AsParallel() |
||
52 | .Select(o => new List<string>(Vassal.wasCSVToEnumerable(o))) |
||
53 | .Where(o => o.Count == 2) |
||
54 | .ToDictionary(o => o.First(), |
||
55 | p => |
||
56 | Vector3.TryParse(p.Last(), out localPosition) |
||
57 | ? localPosition |
||
3 | eva | 58 | : Vector3.Zero)); |
2 | zed | 59 | |
60 | Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => |
||
61 | { |
||
8 | eva | 62 | Vassal.vassalForm.LoadedRegionsBox.Items.Clear(); |
63 | Vassal.vassalForm.LoadedRegionsBox.Items.AddRange( |
||
3 | eva | 64 | ConfiguredRegions.Select( |
2 | zed | 65 | o => (object) new ListViewItem {Text = o.Key, Tag = o.Value}) |
66 | .ToArray()); |
||
3 | eva | 67 | // Update batch restart grid view. |
68 | Vassal.vassalForm.BatchRestartGridView.Rows.Clear(); |
||
69 | foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions) |
||
70 | { |
||
71 | Vassal.vassalForm.BatchRestartGridView.Rows.Add(data.Key, data.Value); |
||
72 | } |
||
7 | zed | 73 | // Update region state grid view. |
74 | Vassal.vassalForm.RegionsStateGridView.Rows.Clear(); |
||
75 | foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions) |
||
76 | { |
||
77 | Vassal.vassalForm.RegionsStateGridView.Rows.Add(data.Key, "Check pending...", |
||
78 | DateTime.Now.ToUniversalTime() |
||
79 | .ToString(Vassal.LINDEN_CONSTANTS.LSL.DATE_TIME_STAMP)); |
||
80 | } |
||
2 | zed | 81 | })); |
82 | |||
83 | Regions.Items.Clear(); |
||
84 | Regions.Items.AddRange( |
||
8 | eva | 85 | ConfiguredRegions.Select( |
86 | o => |
||
87 | (object) |
||
88 | new ListViewItem |
||
89 | { |
||
90 | Text = o.Key + @" " + @"(" + o.Value.ToString() + @")", |
||
91 | Tag = o |
||
92 | }) |
||
2 | zed | 93 | .ToArray()); |
94 | |||
95 | mainForm.StatusText.Text = @"regions loaded"; |
||
96 | mainForm.StatusProgress.Value = 100; |
||
97 | } |
||
98 | catch (Exception ex) |
||
99 | { |
||
100 | mainForm.StatusText.Text = ex.Message; |
||
101 | } |
||
102 | })); |
||
103 | }) |
||
8 | eva | 104 | {IsBackground = true, Priority = ThreadPriority.Normal}.Start(); |
2 | zed | 105 | break; |
106 | } |
||
107 | })); |
||
108 | } |
||
109 | |||
110 | private void SaveRegionsRequested(object sender, EventArgs e) |
||
111 | { |
||
8 | eva | 112 | mainForm.BeginInvoke((MethodInvoker) (() => |
2 | zed | 113 | { |
114 | switch (mainForm.SaveRegionsDialog.ShowDialog()) |
||
115 | { |
||
116 | case DialogResult.OK: |
||
117 | string file = mainForm.SaveRegionsDialog.FileName; |
||
118 | new Thread(() => |
||
119 | { |
||
8 | eva | 120 | mainForm.BeginInvoke((MethodInvoker) (() => |
2 | zed | 121 | { |
122 | try |
||
123 | { |
||
124 | mainForm.StatusText.Text = @"saving regions..."; |
||
125 | mainForm.StatusProgress.Value = 0; |
||
126 | |||
127 | // Save the regions to CSV. |
||
128 | using ( |
||
129 | StreamWriter streamWriter = |
||
130 | new StreamWriter(file, false, |
||
131 | Encoding.UTF8)) |
||
132 | { |
||
3 | eva | 133 | foreach ( |
134 | KeyValuePair<string, Vector3> region in |
||
135 | Regions.Items.Cast<ListViewItem>() |
||
136 | .Select(o => (KeyValuePair<string, Vector3>) o.Tag)) |
||
2 | zed | 137 | { |
138 | streamWriter.Write( |
||
139 | Vassal.wasEnumerableToCSV(new[] {region.Key, region.Value.ToString()})); |
||
140 | streamWriter.Write(Environment.NewLine); |
||
141 | } |
||
142 | } |
||
143 | |||
144 | mainForm.StatusText.Text = @"regions saved"; |
||
145 | mainForm.StatusProgress.Value = 100; |
||
146 | } |
||
147 | catch (Exception ex) |
||
148 | { |
||
149 | mainForm.StatusText.Text = ex.Message; |
||
150 | } |
||
151 | })); |
||
152 | }) |
||
8 | eva | 153 | {IsBackground = true, Priority = ThreadPriority.Normal}.Start(); |
2 | zed | 154 | break; |
155 | } |
||
156 | })); |
||
157 | } |
||
158 | |||
159 | private void RegionEditShown(object sender, EventArgs e) |
||
160 | { |
||
161 | Regions.Items.Clear(); |
||
3 | eva | 162 | // Get all the regions if they exist. |
163 | if (File.Exists(Vassal.VASSAL_CONSTANTS.VASSAL_REGIONS)) |
||
164 | { |
||
165 | Vector3 localPosition; |
||
166 | List<KeyValuePair<string, Vector3>> ConfiguredRegions = new List<KeyValuePair<string, Vector3>>( |
||
167 | File.ReadAllLines(Vassal.VASSAL_CONSTANTS.VASSAL_REGIONS) |
||
168 | .Select(o => new List<string>(Vassal.wasCSVToEnumerable(o))) |
||
169 | .Where(o => o.Count == 2) |
||
170 | .ToDictionary(o => o.First(), |
||
171 | p => |
||
172 | Vector3.TryParse(p.Last(), out localPosition) |
||
173 | ? localPosition |
||
174 | : Vector3.Zero).OrderBy(o => o.Key).ToDictionary(o => o.Key, o => o.Value)); |
||
175 | Regions.Items.AddRange( |
||
176 | ConfiguredRegions.Select( |
||
177 | o => (object) new ListViewItem {Text = o.Key + @" " + @"(" + o.Value.ToString() + @")", Tag = o}) |
||
178 | .ToArray()); |
||
179 | } |
||
2 | zed | 180 | } |
181 | |||
182 | private void RequestAddRegion(object sender, EventArgs e) |
||
183 | { |
||
8 | eva | 184 | mainForm.BeginInvoke((MethodInvoker) (() => |
2 | zed | 185 | { |
186 | if (string.IsNullOrEmpty(RegionName.Text)) |
||
187 | { |
||
188 | RegionName.BackColor = Color.MistyRose; |
||
189 | return; |
||
190 | } |
||
191 | Vector3 position; |
||
192 | if (!Vector3.TryParse(RegionPosition.Text, out position)) |
||
193 | { |
||
194 | RegionPosition.BackColor = Color.MistyRose; |
||
195 | return; |
||
196 | } |
||
197 | RegionName.BackColor = Color.Empty; |
||
198 | RegionPosition.BackColor = Color.Empty; |
||
199 | Regions.Items.Add(new ListViewItem |
||
200 | { |
||
201 | Text = RegionName.Text + @" " + @"(" + position + @")", |
||
202 | Tag = new KeyValuePair<string, Vector3>(RegionName.Text, position) |
||
203 | }); |
||
3 | eva | 204 | |
205 | // Update drop down box. |
||
2 | zed | 206 | Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => |
207 | { |
||
8 | eva | 208 | Vassal.vassalForm.LoadedRegionsBox.Items.Add(new ListViewItem |
2 | zed | 209 | { |
210 | Text = RegionName.Text, |
||
211 | Tag = position |
||
212 | }); |
||
3 | eva | 213 | // Add the row to the batch restart grid view. |
214 | Vassal.vassalForm.BatchRestartGridView.Rows.Add(RegionName.Text, position.ToString()); |
||
7 | zed | 215 | Vassal.vassalForm.RegionsStateGridView.Rows.Add(RegionName.Text, "Check pending...", |
216 | DateTime.Now.ToUniversalTime() |
||
217 | .ToString(Vassal.LINDEN_CONSTANTS.LSL.DATE_TIME_STAMP)); |
||
2 | zed | 218 | })); |
219 | })); |
||
220 | } |
||
221 | |||
222 | private void RequestRemoveRegion(object sender, EventArgs e) |
||
223 | { |
||
8 | eva | 224 | mainForm.BeginInvoke((MethodInvoker) (() => |
2 | zed | 225 | { |
226 | ListViewItem listViewItem = Regions.SelectedItem as ListViewItem; |
||
227 | if (listViewItem == null) |
||
228 | { |
||
229 | Regions.BackColor = Color.MistyRose; |
||
230 | return; |
||
231 | } |
||
3 | eva | 232 | |
2 | zed | 233 | int selectedItemIndex = Regions.SelectedIndex; |
3 | eva | 234 | if (selectedItemIndex == -1) |
235 | return; |
||
2 | zed | 236 | |
3 | eva | 237 | Regions.BackColor = Color.Empty; |
8 | eva | 238 | |
239 | Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => |
||
2 | zed | 240 | { |
8 | eva | 241 | Vassal.vassalForm.LoadedRegionsBox.Items.RemoveAt(selectedItemIndex); |
3 | eva | 242 | // Update the batch restart grid view. |
243 | Vassal.vassalForm.BatchRestartGridView.Rows.RemoveAt(selectedItemIndex); |
||
7 | zed | 244 | Vassal.vassalForm.RegionsStateGridView.Rows.RemoveAt(selectedItemIndex); |
2 | zed | 245 | })); |
246 | |||
247 | Regions.Items.RemoveAt(Regions.SelectedIndex); |
||
248 | })); |
||
249 | } |
||
250 | |||
251 | private void RegionSettingChanged(object sender, EventArgs e) |
||
252 | { |
||
8 | eva | 253 | mainForm.BeginInvoke((MethodInvoker) (() => |
2 | zed | 254 | { |
255 | ListViewItem listViewItem = Regions.SelectedItem as ListViewItem; |
||
256 | if (listViewItem == null) |
||
257 | return; |
||
258 | |||
3 | eva | 259 | int selectedItemIndex = Regions.SelectedIndex; |
260 | if (selectedItemIndex == -1) |
||
261 | return; |
||
262 | |||
2 | zed | 263 | if (string.IsNullOrEmpty(RegionName.Text)) |
264 | { |
||
265 | RegionName.BackColor = Color.MistyRose; |
||
266 | RegionPosition.BackColor = Color.MistyRose; |
||
267 | return; |
||
268 | } |
||
269 | |||
270 | Vector3 position; |
||
271 | if (!Vector3.TryParse(RegionPosition.Text, out position)) |
||
272 | { |
||
273 | RegionPosition.BackColor = Color.MistyRose; |
||
274 | return; |
||
275 | } |
||
276 | |||
277 | RegionName.BackColor = Color.Empty; |
||
278 | RegionPosition.BackColor = Color.Empty; |
||
279 | |||
8 | eva | 280 | |
281 | Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => |
||
2 | zed | 282 | { |
8 | eva | 283 | if (Vassal.vassalForm.LoadedRegionsBox.Items.Count > selectedItemIndex) |
2 | zed | 284 | { |
8 | eva | 285 | Vassal.vassalForm.LoadedRegionsBox.Items[selectedItemIndex] = new ListViewItem |
3 | eva | 286 | { |
287 | Text = RegionName.Text, |
||
288 | Tag = position |
||
289 | }; |
||
290 | } |
||
291 | // Update the batch restart grid view. |
||
292 | if (Vassal.vassalForm.BatchRestartGridView.Rows.Count > selectedItemIndex) |
||
293 | { |
||
294 | Vassal.vassalForm.BatchRestartGridView.Rows[selectedItemIndex].Cells["BatchRestartRegionName"] |
||
295 | .Value |
||
296 | = RegionName.Text; |
||
297 | Vassal.vassalForm.BatchRestartGridView.Rows[selectedItemIndex].Cells["BatchRestartPosition"] |
||
298 | .Value |
||
299 | = position.ToString(); |
||
300 | } |
||
7 | zed | 301 | // Update the region state grid view. |
302 | if (Vassal.vassalForm.RegionsStateGridView.Rows.Count > selectedItemIndex) |
||
303 | { |
||
304 | Vassal.vassalForm.RegionsStateGridView.Rows[selectedItemIndex].Cells["RegionsStateRegionName"] |
||
305 | .Value |
||
306 | = RegionName.Text; |
||
307 | Vassal.vassalForm.RegionsStateGridView.Rows[selectedItemIndex].Cells["RegionsStateLastState"] |
||
308 | .Value |
||
309 | = "Check pending..."; |
||
310 | Vassal.vassalForm.RegionsStateGridView.Rows[selectedItemIndex].Cells["RegionsStateLastCheck"] |
||
311 | .Value |
||
312 | = DateTime.Now.ToUniversalTime() |
||
313 | .ToString(Vassal.LINDEN_CONSTANTS.LSL.DATE_TIME_STAMP); |
||
314 | } |
||
2 | zed | 315 | })); |
316 | |||
317 | Regions.Items[selectedItemIndex] = new ListViewItem |
||
318 | { |
||
319 | Text = RegionName.Text + @" " + @"(" + position + @")", |
||
320 | Tag = new KeyValuePair<string, Vector3>(RegionName.Text, position) |
||
321 | }; |
||
322 | })); |
||
323 | } |
||
324 | |||
325 | private void RegionSelected(object sender, EventArgs e) |
||
326 | { |
||
8 | eva | 327 | mainForm.BeginInvoke((MethodInvoker) (() => |
2 | zed | 328 | { |
329 | ListViewItem listViewItem = Regions.SelectedItem as ListViewItem; |
||
330 | if (listViewItem == null) |
||
331 | return; |
||
3 | eva | 332 | |
333 | int selectedItemIndex = Regions.SelectedIndex; |
||
334 | if (selectedItemIndex == -1) |
||
335 | return; |
||
336 | |||
2 | zed | 337 | KeyValuePair<string, Vector3> region = (KeyValuePair<string, Vector3>) listViewItem.Tag; |
338 | RegionName.Text = region.Key; |
||
339 | RegionPosition.Text = region.Value.ToString(); |
||
340 | })); |
||
341 | } |
||
342 | } |
||
8 | eva | 343 | } |