-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
ModCustomisationHeader.cs
139 lines (120 loc) · 4.58 KB
/
ModCustomisationHeader.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
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Localisation;
using osuTK;
using osuTK.Graphics;
using static osu.Game.Overlays.Mods.ModCustomisationPanel;
namespace osu.Game.Overlays.Mods
{
public partial class ModCustomisationHeader : OsuHoverContainer
{
private Box background = null!;
private Box backgroundFlash = null!;
private SpriteIcon icon = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
public readonly Bindable<ModCustomisationPanelState> ExpandedState = new Bindable<ModCustomisationPanelState>(ModCustomisationPanelState.Collapsed);
private readonly ModCustomisationPanel panel;
public ModCustomisationHeader(ModCustomisationPanel panel)
{
this.panel = panel;
Enabled.Value = false;
}
[BackgroundDependencyLoader]
private void load()
{
CornerRadius = 10f;
Masking = true;
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
backgroundFlash = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White.Opacity(0.4f),
Blending = BlendingParameters.Additive,
Alpha = 0,
},
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = ModSelectOverlayStrings.CustomisationPanelHeader,
UseFullGlyphHeight = false,
Font = OsuFont.Torus.With(size: 20f, weight: FontWeight.SemiBold),
Margin = new MarginPadding { Left = 20f },
},
new Container
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Size = new Vector2(16f),
Margin = new MarginPadding { Right = 20f },
Child = icon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.ChevronDown,
RelativeSizeAxes = Axes.Both,
}
}
};
IdleColour = colourProvider.Dark3;
HoverColour = colourProvider.Light4;
}
protected override void LoadComplete()
{
base.LoadComplete();
Enabled.BindValueChanged(e =>
{
TooltipText = e.NewValue
? string.Empty
: ModSelectOverlayStrings.CustomisationPanelDisabledReason;
if (e.NewValue)
{
backgroundFlash.FadeInFromZero(150, Easing.OutQuad).Then()
.FadeOutFromOne(350, Easing.OutQuad);
}
}, true);
ExpandedState.BindValueChanged(v =>
{
icon.ScaleTo(v.NewValue > ModCustomisationPanelState.Collapsed ? new Vector2(1, -1) : Vector2.One, 300, Easing.OutQuint);
}, true);
}
private bool touchedThisFrame;
protected override bool OnTouchDown(TouchDownEvent e)
{
if (Enabled.Value)
{
touchedThisFrame = true;
Schedule(() => touchedThisFrame = false);
}
return base.OnTouchDown(e);
}
protected override bool OnHover(HoverEvent e)
{
if (Enabled.Value)
{
if (!touchedThisFrame && panel.ExpandedState.Value == ModCustomisationPanelState.Collapsed)
panel.ExpandedState.Value = ModCustomisationPanelState.Expanded;
}
return base.OnHover(e);
}
}
}