corrade-vassal – Diff between revs 3 and 7

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