osu/osu.Game/Overlays/BeatmapSet/BeatmapRulesetTabItem.cs

78 lines
2.4 KiB
C#
Raw Normal View History

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