1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-24 06:33:21 +08:00
osu-lazer/osu.Game/Overlays/BeatmapSet/BeatmapRulesetTabItem.cs

78 lines
2.4 KiB
C#
Raw Normal View History

2019-10-04 22:35:41 +08:00
// 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.Linq;
2019-10-04 22:35:41 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2019-10-04 22:35:41 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Extensions;
2019-10-04 22:35:41 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
2019-10-04 22:35:41 +08:00
using osu.Game.Rulesets;
namespace osu.Game.Overlays.BeatmapSet
{
2020-02-03 19:16:26 +08:00
public class BeatmapRulesetTabItem : OverlayRulesetTabItem
2019-10-04 22:35:41 +08:00
{
public readonly Bindable<APIBeatmapSet> BeatmapSet = new Bindable<APIBeatmapSet>();
2020-02-03 19:16:26 +08:00
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
private OsuSpriteText count;
private Container countContainer;
2019-10-04 22:35:41 +08:00
public BeatmapRulesetTabItem(RulesetInfo value)
: base(value)
{
2020-02-03 19:16:26 +08:00
}
2019-10-04 22:35:41 +08:00
2020-02-03 19:16:26 +08:00
[BackgroundDependencyLoader]
private void load()
{
Add(countContainer = new Container
2019-10-04 22:35:41 +08:00
{
2020-02-03 19:16:26 +08:00
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Masking = true,
CornerRadius = 4f,
Children = new Drawable[]
2019-10-04 22:35:41 +08:00
{
2020-02-03 19:16:26 +08:00
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background6
},
count = new OsuSpriteText
2019-10-04 22:35:41 +08:00
{
2020-02-03 19:16:26 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding { Horizontal = 5f },
Font = OsuFont.Default.With(weight: FontWeight.SemiBold),
Colour = colourProvider.Foreground1,
2019-10-04 22:35:41 +08:00
}
2020-02-03 19:16:26 +08:00
}
});
}
protected override void LoadComplete()
{
base.LoadComplete();
2019-10-04 22:35:41 +08:00
BeatmapSet.BindValueChanged(setInfo =>
{
int beatmapsCount = setInfo.NewValue?.Beatmaps.Count(b => b.Ruleset.MatchesOnlineID(Value)) ?? 0;
2019-10-31 15:23:10 +08:00
count.Text = beatmapsCount.ToString();
2020-02-03 19:16:26 +08:00
countContainer.FadeTo(beatmapsCount > 0 ? 1 : 0);
2019-10-31 15:23:10 +08:00
Enabled.Value = beatmapsCount > 0;
}, true);
2019-10-04 22:35:41 +08:00
}
}
}