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