/
wndAddItem.xaml.cs
821 lines (726 loc) · 33.8 KB
/
wndAddItem.xaml.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using System.Diagnostics.Eventing.Reader;
using System.Drawing;
using System.Reflection;
using System.ComponentModel;
using System.Threading;
using System.Windows.Threading;
using System.Collections.ObjectModel;
using SeeloewenLib;
using System.Diagnostics;
namespace Random_Item_Giver_Updater
{
public partial class wndAddItem : Window
{
//General attributes
public bool isOpen;
public int currentPage = 1;
public ObservableCollection<addItemEntry> itemEntries { get; set; } = new ObservableCollection<addItemEntry>();
public ObservableCollection<addToLootTableEntry> lootTableEntries { get; set; } = new ObservableCollection<addToLootTableEntry>();
double addItemsWorkerProgress;
int addItemsWorkerAddedItems;
int addItemsWorkerAddedItemsLootTables;
DateTime startTime;
//Important references
public MainWindow wndMain = (MainWindow)Application.Current.MainWindow;
private wndSelectLootTables wndSelectLootTables;
public SeeloewenLibTools SeeloewenLibTools = new SeeloewenLibTools();
//Controls
private BackgroundWorker bgwAddItems = new BackgroundWorker();
private TextBlock tblLoadingItems = new TextBlock();
public Wizard wzdAddItems;
//-- Constructor --//
public wndAddItem()
{
InitializeComponent();
SetupControls();
CreateWizard();
DataContext = this;
}
//-- Event Handlers --//
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//Change open state to true
isOpen = true;
//Setup the first page
tblCurrentlySelectedDatapack.Text = string.Format("Currently selected Datapack: {0}\n{1}", wndMain.currentDatapack, wndMain.GetDatapackVersionInfo(wndMain.currentDatapack));
//Setup backgroundworker
bgwAddItems.WorkerReportsProgress = true;
bgwAddItems.DoWork += bgwAddItems_DoWork;
bgwAddItems.RunWorkerCompleted += bgwAddItems_RunWorkerCompleted;
bgwAddItems.ProgressChanged += bgwAddItems_ProgressChanged;
}
private void Window_Unloaded(object sender, RoutedEventArgs e)
{
//Change open state to false
isOpen = false;
}
private void btnAddAdditionalItem_Click(object sender, RoutedEventArgs e)
{
//Add a new empty item
itemEntries.Add(new addItemEntry("minecraft", "", itemEntries.Count));
}
private void bgwAddItems_DoWork(object s, DoWorkEventArgs args)
{
//Reset previous progress
addItemsWorkerProgress = 0;
addItemsWorkerAddedItems = 0;
addItemsWorkerAddedItemsLootTables = 0;
//Go through each loot table and add the items
foreach (lootTable lootTable in wndMain.lootTableList)
{
AddItems(string.Format("{0}/{1}", lootTable.lootTablePath, lootTable.lootTableName));
addItemsWorkerAddedItemsLootTables++;
addItemsWorkerAddedItems = 0;
}
}
private void bgwAddItems_RunWorkerCompleted(object s, RunWorkerCompletedEventArgs args)
{
//Go to the next page
wzdAddItems.ShowNextPage();
}
private void bgwAddItems_ProgressChanged(object s, ProgressChangedEventArgs progress)
{
//Report worker progress to progress bar
pbAddingItems.Value = Convert.ToDouble(progress.UserState);
//Report added items
tblAddingItemsProgress.Text = string.Format("Adding items... (Item {0}/{1} - Loot Table {2}/{3})", progress.ProgressPercentage, itemEntries.Count, addItemsWorkerAddedItemsLootTables, wndMain.lootTableList.Count);
}
//-- Custom Methods --//
private void CreateWizard()
{
//Create the wizard
wzdAddItems = new Wizard(6, 580, 742, btnContinue, btnBack, Close, codeFinish, new Thickness(0, 0, 0, 0));
grdAddItems.Children.Add(wzdAddItems.gbWizard);
gbStep1.Content = null;
gbStep2.Content = null;
gbStep3.Content = null;
gbStep4.Content = null;
gbStep5.Content = null;
gbStep6.Content = null;
wzdAddItems.gbWizard.Foreground = new SolidColorBrush(Colors.White);
wzdAddItems.gbWizard.FontSize = 16;
//Setup the pages
wzdAddItems.pages[0].grdContent.Children.Add(cvsStep1);
wzdAddItems.pages[1].grdContent.Children.Add(cvsStep2);
wzdAddItems.pages[2].grdContent.Children.Add(cvsStep3);
wzdAddItems.pages[3].grdContent.Children.Add(cvsStep4);
wzdAddItems.pages[4].grdContent.Children.Add(cvsStep5);
wzdAddItems.pages[5].grdContent.Children.Add(cvsStep6);
wzdAddItems.pages[2].code = codePage3;
wzdAddItems.pages[2].requirements = requirementsPage3;
wzdAddItems.pages[2].requirementsNotFulfilledMsg = "Please enter items you want to add to the datapack to continue!";
wzdAddItems.pages[3].code = codePage4;
wzdAddItems.pages[4].code = codePage5;
wzdAddItems.pages[4].requirements = requirementsPage5;
wzdAddItems.pages[4].requirementsNotFulfilledMsg = "You have selected to only add the item to certain loot tables without actually selecting any. Please choose any loot tables before continuing.";
wzdAddItems.pages[4].canGoBack = false;
wzdAddItems.pages[4].canContinue = false;
wzdAddItems.pages[5].code = codePage6;
wzdAddItems.pages[5].canGoBack = false;
}
private bool requirementsPage3()
{
//Check if the item name textbox is empty
if (!string.IsNullOrEmpty(tbItemName.Text))
{
return true;
}
else
{
return false;
}
}
private bool requirementsPage5()
{
foreach (addItemEntry addItemEntry in itemEntries)
{
if(addItemEntry.lootTableEntry.allLootTablesChecked == false && string.IsNullOrEmpty(addItemEntry.lootTableEntry.lootTableWhiteList))
{
return false;
}
}
return true;
}
private void codePage3()
{
//Get all items into an array
string[] items = tbItemName.Text.Split('\n');
//Create an entry for every item
itemEntries.Clear();
int index = 0;
if (cbIncludesPrefixes.IsChecked == true)
{
//Split the item into prefix and item name if checkbox for prefixes is checked
foreach (string item in items)
{
string[] line = item.Split(':');
if (line.Length != 2)
{
//If the line actually doesn't contain a prefix, add the item normally with default prefix
itemEntries.Add(new addItemEntry("minecraft", line[0], index));
index++;
}
else
{
//Add the item with prefix and name
itemEntries.Add(new addItemEntry(line[0], line[1], index));
index++;
}
}
}
else
{
//Add the line as an item name if checkbox for prefixes is not checked
foreach (string item in items)
{
itemEntries.Add(new addItemEntry("minecraft", item, index));
index++;
}
}
}
private void codePage4()
{
//Add a loot table entry to every item
lootTableEntries.Clear();
foreach (addItemEntry entry in itemEntries)
{
entry.lootTableEntry = new addToLootTableEntry(string.Format("{0}:{1}", entry.itemPrefix, entry.itemName), entry.itemIndex);
lootTableEntries.Add(entry.lootTableEntry);
}
}
private void codePage5()
{
//Set start time for time calculation afterwards
startTime = DateTime.Now;
//Add the items
bgwAddItems.RunWorkerAsync();
}
private void codePage6()
{
//Add all items to the added items list
foreach (addItemEntry item in itemEntries)
{
tbAddedItemsList.AppendText(string.Format("{0}:{1}\n", item.itemPrefix, item.itemName));
}
//Show the elapsed time
tblElapsedTime.Text = string.Format("Elapsed time: {0}", (DateTime.Now - startTime).ToString(@"hh\:mm\:ss"));
}
public void AddItems(string lootTable)
{
//Load the file
string[] lootTableFile = File.ReadAllLines(lootTable);
List<string> fileEnd = new List<string>();
bool hasNbtEntry = false;
//Remove the last 4 lines to allow adding new items by copying the array into a new array that is 5 lines shorter
string[] fileWithoutEnd = new string[lootTableFile.Length - 4];
Array.Copy(lootTableFile, fileWithoutEnd, lootTableFile.Length - 4);
//Build the file end construct to insert later
for (int i = 0; i < 4; i++)
{
fileEnd.Insert(0, lootTableFile[lootTableFile.Length - i - 1]);
}
//Add a comma at the last bracket
fileWithoutEnd[fileWithoutEnd.Length - 1] = fileWithoutEnd[fileWithoutEnd.Length - 1].Replace("}", "},");
//Write to file
File.WriteAllLines(lootTable, fileWithoutEnd);
//Copy the last part item construct and paste it at the bottom
List<string> itemConstruct = new List<string>();
lootTableFile = File.ReadAllLines(lootTable);
//Remove the comma at the end to avoid corruption
lootTableFile[lootTableFile.Length - 1] = lootTableFile[lootTableFile.Length - 1].Replace("},", "}");
//Start at the end and go through each line until it hits another item
bool doLoop = true;
int index = 0;
while (doLoop == true)
{
if (!(lootTableFile[lootTableFile.Length - index - 1].Contains("},")))
{
//If it contains the item name, replace
if (lootTableFile[lootTableFile.Length - index - 1].Contains("\"name\"") && lootTableFile[lootTableFile.Length - index - 2].Contains("item\""))
{
lootTableFile[lootTableFile.Length - index - 1] = lootTableFile[lootTableFile.Length - index - 1].Replace(GetItemName(lootTableFile[lootTableFile.Length - index - 1]), "{!REPLACE_NAME!}");
}
//If it contains the item NBT, replace
else if (lootTableFile[lootTableFile.Length - index - 1].Contains("\"tag\""))
{
hasNbtEntry = true;
lootTableFile[lootTableFile.Length - index - 1] = lootTableFile[lootTableFile.Length - index - 1].Replace(GetItemNBT(lootTableFile[lootTableFile.Length - index - 1]), "{!REPLACE_NBT!}");
}
//Add line to item construct and continue
itemConstruct.Insert(0, lootTableFile[lootTableFile.Length - index - 1]);
index++;
}
else
{
if (lootTableFile[lootTableFile.Length - index - 2].Contains("\"name\": \"RandomItemGiver\"") || lootTableFile[lootTableFile.Length - index - 2].Contains("\"name\": \"out\"") || lootTableFile[lootTableFile.Length - index - 2].Contains("\"count\":") || lootTableFile[lootTableFile.Length - index - 2].Contains("\"tag\":") || lootTableFile[lootTableFile.Length - index - 2].Contains("}"))
{
//If it contains the item name, replace
if (lootTableFile[lootTableFile.Length - index - 1].Contains("\"name\"") && lootTableFile[lootTableFile.Length - index - 2].Contains("item\""))
{
lootTableFile[lootTableFile.Length - index - 1] = lootTableFile[lootTableFile.Length - index - 1].Replace(GetItemName(lootTableFile[lootTableFile.Length - index - 1]), "{!REPLACE_NAME!}");
}
//If it contains the item NBT, replace
else if (lootTableFile[lootTableFile.Length - index - 1].Contains("\"tag\""))
{
hasNbtEntry = true;
lootTableFile[lootTableFile.Length - index - 1] = lootTableFile[lootTableFile.Length - index - 1].Replace(GetItemNBT(lootTableFile[lootTableFile.Length - index - 1]), "{!REPLACE_NBT!}");
}
//If it has reached a bracket with comma, but not one that indicates another item, add line continue
itemConstruct.Insert(0, lootTableFile[lootTableFile.Length - index - 1]);
index++;
}
else
{
//Stop if it has reached another item
doLoop = false;
}
}
}
//Add the comma back
itemConstruct[itemConstruct.Count - 1] = itemConstruct[itemConstruct.Count - 1] + ",";
//Add all the items to the loot table
foreach (addItemEntry item in itemEntries)
{
//Only add the item to the loot table if selected
if (item.lootTableEntry.allLootTablesChecked == true)
{
if (lootTable.Contains("main") || lootTable.Contains("special") || lootTable.Contains("normal"))
{
List<string> temporaryConstruct = new List<string>();
foreach (string line in itemConstruct)
{
//Replace the name placeholder with the actual prefix and name and add to a temporary construct
if (line.Contains("{!REPLACE_NAME!}"))
{
temporaryConstruct.Add(line.Replace("{!REPLACE_NAME!}", string.Format("{0}:{1}", item.itemPrefix, item.itemName)));
}
//Just add to the temporary construct
else
{
temporaryConstruct.Add(line);
}
}
//If an NBT tag is given
List<string> temporaryFinalConstruct = new List<string>();
if (!string.IsNullOrEmpty(item.itemNBT))
{
//Add nbt entry to construct if a NBT tag is given
if (hasNbtEntry == false)
{
temporaryConstruct = AddNbtEntry(temporaryConstruct);
}
foreach (string line in temporaryConstruct)
{
//Replace the NBT placeholder with the actual NBT tag and add to a temporary construct
if (line.Contains("{!REPLACE_NBT!}"))
{
temporaryFinalConstruct.Add(line.Replace("{!REPLACE_NBT!}", item.itemNBT));
}
else
{
temporaryFinalConstruct.Add(line);
}
}
}
else
{
//Remove nbt entry construct if there is one even though the item has no NBT
if (hasNbtEntry == true)
{
temporaryConstruct = RemoveNbtEntry(temporaryConstruct);
}
//Continue without NBT
temporaryFinalConstruct = temporaryConstruct;
}
//Write the construct with the item prefix, name and nbt to the file
File.AppendAllText(lootTable, string.Join(Environment.NewLine, temporaryFinalConstruct) + "\n");
}
}
else if (item.lootTableEntry.allLootTablesChecked == false && item.lootTableEntry.lootTableWhiteList.Contains(lootTable))
{
List<string> temporaryConstruct = new List<string>();
foreach (string line in itemConstruct)
{
//Replace the name placeholder with the actual prefix and name and add to a temporary construct
if (line.Contains("{!REPLACE_NAME!}"))
{
temporaryConstruct.Add(line.Replace("{!REPLACE_NAME!}", string.Format("{0}:{1}", item.itemPrefix, item.itemName)));
}
//Just add to the temporary construct
else
{
temporaryConstruct.Add(line);
}
}
//If an NBT tag is given
List<string> temporaryFinalConstruct = new List<string>();
if (!string.IsNullOrEmpty(item.itemNBT))
{
//Add nbt entry to construct if a NBT tag is given
if (hasNbtEntry == false)
{
temporaryConstruct = AddNbtEntry(temporaryConstruct);
}
foreach (string line in temporaryConstruct)
{
//Replace the NBT placeholder with the actual NBT tag and add to a temporary construct
if (line.Contains("{!REPLACE_NBT!}"))
{
temporaryFinalConstruct.Add(line.Replace("{!REPLACE_NBT!}", item.itemNBT));
}
else
{
temporaryFinalConstruct.Add(line);
}
}
}
else
{
//Remove nbt entry construct if there is one even though the item has no NBT
if (hasNbtEntry == true)
{
temporaryConstruct = RemoveNbtEntry(temporaryConstruct);
}
//Continue without NBT
temporaryFinalConstruct = temporaryConstruct;
}
//Write the construct with the item prefix, name and nbt to the file
File.AppendAllText(lootTable, string.Join(Environment.NewLine, temporaryFinalConstruct) + "\n");
}
//Report worker progress
addItemsWorkerProgress = addItemsWorkerProgress + (100 / (Convert.ToDouble(itemEntries.Count * wndMain.lootTableList.Count)));
addItemsWorkerAddedItems++;
bgwAddItems.ReportProgress(addItemsWorkerAddedItems, addItemsWorkerProgress);
}
//Remove the comma at the end to avoid corruption
lootTableFile = File.ReadAllLines(lootTable);
lootTableFile[lootTableFile.Length - 1] = lootTableFile[lootTableFile.Length - 1].Replace("},", "}");
File.WriteAllLines(lootTable, lootTableFile);
//Write the end construct to the file
File.AppendAllText(lootTable, string.Join(Environment.NewLine, fileEnd));
}
public string GetItemName(string line)
{
//Remove strings to only return item name
line = line.Replace("\"name\": ", "");
line = line.Replace(" ", "");
line = line.Replace("\"", "");
line = line.Replace(",", "");
return line;
}
public string GetItemNBT(string line)
{
//Remove strings to only return item NBT
line = line.Replace("\"tag\": ", "");
line = line.Replace(" ", "");
line = line.Substring(1, line.Length - 2);
return line;
}
public List<string> AddNbtEntry(List<string> construct)
{
//Check if "functions" entry exists
bool functionsExists = false;
foreach (string line in construct)
{
if (line.Contains("\"functions\": ["))
{
functionsExists = true;
}
}
//If "functions" entry already exists
if (functionsExists == true)
{
construct[construct.Count - 3] = construct[construct.Count - 3].Replace("}", "},");
construct.Insert(construct.Count - 2, " {");
construct.Insert(construct.Count - 2, " \"function\": \"set_nbt\",");
construct.Insert(construct.Count - 2, " \"tag\": \"{!REPLACE_NBT!}\"");
construct.Insert(construct.Count - 2, " }");
return construct;
}
else //If it doesn't exist
{
construct[construct.Count - 2] = construct[construct.Count - 2] + ",";
construct.Insert(construct.Count - 1, " \"functions\": [");
construct.Insert(construct.Count - 1, " {");
construct.Insert(construct.Count - 1, " \"function\": \"set_nbt\",");
construct.Insert(construct.Count - 1, " \"tag\": \"{!REPLACE_NBT!}\"");
construct.Insert(construct.Count - 1, " }");
construct.Insert(construct.Count - 1, " ]");
return construct;
}
}
public List<string> RemoveNbtEntry(List<string> construct)
{
//Create neccessary temporary variables
List<string> tempConstruct = new List<string>();
List<string> endConstruct = new List<string>();
List<string> endConstruct2 = new List<string>();
bool hasCount = false;
bool hasCountSpecial = false;
tempConstruct = construct;
for (int i = construct.Count - 1; i >= 0; i--)
{
//Check if the loot table has a count, and if the count is special
if (construct[i].Contains("\"target\":"))
{
hasCountSpecial = true;
}
else if (construct[i].Contains("\"count\":"))
{
hasCount = true;
//If it's not special, add the "count" section already to the end construct
if (hasCountSpecial == false)
{
endConstruct.Add(construct[i - 2]);
endConstruct.Add(construct[i - 1]);
endConstruct.Add(construct[i]);
}
break;
}
}
if (hasCount == true && hasCountSpecial == false)
{
//If it has count but isn't special add all brackets (end part) to the a temporary end construct 2 until it hits a count or tag part
for (int i = construct.Count - 1; i >= 0; i--)
{
if (construct[i].Contains("\"count\":") || construct[i].Contains("\"tag\":"))
{
break;
}
else if (construct[i].Contains("}") || construct[i].Contains("]"))
{
endConstruct2.Add(construct[i]);
}
}
//Reverse the code and add it to the actual end construct
endConstruct2.Reverse();
foreach (string entry in endConstruct2)
{
endConstruct.Add(entry);
}
}
else if (hasCount == true && hasCountSpecial == true)
{
//If the loot table has special count add all the lines at the end to the temporary end construct 2 until it hits the count part
for (int i = construct.Count - 1; i >= 0; i--)
{
//If it hits the count section add that and stop
if (construct[i].Contains("\"count\":"))
{
endConstruct2.Add(construct[i]);
endConstruct2.Add(construct[i - 1]);
endConstruct2.Add(construct[i - 2]);
break;
}
else
{
endConstruct2.Add(construct[i]);
//If it hits a NBT section skip that
if (construct[i - 1].Contains("\"tag\":"))
{
i = i - 4;
}
}
}
//Reverse the code and add it to the actual end construct
endConstruct2.Reverse();
foreach (string entry in endConstruct2)
{
endConstruct.Add(entry);
}
}
else if (hasCount == false)
{
//If it hasn't got any count, remove the comma in the name part as it is no longer needed and would cause errors
for (int i = construct.Count - 1; i >= 0; i--)
{
if (construct[i].Contains("\"name\":"))
{
tempConstruct[i] = tempConstruct[i].Replace(",", "");
}
}
//Simply add the last character (most likely a comma) to the end construct
endConstruct.Add(construct.Last());
}
for (int i = construct.Count - 1; i >= 0; i--)
{
//If it hasn't got a count, remove everything up until the name part
if (hasCount == false)
{
if (!tempConstruct[i].Contains("\"name\""))
{
tempConstruct.Remove(tempConstruct[i]);
}
else
{
break;
}
}
else
{
//If it has got a count, remove everything up until the beginning of the function part
if (!tempConstruct[i].Contains("\"functions\""))
{
tempConstruct.Remove(tempConstruct[i]);
}
else
{
break;
}
}
}
//Add the end construct to the full construct and return that
foreach (string entry in endConstruct)
{
tempConstruct.Add(entry);
}
return tempConstruct;
}
private T FindVisualChild<T>(DependencyObject parent) where T : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
if (child is T typedChild)
return typedChild;
var childOfChild = FindVisualChild<T>(child);
if (childOfChild != null)
return childOfChild;
}
return null;
}
private void SetupControls()
{
//Create 'Loading' text for loading items
tblLoadingItems.Text = "Processing items, please wait...\nThis may take a few seconds!";
tblLoadingItems.Foreground = new SolidColorBrush(Colors.White);
tblLoadingItems.FontSize = 24;
}
private void codeFinish()
{
//Reload the currently loaded loot table and close this window
if (wndMain.currentLootTable != "none")
{
wndMain.LoadLootTable(wndMain.currentLootTable);
}
Close();
}
//-- Add Item Entry Event Handlers --//
private void btnRemove_Click(object sender, RoutedEventArgs e)
{
if (sender is Button button)
{
//Get the canvas which the button is in
Canvas canvas = SeeloewenLibTools.FindVisualParent<Canvas>(button);
if (canvas.DataContext is addItemEntry item)
{
//Remove the current item from the list
itemEntries.Remove(item);
}
}
}
//-- Add To Loot Table Entry Event Handlers --//
private void btnEditCertainLootTables_Click(object sender, RoutedEventArgs e)
{
if (sender is Button button)
{
//Get the canvas which the button is in
Canvas canvas = SeeloewenLibTools.FindVisualParent<Canvas>(button);
if (canvas.DataContext is addToLootTableEntry item)
{
//Open loot table selection window
wndSelectLootTables = new wndSelectLootTables(item.lootTableCheckList, "Select the Loot Tables, that you want to add the item to.") { Owner = Application.Current.MainWindow };
wndSelectLootTables.Owner = Application.Current.MainWindow;
wndSelectLootTables.ShowDialog();
//Get loot tables string from loot table selection window
foreach (lootTable lootTable in wndSelectLootTables.lootTableList)
{
if (lootTable.cbAddToLootTable.IsChecked == true)
{
item.lootTableWhiteList = string.Format("{0}{1}", item.lootTableWhiteList, lootTable.fullLootTablePath);
}
}
}
}
}
private void rbtnAllLootTables_Checked(object sender, RoutedEventArgs e)
{
if (sender is RadioButton radiobutton)
{
//Get the canvas which the radiobutton is in
Canvas canvas = SeeloewenLibTools.FindVisualParent<Canvas>(radiobutton);
if (canvas.DataContext is addToLootTableEntry item)
{
//Disable edit button
Button button = canvas.FindName("btnEditCertainLootTables") as Button;
button.IsEnabled = false;
//Set checkstate on variable that gets accessed by the item adding thread
item.allLootTablesChecked = true;
}
}
}
private void rbtnCertainLootTables_Checked(object sender, RoutedEventArgs e)
{
if (sender is RadioButton radiobutton)
{
//Get the canvas which the radiobutton is in
Canvas canvas = SeeloewenLibTools.FindVisualParent<Canvas>(radiobutton);
if (canvas.DataContext is addToLootTableEntry item)
{
//Enable edit button
Button button = canvas.FindName("btnEditCertainLootTables") as Button;
button.IsEnabled = true;
//Set checkstate on variable that gets accessed by the item adding thread
item.allLootTablesChecked = false;
}
}
}
private void tbItemName_TextChanged(object sender, TextChangedEventArgs e)
{
if (sender is TextBox textbox)
{
if (textbox.DataContext is addItemEntry item)
{
//Set checkstate on variable that gets accessed by the item adding thread
item.itemName = textbox.Text;
}
}
}
private void tbItemPrefix_TextChanged(object sender, TextChangedEventArgs e)
{
if (sender is TextBox textbox)
{
if (textbox.DataContext is addItemEntry item)
{
//Set checkstate on variable that gets accessed by the item adding thread
item.itemPrefix = textbox.Text;
}
}
}
private void tbItemNBT_TextChanged(object sender, TextChangedEventArgs e)
{
if (sender is TextBox textbox)
{
if (textbox.DataContext is addItemEntry item)
{
//Set checkstate on variable that gets accessed by the item adding thread
item.itemNBT = textbox.Text;
}
}
}
}
}