-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
384 lines (357 loc) · 14.3 KB
/
MainWindow.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
using GenshinConfigurator;
using System.ComponentModel;
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;
using System.Windows.Threading;
namespace GenshinConfigurator
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
SettingsContainer Settings;
ResolutionSettings Resolution;
DispatcherTimer StatusTextTimer;
string status_text;
public string StatusText {
get { return status_text; }
private set { status_text = value; }
}
public MainWindow()
{
StatusTextTimer = new DispatcherTimer();
StatusTextTimer.Interval = TimeSpan.FromSeconds(10);
StatusTextTimer.Tick += new EventHandler(ResetStatusText);
Settings = new SettingsContainer();
Settings.Populate();
Resolution = Settings.Resolution;
InitializeComponent();
ShowStatusText("Loaded config from registry.");
this.DataContext = this;
}
public void SettingsApply(object sender, RoutedEventArgs e)
{
Settings.Apply();
Settings.ToReg();
ShowStatusText("Saved config to registry.");
}
public void SettingsReset(object sender, RoutedEventArgs e)
{
Settings.Populate();
RefreshBoxes();
ShowStatusText("Reloaded config from registry.");
}
public void RefreshBoxes()
{
this.DataContext = null;
this.DataContext = this;
}
public void ShowStatusText(string text)
{
StatusText = text;
StatusLabel.GetBindingExpression(Label.ContentProperty).UpdateTarget();
StatusTextTimer.Stop();
StatusTextTimer.Start();
}
public void ResetStatusText(object sender, EventArgs e)
{
StatusText = "Ready.";
StatusTextTimer.Stop();
StatusLabel.GetBindingExpression(Label.ContentProperty).UpdateTarget();
}
#region Graphics
public void GraphicsLowestSettings()
{
GraphicsFPSIndex = 0;
GraphicsVSync = 1;
GraphicsRenderResolution = 1;
GraphicsShadowQuality = 0;
GraphicsVisualEffects = 0;
GraphicsSFXQuality = 0;
GraphicsEnvironmentDetail = 0;
GraphicsAntialiasing = 0;
GraphicsVolumetricFog = 0;
GraphicsReflections = 0;
GraphicsMotionBlur = 0;
GraphicsBloom = 1;
GraphicsCrowdDensity = 1;
GraphicsSubsurfaceScattering = 0;
GraphicsTeammateEffects = 0;
GraphicsAnisotropicFiltering = 0;
}
public void GraphicsLowSettings()
{
GraphicsFPSIndex = 0;
GraphicsVSync = 1;
GraphicsRenderResolution = 2;
GraphicsShadowQuality = 1;
GraphicsVisualEffects = 1;
GraphicsSFXQuality = 1;
GraphicsEnvironmentDetail = 1;
GraphicsAntialiasing = 2;
GraphicsVolumetricFog = 0;
GraphicsReflections = 0;
GraphicsMotionBlur = 0;
GraphicsBloom = 1;
GraphicsCrowdDensity = 1;
GraphicsSubsurfaceScattering = 1;
GraphicsTeammateEffects = 0;
GraphicsAnisotropicFiltering = 0;
}
public void GraphicsMediumSettings()
{
GraphicsFPSIndex = 1;
GraphicsVSync = 1;
GraphicsRenderResolution = 2;
GraphicsShadowQuality = 2;
GraphicsVisualEffects = 2;
GraphicsSFXQuality = 2;
GraphicsEnvironmentDetail = 2;
GraphicsAntialiasing = 2;
GraphicsVolumetricFog = 1;
GraphicsReflections = 0;
GraphicsMotionBlur = 2;
GraphicsBloom = 1;
GraphicsCrowdDensity = 1;
GraphicsSubsurfaceScattering = 1;
GraphicsTeammateEffects = 0;
GraphicsAnisotropicFiltering = 0;
}
public void GraphicsHighSettings()
{
GraphicsFPSIndex = 1;
GraphicsVSync = 1;
GraphicsRenderResolution = 3;
GraphicsShadowQuality = 3;
GraphicsVisualEffects = 3;
GraphicsSFXQuality = 3;
GraphicsEnvironmentDetail = 3;
GraphicsAntialiasing = 2;
GraphicsVolumetricFog = 1;
GraphicsReflections = 1;
GraphicsMotionBlur = 3;
GraphicsBloom = 1;
GraphicsCrowdDensity = 1;
GraphicsSubsurfaceScattering = 2;
GraphicsTeammateEffects = 0;
GraphicsAnisotropicFiltering = 0;
}
#endregion
#region Input
private void InputPreventInput(object sender, KeyEventArgs e)
{
e.Handled = true;
}
private void InputEditKeyboardKey(object sender, KeyEventArgs e)
{
if (Keycodes.keyboard.ContainsKey(e.Key)) //Valid key
{
((sender as TextBox).Tag as KeyboardKeybind).elementIdentifierId = Keycodes.keyboard[e.Key];
}
InputDeviceComboBox.Focus();
}
private void InputKeyboardToggleEdit(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
if (tb.IsFocused)
{
tb.Text = "Press desired key...";
} else
{
tb.Text = Keycodes.keynames[(tb.Tag as KeyboardKeybind).elementIdentifierId];
}
}
private void InputCheckAxisInvert(object sender, EventArgs e)
{
((sender as CheckBox).Tag as GamepadAxis).invert = (bool)(sender as CheckBox).IsChecked;
}
private void InputCheckCtrl(object sender, EventArgs e)
{
((sender as CheckBox).Tag as KeyboardKeybind).ctrl = (bool)(sender as CheckBox).IsChecked;
}
private void InputCheckAlt(object sender, EventArgs e)
{
((sender as CheckBox).Tag as KeyboardKeybind).alt = (bool)(sender as CheckBox).IsChecked;
}
private void InputCheckShift(object sender, EventArgs e)
{
((sender as CheckBox).Tag as KeyboardKeybind).shift = (bool)(sender as CheckBox).IsChecked;
}
private void InputControllerChange(object sender, SelectionChangedEventArgs e)
{
bool devmode = false;
InputContainer.Children.Clear();
Controller? c = InputDeviceComboBox.SelectedItem as Controller;
if (c != null)
{
foreach (Keybind kb in c.keybinds)
{
string action;
try
{
action = Keycodes.actions[kb.actionId];
}
catch
{
action = "?";
}
if (action.Contains("?") && !devmode) continue;
Grid container = new Grid();
container.ColumnDefinitions.Add(new ColumnDefinition());
container.ColumnDefinitions.Add(new ColumnDefinition());
Label l = new();
l.Content = action;
Grid.SetColumn(l, 0);
Grid.SetRow(l, 0);
container.Children.Add(l);
if (c is KeyboardController)
{
KeyboardKeybind k = (kb as KeyboardKeybind);
StackPanel p = new StackPanel();
p.Orientation = Orientation.Horizontal;
CheckBox ctrl = new CheckBox();
ctrl.Content = "Ctrl";
ctrl.IsChecked = k.ctrl;
ctrl.Checked += new RoutedEventHandler(InputCheckCtrl);
ctrl.Tag = kb;
ctrl.VerticalAlignment = VerticalAlignment.Center;
ctrl.Padding = new Thickness(0, 0, 10, 0);
CheckBox alt = new CheckBox();
alt.Content = "Alt";
alt.IsChecked = k.alt;
alt.Checked += new RoutedEventHandler(InputCheckAlt);
alt.Tag = kb;
alt.VerticalAlignment = VerticalAlignment.Center;
alt.Padding = new Thickness(0, 0, 10, 0);
CheckBox shift = new CheckBox();
shift.Content = "Shift";
shift.IsChecked = k.shift;
shift.Checked += new RoutedEventHandler(InputCheckShift);
shift.Tag = kb;
shift.VerticalAlignment = VerticalAlignment.Center;
shift.Padding = new Thickness(0, 0, 10, 0);
TextBox tb = new TextBox();
tb.MaxHeight = 25;
tb.Width = 120;
tb.Text = Keycodes.keynames[kb.elementIdentifierId];
tb.Tag = kb;
tb.KeyDown += new KeyEventHandler(InputPreventInput);
tb.PreviewKeyDown += new KeyEventHandler(InputEditKeyboardKey);
tb.GotFocus += new RoutedEventHandler(InputKeyboardToggleEdit);
tb.LostFocus += new RoutedEventHandler(InputKeyboardToggleEdit);
p.Children.Add(ctrl);
p.Children.Add(alt);
p.Children.Add(shift);
p.Children.Add(tb);
p.HorizontalAlignment = HorizontalAlignment.Right;
Grid.SetColumn(p, 1);
Grid.SetRow(p, 0);
container.Children.Add(p);
} else
{
ComboBox cb = new();
cb.MaxHeight = 25;
cb.Width = 120;
cb.ItemsSource = Keycodes.xbox_gamepad_Key;
cb.SelectedIndex = kb.elementIdentifierId - Keycodes.AXIS_COUNT;
cb.HorizontalAlignment = HorizontalAlignment.Right;
Grid.SetColumn(cb, 1);
Grid.SetRow(cb, 0);
cb.Tag = kb;
cb.SelectionChanged += new SelectionChangedEventHandler(InputEditGamepadButton);
container.Children.Add(cb);
}
InputContainer.Children.Add(container);
}
foreach (GamepadAxis ax in c.axes)
{
string action;
try
{
action = Keycodes.actions[ax.actionId];
}
catch
{
action = "?";
}
if (action.Contains("?") && !devmode) continue;
Grid container = new Grid();
container.ColumnDefinitions.Add(new ColumnDefinition());
container.ColumnDefinitions.Add(new ColumnDefinition());
Label l = new();
l.Content = action;
Grid.SetColumn(l, 0);
Grid.SetRow(l, 0);
container.Children.Add(l);
StackPanel p = new StackPanel();
p.Orientation = Orientation.Horizontal;
CheckBox inv = new CheckBox();
inv.Content = "Invert";
inv.IsChecked = ax.invert;
inv.Checked += new RoutedEventHandler(InputCheckAxisInvert);
inv.Tag = ax;
inv.VerticalAlignment = VerticalAlignment.Center;
inv.Padding = new Thickness(0, 0, 10, 0);
ComboBox cb = new();
cb.MaxHeight = 25;
cb.Width = 120;
cb.ItemsSource = Keycodes.gamepad_axes;
cb.SelectedIndex = ax.elementIdentifierId;
cb.SelectionChanged += new SelectionChangedEventHandler(InputEditGamepadAxis);
cb.Tag = ax;
p.HorizontalAlignment = HorizontalAlignment.Right;
Grid.SetColumn(p, 1);
Grid.SetRow(p, 0);
p.Children.Add(inv);
p.Children.Add(cb);
container.Children.Add(p);
InputContainer.Children.Add(container);
}
}
}
private void InputEditGamepadAxis(object sender, EventArgs e)
{
((sender as ComboBox).Tag as GamepadAxis).elementIdentifierId = (sender as ComboBox).SelectedIndex;
}
private void InputEditGamepadButton(object sender, EventArgs e)
{
((sender as ComboBox).Tag as GamepadKeybind).elementIdentifierId = (sender as ComboBox).SelectedIndex + Keycodes.AXIS_COUNT;
}
#endregion
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if ((sender as TabControl).SelectedItem == RawConfigTab)
{
ApplyButton.IsEnabled = false;
ResetButton.IsEnabled = false;
} else
{
ApplyButton.IsEnabled = true;
ResetButton.IsEnabled = true;
}
}
private void RawConfigLoad(object sender, RoutedEventArgs e)
{
RawConfigTextBox.Text = Settings.Raw();
SettingsReset(null, null);
ShowStatusText("Loaded raw config from registry.");
}
private void RawConfigSave(object sender, RoutedEventArgs e)
{
Settings.Parse(RawConfigTextBox.Text);
Settings.Apply();
Settings.ToReg();
SettingsReset(null, null);
ShowStatusText("Saved raw config to registry.");
}
}
}