-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStatsEditor.xaml.cs
95 lines (85 loc) · 3.28 KB
/
StatsEditor.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
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace EldenRingTool
{
public partial class StatsEditor : Window
{
List<(string, int)> _stats;
Action<List<(string, int)>> _callback = null;
List<TextBox> _boxes = new List<TextBox>();
public StatsEditor(List<(string, int)> stats, Action<List<(string, int)>> callback)
{
InitializeComponent();
_stats = stats;
_callback = callback;
lblExample.Visibility = Visibility.Hidden;
txtExample.Visibility = Visibility.Hidden;
for (int i = 0; i < stats.Count; i++)
{
statsGrid.RowDefinitions.Add(new RowDefinition());
var lbl = new Label();
lbl.Content = stats[i].Item1;
statsGrid.Children.Add(lbl);
Grid.SetRow(lbl, i);
Grid.SetColumn(lbl, 0);
var txt = new TextBox();
txt.HorizontalAlignment = HorizontalAlignment.Stretch;
txt.VerticalAlignment = VerticalAlignment.Center;
txt.Text = stats[i].Item2.ToString();
_boxes.Add(txt);
var decButton = new Button();
decButton.Height = 18;
decButton.HorizontalAlignment = HorizontalAlignment.Stretch;
decButton.IsTabStop = false;
decButton.Content = "-";
decButton.Click += (sender, e) => Button_DecreaseStat(txt);
var incButton = new Button();
incButton.Height = 18;
incButton.HorizontalAlignment = HorizontalAlignment.Stretch;
incButton.IsTabStop = false;
incButton.Content = "+";
incButton.Click += (sender, e) => Button_IncreaseStat(txt);
Grid.SetRow(decButton, i);
Grid.SetColumn(decButton, 1);
Grid.SetRow(txt, i);
Grid.SetColumn(txt, 2);
Grid.SetRow(incButton, i);
Grid.SetColumn(incButton, 3);
statsGrid.Children.Add(txt);
statsGrid.Children.Add(decButton);
statsGrid.Children.Add(incButton);
}
}
private void okClicked(object sender, RoutedEventArgs e)
{
for (int i = 0; i < _stats.Count; i++)
{
if (int.TryParse(_boxes[i].Text, out var stat))
{
_stats[i] = (_stats[i].Item1, stat);
}
}
_callback(_stats);
Close();
}
private void TextBox_GotKeyboardFocus(object sender, RoutedEventArgs e)
{
(sender as TextBox)?.SelectAll();
}
private void Button_DecreaseStat(TextBox txt)
{
if (int.TryParse(txt.Text, out int value)) {
txt.Text = (--value).ToString();
}
}
private void Button_IncreaseStat(TextBox txt)
{
if (int.TryParse(txt.Text, out int value)) {
txt.Text = (++value).ToString();
}
}
}
}