-
Notifications
You must be signed in to change notification settings - Fork 3
/
CustomiseWindow.xaml.cs
183 lines (170 loc) · 6.59 KB
/
CustomiseWindow.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
/*
* Candy Clicker ver. 1.1.1
* Copyright © 2021-2022 Ptolemy Hill
*/
using Microsoft.Win32;
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace CandyClicker
{
/// <summary>
/// Interaction logic for CustomiseWindow.xaml
/// </summary>
public partial class CustomiseWindow : Window
{
string currentImagePath;
public CustomiseWindow(MainWindow parentWindow)
{
Owner = parentWindow;
InitializeComponent();
(Color startingBackground, Color startingForeground, currentImagePath) = ((MainWindow)Owner).GetCustomisations();
sliderBackgroundRed.Value = startingBackground.R;
sliderBackgroundGreen.Value = startingBackground.G;
sliderBackgroundBlue.Value = startingBackground.B;
sliderForegroundRed.Value = startingForeground.R;
sliderForegroundGreen.Value = startingForeground.G;
sliderForegroundBlue.Value = startingForeground.B;
if (currentImagePath != null)
{
textBlockImagePath.Text = currentImagePath;
}
UpdatePreview();
}
private void UpdatePreview()
{
Color newBackground = new()
{
A = 0xFF,
R = (byte)sliderBackgroundRed.Value,
G = (byte)sliderBackgroundGreen.Value,
B = (byte)sliderBackgroundBlue.Value
};
Color newForeground = new()
{
A = 0xFF,
R = (byte)sliderForegroundRed.Value,
G = (byte)sliderForegroundGreen.Value,
B = (byte)sliderForegroundBlue.Value
};
stackPanelPreview.Background = new SolidColorBrush(newBackground);
textBlockPreview.Foreground = new SolidColorBrush(newForeground);
if (currentImagePath != null)
{
imagePreview.Source = new BitmapImage(new Uri(currentImagePath));
}
}
private void ButtonImageChange_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog fileDialog = new()
{
Title = "Select Image",
Filter = "Images|*.png;*.jpg;*.jpeg"
};
bool? success = fileDialog.ShowDialog();
if (success.HasValue && success.Value && fileDialog.FileName != string.Empty)
{
currentImagePath = fileDialog.FileName;
textBlockImagePath.Text = currentImagePath;
UpdatePreview();
}
}
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Color newBackground = new()
{
A = 0xFF,
R = (byte)sliderBackgroundRed.Value,
G = (byte)sliderBackgroundGreen.Value,
B = (byte)sliderBackgroundBlue.Value
};
Color newForeground = new()
{
A = 0xFF,
R = (byte)sliderForegroundRed.Value,
G = (byte)sliderForegroundGreen.Value,
B = (byte)sliderForegroundBlue.Value
};
textBlockBackgroundRed.Text = $"Red ({newBackground.R})";
textBlockBackgroundGreen.Text = $"Green ({newBackground.G})";
textBlockBackgroundBlue.Text = $"Blue ({newBackground.B})";
textBlockForegroundRed.Text = $"Red ({newForeground.R})";
textBlockForegroundGreen.Text = $"Green ({newForeground.G})";
textBlockForegroundBlue.Text = $"Blue ({newForeground.B})";
UpdatePreview();
}
private void ButtonReset_Click(object sender, RoutedEventArgs e)
{
((MainWindow)Owner).ResetCustomisations();
Close();
}
private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
Color newBackground = new()
{
A = 0xFF,
R = (byte)sliderBackgroundRed.Value,
G = (byte)sliderBackgroundGreen.Value,
B = (byte)sliderBackgroundBlue.Value
};
Color newForeground = new()
{
A = 0xFF,
R = (byte)sliderForegroundRed.Value,
G = (byte)sliderForegroundGreen.Value,
B = (byte)sliderForegroundBlue.Value
};
((MainWindow)Owner).SetCustomisations(newBackground, newForeground, currentImagePath);
Close();
}
private void ImagePreview_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (e.ChangedButton == System.Windows.Input.MouseButton.Right)
{
Storyboard sb = new()
{
Duration = new Duration(TimeSpan.FromSeconds(0.25))
};
DoubleAnimation rotateCandy = new()
{
From = 0,
To = 360,
Duration = sb.Duration
};
Storyboard.SetTarget(rotateCandy, imagePreview);
Storyboard.SetTargetProperty(rotateCandy, new PropertyPath("RenderTransform.(TransformGroup.Children)[0].Angle"));
sb.Children.Add(rotateCandy);
sb.Begin();
}
else if (e.ChangedButton == System.Windows.Input.MouseButton.Left)
{
Storyboard sb = new()
{
Duration = new Duration(TimeSpan.FromSeconds(0.25))
};
DoubleAnimation shrinkX = new()
{
From = 1,
To = 0.9,
Duration = sb.Duration.TimeSpan / 2
};
Storyboard.SetTarget(shrinkX, imagePreview);
Storyboard.SetTargetProperty(shrinkX, new PropertyPath("RenderTransform.(TransformGroup.Children)[1].ScaleX"));
sb.Children.Add(shrinkX);
DoubleAnimation growX = new()
{
From = 0.9,
To = 1,
Duration = sb.Duration.TimeSpan / 2,
BeginTime = sb.Duration.TimeSpan / 2
};
Storyboard.SetTarget(growX, imagePreview);
Storyboard.SetTargetProperty(growX, new PropertyPath("RenderTransform.(TransformGroup.Children)[1].ScaleX"));
sb.Children.Add(growX);
sb.Begin();
}
}
}
}