-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathPanelGroup.cs
More file actions
202 lines (176 loc) · 6.91 KB
/
PanelGroup.cs
File metadata and controls
202 lines (176 loc) · 6.91 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// 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;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Carousel;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Overlays;
using osuTK;
using osuTK.Graphics;
using WebCommonStrings = osu.Game.Resources.Localisation.Web.CommonStrings;
namespace osu.Game.Screens.Select
{
public partial class PanelGroup : Panel
{
public const float HEIGHT = CarouselItem.DEFAULT_HEIGHT * 1.2f;
private Drawable iconContainer = null!;
private OsuSpriteText titleText = null!;
private TrianglesV2 triangles = null!;
private CircularContainer countPill = null!;
private OsuSpriteText countText = null!;
private Box glow = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
[Resolved]
private ISongSelect? songSelect { get; set; }
[BackgroundDependencyLoader]
private void load()
{
Height = HEIGHT;
Icon = iconContainer = new Container
{
AlwaysPresent = true,
RelativeSizeAxes = Axes.Y,
Alpha = 0f,
Child = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.ChevronDown,
Size = new Vector2(12),
Colour = colourProvider.Background3,
},
};
Background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Highlight1,
};
AccentColour = colourProvider.Highlight1;
Content.Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5,
},
triangles = new TrianglesV2
{
RelativeSizeAxes = Axes.Both,
Thickness = 0.02f,
SpawnRatio = 0.6f,
Colour = ColourInfo.GradientHorizontal(colourProvider.Background6, colourProvider.Background5)
},
glow = new Box
{
RelativeSizeAxes = Axes.Both,
Width = 0.5f,
Colour = ColourInfo.GradientHorizontal(colourProvider.Highlight1, colourProvider.Highlight1.Opacity(0f)),
},
titleText = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.Style.Heading2,
UseFullGlyphHeight = false,
X = 10f,
},
countPill = new CircularContainer
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Size = new Vector2(50f, 14f),
Margin = new MarginPadding { Right = 30f },
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black.Opacity(0.7f),
},
countText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Style.Caption1.With(weight: FontWeight.Bold),
UseFullGlyphHeight = false,
}
},
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Expanded.BindValueChanged(_ => onExpanded(), true);
}
private void onExpanded()
{
const float duration = 500;
iconContainer.ResizeWidthTo(Expanded.Value ? 20f : 5f, duration, Easing.OutQuint);
iconContainer.FadeTo(Expanded.Value ? 1f : 0f, duration, Easing.OutQuint);
ColourInfo colour = Expanded.Value
? ColourInfo.GradientHorizontal(colourProvider.Highlight1.Opacity(0.25f), colourProvider.Highlight1.Opacity(0f))
: ColourInfo.GradientHorizontal(colourProvider.Background6, colourProvider.Background5);
triangles.FadeColour(colour, duration, Easing.OutQuint);
glow.FadeTo(Expanded.Value ? 0.4f : 0, duration, Easing.OutQuint);
}
protected override void PrepareForUse()
{
base.PrepareForUse();
Debug.Assert(Item != null);
GroupDefinition group = (GroupDefinition)Item.Model;
titleText.Text = group.Title;
countText.Text = Item.NestedItemCount.ToString("N0");
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
// Move the count pill in the opposite direction to keep it pinned to the screen regardless of the X position of TopLevelContent.
countPill.X = -TopLevelContent.X;
}
public override MenuItem[] ContextMenuItems
{
get
{
if (Item == null)
return Array.Empty<MenuItem>();
var group = (GroupDefinition)Item.Model;
var expandItem = new OsuMenuItem(
Expanded.Value ? WebCommonStrings.ButtonsCollapse.ToSentence() : WebCommonStrings.ButtonsExpand.ToSentence(),
MenuItemType.Highlighted,
() => TriggerClick());
if (songSelect == null)
{
return new MenuItem[]
{
expandItem
};
}
return new MenuItem[]
{
expandItem,
new OsuMenuItemSpacer(),
new OsuMenuItem(
SongSelectStrings.DeleteAllInGroup,
MenuItemType.Destructive,
() => songSelect.DeleteGroup(group))
};
}
}
}
}