-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathDialogWindow.xaml.cs
180 lines (170 loc) · 5.6 KB
/
DialogWindow.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
using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace BetterHI3Launcher
{
public partial class DialogWindow : Window
{
public enum DialogType
{
Confirmation, Question, Install, Uninstall, CustomLaunchOptions, CustomBackground
}
public DialogWindow(string title, string message, DialogType type = DialogType.Confirmation)
{
Owner = Application.Current.MainWindow;
Left = Application.Current.MainWindow.Left + 10;
Top = Application.Current.MainWindow.Top + 10;
InitializeComponent();
DialogTitle.Text = title;
DialogMessage.Text = message;
ConfirmButton.Content = App.TextStrings["button_confirm"];
CancelButton.Content = App.TextStrings["button_cancel"];
switch(type)
{
case DialogType.Confirmation:
ConfirmButton.Content = App.TextStrings["button_ok"];
CancelButton.Visibility = Visibility.Collapsed;
break;
case DialogType.Question:
ConfirmButton.Content = App.TextStrings["button_yes"];
CancelButton.Content = App.TextStrings["button_no"];
break;
case DialogType.Install:
DialogMessageScrollViewer.Margin = new Thickness(0, 0, 0, 75);
DialogMessageScrollViewer.Height = 100;
InstallStackPanel.Visibility = Visibility.Visible;
break;
case DialogType.Uninstall:
DialogMessageScrollViewer.Margin = new Thickness(0, 0, 0, 100);
DialogMessageScrollViewer.Height = 50;
UninstallStackPanel.Visibility = Visibility.Visible;
UninstallGameFilesLabel.Text = App.TextStrings["msgbox_uninstall_game_files"];
UninstallGameCacheLabel.Text = App.TextStrings["msgbox_uninstall_game_cache"];
UninstallGameSettingsLabel.Text = App.TextStrings["msgbox_uninstall_game_settings"];
if(!Directory.Exists(MainWindow.GameCachePath))
{
UninstallGameCacheCheckBox.IsChecked = false;
UninstallGameCacheCheckBox.IsEnabled = false;
}
if(Registry.CurrentUser.OpenSubKey(MainWindow.GameRegistryPath) == null)
{
UninstallGameSettingsCheckBox.IsChecked = false;
UninstallGameSettingsCheckBox.IsEnabled = false;
}
break;
case DialogType.CustomLaunchOptions:
DialogMessageScrollViewer.Margin = new Thickness(0, 0, 0, 75);
DialogMessageScrollViewer.Height = 100;
CustomLaunchOptionsStackPanel.Visibility = Visibility.Visible;
break;
case DialogType.CustomBackground:
DialogMessageScrollViewer.Margin = new Thickness(0, 0, 0, 75);
DialogMessageScrollViewer.Height = 80;
CustomBackgroundStackPanel.Visibility = Visibility.Visible;
CustomBackgroundEditLabel.Text = App.TextStrings["msgbox_custom_background_edit"];
CustomBackgroundDeleteLabel.Text = App.TextStrings["msgbox_custom_background_delete"];
break;
}
switch(App.LauncherLanguage)
{
case "en":
case "zh-CN":
break;
case "ja":
Resources["Font"] = new FontFamily("Meiryo UI Bold");
break;
default:
Resources["Font"] = new FontFamily("Segoe UI Bold");
break;
}
Application.Current.MainWindow.WindowState = WindowState.Normal;
BpUtility.PlaySound(Properties.Resources.Window_Open);
}
private void ConfirmButton_Click(object sender, RoutedEventArgs e)
{
BpUtility.PlaySound(Properties.Resources.Click);
DialogResult = true;
Close();
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
BpUtility.PlaySound(Properties.Resources.Click);
Close();
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
BpUtility.PlaySound(Properties.Resources.Click);
var dialog = new CommonOpenFileDialog
{
IsFolderPicker = true,
Multiselect = false,
DefaultDirectory = InstallPathTextBox.Text,
AddToMostRecentlyUsedList = false,
AllowNonFileSystemItems = false,
EnsurePathExists = true,
EnsureReadOnly = false,
EnsureValidNames = true
};
if(dialog.ShowDialog(this) == CommonFileDialogResult.Ok)
{
InstallPathTextBox.Text = Path.Combine(dialog.FileName, MainWindow.GameFullName);
string[] game_full_names = {"Honkai Impact 3rd", "Honkai Impact 3", "崩坏3", "崩壞3", "붕괴3rd", "Honkai Impact 3rd glb", "Honkai Impact 3 sea", "Honkai Impact 3rd tw", "Honkai Impact 3rd kr"};
foreach(string game_full_name in game_full_names)
{
if(dialog.FileName.Contains(game_full_name))
{
InstallPathTextBox.Text = dialog.FileName;
break;
}
}
}
}
private void InstallPathTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if(string.IsNullOrEmpty(InstallPathTextBox.Text))
{
ConfirmButton.IsEnabled = false;
}
else
{
ConfirmButton.IsEnabled = true;
}
}
private void UninstallCheckBox_Click(object sender, RoutedEventArgs e)
{
BpUtility.PlaySound(Properties.Resources.Click);
if(!(bool)UninstallGameFilesCheckBox.IsChecked && !(bool)UninstallGameCacheCheckBox.IsChecked && !(bool)UninstallGameSettingsCheckBox.IsChecked)
{
ConfirmButton.IsEnabled = false;
}
else
{
ConfirmButton.IsEnabled = true;
}
}
private void CustomBackgroundRadioButton_Click(object sender, RoutedEventArgs e)
{
BpUtility.PlaySound(Properties.Resources.Click);
}
protected override void OnKeyDown(KeyEventArgs e)
{
if(Keyboard.Modifiers == ModifierKeys.Alt && e.SystemKey == Key.Space)
{
e.Handled = true;
}
else
{
base.OnKeyDown(e);
}
}
private void DialogWindow_Closing(object sender, CancelEventArgs e)
{
BpUtility.PlaySound(Properties.Resources.Window_Close);
}
}
}