-
Notifications
You must be signed in to change notification settings - Fork 0
/
Window1.xaml.cs
767 lines (687 loc) · 27.2 KB
/
Window1.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
CombatTable listi;
string loadedFile;
string loadedFileDir;
string execDirectory;
public Window1()
{
InitializeComponent();
// Select the text in a TextBox when it recieves focus.
EventManager.RegisterClassHandler(typeof(TextBox), TextBox.PreviewMouseLeftButtonDownEvent,
new MouseButtonEventHandler(SelectivelyIgnoreMouseButton));
EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotKeyboardFocusEvent,
new RoutedEventHandler(SelectAllText));
EventManager.RegisterClassHandler(typeof(TextBox), TextBox.MouseDoubleClickEvent,
new RoutedEventHandler(SelectAllText));
listi = new CombatTable();
listBox1.DataContext = listi;
execDirectory = Environment.CurrentDirectory;
}
void SelectivelyIgnoreMouseButton(object sender, MouseButtonEventArgs e)
{
// Find the TextBox
DependencyObject parent = e.OriginalSource as UIElement;
while (parent != null && !(parent is TextBox))
parent = VisualTreeHelper.GetParent(parent);
if (parent != null)
{
var textBox = (TextBox)parent;
if (!textBox.IsKeyboardFocusWithin)
{
// If the text box is not yet focussed, give it the focus and
// stop further processing of this click event.
textBox.Focus();
e.Handled = true;
}
}
}
void SelectAllText(object sender, RoutedEventArgs e)
{
var textBox = e.OriginalSource as TextBox;
if (textBox != null)
textBox.SelectAll();
}
private void Undo(object sender, ExecutedRoutedEventArgs e)
{
UndoableCommand.Undo();
}
private void Redo(object sender, ExecutedRoutedEventArgs e)
{
UndoableCommand.Redo();
}
#region CombatTable Edition Methods
private Combatant getSelectedCombatant()
{
Combatant combatant = (Combatant)listBox1.SelectedItem;
if (combatant == null)
{
MessageBox.Show("Select a Character", "Invalid Character", MessageBoxButton.OK, MessageBoxImage.Information);
}
return combatant;
}
private void AddNewCombatant(object sender, ExecutedRoutedEventArgs e)
{
NewCombatant windowNew = new NewCombatant( listi );
windowNew.ShowDialog();
}
private void cloneSelectedCombatant_Click(object sender, RoutedEventArgs e)
{
Combatant selectedCombatant = getSelectedCombatant();
if (selectedCombatant == null)
return;
Combatant clone = selectedCombatant.Clone();
CommAddCombatant commAdd = new CommAddCombatant(listi, clone);
commAdd.Execute();
}
private void RemoveSelectedCombatant(object sender, ExecutedRoutedEventArgs e)
{
Combatant toBeRemovedCombatant = getSelectedCombatant();
if (toBeRemovedCombatant != null)
{
CommRemoveCombatant commRmv = new CommRemoveCombatant(listi, toBeRemovedCombatant);
commRmv.Execute();
}
}
private void MoveCombatantUp(object sender, RoutedEventArgs e)
{
Combatant toBeShiftedCombatant = getSelectedCombatant();
if (toBeShiftedCombatant != null)
{
CommRepositionCombatant commRmv = new CommRepositionCombatant(listi, toBeShiftedCombatant, -1);
commRmv.Execute();
}
}
private void MoveCombatantDown(object sender, RoutedEventArgs e)
{
Combatant toBeShiftedCombatant = getSelectedCombatant();
if (toBeShiftedCombatant != null)
{
CommRepositionCombatant commRmv = new CommRepositionCombatant(listi, toBeShiftedCombatant, 1);
commRmv.Execute();
}
}
private void damageHeal_Click(object sender, RoutedEventArgs e)
{
float lifeAmount = App.getFloatFromString(damageHealBox.Text);
if (lifeAmount != 0)
{
Combatant toBeDamagedCombatant = getSelectedCombatant();
if (toBeDamagedCombatant == null)
return;
float previousHP = toBeDamagedCombatant.HP;
CommUpdateCombatant commUpdt = new CommUpdateCombatant(toBeDamagedCombatant, CombatantAttributes.hp, previousHP - lifeAmount);
commUpdt.Execute();
}
}
#endregion
#region quick damage/heal buttons
private void applyDamage(float damageAmount)
{
Combatant toBeDamagedCombatant = getSelectedCombatant();
if (toBeDamagedCombatant == null)
return;
float previousHP = toBeDamagedCombatant.HP;
CommUpdateCombatant commUpdt = new CommUpdateCombatant(toBeDamagedCombatant, CombatantAttributes.hp, previousHP + damageAmount);
commUpdt.Execute();
}
private void plus1Dmg_Click(object sender, RoutedEventArgs e)
{
applyDamage(1);
}
private void plus3Dmg_Click(object sender, RoutedEventArgs e)
{
applyDamage(3);
}
private void plus5Dmg_Click(object sender, RoutedEventArgs e)
{
applyDamage(5);
}
private void plus10Dmg_Click(object sender, RoutedEventArgs e)
{
applyDamage(10);
}
private void minus1Dmg_Click(object sender, RoutedEventArgs e)
{
applyDamage(-1);
}
private void minus2Dmg_Click(object sender, RoutedEventArgs e)
{
applyDamage(-3);
}
private void minus5Dmg_Click(object sender, RoutedEventArgs e)
{
applyDamage(-5);
}
private void minus10Dmg_Click(object sender, RoutedEventArgs e)
{
applyDamage(-10);
}
#endregion
#region Combat management methods
private void setInitiativeButton_Click(object sender, RoutedEventArgs e)
{
InitiativeSet initWindow = new InitiativeSet(listi);
initWindow.ShowDialog();
}
private void restoreAllHP_Click(object sender, RoutedEventArgs e)
{
for (int i = 0; i < listi.Count; i++)
{
Combatant toBeRestoredCombatant = listi[i];
float maxHP = toBeRestoredCombatant.MaxHP;
CommUpdateCombatant commUpdt = new CommUpdateCombatant(toBeRestoredCombatant, CombatantAttributes.hp, maxHP);
commUpdt.Execute();
}
}
private void restoreSelectedHp_Click(object sender, RoutedEventArgs e)
{
Combatant toBeRestoredCombatant = getSelectedCombatant();
if (toBeRestoredCombatant == null)
return;
float maxHP = toBeRestoredCombatant.MaxHP;
CommUpdateCombatant commUpdt = new CommUpdateCombatant(toBeRestoredCombatant, CombatantAttributes.hp, maxHP);
commUpdt.Execute();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
float newInititive = App.getFloatFromString(initiativeBox.Text);
if (newInititive != 0)
{
Combatant newInitiativeCombatant = getSelectedCombatant();
if (newInitiativeCombatant == null)
return;
float previousHP = newInitiativeCombatant.HP;
CommUpdateCombatant commUpdt = new CommUpdateCombatant(newInitiativeCombatant, CombatantAttributes.initiative, newInititive);
commUpdt.Execute();
}
}
private void editCombatant_Click(object sender, RoutedEventArgs e)
{
Combatant combatant = getSelectedCombatant();
if (combatant != null)
{
CompleteSheet completeSheet = new CompleteSheet(getSelectedCombatant());
completeSheet.ShowDialog();
}
}
private void orderByInit_Click(object sender, RoutedEventArgs e)
{
IEnumerable<Combatant> sortedCombatants =
from combatant in listi
orderby -combatant.Initiative
select combatant;
int count = listi.Count;
for (int i = 0; i < count; i++)
{
Combatant combatant = sortedCombatants.ElementAt(i);
int index = listi.IndexOf(combatant);
CommRepositionCombatant commRps = new CommRepositionCombatant(listi, combatant, i - index);
commRps.Execute();
}
}
private void restoreNPCHP_Click(object sender, RoutedEventArgs e)
{
List<UndoableCommand> commList = new List<UndoableCommand>();
for (int i = 0; i < listi.Count; i++)
{
Combatant toBeRestoredCombatant = listi[i];
if (toBeRestoredCombatant.IsNPC)
{
float maxHP = toBeRestoredCombatant.MaxHP;
CommUpdateCombatant commUpdt = new CommUpdateCombatant(toBeRestoredCombatant, CombatantAttributes.hp, maxHP);
commList.Add(commUpdt);
}
}
if (commList.Count > 0)
{
CommCommandPackStarter commPack = new CommCommandPackStarter(commList);
commPack.Execute();
}
}
private void rollNPCInit_Click(object sender, RoutedEventArgs e)
{
List<UndoableCommand> commList = new List<UndoableCommand>();
Random random = new Random();
for (int i = 0; i < listi.Count; i++)
{
Combatant rollInitCombatant = listi[i];
if (rollInitCombatant.IsNPC)
{
float initiative = rollInitCombatant.InitMod + random.Next(1, 21);
CommUpdateCombatant commUpdt = new CommUpdateCombatant(rollInitCombatant, CombatantAttributes.initiative, initiative);
commList.Add(commUpdt);
}
}
if (commList.Count > 0)
{
CommCommandPackStarter commPack = new CommCommandPackStarter(commList);
commPack.Execute();
}
}
private void clearDead_Click(object sender, RoutedEventArgs e)
{
int count = listi.Count;
List<Combatant> toBeRemoved = new List<Combatant>();
for (int i = 0; i < count; i++)
{
Combatant combatant = listi[i];
if (combatant.HP < 0)
{
toBeRemoved.Add(combatant);
}
}
foreach (Combatant exCombatant in toBeRemoved)
{
CommRemoveCombatant commRmv = new CommRemoveCombatant(listi, exCombatant);
commRmv.Execute();
}
}
private void clearNPC_Click(object sender, RoutedEventArgs e)
{
int count = listi.Count;
List<Combatant> toBeRemoved = new List<Combatant>();
for (int i = 0; i < count; i++)
{
Combatant combatant = listi[i];
if (combatant.IsNPC)
{
toBeRemoved.Add(combatant);
}
}
foreach (Combatant exCombatant in toBeRemoved)
{
CommRemoveCombatant commRmv = new CommRemoveCombatant(listi, exCombatant);
commRmv.Execute();
}
}
private void startEncounter_Click(object sender, RoutedEventArgs e)
{
CommStartEncounter commStrt = new CommStartEncounter(listi);
commStrt.Execute();
}
private void stopCombat_Click(object sender, RoutedEventArgs e)
{
CommFinishEncounter commFnsh = new CommFinishEncounter(listi);
commFnsh.Execute();
}
private void next_Click(object sender, RoutedEventArgs e)
{
CommNextCombatant commNxt = new CommNextCombatant(listi);
commNxt.Execute();
}
private void previous_Click(object sender, RoutedEventArgs e)
{
CommPreviousCombatant commPrvs = new CommPreviousCombatant(listi);
commPrvs.Execute();
}
private void ClearAll_Click(object sender, RoutedEventArgs e)
{
CommClearCombatTable commClr = new CommClearCombatTable(listi);
commClr.Execute();
}
#endregion
#region IO methods
private void Load_Click(object sender, RoutedEventArgs e)
{
try
{
Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
Nullable<bool> result = ofd.ShowDialog();
string temps;
if (result == true)
{
temps = ofd.FileName;
}
else
return;
this.loadedFile = temps;
this.loadedFileDir = Environment.CurrentDirectory;
CommClearCombatTable commClr = new CommClearCombatTable(listi);
commClr.Execute();
this.Title = "TableTop Manager" + temps;
System.IO.StreamReader SR;
SR = System.IO.File.OpenText(temps);
String combatantString = SR.ReadToEnd();
JsonExporter.combatTableFromJsonFile(listi, combatantString);
}
catch
{
MessageBox.Show("Invalid File");
}
}
private void Include_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
Nullable<bool> result = ofd.ShowDialog();
string temps;
if (result == true)
{
temps = ofd.FileName;
}
else
return;
System.IO.StreamReader SR;
SR = System.IO.File.OpenText(temps);
String combatantString = SR.ReadToEnd();
JsonExporter.combatTableFromJsonFile(listi, combatantString);
}
private void SaveAs_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.SaveFileDialog ofd = new Microsoft.Win32.SaveFileDialog();
ofd.AddExtension = true;
ofd.DefaultExt = "tm1";
Nullable<bool> result = ofd.ShowDialog();
string temps;
if (result == true)
{
temps = ofd.FileName;
}
else
return;
this.loadedFile = temps;
this.loadedFileDir = Environment.CurrentDirectory;
System.IO.StreamWriter SW = System.IO.File.CreateText(temps);
SW.WriteLine(JsonExporter.jsonFileFromCombatTable(listi));
SW.Close();
}
private void Save_Click(object sender, RoutedEventArgs e)
{
if (loadedFile == null)
{
MessageBox.Show("invalid file: " + loadedFile);
return;
}
System.IO.StreamWriter SW = System.IO.File.CreateText(this.loadedFile);
SW.WriteLine(JsonExporter.jsonFileFromCombatTable(listi));
SW.Close();
}
private void exportCharacter_Click(object sender, RoutedEventArgs e)
{
Combatant selectedCombatant = getSelectedCombatant();
if (selectedCombatant == null)
return;
Microsoft.Win32.SaveFileDialog ofd = new Microsoft.Win32.SaveFileDialog();
ofd.AddExtension = true;
ofd.DefaultExt = "tm1";
Nullable<bool> result = ofd.ShowDialog();
string temps;
if (result == true)
{
temps = ofd.FileName;
}
else
return;
System.IO.StreamWriter SW = System.IO.File.CreateText(temps);
SW.WriteLine(JsonExporter.jsonFileFromCombatant(selectedCombatant));
SW.Close();
}
private void exportAll_Click(object sender, RoutedEventArgs e)
{
if (loadedFile == null)
{
MessageBox.Show("invalid file: " + loadedFile);
return;
}
string directoryToExport = this.loadedFileDir + "\\exported\\";
System.IO.Directory.CreateDirectory(directoryToExport);
foreach (Combatant combatant in listi)
{
string combatantFilePath = directoryToExport + combatant.CName + ".tm1";
System.IO.StreamWriter SW = System.IO.File.CreateText(combatantFilePath);
SW.WriteLine(JsonExporter.jsonFileFromCombatant(combatant));
SW.Close();
}
}
#endregion
#region Dice Roll Button events
private void d2_Click(object sender, RoutedEventArgs e)
{
Random random = new Random();
resultBox.Text = System.Convert.ToString(random.Next(1, 3));
}
private void d4_Click(object sender, RoutedEventArgs e)
{
Random random = new Random();
resultBox.Text = System.Convert.ToString(random.Next(1, 5));
}
private void d6_Click(object sender, RoutedEventArgs e)
{
Random random = new Random();
resultBox.Text = System.Convert.ToString(random.Next(1, 7));
}
private void d8_Click(object sender, RoutedEventArgs e)
{
Random random = new Random();
resultBox.Text = System.Convert.ToString(random.Next(1, 9));
}
private void d10_Click(object sender, RoutedEventArgs e)
{
Random random = new Random();
resultBox.Text = System.Convert.ToString(random.Next(1, 11));
}
private void d12_Click(object sender, RoutedEventArgs e)
{
Random random = new Random();
resultBox.Text = System.Convert.ToString(random.Next(1, 13));
}
private void d20_Click(object sender, RoutedEventArgs e)
{
Random random = new Random();
resultBox.Text = System.Convert.ToString(random.Next(1, 21));
}
private void d100_Click(object sender, RoutedEventArgs e)
{
Random random = new Random();
resultBox.Text = System.Convert.ToString(random.Next(1, 101));
}
#endregion
#region Gold XP SpellBook and Roll Check
private void GiveGold_Click(object sender, RoutedEventArgs e)
{
List<UndoableCommand> commList = new List<UndoableCommand>();
int numPCs = 0;
for (int i = 0; i < listi.Count; i++)
{
if (!listi[i].IsNPC)
{
numPCs++;
}
}
Window2 inputGetter = new Window2("How much gold will be Awarded?");
inputGetter.ShowDialog();
float goldShare = App.getFloatFromString(inputGetter.InputValue) / (float)numPCs;
for (int i = 0; i < listi.Count; i++)
{
if (!listi[i].IsNPC)
{
float gold = listi[i].Gold + goldShare;
CommUpdateCombatant commUpdt = new CommUpdateCombatant(listi[i], CombatantAttributes.gold, gold);
commList.Add(commUpdt);
}
}
if (commList.Count > 0)
{
CommCommandPackStarter commPack = new CommCommandPackStarter(commList);
commPack.Execute();
}
}
private void GiveXP_Click(object sender, RoutedEventArgs e)
{
List<UndoableCommand> commList = new List<UndoableCommand>();
int numPCs = 0;
for (int i = 0; i < listi.Count; i++)
{
if (!listi[i].IsNPC)
{
numPCs++;
}
}
Window2 inputGetter = new Window2("How much xp will be Awarded?");
inputGetter.ShowDialog();
float xpShare = App.getFloatFromString(inputGetter.InputValue) / (float)numPCs;
for (int i = 0; i < listi.Count; i++)
{
if (!listi[i].IsNPC)
{
float xp = listi[i].XP + xpShare;
CommUpdateCombatant commUpdt = new CommUpdateCombatant(listi[i], CombatantAttributes.xp, xp);
commList.Add(commUpdt);
}
}
if (commList.Count > 0)
{
CommCommandPackStarter commPack = new CommCommandPackStarter(commList);
commPack.Execute();
}
}
private void rollCheck_Click(object sender, RoutedEventArgs e)
{
Random randomizer = new Random();
string menuItemHeader = (string)((MenuItem)sender).Header;
string msg = "Results:\n";
foreach (Combatant combatant in listi)
{
if (menuItemHeader == "Fortitude")
{
msg = msg + combatant.CName + " = " + System.Convert.ToString(combatant.Fort + randomizer.Next(1, 21)) + "\n";
}
else if (menuItemHeader == "Reflex")
{
msg = msg + combatant.CName + " = " + System.Convert.ToString(combatant.Refl + randomizer.Next(1, 21)) + "\n";
}
else if (menuItemHeader == "Will")
{
msg = msg + combatant.CName + " = " + System.Convert.ToString(combatant.Will + randomizer.Next(1, 21)) + "\n";
}
else if (menuItemHeader == "Spot")
{
msg = msg + combatant.CName + " = " + System.Convert.ToString(combatant.Spot + randomizer.Next(1, 21)) + "\n";
}
else if (menuItemHeader == "Sense Motive")
{
msg = msg + combatant.CName + " = " + System.Convert.ToString(combatant.Sense + randomizer.Next(1, 21)) + "\n";
}
else
{
msg = msg + combatant.CName + " = " + System.Convert.ToString(combatant.Listen + randomizer.Next(1, 21)) + "\n";
}
}
string title = "Rolls Results";
MessageBox.Show(msg, title);
}
private void Gold_Click(object sender, RoutedEventArgs e)
{
float goldAmount = App.getFloatFromString(damageHealBox.Text);
if (goldAmount != 0)
{
Combatant toBeGoldedCombatant = getSelectedCombatant();
if (toBeGoldedCombatant == null)
return;
float previousGold = toBeGoldedCombatant.Gold;
CommUpdateCombatant commUpdt = new CommUpdateCombatant(toBeGoldedCombatant, CombatantAttributes.gold, previousGold + goldAmount);
commUpdt.Execute();
}
}
private void XP_Click(object sender, RoutedEventArgs e)
{
float xpAmount = App.getFloatFromString(damageHealBox.Text);
if (xpAmount != 0)
{
Combatant toBexpedCombatant = getSelectedCombatant();
if (toBexpedCombatant == null)
return;
float previousxp = toBexpedCombatant.XP;
CommUpdateCombatant commUpdt = new CommUpdateCombatant(toBexpedCombatant, CombatantAttributes.xp, previousxp + xpAmount);
commUpdt.Execute();
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
Table table = new Table(execDirectory);
table.Show();
}
private void randomSpellbook_Click(object sender, RoutedEventArgs e)
{
Spellbook window = new Spellbook(execDirectory, 0, 9, (string)((MenuItem)sender).Header);
window.Show();
}
#endregion
private void StackPanel_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
newItem itemAdder = new newItem();
Combatant combatant = (Combatant)quickSheet.DataContext;
itemAdder.Item = combatant.Items[itemListBox.SelectedIndex];
itemAdder.ShowDialog();
}
private void newItemButton_Click(object sender, RoutedEventArgs e)
{
newItem itemAdder = new newItem();
itemAdder.ShowDialog();
if (itemAdder.gotItem)
{
Combatant combatant = (Combatant)quickSheet.DataContext;
combatant.addItem(itemAdder.Item);
}
}
private void removeItemButton_Click(object sender, RoutedEventArgs e)
{
Combatant combatant = (Combatant)quickSheet.DataContext;
if (itemListBox.SelectedIndex == -1)
MessageBox.Show("No selected item");
else
combatant.removeItem(itemListBox.SelectedIndex);
}
private void combatantRow_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
quickSheet.DataContext = getSelectedCombatant();
}
private void openTable_Click(object sender, RoutedEventArgs e)
{
string tableFileTag = (string)((MenuItem)sender).Tag + ".jpg";
TableViewer window = new TableViewer();
if(window.SetImage(execDirectory, tableFileTag))
window.Show();
}
private void textBox3_GotFocus(object sender, RoutedEventArgs e)
{
textBox3.SelectAll();
}
private void newFeatButton_Click(object sender, RoutedEventArgs e)
{
NewListboxItem itemAdder = new NewListboxItem();
itemAdder.ShowDialog();
if (itemAdder.gotItem)
{
Combatant combatant = (Combatant)quickSheet.DataContext;
combatant.Feats.Add(itemAdder.item);
}
}
private void removeFeatButton_Click(object sender, RoutedEventArgs e)
{
Combatant combatant = (Combatant)quickSheet.DataContext;
if (featListBox.SelectedIndex == -1)
MessageBox.Show("No selected item");
else
combatant.removeFeat(featListBox.SelectedIndex);
}
}
}