-
Notifications
You must be signed in to change notification settings - Fork 1
/
SettingPanel.xaml.cs
178 lines (162 loc) · 5.4 KB
/
SettingPanel.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
using MaterialDesignThemes.Wpf;
using MaterialDesignColors;
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace BongoPawClicker
{
/// <summary>
/// SettingPanel.xaml
/// </summary>
public partial class SettingPanel : Window
{
private Key hotKey;
private ModifierKeys hotKeyModifiers;
public SettingPanel(Key key, ModifierKeys modifiers)
{
InitializeComponent();
hotKey = key;
hotKeyModifiers = modifiers;
UpdateHotKeyText();
}
private void SettingPanelDragZone(object sender, MouseButtonEventArgs e)
{
DragMove();
}
private void SettingPanel_CloseButton_Click(object sender, RoutedEventArgs e)
{
//Close Animation
var story = (Storyboard)this.Resources["HideWindow"];
if (story != null)
{
story.Completed += delegate { Close(); };
story.Begin(this);
}
//Close();
}
private void SettingPanel_Loaded(object sender, RoutedEventArgs e)
{
//Read Main Windows's Current Status
if (Owner is MainWindow mainWindow)
{
AlwaysOnTopToggleButton.IsChecked = mainWindow.topmost;
MeowButton.IsChecked = mainWindow.meow;
DarkModeToggleButton.IsChecked = mainWindow.darkMode;
}
}
#region HotKey
private void UpdateHotKeyText()
{
HotKeyTextBox.Text = $"{hotKeyModifiers} + {hotKey}";
}
private void HotKeyChangeButton_Click(object sender, RoutedEventArgs e)
{
if (Owner is MainWindow mainWindow)
{
mainWindow.UpdateHotKey(hotKey, hotKeyModifiers);
}
}
private void HotKeyTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
try
{
//Verify if the Key is valid
if (IsForbiddenKey(e.Key))
{
e.Handled = true;
return;
}
hotKey = e.Key;
hotKeyModifiers = Keyboard.Modifiers;
UpdateHotKeyText();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
}
private bool IsForbiddenKey(Key key)
{
return Enum.IsDefined(typeof(ForbiddenKeys), key.ToString());
}
public enum ForbiddenKeys
{
Back,
Capital, CapsLock,
Delete, Down,
End, Enter, Escape,
Home,
Insert,
Left, LeftAlt, LeftCtrl, LeftShift, LWin,
Next, NumLock,
PageDown, PageUp, Pause, PrintScreen,
Return, Right, RightAlt, RightCtrl, RightShift, RWin,
System,
Tab,
Up,
VolumeDown, VolumeMute, VolumeUp
};
#endregion
#region Always On Top
private void AlwaysOnTopToggleButton_Checked(object sender, RoutedEventArgs e)
{
if (Owner is MainWindow mainWindow)
{
//Make the main window visible again
mainWindow.topmost = true;
mainWindow.Topmost = true;
}
}
private void AlwaysOnTopToggleButton_Unchecked(object sender, RoutedEventArgs e)
{
if (Owner is MainWindow mainWindow)
{
//Make the main window visible again
mainWindow.topmost = false;
mainWindow.Topmost = false;
}
}
#endregion
#region Meow
private void MeowButton_Checked(object sender, RoutedEventArgs e)
{
if (Owner is MainWindow mainWindow)
{
mainWindow.meow = true;
}
}
private void MeowButton_Unchecked(object sender, RoutedEventArgs e)
{
if (Owner is MainWindow mainWindow)
{
mainWindow.meow = false;
}
}
#endregion
#region Dark Mode
private void DarkModeToggleButton_Checked(object sender, RoutedEventArgs e)
{
if (Owner is MainWindow mainWindow)
{
mainWindow.SwitchToDarkMode();
}
//Force the current window to refresh dynamic resources
Resources["CardBackgroundColor"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3d3d3d"));
Resources["IndicatorColor"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffb330"));
}
private void DarkModeToggleButton_Unchecked(object sender, RoutedEventArgs e)
{
if (Owner is MainWindow mainWindow)
{
mainWindow.SwitchToLightMode();
}
//Force the current window to refresh dynamic resources
Resources["CardBackgroundColor"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#f8f8ff"));
Resources["IndicatorColor"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b39ddb"));
}
#endregion
}
}