2019-06-16 01:02:26 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Allocation;
|
2018-07-13 16:15:06 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-07-13 16:15:06 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-06-16 01:02:26 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-07-13 16:15:06 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2019-06-16 01:02:26 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-06-16 01:02:26 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-12-27 17:16:17 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables
|
|
|
|
|
{
|
2019-06-16 01:02:26 +08:00
|
|
|
|
public class DifficultyIcon : DifficultyColouredContainer, IHasCustomTooltip
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-12-27 17:16:17 +08:00
|
|
|
|
private readonly RulesetInfo ruleset;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-17 23:44:28 +08:00
|
|
|
|
public DifficultyIcon(BeatmapInfo beatmap, RulesetInfo ruleset = null, Boolean shouldShowTooltip = false)
|
2018-07-13 16:15:06 +08:00
|
|
|
|
: base(beatmap)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
if (beatmap == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(beatmap));
|
|
|
|
|
|
2018-12-27 17:16:17 +08:00
|
|
|
|
this.ruleset = ruleset ?? beatmap.Ruleset;
|
2019-06-20 00:10:14 +08:00
|
|
|
|
TooltipText = shouldShowTooltip ? $"{beatmap.Version}${beatmap.StarDifficulty:0.##}" : String.Empty;
|
2018-12-27 17:16:17 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Size = new Vector2(20);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-16 01:02:26 +08:00
|
|
|
|
public string TooltipText { get; set; }
|
|
|
|
|
|
2019-06-16 01:40:44 +08:00
|
|
|
|
public ITooltip GetCustomTooltip() => new DifficultyIconTooltip(AccentColour);
|
2019-06-16 01:02:26 +08:00
|
|
|
|
|
|
|
|
|
public class DifficultyIconTooltip : VisibilityContainer, ITooltip
|
|
|
|
|
{
|
|
|
|
|
private readonly OsuSpriteText difficultyName, starRating;
|
|
|
|
|
private readonly Box background;
|
|
|
|
|
|
|
|
|
|
public string TooltipText { get; set; }
|
|
|
|
|
|
2019-06-16 01:40:44 +08:00
|
|
|
|
public DifficultyIconTooltip(Color4 accentColour)
|
2019-06-16 01:02:26 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Masking = true;
|
|
|
|
|
CornerRadius = 5;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Padding = new MarginPadding(10),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
difficultyName = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
starRating = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Regular),
|
2019-06-16 01:40:44 +08:00
|
|
|
|
Colour = accentColour
|
2019-06-16 01:02:26 +08:00
|
|
|
|
},
|
|
|
|
|
new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Margin = new MarginPadding { Left = 4 },
|
|
|
|
|
Icon = FontAwesome.Solid.Star,
|
|
|
|
|
Size = new Vector2(12),
|
2019-06-16 01:40:44 +08:00
|
|
|
|
Colour = accentColour,
|
2019-06-16 01:02:26 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
background.Colour = colours.GreyCarmineDark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Refresh()
|
|
|
|
|
{
|
|
|
|
|
var info = TooltipText.Split('$');
|
|
|
|
|
difficultyName.Text = info[0];
|
|
|
|
|
starRating.Text = info[1];
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-17 23:44:28 +08:00
|
|
|
|
public void Move(Vector2 pos) => Position = pos;
|
2019-06-16 01:02:26 +08:00
|
|
|
|
|
|
|
|
|
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-07-13 16:15:06 +08:00
|
|
|
|
new CircularContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-07-13 16:15:06 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Scale = new Vector2(0.84f),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2018-07-13 16:15:06 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Colour = Color4.Black.Opacity(0.08f),
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Radius = 5,
|
|
|
|
|
},
|
|
|
|
|
Child = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = AccentColour,
|
|
|
|
|
},
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
new ConstrainedIconContainer
|
|
|
|
|
{
|
2018-07-13 16:15:06 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
// the null coalesce here is only present to make unit tests work (ruleset dlls aren't copied correctly for testing at the moment)
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = ruleset?.CreateInstance().CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|