-
-
Notifications
You must be signed in to change notification settings - Fork 250
/
Copy pathForm1.cs
4115 lines (3567 loc) · 183 KB
/
Form1.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 ARKBreedingStats.importExported;
using ARKBreedingStats.library;
using ARKBreedingStats.Library;
using ARKBreedingStats.ocr;
using ARKBreedingStats.settings;
using ARKBreedingStats.species;
using ARKBreedingStats.uiControls;
using ARKBreedingStats.values;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Windows.Forms;
using ARKBreedingStats.mods;
using ARKBreedingStats.NamePatterns;
using ARKBreedingStats.StatsOptions;
using ARKBreedingStats.StatsOptions.TopStatsSettings;
using ARKBreedingStats.utils;
using static ARKBreedingStats.settings.Settings;
using Color = System.Drawing.Color;
using static ARKBreedingStats.uiControls.StatWeighting;
namespace ARKBreedingStats
{
public partial class Form1 : Form
{
private CreatureCollection _creatureCollection = new CreatureCollection();
private string _currentFilePath;
private bool _collectionDirty;
/// <summary>
/// List of all top stats per species
/// </summary>
private readonly Dictionary<Species, TopLevels> _topLevels = new Dictionary<Species, TopLevels>();
private readonly StatIO[] _statIOs = new StatIO[Stats.StatsCount];
private readonly StatIO[] _testingIOs = new StatIO[Stats.StatsCount];
private int _activeStatIndex = -1;
/// <summary>
/// stats used by the creature (some don't use oxygen)
/// </summary>
private readonly bool[] _activeStats = Enumerable.Repeat(true, Stats.StatsCount).ToArray();
private bool _libraryNeedsUpdate;
public delegate void
CollectionChangedEventHandler(bool changed = true,
Species species = null, // if null is passed for species, breeding-related controls are not updated
bool triggeredByFileWatcher = false);
public delegate void SetMessageLabelTextEventHandler(string text = null, MessageBoxIcon icon = MessageBoxIcon.None,
string path = null, string clipboardContent = null, bool displayPopup = false, string customPopupMessage = null);
private bool _updateTorporInTester;
private bool _filterListAllowed;
private DateTime _lastAutoSaveBackup;
private Creature _creatureTesterEdit;
private int _hiddenLevelsCreatureTester;
private FileSync _fileSync;
private FileWatcherExports _fileWatcherExports;
private readonly Extraction _extractor = new Extraction();
private SpeechRecognition _speechRecognition;
private readonly Timer _timerGlobal = new Timer();
private ExportedCreatureList _exportedCreatureList;
private ExportedCreatureControl _exportedCreatureControl;
private readonly ToolTip _tt;
private bool _reactOnCreatureSelectionChange;
private bool _clearExtractionCreatureData;
/// <summary>
/// The last tab-page opened in the settings.
/// </summary>
private SettingsTabPages _settingsLastTabPage;
/// <summary>
/// Custom replacings for species names used in naming patterns.
/// </summary>
private Dictionary<string, string> _customReplacingNamingPattern;
/// <summary>
/// Some species can have specific issues when extracting.
/// </summary>
private readonly Dictionary<string, string> _speciesSpecificExtractionFails
= FileService.LoadJsonFileIfAvailable<Dictionary<string, string>>(FileService.GetJsonPath("speciesSpecificExtractionFails.json"));
// OCR stuff
private ARKOverlay _overlay;
private static double[] _lastOcrValues;
private Species _lastOcrSpecies;
internal static readonly StatsOptionsSettings<StatLevelColors> StatsOptionsLevelColors = new StatsOptionsSettings<StatLevelColors>("statsLevelColors.json", "Level colors");
internal static readonly StatsOptionsSettings<ConsiderTopStats> StatsOptionsConsiderTopStats = new StatsOptionsSettings<ConsiderTopStats>("statsTopStats.json", "Consider for top stats");
public Form1()
{
// load settings of older version if possible after an upgrade
if (Properties.Settings.Default.UpgradeRequired)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
Properties.Settings.Default.UpgradeRequired = false;
Properties.Settings.Default.Save();
}
// #if DEBUG
// Properties.Settings.Default.Reset();
// #endif
_tt = new ToolTip();
InitLocalization();
InitializeComponent();
// Create an instance of a ListView column sorter and assign it
// to the ListView controls
listViewPossibilities.ListViewItemSorter = new ListViewColumnSorter();
timerList1.ColumnSorter = new ListViewColumnSorter();
listViewLibrary.DoubleBuffered(true);
toolStripStatusLabel.Text = Application.ProductVersion;
// delegates
pedigree1.EditCreature += EditCreatureInTester;
pedigree1.BestBreedingPartners += ShowBestBreedingPartner;
breedingPlan1.EditCreature += EditCreatureInTester;
breedingPlan1.DisplayInPedigree += DisplayCreatureInPedigree;
breedingPlan1.CreateIncubationTimer += CreateIncubationTimer;
breedingPlan1.BestBreedingPartners += ShowBestBreedingPartner;
breedingPlan1.SetGlobalSpecies += SetSpecies;
breedingPlan1.SetMessageLabelText += SetMessageLabelText;
creatureInfoInputExtractor.SetMessageLabelText += SetMessageLabelText;
creatureInfoInputTester.SetMessageLabelText += SetMessageLabelText;
statsMultiplierTesting1.SetMessageLabelText += SetMessageLabelText;
timerList1.OnTimerChange += SetCollectionChanged;
timerList1.TimerAddedRemoved += EnableGlobalTimerIfNeeded;
breedingPlan1.BindChildrenControlEvents();
raisingControl1.onChange += SetCollectionChanged;
tamingControl1.CreateTimer += CreateTimer;
raisingControl1.ExtractBaby += ExtractBaby;
raisingControl1.SetGlobalSpecies += SetSpecies;
raisingControl1.timerControl = timerList1;
raisingControl1.TimerAddedRemoved += EnableGlobalTimerIfNeeded;
notesControl1.changed += SetCollectionChanged;
creatureInfoInputExtractor.CreatureDataRequested += CreatureInfoInput_CreatureDataRequested;
creatureInfoInputTester.CreatureDataRequested += CreatureInfoInput_CreatureDataRequested;
creatureInfoInputExtractor.ColorsChanged += CreatureInfoInputColorsChanged;
creatureInfoInputTester.ColorsChanged += CreatureInfoInputColorsChanged;
speciesSelector1.OnSpeciesSelected += SpeciesSelector1OnSpeciesSelected;
speciesSelector1.ToggleVisibility += ToggleViewSpeciesSelector;
statsMultiplierTesting1.OnApplyMultipliers += StatsMultiplierTesting1_OnApplyMultipliers;
raisingControl1.AdjustTimersByOffset += timerList1.AdjustAllTimersByOffset;
listViewLibrary.VirtualMode = true;
listViewLibrary.RetrieveVirtualItem += ListViewLibrary_RetrieveVirtualItem;
listViewLibrary.CacheVirtualItems += ListViewLibrary_CacheVirtualItems;
listViewLibrary.OwnerDraw = true;
listViewLibrary.DrawItem += ListViewLibrary_DrawItem;
listViewLibrary.DrawColumnHeader += (sender, args) => args.DrawDefault = true;
listViewLibrary.DrawSubItem += ListViewLibrary_DrawSubItem;
speciesSelector1.SetTextBox(tbSpeciesGlobal);
ArkOcr.Ocr.SetOcrControl(ocrControl1);
ocrControl1.UpdateWhiteThreshold += OcrUpdateWhiteThreshold;
ocrControl1.DoOcr += DoOcr;
ocrControl1.OcrLabelSetsChanged += InitializeOcrLabelSets;
ocrControl1.OcrLabelSelectedSetChanged += SetCurrentOcrLabelSet;
StatsOptionsLevelColors.SettingsChanged += StatsOptionsLevelColorsSettingsChanged;
openSettingsToolStripMenuItem.ShortcutKeyDisplayString = new KeysConverter()
.ConvertTo(Keys.Control, typeof(string))?.ToString().Replace("None", ",");
for (int s = 0; s < Stats.StatsCount; s++)
{
var statIo = new StatIO
{
InputType = StatIOInputType.FinalValueInputType,
Title = Utils.StatName(s),
statIndex = s
};
var statIoTesting = new StatIO
{
InputType = StatIOInputType.LevelsInputType,
Title = Utils.StatName(s),
statIndex = s
};
if (Stats.IsPercentage(s))
{
statIo.Percent = true;
statIoTesting.Percent = true;
}
statIoTesting.LevelChanged += TestingStatIoValueUpdate;
statIo.InputValueChanged += StatIOQuickWildLevelCheck;
statIo.LevelChanged += ExtractorStatLevelChanged;
statIo.Click += StatIO_Click;
_statIOs[s] = statIo;
_testingIOs[s] = statIoTesting;
}
// add controls in the order they are shown in-game
foreach (var si in Stats.DisplayOrder)
{
flowLayoutPanelStatIOsExtractor.Controls.Add(_statIOs[si]);
flowLayoutPanelStatIOsTester.Controls.Add(_testingIOs[si]);
}
_timerGlobal.Interval = 1000;
_timerGlobal.Tick += TimerGlobal_Tick;
ReloadNamePatternCustomReplacings();
lbTesterWildLevel.ContextMenu = new ContextMenu(new[] { new MenuItem("Set random wild levels", SetRandomWildLevels) });
// name patterns menu entries
const int namePatternCount = 6;
var namePatternMenuItems = new ToolStripMenuItem[namePatternCount];
var libraryContextMenuItems = new ToolStripMenuItem[namePatternCount];
for (int i = 0; i < namePatternCount; i++)
{
var displayedPatternIndex = i + 1;
var mi = new ToolStripMenuItem { Text = $"Pattern {displayedPatternIndex}{(i == 0 ? " (used for auto import)" : string.Empty)}", Tag = i };
mi.Click += MenuOpenNamePattern;
namePatternMenuItems[i] = mi;
// library context menu
mi = new ToolStripMenuItem { Text = $"Pattern {i + 1} (NumPad{displayedPatternIndex})", Tag = i };
mi.Click += GenerateCreatureNames;
libraryContextMenuItems[i] = mi;
}
libraryContextMenuItems[0].ShortcutKeys = Keys.Control | Keys.G;
var libraryContextMenuMaturitySettings = new[] { 0, 0.05, 0.1, 0.25, 0.5, 0.75, 1 };
foreach (var m in libraryContextMenuMaturitySettings)
{
var suffix = m < 0.1 ? "baby" : m < 1 ? "juvenile" : "mature";
var tsmi = new ToolStripMenuItem($"Set maturity to {m:p0} ({suffix})", null, SetMaturityToolStripMenuItem_Click);
tsmi.Tag = m;
SetMaturityCooldownToolStripMenuItem.DropDownItems.Add(tsmi);
}
nameGeneratorToolStripMenuItem.DropDownItems.AddRange(namePatternMenuItems);
toolStripMenuItemGenerateCreatureName.DropDownItems.AddRange(libraryContextMenuItems);
var copyTopCreatureStatsToClipboardMenuItem = new ToolStripMenuItem("Copy library top stats to clipboard");
copyTopCreatureStatsToClipboardMenuItem.Click += CopyTopCreatureStatsToClipboard;
editToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator());
editToolStripMenuItem.DropDownItems.Add(copyTopCreatureStatsToClipboardMenuItem);
listBoxSpeciesLib.SupportSeparatorLines();
_reactOnCreatureSelectionChange = true;
}
private void Form1_Load(object sender, EventArgs e)
{
SetLocalizations(false);
// load window-position and size
Utils.SetWindowRectangle(this, Properties.Settings.Default.MainWindowRect,
Properties.Settings.Default.MainWindowMaximized);
LoadAppSettings();
// torpor should not show bar, it gets too wide and is not interesting for breeding
_statIOs[Stats.Torpidity].ShowBarAndLock = false;
_testingIOs[Stats.Torpidity].ShowBarAndLock = false;
// move sums and footnote to bottom
flowLayoutPanelStatIOsExtractor.Controls.Add(panelSums);
flowLayoutPanelStatIOsExtractor.Controls.Add(labelFootnote);
flowLayoutPanelStatIOsTester.Controls.Add(panelStatTesterFootnote);
// enable 0-lock for dom-levels of oxygen, food (most often they are not leveled up)
_statIOs[Stats.Oxygen].DomLevelLockedZero = true;
_statIOs[Stats.Food].DomLevelLockedZero = true;
LbWarningLevel255.Visible = false;
InitializeCollection();
CreatureColored.InitializeSpeciesImageLocation();
if (!LoadStatAndKibbleValues(false).statValuesLoaded || !Values.V.species.Any())
{
MessageBoxes.ShowMessageBox(Loc.S("valuesFileLoadingError"),
$"{Loc.S("error")}: Values-file not found");
Environment.Exit(1);
}
statsMultiplierTesting1.SetGameDefaultMultiplier();
for (int s = 0; s < Stats.StatsCount; s++)
{
_statIOs[s].Input = 0;
}
creatureInfoInputTester.PbColorRegion = pictureBoxColorRegionsTester;
creatureInfoInputExtractor.PbColorRegion = PbCreatureColorsExtractor;
creatureInfoInputExtractor.ParentInheritance = parentInheritanceExtractor;
parentInheritanceExtractor.Visible = false;
// set last species
speciesSelector1.LastSpecies = Properties.Settings.Default.lastSpecies;
if (Properties.Settings.Default.lastSpecies?.Any() == true)
{
speciesSelector1.SetSpecies(Values.V.SpeciesByBlueprint(Properties.Settings.Default.lastSpecies[0]));
}
if (speciesSelector1.SelectedSpecies == null && Values.V.species.Any())
speciesSelector1.SetSpecies(Values.V.species[0]);
tamingControl1.SetSpecies(speciesSelector1.SelectedSpecies);
// OCR
ocrControl1.Initialize();
InitializeOcrLabelSets();
// initialize speech recognition if enabled
InitializeSpeechRecognition();
// UI loaded
// set theme colors
//this.InitializeTabControls();
//this.SetColors(Color.FromArgb(20, 20, 20), Color.LightGray);
//// initialize controls
extractionTestControl1.CopyToExtractor += ExtractionTestControl1_CopyToExtractor;
extractionTestControl1.CopyToTester += ExtractionTestControl1_CopyToTester;
// dev tabs
if (!Properties.Settings.Default.DevTools)
{
tabControlMain.TabPages.Remove(tabPageExtractionTests);
tabControlMain.TabPages.Remove(tabPageMultiplierTesting);
devToolStripMenuItem.Visible = false;
sendExampleCreatureToolStripMenuItem.Visible = false;
sendServerCreatureStatusNeuterToolStripMenuItem.Visible = false;
sendServerCreatureStatusDeadToolStripMenuItem.Visible = false;
cbExactlyImprinting.Visible = false;
}
else
{
extractionTestControl1.LoadExtractionTestCases(Properties.Settings.Default.LastSaveFileTestCases);
}
// set TLS-protocol (github needs at least TLS 1.2) for update-check
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
// check for updates
if (DateTime.Now.AddHours(-20) > Properties.Settings.Default.lastUpdateCheck)
{
bool selectDefaultImagesIfNotYet = false;
bool initializeImages = false;
if (!Properties.Settings.Default.AlreadyAskedToDownloadSpeciesImageFiles)
{
Properties.Settings.Default.AlreadyAskedToDownloadSpeciesImageFiles = true;
if (Updater.Updater.IsProgramInstalled)
initializeImages = true;
else
selectDefaultImagesIfNotYet = true;
}
CheckForUpdates(true, selectDefaultImagesIfNotYet, initializeImages);
}
RemoveNonExistingFilesInRecentlyUsedFiles();
_filterListAllowed = true;
// load last loaded file
bool createNewCollection = string.IsNullOrEmpty(Properties.Settings.Default.LastSaveFile);
if (!createNewCollection)
{
// if the last loaded file was already converted by someone else (e.g. if the library-file is shared),
// ask if the converted version should be loaded instead.
if (Path.GetExtension(Properties.Settings.Default.LastSaveFile).ToLower() == ".xml")
{
string possibleConvertedCollectionPath = Path.Combine(
Path.GetDirectoryName(Properties.Settings.Default.LastSaveFile),
Path.GetFileNameWithoutExtension(Properties.Settings.Default.LastSaveFile) +
CollectionFileExtension);
if (File.Exists(possibleConvertedCollectionPath)
&& MessageBox.Show(
"The creature collection file seems to be already converted to the new file format.\n"
+ "Path of the collection file:\n" + Properties.Settings.Default.LastSaveFile
+ "\n\nIf you click No, the old file-version will be loaded and then automatically converted."
+ "\nIt is recommended to load the already converted version to avoid synchronisation-issues."
+ "\nDo you want to load the converted version?", "Library seems to be already converted",
MessageBoxButtons.YesNo, MessageBoxIcon.Question
) == DialogResult.Yes)
{
Properties.Settings.Default.LastSaveFile = possibleConvertedCollectionPath;
}
}
// load last save file:
if (!LoadCollectionFile(Properties.Settings.Default.LastSaveFile))
createNewCollection = true;
}
if (createNewCollection)
{
NewCollection();
UpdateRecentlyUsedFileMenu();
}
UpdateAsaIndicator();
if (Properties.Settings.Default.BeginServerListeningOnLaunch)
{
AsbServerStartListening();
listenToolStripMenuItem.Checked = true;
}
}
private void LoadAppSettings()
{
// the eol is changed during the loading of the settings, the \r is removed. re-add it.
var namingPatterns = Properties.Settings.Default.NamingPatterns;
if (namingPatterns != null)
{
for (int i = 0; i < namingPatterns.Length; i++)
{
if (!string.IsNullOrEmpty(namingPatterns[i]))
namingPatterns[i] = namingPatterns[i].Replace("\r", string.Empty).Replace("\n", "\r\n");
}
}
UpdatePatternButtons();
// Load column-widths, display-indices and sort-order of the TimerControlListView
LoadListViewSettings(timerList1.ListViewTimers, nameof(Properties.Settings.Default.TCLVColumnWidths),
nameof(Properties.Settings.Default.TCLVColumnDisplayIndices),
nameof(Properties.Settings.Default.TCLVSortCol), nameof(Properties.Settings.Default.TCLVSortAsc));
if (Properties.Settings.Default.PedigreeWidthLeftColum > 20)
pedigree1.LeftColumnWidth = Properties.Settings.Default.PedigreeWidthLeftColum;
LoadListViewSettings(pedigree1.ListViewCreatures, nameof(Properties.Settings.Default.PedigreeListViewColumnWidths));
// Load column-widths, display-indices and sort-order of the listViewLibrary
// new columns were added, reset widths and order, old settings don't match the new indices
if ((Properties.Settings.Default.columnWidths?.Length ?? 0) < 40)
{
resetColumnOrderToolStripMenuItem_Click(null, null);
toolStripMenuItemResetLibraryColumnWidths_Click(null, null);
}
else
LoadListViewSettings(listViewLibrary, nameof(Properties.Settings.Default.columnWidths), nameof(Properties.Settings.Default.libraryColumnDisplayIndices));
if (Properties.Settings.Default.LibraryShowMutationLevelColumns)
toolStripMenuItemMutationColumns.Checked = true;
else
ToggleLibraryMutationLevelColumns(false);
_creatureListSorter.SortColumnIndex = Properties.Settings.Default.listViewSortCol;
_creatureListSorter.Order = Properties.Settings.Default.listViewSortAsc
? SortOrder.Ascending
: SortOrder.Descending;
LoadListViewSettings(tribesControl1.ListViewPlayers, nameof(Properties.Settings.Default.PlayerListColumnWidths), nameof(Properties.Settings.Default.PlayerListColumnDisplayIndices),
nameof(Properties.Settings.Default.PlayerListSortColumn), nameof(Properties.Settings.Default.PlayerListSortAsc));
_creatureListSorter.UseNaturalSort = Properties.Settings.Default.UseNaturalSort;
_creatureListSorter.IgnoreSpacesBetweenWords = Properties.Settings.Default.NaturalSortIgnoreSpaces;
CbLibraryInfoUseFilter.Checked = Properties.Settings.Default.LibraryColorInfoUseFilter;
showTokenPopupOnListeningToolStripMenuItem.Checked = Properties.Settings.Default.DisplayPopupForServerToken;
beginListeningToExportGunOnLaunchToolStripMenuItem.Checked = Properties.Settings.Default.BeginServerListeningOnLaunch;
// load stat weights
double[][] custWd = Properties.Settings.Default.customStatWeights;
var customStatWeightsOddEven = Properties.Settings.Default.CustomStatWeightsOddEven;
// backwards compatibility
var customStatWeightOddEven = Properties.Settings.Default.CustomStatWeightOddEven;
if (customStatWeightOddEven != null)
{
customStatWeightsOddEven = new StatValueEvenOdd[customStatWeightOddEven.Length][];
for (var i = 0; i < customStatWeightOddEven.Length; i++)
{
customStatWeightsOddEven[i] = customStatWeightOddEven[i].Select(w =>
w == 1 ? StatValueEvenOdd.Odd :
w == 2 ? StatValueEvenOdd.Even : StatValueEvenOdd.Indifferent)
.ToArray();
}
customStatWeightOddEven = null;
Properties.Settings.Default.CustomStatWeightOddEven = null;
}
string[] custWs = Properties.Settings.Default.customStatWeightNames;
var custW = new Dictionary<string, (double[], StatValueEvenOdd[])>();
if (custWs != null && custWd != null)
{
for (int i = 0; i < custWs.Length && i < custWd.Length && i < customStatWeightsOddEven.Length; i++)
{
custW.Add(custWs[i], (custWd[i], customStatWeightsOddEven[i]));
}
}
breedingPlan1.StatWeighting.CustomWeightings = custW;
// last set values are saved at the end of the custom weightings
if (custWs != null && custWd != null && custWd.Length > custWs.Length)
breedingPlan1.StatWeighting.WeightValues = custWd[custWs.Length];
if (custWs != null && customStatWeightOddEven != null && customStatWeightOddEven.Length > custWs.Length)
breedingPlan1.StatWeighting.AnyOddEven = customStatWeightsOddEven[custWs.Length];
// load weapon damages
tamingControl1.WeaponDamages = Properties.Settings.Default.weaponDamages;
tamingControl1.WeaponDamagesEnabled = Properties.Settings.Default.weaponDamagesEnabled;
breedingPlan1.MutationLimit = Properties.Settings.Default.MutationLimitBreedingPlanner;
cbGuessSpecies.Checked = Properties.Settings.Default.OcrGuessSpecies;
// default owner and tribe
creatureInfoInputExtractor.CreatureOwner = Properties.Settings.Default.DefaultOwnerName;
creatureInfoInputExtractor.CreatureTribe = Properties.Settings.Default.DefaultTribeName;
creatureInfoInputExtractor.CreatureServer = Properties.Settings.Default.DefaultServerName;
creatureInfoInputExtractor.OwnerLock = Properties.Settings.Default.OwnerNameLocked;
creatureInfoInputExtractor.TribeLock = Properties.Settings.Default.TribeNameLocked;
creatureInfoInputExtractor.LockServer = Properties.Settings.Default.ServerNameLocked;
CbLinkWildMutatedLevelsTester.Checked = Properties.Settings.Default.TesterLinkWildMutatedLevels;
// if no export folder is set, try to detect it
if ((Properties.Settings.Default.ExportCreatureFolders == null
|| Properties.Settings.Default.ExportCreatureFolders.Length == 0)
&& ArkInstallationPath.GetListOfExportFolders(
out (string path, string steamPlayerName)[] arkInstallFolders, out _))
{
var orderedList = ArkInstallationPath.OrderByNewestFileInFolders(arkInstallFolders.Select(l => (l.path, l)));
Properties.Settings.Default.ExportCreatureFolders = orderedList
.Select(f => $"{f.steamPlayerName}||{f.path}").ToArray();
}
var filterPresets = Properties.Settings.Default.LibraryFilterPresets;
if (filterPresets != null)
{
ToolStripTextBoxLibraryFilter.AutoCompleteCustomSource.Clear();
ToolStripTextBoxLibraryFilter.AutoCompleteCustomSource.AddRange(filterPresets);
}
timerList1.SetTimerPresets(Properties.Settings.Default.TimerPresets);
SetupAutoLoadFileWatcher();
SetupExportFileWatcher();
}
/// <summary>
/// If the according property is set, the speechRecognition is initialized. Else it's disposed.
/// </summary>
private void InitializeSpeechRecognition()
{
bool speechRecognitionInitialized = false;
if (Properties.Settings.Default.SpeechRecognition)
{
try
{
_speechRecognition = new SpeechRecognition(_creatureCollection.maxWildLevel,
_creatureCollection.considerWildLevelSteps ? _creatureCollection.wildLevelStep : 1,
Values.V.speciesWithAliasesList, lbListening);
if (_speechRecognition.Initialized)
{
speechRecognitionInitialized = true;
_speechRecognition.SpeechCreatureRecognized += TellTamingData;
_speechRecognition.SpeechCommandRecognized += SpeechCommand;
lbListening.Visible = true;
}
else
{
Properties.Settings.Default.SpeechRecognition = false;
}
}
catch (PlatformNotSupportedException ex)
{
MessageBoxes.ExceptionMessageBox(ex,
"The speech recognition could not be initialized on this system.");
}
}
if (!speechRecognitionInitialized)
{
_speechRecognition?.Dispose();
_speechRecognition = null;
lbListening.Visible = false;
}
}
private void SetSpecies(Species species)
{
speciesSelector1.SetSpecies(species);
}
private void TellTamingData(string speciesName, int level)
{
speciesSelector1.SetSpeciesByName(speciesName);
if (speciesSelector1.SelectedSpecies?.taming?.eats?.Any() == true)
{
tamingControl1.SetLevel(level, false);
tamingControl1.SetSpecies(speciesSelector1.SelectedSpecies);
_overlay?.SetInfoText($"{speciesName} ({Loc.S("Level")} {level}):\n{tamingControl1.quickTamingInfos}");
}
}
private void SpeechCommand(SpeechRecognition.Commands command)
{
// currently this command does not exist, accidental execution occurred too often
if (command == SpeechRecognition.Commands.Extract)
DoOcr();
}
private void radioButtonWild_CheckedChanged(object sender, EventArgs e)
{
if (rbWildExtractor.Checked)
UpdateExtractorDetails();
}
private void radioButtonTamed_CheckedChanged(object sender, EventArgs e)
{
if (rbTamedExtractor.Checked)
UpdateExtractorDetails();
}
private void radioButtonBred_CheckedChanged(object sender, EventArgs e)
{
if (rbBredExtractor.Checked)
UpdateExtractorDetails();
}
private void radioButtonTesterWild_CheckedChanged(object sender, EventArgs e)
{
if (rbWildTester.Checked)
UpdateTesterDetails();
}
private void radioButtonTesterTamed_CheckedChanged(object sender, EventArgs e)
{
if (rbTamedTester.Checked)
UpdateTesterDetails();
lbWildLevelTester.Visible = rbTamedTester.Checked;
}
private void radioButtonTesterBred_CheckedChanged(object sender, EventArgs e)
{
if (rbBredTester.Checked)
UpdateTesterDetails();
}
private void StatIO_Click(object sender, EventArgs e)
{
StatIO se = (StatIO)sender;
if (se != null)
{
SetActiveStat(se.statIndex);
}
}
private void tbSpeciesGlobal_Click(object sender, EventArgs e)
{
ToggleViewSpeciesSelector(true);
}
private void tbSpeciesGlobal_Enter(object sender, EventArgs e)
{
ToggleViewSpeciesSelector(true);
}
private void pbSpecies_Click(object sender, EventArgs e)
{
if (tabControlMain.Visible)
{
if (tbSpeciesGlobal.Focused)
pbSpecies.Focus();
tbSpeciesGlobal.Focus();
}
else
{
ToggleViewSpeciesSelector(false);
}
}
private void ToggleViewSpeciesSelector(bool showSpeciesSelector)
{
tabControlMain.Visible = !showSpeciesSelector;
speciesSelector1.Visible = showSpeciesSelector;
}
private void TbSpeciesGlobal_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode != Keys.Enter && e.KeyCode != Keys.Tab) return;
if (speciesSelector1.SetSpeciesByEntryName(tbSpeciesGlobal.Text))
ToggleViewSpeciesSelector(false);
}
// global species changed / globalspecieschanged
private void SpeciesSelector1OnSpeciesSelected(bool speciesChanged)
{
Species species = speciesSelector1.SelectedSpecies;
ToggleViewSpeciesSelector(false);
tbSpeciesGlobal.Text = species.name;
LbBlueprintPath.Text = species.blueprintPath;
if (!speciesChanged) return;
// as soon as the user changes the species, it's assumed it's not an exported creature anymore
_clearExtractionCreatureData = true;
pbSpecies.Image = speciesSelector1.SpeciesImage();
creatureInfoInputExtractor.SelectedSpecies = species;
creatureInfoInputTester.SelectedSpecies = species;
radarChart1.SetLevels(species: species);
var statNames = species.statNames;
var levelGraphRepresentations = StatsOptionsLevelColors.GetStatsOptions(species);
for (int s = 0; s < Stats.StatsCount; s++)
{
_activeStats[s] = Properties.Settings.Default.DisplayHiddenStats
? species.UsesStat(s)
: species.DisplaysStat(s);
_statIOs[s].IsActive = _activeStats[s];
_statIOs[s].Visible = species.UsesStat(s);
if (species.UsesStat(s))
{
_testingIOs[s].Visible = true;
}
else
{
_testingIOs[s].Visible = false;
_testingIOs[s].LevelWild = 0;
_testingIOs[s].LevelMut = 0;
_testingIOs[s].LevelDom = 0;
}
if (!_activeStats[s]) _statIOs[s].Input = 0;
_statIOs[s].Title = Utils.StatName(s, false, statNames);
_testingIOs[s].Title = Utils.StatName(s, false, statNames);
_statIOs[s].SetStatOptions(levelGraphRepresentations.StatOptions[s]);
_testingIOs[s].SetStatOptions(levelGraphRepresentations.StatOptions[s]);
// don't lock special stats of glow species
if ((statNames != null &&
(s == Stats.Stamina
|| s == Stats.Oxygen
|| s == Stats.MeleeDamageMultiplier)
)
|| (species.name.Contains("Daeodon")
&& s == Stats.Food
)
)
{
_statIOs[s].DomLevelLockedZero = false;
}
}
if (tabControlMain.SelectedTab == tabPageExtractor)
{
ClearAll();
// warn if a species selected that has a possible mod variant
if ((species.Mod == null || species.Mod.expansion)
&& Values.V.TryGetSpeciesByName(species.name, out var modSpecies)
&& modSpecies.Mod?.expansion == false
)
{
SetMessageLabelText(
$"The selected species \"{species}\" is not from a mod, but there is a variant of that species that appears in the loaded mod \"{modSpecies.Mod.title}\". Probably you want to select the mod variant",
MessageBoxIcon.Warning);
}
}
else if (tabControlMain.SelectedTab == tabPageStatTesting)
{
UpdateAllTesterValues();
statPotentials1.Species = species;
statPotentials1.SetLevels(_testingIOs.Select(s => s.LevelWild).ToArray(), _testingIOs.Select(s => s.LevelMut).ToArray(), true);
SetInfoInputCreature();
}
else if (tabControlMain.SelectedTab == tabPageLibrary)
{
if (Properties.Settings.Default.ApplyGlobalSpeciesToLibrary)
listBoxSpeciesLib.SelectedItem = species;
}
else if (tabControlMain.SelectedTab == tabPageLibraryInfo)
{
LibraryInfo.SetColorInfo(speciesSelector1.SelectedSpecies, CbLibraryInfoUseFilter.Checked ? (IList<Creature>)ApplyLibraryFilterSettings(_creatureCollection.creatures).ToArray() : _creatureCollection.creatures, CbLibraryInfoUseFilter.Checked, libraryInfoControl1.TlpColorInfoText);
libraryInfoControl1.SetSpecies(speciesSelector1.SelectedSpecies);
}
else if (tabControlMain.SelectedTab == tabPagePedigree)
{
pedigree1.SetSpecies(species);
}
else if (tabControlMain.SelectedTab == tabPageTaming)
{
tamingControl1.SetSpecies(species);
}
else if (tabControlMain.SelectedTab == tabPageRaising)
{
raisingControl1.UpdateRaisingData(species);
}
else if (tabControlMain.SelectedTab == tabPageMultiplierTesting)
{
statsMultiplierTesting1.SetSpecies(species);
}
else if (tabControlMain.SelectedTab == tabPageBreedingPlan)
{
if (breedingPlan1.CurrentSpecies == species)
breedingPlan1.UpdateIfNeeded();
else
{
breedingPlan1.SetSpecies(species);
}
}
hatching1.SetSpecies(species, _topLevels.TryGetValue(species, out var tl) ? tl : null);
_hiddenLevelsCreatureTester = 0;
_tt.SetToolTip(tbSpeciesGlobal, species.DescriptiveNameAndMod + "\n" + species.blueprintPath);
}
/// <summary>
/// Applies the level color settings to the stat controls. Call if a species setting was added or removed.
/// </summary>
private void StatsOptionsLevelColorsSettingsChanged()
{
var levelGraphRepresentations = StatsOptionsLevelColors.GetStatsOptions(speciesSelector1.SelectedSpecies);
if (levelGraphRepresentations == null) return;
for (int s = 0; s < Stats.StatsCount; s++)
{
_statIOs[s].SetStatOptions(levelGraphRepresentations.StatOptions[s]);
_testingIOs[s].SetStatOptions(levelGraphRepresentations.StatOptions[s]);
}
}
private void numericUpDown_Enter(object sender, EventArgs e)
{
NumericUpDown n = (NumericUpDown)sender;
n?.Select(0, n.Text.Length);
}
/// <summary>
/// Recalculate cached values affected by global stat-multipliers.
/// </summary>
private void ApplySettingsToValues()
{
if (_creatureCollection.serverMultipliers == null)
return; // nothing to apply from, settings are loaded soon, then applied
// apply multipliers
Values.V.ApplyMultipliers(_creatureCollection, cbEventMultipliers.Checked);
tamingControl1.SetServerMultipliers(Values.V.currentServerMultipliers);
ColorModeColors.SetColors((ColorModeColors.AsbColorMode)Properties.Settings.Default.ColorMode);
RecalculateAllCreaturesValues();
breedingPlan1.UpdateBreedingData();
raisingControl1.UpdateRaisingData();
// apply level settings
creatureBoxListView.CreatureCollection = _creatureCollection;
for (int s = 0; s < Stats.StatsCount; s++)
{
_statIOs[s].barMaxLevel = _creatureCollection.maxChartLevel;
_testingIOs[s].barMaxLevel = _creatureCollection.maxChartLevel;
}
breedingPlan1.MaxWildLevels = _creatureCollection.maxWildLevel;
radarChart1.InitializeVariables(_creatureCollection.maxChartLevel);
radarChartExtractor.InitializeVariables(_creatureCollection.maxChartLevel);
radarChartLibrary.InitializeVariables(_creatureCollection.maxChartLevel);
statPotentials1.LevelDomMax = _creatureCollection.maxDomLevel;
statPotentials1.LevelGraphMax = _creatureCollection.maxChartLevel;
try
{
_speechRecognition?.SetMaxLevelAndSpecies(_creatureCollection.maxWildLevel,
_creatureCollection.considerWildLevelSteps ? _creatureCollection.wildLevelStep : 1,
Values.V.speciesWithAliasesList);
}
catch (Exception ex)
{
// rarely GrammarBuilder System.Speech.Internal.SrgsParser.XmlParser raised System.FormatException: 'one-of' must contain at least one 'item' element occured
MessageBoxes.ExceptionMessageBox(ex);
}
if (_overlay != null)
{
_overlay.InfoDuration = Properties.Settings.Default.OverlayInfoDuration;
_overlay.checkInventoryStats = Properties.Settings.Default.inventoryCheckTimer;
}
ArkOcr.Ocr.screenCaptureApplicationName = Properties.Settings.Default.OCRApp;
if (Properties.Settings.Default.showOCRButton)
{
Loc.ControlText(btReadValuesFromArk, _tt);
}
else
{
btReadValuesFromArk.Text = "Import Exported Data";
_tt.SetToolTip(btReadValuesFromArk,
"Displays all exported creatures in the default-folder (needs to be set in the settings).");
}
ArkOcr.Ocr.waitBeforeScreenCapture = Properties.Settings.Default.waitBeforeScreenCapture;
ocrControl1.SetWhiteThreshold(Properties.Settings.Default.OCRWhiteThreshold);
int maxImprintingPercentage = _creatureCollection.allowMoreThanHundredImprinting ? 100000 : 100;
numericUpDownImprintingBonusExtractor.Maximum = maxImprintingPercentage;
numericUpDownImprintingBonusTester.Maximum = maxImprintingPercentage;
// sound-files
timerList1.sounds = new[]
{
File.Exists(Properties.Settings.Default.soundStarving)
? new System.Media.SoundPlayer(Properties.Settings.Default.soundStarving)
: null,
File.Exists(Properties.Settings.Default.soundWakeup)
? new System.Media.SoundPlayer(Properties.Settings.Default.soundWakeup)
: null,
File.Exists(Properties.Settings.Default.soundBirth)
? new System.Media.SoundPlayer(Properties.Settings.Default.soundBirth)
: null,
File.Exists(Properties.Settings.Default.soundCustom)
? new System.Media.SoundPlayer(Properties.Settings.Default.soundCustom)
: null
};
timerList1.TimerAlertsCSV = Properties.Settings.Default.playAlarmTimes;
ClearAll();
// update enabled stats
for (int s = 0; s < Stats.StatsCount; s++)
{
_activeStats[s] = speciesSelector1.SelectedSpecies == null
? (Species.displayedStatsDefault & 1 << s) != 0
: Properties.Settings.Default.DisplayHiddenStats
? speciesSelector1.SelectedSpecies.UsesStat(s)
: speciesSelector1.SelectedSpecies.DisplaysStat(s);
_statIOs[s].IsActive = _activeStats[s];
if (!_activeStats[s]) _statIOs[s].Input = 0;
}
if (tabControlMain.SelectedTab == tabPageStatTesting)
{
UpdateAllTesterValues();
}
CreateImportExportedMenu();
CreateSavegameImportMenu();
}
private void CreateSavegameImportMenu()
{
importingFromSavegameToolStripMenuItem.DropDownItems.Clear();
if (Properties.Settings.Default.arkSavegamePaths?.Any() != true)
{
TsbQuickSaveGameImport.ToolTipText = "No quick import save files configured,\nyou can do this in the settings.";
}
else
{
var quickImportInfo = new List<string>();
foreach (string f in Properties.Settings.Default.arkSavegamePaths)
{
ATImportFileLocation atImportFileLocation = ATImportFileLocation.CreateFromString(f);
string menuItemHeader = string.IsNullOrEmpty(atImportFileLocation.ConvenientName)
? Utils.ShortPath(atImportFileLocation.FileLocation)
: atImportFileLocation.ConvenientName;
ToolStripMenuItem tsmi = new ToolStripMenuItem(menuItemHeader)
{
Tag = atImportFileLocation,
ToolTipText = atImportFileLocation.FileLocation
};
tsmi.Click += SavegameImportClick;
importingFromSavegameToolStripMenuItem.DropDownItems.Add(tsmi);
if (atImportFileLocation.ImportWithQuickImport)
quickImportInfo.Add($"{atImportFileLocation.ConvenientName} ({atImportFileLocation.FileLocation})");
}
TsbQuickSaveGameImport.ToolTipText = quickImportInfo.Any()
? "Quick save game import. The following save files will be imported:\n\n" + string.Join("\n", quickImportInfo)
: "No quick import save files configured,\nyou can do this in the settings.";
importingFromSavegameToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator());
}
importingFromSavegameToolStripMenuItem.DropDownItems.Add(selectSavegameFileToolStripMenuItem);
importingFromSavegameToolStripMenuItem.DropDownItems.Add(configureSavegameImportToolStripMenuItem);
}
private void importingFromSavegameEmptyToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenSettingsDialog(SettingsTabPages.SaveImport);