1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 08:12:56 +08:00

Merge remote-tracking branch 'refs/remotes/ppy/master' into kudosu-info

This commit is contained in:
Andrei Zavatski 2019-08-19 17:16:50 +03:00
commit fd21e06389
12 changed files with 228 additions and 115 deletions

View File

@ -129,6 +129,23 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
public List<ScoreInfo> Scores { get; set; } public List<ScoreInfo> Scores { get; set; }
[JsonIgnore]
public DifficultyRating DifficultyRating
{
get
{
var rating = StarDifficulty;
if (rating < 2.0) return DifficultyRating.Easy;
if (rating < 2.7) return DifficultyRating.Normal;
if (rating < 4.0) return DifficultyRating.Hard;
if (rating < 5.3) return DifficultyRating.Insane;
if (rating < 6.5) return DifficultyRating.Expert;
return DifficultyRating.ExpertPlus;
}
}
public override string ToString() => $"{Metadata} [{Version}]".Trim(); public override string ToString() => $"{Metadata} [{Version}]".Trim();
public bool Equals(BeatmapInfo other) public bool Equals(BeatmapInfo other)

View File

@ -0,0 +1,15 @@
// 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.
namespace osu.Game.Beatmaps
{
public enum DifficultyRating
{
Easy,
Normal,
Hard,
Insane,
Expert,
ExpertPlus
}
}

View File

@ -1,85 +0,0 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osuTK.Graphics;
namespace osu.Game.Beatmaps.Drawables
{
public abstract class DifficultyColouredContainer : Container, IHasAccentColour
{
public Color4 AccentColour { get; set; }
private readonly BeatmapInfo beatmap;
private OsuColour palette;
protected DifficultyColouredContainer(BeatmapInfo beatmap)
{
this.beatmap = beatmap;
}
[BackgroundDependencyLoader]
private void load(OsuColour palette)
{
if (palette == null)
throw new ArgumentNullException(nameof(palette));
this.palette = palette;
AccentColour = getColour(beatmap);
}
private enum DifficultyRating
{
Easy,
Normal,
Hard,
Insane,
Expert,
ExpertPlus
}
private DifficultyRating getDifficultyRating(BeatmapInfo beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
var rating = beatmap.StarDifficulty;
if (rating < 2.0) return DifficultyRating.Easy;
if (rating < 2.7) return DifficultyRating.Normal;
if (rating < 4.0) return DifficultyRating.Hard;
if (rating < 5.3) return DifficultyRating.Insane;
if (rating < 6.5) return DifficultyRating.Expert;
return DifficultyRating.ExpertPlus;
}
private Color4 getColour(BeatmapInfo beatmap)
{
switch (getDifficultyRating(beatmap))
{
case DifficultyRating.Easy:
return palette.Green;
default:
case DifficultyRating.Normal:
return palette.Blue;
case DifficultyRating.Hard:
return palette.Yellow;
case DifficultyRating.Insane:
return palette.Pink;
case DifficultyRating.Expert:
return palette.Purple;
case DifficultyRating.ExpertPlus:
return palette.Gray0;
}
}
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System; using System;
@ -6,33 +6,46 @@ using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Beatmaps.Drawables namespace osu.Game.Beatmaps.Drawables
{ {
public class DifficultyIcon : DifficultyColouredContainer public class DifficultyIcon : Container, IHasCustomTooltip
{ {
private readonly BeatmapInfo beatmap;
private readonly RulesetInfo ruleset; private readonly RulesetInfo ruleset;
public DifficultyIcon(BeatmapInfo beatmap, RulesetInfo ruleset = null) public DifficultyIcon(BeatmapInfo beatmap, RulesetInfo ruleset = null, bool shouldShowTooltip = true)
: base(beatmap)
{ {
if (beatmap == null) if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap)); throw new ArgumentNullException(nameof(beatmap));
this.beatmap = beatmap;
this.ruleset = ruleset ?? beatmap.Ruleset; this.ruleset = ruleset ?? beatmap.Ruleset;
if (shouldShowTooltip)
TooltipContent = beatmap;
Size = new Vector2(20); Size = new Vector2(20);
} }
public string TooltipText { get; set; }
public ITooltip GetCustomTooltip() => new DifficultyIconTooltip();
public object TooltipContent { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(OsuColour colours)
{ {
Children = new Drawable[] Children = new Drawable[]
{ {
@ -52,7 +65,7 @@ namespace osu.Game.Beatmaps.Drawables
Child = new Box Child = new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = AccentColour, Colour = colours.ForDifficultyRating(beatmap.DifficultyRating),
}, },
}, },
new ConstrainedIconContainer new ConstrainedIconContainer
@ -65,5 +78,105 @@ namespace osu.Game.Beatmaps.Drawables
} }
}; };
} }
private class DifficultyIconTooltip : VisibilityContainer, ITooltip
{
private readonly OsuSpriteText difficultyName, starRating;
private readonly Box background;
private readonly FillFlowContainer difficultyFlow;
public string TooltipText
{
set { }
}
public DifficultyIconTooltip()
{
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 5;
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
AutoSizeDuration = 200,
AutoSizeEasing = Easing.OutQuint,
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),
},
difficultyFlow = 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),
},
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding { Left = 4 },
Icon = FontAwesome.Solid.Star,
Size = new Vector2(12),
},
}
}
}
}
};
}
private OsuColour colours;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
this.colours = colours;
background.Colour = colours.Gray3;
}
public bool SetContent(object content)
{
if (!(content is BeatmapInfo beatmap))
return false;
difficultyName.Text = beatmap.Version;
starRating.Text = $"{beatmap.StarDifficulty:0.##}";
difficultyFlow.Colour = colours.ForDifficultyRating(beatmap.DifficultyRating);
return true;
}
public void Refresh()
{
}
public void Move(Vector2 pos) => Position = pos;
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
}
} }
} }

View File

@ -30,22 +30,24 @@ namespace osu.Game.Graphics.Cursor
private readonly OsuSpriteText text; private readonly OsuSpriteText text;
private bool instantMovement = true; private bool instantMovement = true;
public override string TooltipText public override bool SetContent(object content)
{ {
set if (!(content is string contentString))
return false;
if (contentString == text.Text) return true;
text.Text = contentString;
if (IsPresent)
{ {
if (value == text.Text) return; AutoSizeDuration = 250;
background.FlashColour(OsuColour.Gray(0.4f), 1000, Easing.OutQuint);
text.Text = value;
if (IsPresent)
{
AutoSizeDuration = 250;
background.FlashColour(OsuColour.Gray(0.4f), 1000, Easing.OutQuint);
}
else
AutoSizeDuration = 0;
} }
else
AutoSizeDuration = 0;
return true;
} }
public OsuTooltip() public OsuTooltip()

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using osu.Game.Beatmaps;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Graphics namespace osu.Game.Graphics
@ -37,6 +38,31 @@ namespace osu.Game.Graphics
} }
} }
public Color4 ForDifficultyRating(DifficultyRating difficulty)
{
switch (difficulty)
{
case DifficultyRating.Easy:
return Green;
default:
case DifficultyRating.Normal:
return Blue;
case DifficultyRating.Hard:
return Yellow;
case DifficultyRating.Insane:
return Pink;
case DifficultyRating.Expert:
return Purple;
case DifficultyRating.ExpertPlus:
return Gray0;
}
}
// See https://github.com/ppy/osu-web/blob/master/resources/assets/less/colors.less // See https://github.com/ppy/osu-web/blob/master/resources/assets/less/colors.less
public readonly Color4 PurpleLighter = FromHex(@"eeeeff"); public readonly Color4 PurpleLighter = FromHex(@"eeeeff");
public readonly Color4 PurpleLight = FromHex(@"aa88ff"); public readonly Color4 PurpleLight = FromHex(@"aa88ff");

View File

@ -234,7 +234,7 @@ namespace osu.Game.Overlays.BeatmapSet
Colour = Color4.Black.Opacity(0.5f), Colour = Color4.Black.Opacity(0.5f),
}, },
}, },
icon = new DifficultyIcon(beatmap) icon = new DifficultyIcon(beatmap, shouldShowTooltip: false)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,

View File

@ -92,6 +92,15 @@ namespace osu.Game.Overlays
}); });
} }
/// <summary>
/// Start playing the current track (if not already playing).
/// </summary>
public void Play()
{
if (!IsPlaying)
TogglePause();
}
/// <summary> /// <summary>
/// Toggle pause / play. /// Toggle pause / play.
/// </summary> /// </summary>

View File

@ -46,8 +46,11 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
if (!s.OnlineBeatmapSetID.HasValue) if (!s.OnlineBeatmapSetID.HasValue)
continue; continue;
var panel = new DirectGridPanel(s.ToBeatmapSet(Rulesets)); ItemsContainer.Add(new DirectGridPanel(s.ToBeatmapSet(Rulesets))
ItemsContainer.Add(panel); {
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
});
} }
}); });

View File

@ -402,31 +402,35 @@ namespace osu.Game.Screens.Select
} }
} }
private class DifficultyColourBar : DifficultyColouredContainer private class DifficultyColourBar : Container
{ {
private readonly BeatmapInfo beatmap;
public DifficultyColourBar(BeatmapInfo beatmap) public DifficultyColourBar(BeatmapInfo beatmap)
: base(beatmap)
{ {
this.beatmap = beatmap;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(OsuColour colours)
{ {
const float full_opacity_ratio = 0.7f; const float full_opacity_ratio = 0.7f;
var difficultyColour = colours.ForDifficultyRating(beatmap.DifficultyRating);
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = AccentColour, Colour = difficultyColour,
Width = full_opacity_ratio, Width = full_opacity_ratio,
}, },
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both, RelativePositionAxes = Axes.Both,
Colour = AccentColour, Colour = difficultyColour,
Alpha = 0.5f, Alpha = 0.5f,
X = full_opacity_ratio, X = full_opacity_ratio,
Width = 1 - full_opacity_ratio, Width = 1 - full_opacity_ratio,

View File

@ -82,7 +82,7 @@ namespace osu.Game.Screens.Select.Carousel
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Children = new Drawable[] Children = new Drawable[]
{ {
new DifficultyIcon(beatmap) new DifficultyIcon(beatmap, shouldShowTooltip: false)
{ {
Scale = new Vector2(1.8f), Scale = new Vector2(1.8f),
}, },

View File

@ -359,6 +359,7 @@ namespace osu.Game.Screens.Select
return; return;
beatmapNoDebounce = beatmap; beatmapNoDebounce = beatmap;
performUpdateSelected(); performUpdateSelected();
} }
@ -586,10 +587,18 @@ namespace osu.Game.Screens.Select
{ {
Track track = Beatmap.Value.Track; Track track = Beatmap.Value.Track;
if ((!track.IsRunning || restart) && music?.IsUserPaused != true) if (!track.IsRunning || restart)
{ {
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime; track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
track.Restart();
if (music != null)
{
// use the global music controller (when available) to cancel a potential local user paused state.
music.SeekTo(track.RestartPoint);
music.Play();
}
else
track.Restart();
} }
} }