-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathShopControl.xaml.cs
118 lines (105 loc) · 3.99 KB
/
ShopControl.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
/*
* Candy Clicker ver. 1.1.1
* Copyright © 2021-2022 Ptolemy Hill
*/
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace CandyClicker
{
/// <summary>
/// Interaction logic for ShopControl.xaml
/// </summary>
public partial class ShopControl : UserControl
{
public static readonly DependencyProperty ShopItemNameProperty = DependencyProperty.Register("ShopItemName", typeof(string), typeof(ShopControl));
public string ShopItemName
{
get => (string)GetValue(ShopItemNameProperty);
set => SetValue(ShopItemNameProperty, value);
}
public static readonly DependencyProperty ShopItemPriceProperty = DependencyProperty.Register("ShopItemPrice", typeof(ulong), typeof(ShopControl));
public ulong ShopItemPrice
{
get => (ulong)GetValue(ShopItemPriceProperty);
set => SetValue(ShopItemPriceProperty, value);
}
public static readonly DependencyProperty PriceForegroundProperty = DependencyProperty.Register("PriceForeground", typeof(Brush), typeof(ShopControl));
public Brush PriceForeground
{
get => (Brush)GetValue(PriceForegroundProperty);
set => SetValue(PriceForegroundProperty, value);
}
public ShopControl()
{
InitializeComponent();
}
private void UserControlShopItem_MouseEnter(object sender, MouseEventArgs e)
{
Storyboard sb = new()
{
Duration = new Duration(TimeSpan.FromSeconds(0.25))
};
DoubleAnimation slightWhiteFade = new()
{
From = 0,
To = 0.4,
Duration = sb.Duration
};
Storyboard.SetTarget(slightWhiteFade, rectangleFlasher);
Storyboard.SetTargetProperty(slightWhiteFade, new PropertyPath(OpacityProperty));
sb.Children.Add(slightWhiteFade);
sb.Begin();
}
private void UserControlShopItem_MouseLeave(object sender, MouseEventArgs e)
{
Storyboard sb = new()
{
Duration = new Duration(TimeSpan.FromSeconds(0.25))
};
DoubleAnimation slightWhiteFade = new()
{
From = 0.4,
To = 0,
Duration = sb.Duration
};
Storyboard.SetTarget(slightWhiteFade, rectangleFlasher);
Storyboard.SetTargetProperty(slightWhiteFade, new PropertyPath(OpacityProperty));
sb.Children.Add(slightWhiteFade);
sb.Begin();
}
private void UserControlShopItem_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
Storyboard sb = new()
{
Duration = new Duration(TimeSpan.FromSeconds(0.2))
};
DoubleAnimation slightWhiteFadeIn = new()
{
From = 0.4,
To = 1,
Duration = sb.Duration.TimeSpan / 2
};
Storyboard.SetTarget(slightWhiteFadeIn, rectangleFlasher);
Storyboard.SetTargetProperty(slightWhiteFadeIn, new PropertyPath(OpacityProperty));
sb.Children.Add(slightWhiteFadeIn);
DoubleAnimation slightWhiteFadeOut = new()
{
From = 1,
To = 0.4,
Duration = sb.Duration.TimeSpan / 2,
BeginTime = sb.Duration.TimeSpan / 2
};
Storyboard.SetTarget(slightWhiteFadeOut, rectangleFlasher);
Storyboard.SetTargetProperty(slightWhiteFadeOut, new PropertyPath(OpacityProperty));
sb.Children.Add(slightWhiteFadeOut);
sb.Begin();
}
}
}
}