-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
148 lines (126 loc) · 4.95 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
148 lines (126 loc) · 4.95 KB
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
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using System.Globalization;
using System.Linq;
using Microsoft.Win32;
using ControlzEx.Theming;
using System.Windows.Markup;
namespace bagpipe {
public partial class MainWindow : MetroWindow {
private readonly Profile profile;
public MainWindow() {
InitializeComponent();
Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name);
ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAppMode;
ThemeManager.Current.SyncTheme();
profile = new Profile();
DataContext = new ProfileViewModel(profile);
}
#region File Handling
private readonly OpenFileDialog openDialog = new OpenFileDialog() {
Filter = "Profile Files|profile.bin;Player.wsg|All Files (*.*)|*.*"
};
private readonly SaveFileDialog saveDialog = new SaveFileDialog() {
Filter = "Profile Files|profile.bin;Player.wsg"
};
private async void OpenButton_Click(object sender, RoutedEventArgs e) {
openDialog.FileName = "";
bool? ok = openDialog.ShowDialog();
if (ok.HasValue && ok.Value) {
ProgressRingDialog progress = new ProgressRingDialog(this);
MetroDialogSettings progressSettings = new MetroDialogSettings() {
AnimateShow = false,
AnimateHide = false,
OwnerCanCloseWithDialog = true,
};
await this.ShowMetroDialogAsync(progress, progressSettings);
bool warn = profile.Load(openDialog.FileName);
await this.HideMetroDialogAsync(progress, progressSettings);
if (warn) {
await this.ShowMessageAsync(
"Warning",
"Unexpected data was encountered while loading the profile. This may have caused some values to be intepreted incorrectly."
);
}
}
}
private async void SaveButton_Click(object sender, RoutedEventArgs e) {
saveDialog.FileName = "";
bool? ok = saveDialog.ShowDialog();
if (ok.HasValue && ok.Value) {
ProgressRingDialog progress = new ProgressRingDialog(this);
MetroDialogSettings progressSettings = new MetroDialogSettings() {
AnimateShow = false,
AnimateHide = false,
OwnerCanCloseWithDialog = true,
};
await this.ShowMetroDialogAsync(progress, progressSettings);
bool isOverSizeLimit = profile.IsOverSizeLimit();
if (isOverSizeLimit) {
await this.HideMetroDialogAsync(progress, progressSettings);
MessageDialogResult res = await this.ShowMessageAsync(
"Warning",
"This profile contains over 9000 bytes of raw data, which may make the game read it as corrupt. Do you want to continue?",
MessageDialogStyle.AffirmativeAndNegative,
new MetroDialogSettings() {
AffirmativeButtonText = "Yes",
NegativeButtonText = "No",
AnimateShow = false,
AnimateHide = false,
OwnerCanCloseWithDialog = true,
}
);
if (res != MessageDialogResult.Affirmative) {
return;
}
await this.ShowMetroDialogAsync(progress, progressSettings);
}
profile.Save(saveDialog.FileName);
await this.HideMetroDialogAsync(progress, progressSettings);
}
}
#endregion
#region Entry Manipulation
private async void NewButton_Click(object sender, RoutedEventArgs e) {
NewEntryDialog dialog = new NewEntryDialog(
this,
new MetroDialogSettings() {
AffirmativeButtonText = "Yes",
NegativeButtonText = "No",
OwnerCanCloseWithDialog = true,
},
((ProfileViewModel)DataContext).DisplayGame
);
await this.ShowMetroDialogAsync(dialog);
ProfileEntry entry = await dialog.GetCreatedEntry();
if (!(entry is null)) {
profile.Entries.Add(entry);
}
await this.HideMetroDialogAsync(dialog);
}
private bool DeleteRawEntries() {
if (AdvancedSwitch.IsOn) {
IEnumerable<int> selectedIndexes = RawListView.SelectedItems.Cast<ProfileEntryViewModel>().Select(x => RawListView.Items.IndexOf(x));
foreach (int idx in selectedIndexes.OrderByDescending(x => x)) {
profile.Entries.RemoveAt(idx);
}
return true;
}
return false;
}
private void DeleteButton_Click(object sender, RoutedEventArgs e) {
DeleteRawEntries();
}
private void RawListView_KeyDown(object sender, KeyEventArgs e) {
if (e.Key == Key.Delete) {
e.Handled |= DeleteRawEntries();
}
}
#endregion
private void UnlockCustomizations_Click(object sender, RoutedEventArgs e) => ((ProfileViewModel)DataContext).UpdateCustomizations(true);
private void LockCustomizations_Click(object sender, RoutedEventArgs e) => ((ProfileViewModel)DataContext).UpdateCustomizations(false);
}
}