-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathFormMain.cs
2797 lines (2520 loc) · 120 KB
/
FormMain.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Rawr.Forms;
using Rawr.UserControls;
using System.IO;
using System.Threading;
using System.Drawing.Imaging;
namespace Rawr
{
public partial class FormMain : Form, IFormItemSelectionProvider
{
private string _storedCharacterPath;
private bool _storedUnsavedChanged;
private Character _storedCharacter;
private BatchCharacter _batchCharacter;
private FormSplash _splash = new FormSplash();
private string _characterPath = "";
private bool _unsavedChanges = false;
private CharacterCalculationsBase _calculatedStats = null;
private List<ToolStripMenuItem> _recentCharacterMenuItems = new List<ToolStripMenuItem>();
private bool _loadingCharacter = false;
private Character _character = null;
private List<ToolStripMenuItem> _customChartMenuItems = new List<ToolStripMenuItem>();
private Status _statusForm;
private string _formatWindowTitle = "Rawr v{0}";
private Color _defaultColor = Color.White;
private System.Threading.Timer _timerCheckForUpdates;
// we want this access so we can check cancel request from workers
public Status Status { get { return _statusForm; } }
private FormRelevantItemRefinement _itemRefinement;
public FormRelevantItemRefinement ItemRefinement
{
get
{
if (_itemRefinement == null || _itemRefinement.IsDisposed)
_itemRefinement = new FormRelevantItemRefinement(null);
return _itemRefinement;
}
}
private FormItemComparison _itemComparison;
private FormItemFilter _formItemFilter;
public FormItemFilter FormItemFilter
{
get
{
if (_formItemFilter == null || _formItemFilter.IsDisposed)
_formItemFilter = new FormItemFilter();
return _formItemFilter;
}
}
private FormItemSelection _formItemSelection;
public FormItemSelection FormItemSelection
{
get
{
if (_formItemSelection == null || _formItemSelection.IsDisposed)
_formItemSelection = new FormItemSelection();
return _formItemSelection;
}
}
public TalentPicker TalentPicker { get { return talentPicker1; } }
private ItemFilterTreeView itemFilterTreeView;
private static FormMain _instance;
public static FormMain Instance { get { return FormMain._instance; } }
public FormMain()
{
_instance = this;
_splash.Show();
_statusForm = new Status();
Application.DoEvents();
Version version = System.Reflection.Assembly.GetCallingAssembly().GetName().Version;
_formatWindowTitle = string.Format(_formatWindowTitle, version.Major.ToString() + "." + version.Minor.ToString() + "." + version.Build.ToString());
asyncCalculationStart = new AsynchronousDisplayCalculationDelegate(AsyncCalculationStart);
asyncCalculationCompleted = new SendOrPostCallback(AsyncCalculationCompleted);
Rawr.UserControls.Options.GeneralSettings.HideProfessionsChanged += new EventHandler(GeneralSettings_HideProfessionsChanged);
LoadModel(ConfigModel);
InitializeComponent();
_defaultColor = itemButtonHead.BackColor;
if (Type.GetType("Mono.Runtime") != null)
copyDataToClipboardToolStripMenuItem.Text += " (Doesn't work under Mono)";
Application.DoEvents();
Rectangle bounds = ConfigBounds;
if (bounds.Width >= this.MinimumSize.Width && bounds.Height >= this.MinimumSize.Height)
{
this.StartPosition = FormStartPosition.Manual;
this.Bounds = bounds;
}
Image icon = ItemIcons.GetItemIcon(Calculations.ModelIcons[ConfigModel], true);
if (icon != null)
{
this.Icon = Icon.FromHandle((icon as Bitmap).GetHicon());
}
UpdateRecentCharacterMenuItems();
//ToolStripMenuItem modelsToolStripMenuItem = new ToolStripMenuItem("Models");
//menuStripMain.Items.Add(modelsToolStripMenuItem);
//foreach (KeyValuePair<string, Type> kvp in Calculations.Models)
//{
// ToolStripMenuItem modelToolStripMenuItem = new ToolStripMenuItem(kvp.Key);
// modelToolStripMenuItem.Click += new EventHandler(modelToolStripMenuItem_Click);
// modelToolStripMenuItem.Checked = kvp.Value == Calculations.Instance.GetType();
// modelToolStripMenuItem.Tag = kvp;
// modelsToolStripMenuItem.DropDownItems.Add(modelToolStripMenuItem);
//}
this.Shown += new EventHandler(FormMain_Shown);
ItemCache.Instance.ItemsChanged += new EventHandler(ItemCache_ItemsChanged);
Calculations.ModelChanging += new EventHandler(Calculations_ModelChanging);
Calculations.ModelChanged += new EventHandler(Calculations_ModelChanged);
// at this point there is no character
_character = new Character();
_character.CurrentModel = ConfigModel;
_character.Class = Calculations.ModelClasses[_character.CurrentModel];
_characterPath = string.Empty;
_unsavedChanges = false;
// we didn't actually set up the character yet
// model change will force it to reload and set up all needed events and everything
Calculations_ModelChanged(null, null);
_loadingCharacter = true;
sortToolStripMenuItem_Click(overallToolStripMenuItem, EventArgs.Empty);
slotToolStripMenuItem_Click(headToolStripMenuItem, EventArgs.Empty);
_loadingCharacter = false;
itemFilterTreeView = new ItemFilterTreeView();
itemFilterTreeView.EditMode = false;
itemFilterTreeView.BorderStyle = BorderStyle.None;
itemFilterTreeView.Size = new Size(275, 400);
ToolStripDropDown dropDown = new ToolStripDropDown();
dropDown.Items.Add(new ToolStripControlHost(itemFilterTreeView));
toolStripDropDownButtonFilter.DropDown = dropDown;
}
private bool _checkForUpdatesEnabled = true;
void _timerCheckForUpdates_Callback(object data)
{
if (_checkForUpdatesEnabled)
{
string latestVersion = new Rawr.WebRequestWrapper().GetBetaVersionString();
if (!string.IsNullOrEmpty(latestVersion))
{
string currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
if (currentVersion != latestVersion)
{
_checkForUpdatesEnabled = false;
DialogResult result = MessageBox.Show(string.Format("A new version of Rawr has been released, version {0}! Would you like to go to the Rawr site to download the new version?",
latestVersion), "New Version Released!", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
Help.ShowHelp(null, "http://rawr.codeplex.com/");
}
}
}
}
}
void Calculations_ModelChanging(object sender, EventArgs e)
{
Character.SerializeCalculationOptions();
}
public Character Character
{
get
{
if (_character == null)
{
Character character = new Character();
character.CurrentModel = ConfigModel;
character.Class = Calculations.ModelClasses[character.CurrentModel];
Character = character;
_characterPath = string.Empty;
_unsavedChanges = false;
}
return _character;
}
set
{
if (_character != null)
{
_character.ClassChanged -= new EventHandler(_character_ClassChanged);
_character.CalculationsInvalidated -= new EventHandler(_character_ItemsChanged);
_character.AvailableItemsChanged -= new EventHandler(_character_AvailableItemsChanged);
}
_character = value;
if (_batchCharacter != null && _batchCharacter.Character != _character)
{
// we're loading a character that is not a batch character
_batchCharacter = null;
}
if (_character != null)
{
this.Cursor = Cursors.WaitCursor;
_character.IsLoading = true; // we do not need ItemsChanged event triggering until we call OnItemsChanged at the end
Character.CurrentModel = null;
Calculations.CalculationOptionsPanel.Character = _character;
ItemToolTip.Instance.Character = FormItemSelection.Character = talentPicker1.Character =
ItemEnchantContextualMenu.Instance.Character = ItemContextualMenu.Instance.Character = buffSelector1.Character = itemComparison1.Character =
itemButtonBack.Character = itemButtonChest.Character = itemButtonFeet.Character =
itemButtonFinger1.Character = itemButtonFinger2.Character = itemButtonHands.Character =
itemButtonHead.Character = itemButtonRanged.Character = itemButtonLegs.Character =
itemButtonNeck.Character = itemButtonShirt.Character = itemButtonShoulders.Character =
itemButtonTabard.Character = itemButtonTrinket1.Character = itemButtonTrinket2.Character =
itemButtonWaist.Character = itemButtonMainHand.Character = itemButtonOffHand.Character =
itemButtonProjectile.Character = itemButtonProjectileBag.Character = itemButtonWrist.Character = _character;
//Ahhh ahhh ahhh ahhh ahhh ahhh ahhh ahhh...
if (_itemComparison != null && !_itemComparison.IsDisposed) _itemComparison.Character = _character;
_character.ClassChanged += new EventHandler(_character_ClassChanged);
_character.CalculationsInvalidated += new EventHandler(_character_ItemsChanged);
_character.AvailableItemsChanged += new EventHandler(_character_AvailableItemsChanged);
_loadingCharacter = true;
textBoxName.Text = Character.Name;
textBoxRealm.Text = Character.Realm;
comboBoxRegion.Text = Character.Region.ToString();
comboBoxRace.Text = Character.Race.ToString();
comboBoxProfession1.Text = Character.PrimaryProfession.ToString();
comboBoxProfession2.Text = Character.SecondaryProfession.ToString();
checkBoxEnforceGemRequirements.Checked = Character.EnforceGemRequirements;
checkBoxWaistBlacksmithingSocket.Checked = Character.WaistBlacksmithingSocketEnabled;
checkBoxWristBlacksmithingSocket.Checked = Character.WristBlacksmithingSocketEnabled;
checkBoxHandsBlacksmithingSocket.Checked = Character.HandsBlacksmithingSocketEnabled;
if (comboBoxClass.Text != Character.Class.ToString())
{
comboBoxClass.Text = Character.Class.ToString();
_character_ClassChanged(null, null);
}
if (_character.LoadItemFilterEnabledOverride())
{
itemFilterTreeView.GenerateNodes();
ItemCache.OnItemsChanged();
}
//if (_itemComparison != null && !_itemComparison.IsDisposed)
//{
// _itemComparison.Hide();
// _itemComparison.Dispose();
//}
_loadingCharacter = false;
UpdateProfessionControls();
_character.IsLoading = false;
//_character.OnCalculationsInvalidated(); nothing actually changed on the character, we just need calculations
_character_ItemsChanged(_character, EventArgs.Empty); // this way it won't cause extra invalidations for other listeners of the event
}
}
}
void _character_ClassChanged(object sender, EventArgs e)
{
_unsavedChanges = true;
this.Cursor = Cursors.WaitCursor;
string oldModel = (string)comboBoxModel.SelectedValue;
if (string.IsNullOrEmpty(oldModel)) oldModel = ConfigModel;
comboBoxModel.Items.Clear();
List<string> items = new List<string>();
foreach (KeyValuePair<string, CharacterClass> kvp in Calculations.ModelClasses)
{
if (kvp.Value == _character.Class)
{
items.Add(kvp.Key);
}
}
comboBoxModel.Items.AddRange(items.ToArray());
if (items.Contains(oldModel)) comboBoxModel.SelectedIndex = items.IndexOf(oldModel);
else if (comboBoxModel.Items.Count > 0) comboBoxModel.SelectedIndex = 0;
this.Cursor = Cursors.Default;
}
private void SetTitle()
{
StringBuilder sb = new StringBuilder(_formatWindowTitle);
if (_character != null && !String.IsNullOrEmpty(_character.Name))
{
sb.Append(" - ");
sb.Append(_character.Name);
}
if (!String.IsNullOrEmpty(_characterPath))
{
sb.Append(" - ");
sb.Append(Path.GetFileName(_characterPath));
if (_unsavedChanges)
{
sb.Append("*");
}
}
this.Text = sb.ToString();
}
void _character_AvailableItemsChanged(object sender, EventArgs e)
{
_unsavedChanges = true;
}
//private void ItemEnchantsChanged()
//{
// _loadingCharacter = true;
// comboBoxEnchantBack.SelectedItem = Character.BackEnchant;
// comboBoxEnchantChest.SelectedItem = Character.ChestEnchant;
// comboBoxEnchantFeet.SelectedItem = Character.FeetEnchant;
// comboBoxEnchantFinger1.SelectedItem = Character.Finger1Enchant;
// comboBoxEnchantFinger2.SelectedItem = Character.Finger2Enchant;
// comboBoxEnchantHands.SelectedItem = Character.HandsEnchant;
// comboBoxEnchantHead.SelectedItem = Character.HeadEnchant;
// comboBoxEnchantLegs.SelectedItem = Character.LegsEnchant;
// comboBoxEnchantShoulders.SelectedItem = Character.ShouldersEnchant;
// comboBoxEnchantMainHand.SelectedItem = Character.MainHandEnchant;
// comboBoxEnchantOffHand.SelectedItem = Character.OffHandEnchant;
// comboBoxEnchantRanged.SelectedItem = Character.RangedEnchant;
// comboBoxEnchantWrists.SelectedItem = Character.WristEnchant;
// _loadingCharacter = false;
//}
private delegate void AsynchronousDisplayCalculationDelegate(CharacterCalculationsBase calculations, AsyncOperation asyncCalculation);
private class AsyncCalculationResult
{
public CharacterCalculationsBase Calculations;
public Dictionary<string, string> DisplayCalculationValues;
}
AsynchronousDisplayCalculationDelegate asyncCalculationStart;
SendOrPostCallback asyncCalculationCompleted;
AsyncOperation asyncCalculation;
private void AsyncCalculationStart(CharacterCalculationsBase calculations, AsyncOperation asyncCalculation)
{
Dictionary<string, string> result = calculations.GetAsynchronousCharacterDisplayCalculationValues();
asyncCalculation.PostOperationCompleted(asyncCalculationCompleted, new AsyncCalculationResult() { Calculations = calculations, DisplayCalculationValues = result });
}
private void AsyncCalculationCompleted(object arg)
{
AsyncCalculationResult result = (AsyncCalculationResult)arg;
if (result.DisplayCalculationValues != null && result.Calculations == _calculatedStats)
{
UpdateDisplayCalculationValues(result.DisplayCalculationValues);
// refresh chart if it's custom chart
foreach (ToolStripItem item in toolStripDropDownButtonSlot.DropDownItems)
{
if (item is ToolStripMenuItem && (item as ToolStripMenuItem).Checked && item.Tag != null)
{
itemComparison1.DisplayMode = ComparisonGraph.GraphDisplayMode.Subpoints;
string[] tag = item.Tag.ToString().Split('.');
switch (tag[0])
{
case "Custom":
itemComparison1.LoadCustomChart(tag[1]);
break;
case "CustomRendered":
itemComparison1.LoadCustomRenderedChart(tag[1]);
break;
}
break;
}
}
asyncCalculation = null;
}
}
void _character_ItemsChanged(object sender, EventArgs e)
{
if (this.InvokeRequired)
{
Invoke((EventHandler)_character_ItemsChanged, sender, e);
//InvokeHelper.Invoke(this, "_character_ItemsChanged", new object[] { sender, e });
return;
}
this.Cursor = Cursors.WaitCursor;
if (asyncCalculation != null)
{
CharacterCalculationsBase oldCalcs = _calculatedStats;
_calculatedStats = null;
oldCalcs.CancelAsynchronousCharacterDisplayCalculation();
asyncCalculation = null;
}
_unsavedChanges = true;
//itemButtonOffHand.Enabled = _character.MainHand == null || _character.MainHand.Slot != ItemSlot.TwoHand;
if (!_loadingCharacter)
{
itemButtonBack.UpdateSelectedItem(); itemButtonChest.UpdateSelectedItem(); itemButtonFeet.UpdateSelectedItem();
itemButtonFinger1.UpdateSelectedItem(); itemButtonFinger2.UpdateSelectedItem(); itemButtonHands.UpdateSelectedItem();
itemButtonHead.UpdateSelectedItem(); itemButtonRanged.UpdateSelectedItem(); itemButtonLegs.UpdateSelectedItem();
itemButtonNeck.UpdateSelectedItem(); itemButtonShirt.UpdateSelectedItem(); itemButtonShoulders.UpdateSelectedItem();
itemButtonTabard.UpdateSelectedItem(); itemButtonTrinket1.UpdateSelectedItem(); itemButtonTrinket2.UpdateSelectedItem();
itemButtonWaist.UpdateSelectedItem(); itemButtonMainHand.UpdateSelectedItem(); itemButtonOffHand.UpdateSelectedItem();
itemButtonProjectile.UpdateSelectedItem(); itemButtonProjectileBag.UpdateSelectedItem(); itemButtonWrist.UpdateSelectedItem();
//ItemEnchantsChanged();
}
//and the clouds above move closer / looking so dissatisfied
Calculations.ClearCache();
CharacterCalculationsBase calcs = Calculations.GetCharacterCalculations(Character, null, true, true, true);
_calculatedStats = calcs;
FormItemSelection.CurrentCalculations = calcs;
UpdateDisplayCalculationValues(calcs.GetCharacterDisplayCalculationValues());
if (Character.IsMetaGemActive)
itemButtonHead.BackColor = _defaultColor;
else
itemButtonHead.BackColor = Color.Red;
LoadComparisonData();
if (calcs.RequiresAsynchronousDisplayCalculation)
{
asyncCalculation = AsyncOperationManager.CreateOperation(null);
asyncCalculationStart.BeginInvoke(calcs, asyncCalculation, null, null);
}
this.Cursor = Cursors.Default;
//and the ground below grew colder / as they put you down inside
}
public void UpdateDisplayCalculationValues(Dictionary<string, string> displayCalculationValues)
{
calculationDisplay1.SetCalculations(displayCalculationValues);
string status;
if (!displayCalculationValues.TryGetValue("Status", out status))
{
int i = 0;
status = "Overall: " + Math.Round(_calculatedStats.OverallPoints);
foreach (KeyValuePair<string, Color> kvp in Calculations.SubPointNameColors)
{
status += ", " + kvp.Key + ": " + Math.Round(_calculatedStats.SubPoints[i]);
i++;
}
//status = "Rawr version " + typeof(Calculations).Assembly.GetName().Version.ToString();
}
toolStripStatusLabel.Text = status;
}
public void LoadModel(string displayName)
{
try
{
Calculations.LoadModel(Calculations.Models[displayName]);
}
finally
{
this.ConfigModel = displayName;
Image icon = ItemIcons.GetItemIcon(Calculations.ModelIcons[displayName], true);
if (icon != null)
{
this.Icon = Icon.FromHandle((icon as Bitmap).GetHicon());
}
}
}
public string ConfigModel
{
get
{
return Calculations.ValidModel(Properties.Recent.Default.RecentModel);
}
set { Properties.Recent.Default.RecentModel = value; }
}
public Rectangle ConfigBounds
{
get
{
return new Rectangle(Properties.Recent.Default.WindowLocation,
Properties.Recent.Default.WindowSize);
}
set
{
Properties.Recent.Default.WindowLocation = value.Location;
Properties.Recent.Default.WindowSize = value.Size;
}
}
public enum FileType
{
Character,
Batch
}
public FileType GetFileType(string file)
{
StreamReader reader = new StreamReader(file);
reader.ReadLine(); // xml declaration
string root = reader.ReadLine();
if (root.StartsWith("<Character"))
{
return FileType.Character;
}
else if (root.StartsWith("<ArrayOfBatchCharacter"))
{
return FileType.Batch;
}
// otherwise assume Character, it won't load anyway
return FileType.Character;
}
public string[] ConfigRecentCharacters
{
get
{
string recentCharacters = Properties.Recent.Default.RecentFiles;
if (string.IsNullOrEmpty(recentCharacters))
{
return new string[0];
}
else
{
return recentCharacters.Split(';');
}
}
set { Properties.Recent.Default.RecentFiles = string.Join(";", value); }
}
private delegate void AddRecentCharacterDelegate(string character);
public void AddRecentCharacter(string character)
{
List<string> recentCharacters = new List<string>(ConfigRecentCharacters);
recentCharacters.Remove(character);
recentCharacters.Add(character);
while (recentCharacters.Count > 8)
recentCharacters.RemoveRange(0, recentCharacters.Count - 8);
ConfigRecentCharacters = recentCharacters.ToArray();
UpdateRecentCharacterMenuItems();
}
public void UpdateRecentCharacterMenuItems()
{
foreach (ToolStripMenuItem item in _recentCharacterMenuItems)
{
fileToolStripMenuItem.DropDownItems.Remove(item);
item.Dispose();
}
_recentCharacterMenuItems.Clear();
foreach (string recentCharacter in ConfigRecentCharacters)
{
string fileName = System.IO.Path.GetFileName(recentCharacter);
ToolStripMenuItem recentCharacterMenuItem = new ToolStripMenuItem(fileName);
recentCharacterMenuItem.Tag = recentCharacter;
recentCharacterMenuItem.Click += new EventHandler(recentCharacterMenuItem_Click);
_recentCharacterMenuItems.Add(recentCharacterMenuItem);
fileToolStripMenuItem.DropDownItems.Insert(6, recentCharacterMenuItem);
}
}
public void UpdateCustomChartMenuItems()
{
foreach (ToolStripMenuItem item in _customChartMenuItems)
{
toolStripDropDownButtonSlot.DropDownItems.Remove(item);
item.Dispose();
}
_customChartMenuItems.Clear();
foreach (string chartName in Calculations.CustomChartNames)
{
ToolStripMenuItem customChartMenuItem = new ToolStripMenuItem(chartName);
customChartMenuItem.Tag = "Custom." + chartName;
customChartMenuItem.Click += new EventHandler(slotToolStripMenuItem_Click);
_customChartMenuItems.Add(customChartMenuItem);
toolStripDropDownButtonSlot.DropDownItems.Add(customChartMenuItem);
}
foreach (string chartName in Calculations.CustomRenderedChartNames)
{
ToolStripMenuItem customChartMenuItem = new ToolStripMenuItem(chartName);
customChartMenuItem.Tag = "CustomRendered." + chartName;
customChartMenuItem.Click += new EventHandler(slotToolStripMenuItem_Click);
_customChartMenuItems.Add(customChartMenuItem);
toolStripDropDownButtonSlot.DropDownItems.Add(customChartMenuItem);
}
}
void recentCharacterMenuItem_Click(object sender, EventArgs e)
{
if (PromptToSaveBeforeClosing())
{
LoadSavedCharacter((sender as ToolStripMenuItem).Tag.ToString());
}
}
//private void modelToolStripMenuItem_Click(object sender, EventArgs e)
//{
// ToolStripMenuItem modelToolStripMenuItem = sender as ToolStripMenuItem;
// if (!modelToolStripMenuItem.Checked)
// {
// foreach (ToolStripMenuItem item in _customChartMenuItems)
// if (item.Checked)
// slotToolStripMenuItem_Click(toolStripDropDownButtonSlot.DropDownItems[1], null);
// foreach (ToolStripMenuItem item in (modelToolStripMenuItem.OwnerItem as ToolStripMenuItem).DropDownItems)
// item.Checked = item == modelToolStripMenuItem;
// KeyValuePair<string, Type> kvpModel = (KeyValuePair<string, Type>)modelToolStripMenuItem.Tag;
// Image icon = ItemIcons.GetItemIcon(Calculations.ModelIcons[kvpModel.Key], true);
// if (icon != null)
// {
// this.Icon = Icon.FromHandle((icon as Bitmap).GetHicon());
// }
// this.LoadModel(kvpModel.Key);
// }
//}
private void Calculations_ModelChanged(object sender, EventArgs e)
{
bool unsavedChanges = _unsavedChanges;
Character.CurrentModel = null;
UpdateCustomChartMenuItems();
toolStripDropDownButtonSort.DropDownItems.Clear();
toolStripDropDownButtonSort.DropDownItems.Add(overallToolStripMenuItem);
toolStripDropDownButtonSort.DropDownItems.Add(alphabeticalToolStripMenuItem);
foreach (string name in Calculations.SubPointNameColors.Keys)
{
ToolStripMenuItem toolStripMenuItemSubPoint = new ToolStripMenuItem(name);
toolStripMenuItemSubPoint.Tag = toolStripDropDownButtonSort.DropDownItems.Count - 2;
toolStripMenuItemSubPoint.Click += new System.EventHandler(this.sortToolStripMenuItem_Click);
toolStripDropDownButtonSort.DropDownItems.Add(toolStripMenuItemSubPoint);
}
Calculations.CalculationOptionsPanel.Dock = DockStyle.Fill;
tabPageOptions.Controls.Clear();
tabPageOptions.Controls.Add(Calculations.CalculationOptionsPanel);
itemButtonProjectile.Visible = itemButtonProjectileBag.Visible = Calculations.CanUseAmmo;
_loadingCharacter = true; // no need to load the comparison charts for this, it's done when reloading the character
ItemRefinement.resetLists();
ItemCache.OnItemsChanged();
_loadingCharacter = false;
Character = Character; //Reload the character
_unsavedChanges = unsavedChanges;
}
void FormMain_Shown(object sender, EventArgs e)
{
_splash.Close();
_splash.Dispose();
SetTitle();
// reset filter regex
ItemFilterRegex.RegexCompiled = true;
// compile regex and save files in background
ThreadPool.QueueUserWorkItem((object state) =>
{
Thread.Sleep(1000); // wait a bit while windows are still drawing so it doesn't look laggy
ItemFilter.Compile();
Buff.SaveBuffs();
Enchant.SaveEnchants();
});
if (!Properties.GeneralSettings.Default.SeenRawr3Note)
{
MessageBox.Show(
@"We're pleased to announce that, after long last, Rawr3 has entered public beta. You're still welcome to continue using Rawr2 (that's what you're using right now), but we urge you to try out Rawr3, and enjoy all the new features and benefits. Rawr3 is a port of Rawr to Silverlight, which means:
- You can run Rawr3 in your web browser.
- No need to download or install anything.
- It runs on Mac OS X (Intel). Welcome to Rawr, Mac users!
- You can optionally install it locally with 2 clicks from the web version, if you want to have it locally for offline use.
- Lots more.
So give Rawr3 a try today! Get started at: http://elitistjerks.com/rawr.php
Please remember that it's still a beta, though, so lots of things are likely to be buggy or incomplete!",
"A Message from the Rawr Development Team");
Properties.GeneralSettings.Default.SeenRawr3Note = true;
Properties.GeneralSettings.Default.Save();
}
//if (Properties.Recent.Default.SeenIntroVersion < INTRO_VERSION)
//{
// Properties.Recent.Default.SeenIntroVersion = INTRO_VERSION;
// MessageBox.Show(INTRO_TEXT);
//}
}
private void FormMain_Load(object sender, EventArgs e)
{
Character.ToString();//Load the saved character
StatusMessaging.Ready = true;
_timerCheckForUpdates = new System.Threading.Timer(new System.Threading.TimerCallback(_timerCheckForUpdates_Callback));
_timerCheckForUpdates.Change(3000, 1000 * 60 * 60 * 8); //Check for updates 3 sec after the form loads, and then again every 8 hours
if (Properties.Recent.Default.ShowStartPage)
ShowStartPage();
}
private void ShowStartPage()
{
FormStart formStart = new FormStart(this);
formStart.Left = this.Left + this.Width / 2 - formStart.Width / 2;
formStart.Top = this.Top + this.Height / 2 - formStart.Height / 2;
formStart.Show(this);
}
void ItemCache_ItemsChanged(object sender, EventArgs e)
{
// when item is deleted from item cache we have to make sure to update
// all items needed by current character (essentially we have to prevent the item from
// being deleted)
if (!_loadingCharacter)
{
_loadingCharacter = true; // suppress item changed event
EnsureItemsLoaded(_character.GetAllEquippedAndAvailableGearIds());
_loadingCharacter = false;
}
if (this.InvokeRequired)
{
if (_loadingCharacter)
{
Character.InvalidateItemInstances();
}
else
{
BeginInvoke((EventHandler)ItemCache_ItemsChanged, sender, e);
}
}
else
{
Character.InvalidateItemInstances();
if (!_loadingCharacter)
{
LoadComparisonData();
}
}
}
void refineEquipmentParametersToolStripMenuItem_Click(object sender, EventArgs e)
{
ItemRefinement.updateBoxes();
if (ItemRefinement.ShowDialog(this) == DialogResult.OK)
{
ItemFilter.Save(GetItemFilterFilePath());
}
}
void defaultGemControlToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
FormGemmingTemplates GemControl = new FormGemmingTemplates();
GemControl.ShowDialog(this);
this.Cursor = Cursors.Default;
List<GemmingTemplate> copy = new List<GemmingTemplate>(Character.CustomGemmingTemplates);
if (GemControl.DialogResult.Equals(DialogResult.OK))
{
ItemCache.OnItemsChanged();
}
else
{
Character.CustomGemmingTemplates = copy;
}
}
private void editItemsToolStripMenuItem_Click(object sender, EventArgs e)
{
FormItemEditor itemEditor = new FormItemEditor(Character);
itemEditor.ShowDialog(this);
ItemCache.OnItemsChanged();
}
//{
// OpenItemEditor();
//}
//public void OpenItemEditor() { OpenItemEditor(null); }
//public void OpenItemEditor(Item selectedItem)
//{
// this.Invoke(new OpenItemEditorDel(_openItemEditor), selectedItem);
//}
//private delegate void OpenItemEditorDel(Item selectedItem);
//private void _openItemEditor(Item selectedItem)
//{
// FormItemEditor itemEditor = new FormItemEditor(Character);
// if (selectedItem != null) itemEditor.SelectItem(selectedItem, true);
// itemEditor.ShowDialog(this);
// ItemCache.OnItemsChanged();
//}
#region File Commands
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
NewCharacter();
}
public bool NewCharacter()
{
bool ret = false;
if (PromptToSaveBeforeClosing())
{
_characterPath = null;
LoadCharacterIntoForm(new Character());
ret = true;
}
return ret;
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenCharacter();
}
public bool OpenCharacter()
{
bool ret = false;
if (PromptToSaveBeforeClosing())
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.DefaultExt = ".xml";
dialog.Filter = "Rawr Xml Character Files | *.xml";
dialog.Multiselect = false;
if (dialog.ShowDialog(this) == DialogResult.OK)
{
LoadSavedCharacter(dialog.FileName);
ret = true;
}
dialog.Dispose();
}
return ret;
}
private void LoadCharacterIntoForm(Character character)
{
LoadCharacterIntoForm(character, false);
}
private void LoadCharacterIntoForm(Character character, bool unsavedChanges)
{
string characterModel = character.CurrentModel;
// if the current character is already using the target model (majority case), then we can skip this whole mess
if (Character.CurrentModel != characterModel)
{
Character c = new Character();
// set the race/class/model of target character to minimize model swaps
c.Class = character.Class;
c.Race = character.Race;
c.CurrentModel = characterModel;
// now load blank character and force a model change
// TODO: this can probably be optimized still, don't need to do charts etc for the blank character
Character = c;
LoadModel(characterModel);
}
// now load the character without poluting it with previous model
Character = character;
_unsavedChanges = unsavedChanges;
SetTitle();
comboBoxModel.SelectedItem = characterModel;
}
public void BatchCharacterSaved(BatchCharacter character)
{
if (_batchCharacter == character)
{
_unsavedChanges = false;
SetTitle();
}
}
public void LoadBatchCharacter(BatchCharacter character)
{
if (character.Character != null)
{
if (_batchCharacter == null)
{
_storedCharacter = _character;
_storedCharacterPath = _characterPath;
_storedUnsavedChanged = _unsavedChanges;
}
_batchCharacter = character;
_characterPath = character.AbsolutePath;
EnsureItemsLoaded(character.Character.GetAllEquippedAndAvailableGearIds());
LoadCharacterIntoForm(character.Character, character.UnsavedChanges);
}
}
public void UnloadBatchCharacter()
{
if (_batchCharacter != null)
{
_batchCharacter = null;
_characterPath = _storedCharacterPath;
LoadCharacterIntoForm(_storedCharacter, _storedUnsavedChanged);
_storedCharacter = null;
}
}
public void LoadSavedCharacter(string path)
{
if (!File.Exists(path)) {
MessageBox.Show("That file no longer exists.\n\nRawr will now skip the remainder of the attempt to open the file",
"Error Opening File",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
switch (GetFileType(path))
{
case FileType.Character:
StartProcessing();
BackgroundWorker bw = new BackgroundWorker();
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_LoadSavedCharacterComplete);
bw.DoWork += new DoWorkEventHandler(bw_LoadSavedCharacter);
bw.RunWorkerAsync(path);
break;
case FileType.Batch:
FormBatchTools form = new FormBatchTools(this);
AddRecentCharacter(path);
form.batchTools.BatchCharacterList = BatchCharacterList.Load(path);
form.batchCharacterListBindingSource.DataSource = form.batchTools.BatchCharacterList;
form.Show();
break;
}
}
void bw_LoadSavedCharacter(object sender, DoWorkEventArgs e)
{
WebRequestWrapper.ResetFatalErrorIndicator();
StatusMessaging.UpdateStatus("Loading Character", "Loading Saved Character");
StatusMessaging.UpdateStatus("Update Item Cache", "Queued");
StatusMessaging.UpdateStatus("Cache Item Icons", "Queued");
_loadingCharacter = true; // suppress item changed event
Character character = Character.Load(e.Argument as string);
_loadingCharacter = false;
StatusMessaging.UpdateStatusFinished("Loading Character");
if (character != null)
{
_loadingCharacter = true; // suppress item changed event
this.EnsureItemsLoaded(character.GetAllEquippedAndAvailableGearIds());
_loadingCharacter = false;
_characterPath = e.Argument as string;
Invoke((AddRecentCharacterDelegate)AddRecentCharacter, e.Argument);
//InvokeHelper.Invoke(this, "AddRecentCharacter", new object[] { e.Argument});
e.Result = character;
}
}
void bw_LoadSavedCharacterComplete(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null) {
MessageBox.Show(e.Error.Message, "Error loading Saved Character file");
} else {
//Load Character into UI
LoadCharacterIntoForm(e.Result as Character);
}
FinishedProcessing();
}
private void loadFromArmoryToolStripMenuItem_Click(object sender, EventArgs e)
{
LoadCharacterFromArmory();
}
public bool LoadCharacterFromArmory()
{
bool ret = false;
if (PromptToSaveBeforeClosing())
{
FormEnterNameRealm form = new FormEnterNameRealm();
form.Icon = this.Icon;
if (form.ShowDialog(this) == DialogResult.OK)
{
// The removes force it to put those items at the end.
// So we can use that for recall later on what was last used
if (Rawr.Properties.Recent.Default.RecentChars.Contains(form.textBoxName.Text)) {
Rawr.Properties.Recent.Default.RecentChars.Remove(form.textBoxName.Text);
}
if (Rawr.Properties.Recent.Default.RecentServers.Contains(form.textBoxRealm.Text)) {
Rawr.Properties.Recent.Default.RecentServers.Remove(form.textBoxRealm.Text);
}
Rawr.Properties.Recent.Default.RecentChars.Add(form.textBoxName.Text);
Rawr.Properties.Recent.Default.RecentServers.Add(form.textBoxRealm.Text);
Rawr.Properties.Recent.Default.RecentRegion = form.comboBoxRegion.Text;
//
StartProcessing();
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(bw_ArmoryGetCharacter);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_ArmoryGetCharacterComplete);