2023-01-16 15:57:18 +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.
|
|
|
|
|
2023-01-16 17:03:38 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2023-01-16 15:57:18 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-01-16 16:35:27 +00:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2023-01-16 15:57:18 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2023-01-16 17:03:38 +00:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2023-01-16 16:15:37 +00:00
|
|
|
using osu.Framework.Input.Events;
|
2023-01-16 16:35:27 +00:00
|
|
|
using osu.Framework.Localisation;
|
2023-01-16 17:03:38 +00:00
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Game.Database;
|
2023-01-16 16:35:27 +00:00
|
|
|
using osu.Game.Graphics;
|
2023-01-16 15:57:18 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
2023-01-16 16:35:27 +00:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2023-01-16 17:03:38 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2023-01-16 16:15:37 +00:00
|
|
|
using osu.Game.Overlays;
|
2023-01-16 17:03:38 +00:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.UI;
|
2023-01-16 16:35:27 +00:00
|
|
|
using osu.Game.Scoring;
|
2023-01-16 17:03:38 +00:00
|
|
|
using osu.Game.Screens.Select;
|
2023-01-16 16:35:27 +00:00
|
|
|
using osu.Game.Utils;
|
2023-01-16 15:57:18 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Leaderboards
|
|
|
|
{
|
2023-01-16 17:03:38 +00:00
|
|
|
public partial class LeaderBoardScoreV2 : OsuClickableContainer, IHasContextMenu
|
2023-01-16 15:57:18 +00:00
|
|
|
{
|
2023-01-16 16:35:27 +00:00
|
|
|
private readonly ScoreInfo score;
|
|
|
|
|
2023-01-16 15:57:18 +00:00
|
|
|
private const int HEIGHT = 60;
|
|
|
|
private const int corner_radius = 10;
|
2023-01-16 16:15:37 +00:00
|
|
|
private const int transition_duration = 200;
|
|
|
|
|
2023-01-16 16:35:27 +00:00
|
|
|
private readonly int? rank;
|
|
|
|
|
|
|
|
private readonly bool isPersonalBest;
|
|
|
|
|
2023-01-16 16:15:37 +00:00
|
|
|
private Colour4 foregroundColour;
|
|
|
|
private Colour4 backgroundColour;
|
2023-01-16 15:57:18 +00:00
|
|
|
|
|
|
|
private static readonly Vector2 shear = new Vector2(0.15f, 0);
|
|
|
|
|
2023-01-16 16:15:37 +00:00
|
|
|
[Cached]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
|
|
|
|
|
2023-01-16 17:03:38 +00:00
|
|
|
[Resolved]
|
|
|
|
private SongSelect? songSelect { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IDialogOverlay? dialogOverlay { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private Storage storage { get; set; } = null!;
|
|
|
|
|
2023-01-16 15:57:18 +00:00
|
|
|
private Container content = null!;
|
2023-01-16 16:15:37 +00:00
|
|
|
private Box background = null!;
|
|
|
|
private Box foreground = null!;
|
|
|
|
|
2023-01-16 17:03:38 +00:00
|
|
|
protected Container RankContainer { get; private set; } = null!;
|
|
|
|
private FillFlowContainer<ColouredModSwitchTiny> modsContainer = null!;
|
|
|
|
|
|
|
|
private OsuSpriteText scoreText = null!;
|
|
|
|
private Drawable scoreRank = null!;
|
|
|
|
|
2023-01-16 16:35:27 +00:00
|
|
|
public LeaderBoardScoreV2(ScoreInfo score, int? rank, bool isPersonalBest = false)
|
2023-01-16 16:15:37 +00:00
|
|
|
{
|
2023-01-16 16:35:27 +00:00
|
|
|
this.score = score;
|
|
|
|
this.rank = rank;
|
2023-01-16 16:15:37 +00:00
|
|
|
this.isPersonalBest = isPersonalBest;
|
|
|
|
}
|
2023-01-16 15:57:18 +00:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2023-01-16 17:03:38 +00:00
|
|
|
private void load(ScoreManager scoreManager)
|
2023-01-16 15:57:18 +00:00
|
|
|
{
|
2023-01-16 16:15:37 +00:00
|
|
|
foregroundColour = isPersonalBest ? colourProvider.Background1 : colourProvider.Background5;
|
|
|
|
backgroundColour = isPersonalBest ? colourProvider.Background2 : colourProvider.Background4;
|
|
|
|
|
2023-01-16 15:57:18 +00:00
|
|
|
Shear = shear;
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Height = HEIGHT;
|
|
|
|
Child = content = new Container
|
|
|
|
{
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = corner_radius,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2023-01-16 16:15:37 +00:00
|
|
|
background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = backgroundColour
|
|
|
|
},
|
|
|
|
new GridContainer
|
2023-01-16 15:57:18 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2023-01-16 16:15:37 +00:00
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.Absolute, 65),
|
|
|
|
new Dimension(),
|
|
|
|
new Dimension(GridSizeMode.Absolute, 176)
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
2023-01-16 17:03:38 +00:00
|
|
|
new Drawable[]
|
2023-01-16 16:15:37 +00:00
|
|
|
{
|
2023-01-16 16:35:27 +00:00
|
|
|
new RankLabel(rank)
|
|
|
|
{
|
|
|
|
Shear = -shear,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Width = 35
|
|
|
|
},
|
2023-01-16 16:15:37 +00:00
|
|
|
createCentreContent(),
|
2023-01-16 17:03:38 +00:00
|
|
|
createRightSideContent(scoreManager)
|
2023-01-16 16:15:37 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-16 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2023-01-16 17:03:38 +00:00
|
|
|
|
|
|
|
modsContainer.Spacing = new Vector2(modsContainer.Children.Count > 5 ? -20 : 2, 0);
|
|
|
|
modsContainer.Padding = new MarginPadding { Top = modsContainer.Children.Count > 0 ? 4 : 0 };
|
2023-01-16 15:57:18 +00:00
|
|
|
}
|
2023-01-16 16:15:37 +00:00
|
|
|
|
|
|
|
private Container createCentreContent() =>
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = corner_radius,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
foreground = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = foregroundColour
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-16 17:03:38 +00:00
|
|
|
private FillFlowContainer createRightSideContent(ScoreManager scoreManager) =>
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Padding = new MarginPadding { Left = 11, Right = 15 },
|
|
|
|
Y = -5,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(13, 0f),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
scoreText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Shear = -shear,
|
|
|
|
Current = scoreManager.GetBindableTotalScoreString(score),
|
|
|
|
|
|
|
|
//Does not match figma, adjusted to allow 8 digits to fit comfortably
|
|
|
|
Font = OsuFont.GetFont(size: 28, weight: FontWeight.SemiBold, fixedWidth: false),
|
|
|
|
},
|
|
|
|
RankContainer = new Container
|
|
|
|
{
|
|
|
|
BypassAutoSizeAxes = Axes.Both,
|
|
|
|
Y = 2,
|
|
|
|
Shear = -shear,
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
scoreRank = new UpdateableRank(score.Rank)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
modsContainer = new FillFlowContainer<ColouredModSwitchTiny>
|
|
|
|
{
|
|
|
|
Shear = -shear,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
ChildrenEnumerable = score.Mods.Select(mod => new ColouredModSwitchTiny(mod) { Scale = new Vector2(0.375f) })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-16 16:15:37 +00:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
foreground.FadeColour(IsHovered ? foregroundColour.Lighten(0.2f) : foregroundColour, transition_duration, Easing.OutQuint);
|
|
|
|
background.FadeColour(IsHovered ? backgroundColour.Lighten(0.2f) : backgroundColour, transition_duration, Easing.OutQuint);
|
|
|
|
}
|
2023-01-16 16:35:27 +00:00
|
|
|
|
|
|
|
private partial class RankLabel : Container, IHasTooltip
|
|
|
|
{
|
|
|
|
public RankLabel(int? rank)
|
|
|
|
{
|
|
|
|
if (rank >= 1000)
|
|
|
|
TooltipText = $"#{rank:N0}";
|
|
|
|
|
|
|
|
Child = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 20, weight: FontWeight.SemiBold, italics: true),
|
|
|
|
Text = rank == null ? "-" : rank.Value.FormatRank().Insert(0, "#")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public LocalisableString TooltipText { get; }
|
|
|
|
}
|
2023-01-16 17:03:38 +00:00
|
|
|
|
|
|
|
private partial class ColouredModSwitchTiny : ModSwitchTiny
|
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
|
|
|
|
|
|
|
public ColouredModSwitchTiny(IMod mod)
|
|
|
|
: base(mod)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateState()
|
|
|
|
{
|
|
|
|
AcronymText.Colour = Colour4.FromHex("#555555");
|
|
|
|
Background.Colour = colours.Yellow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public MenuItem[] ContextMenuItems
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
List<MenuItem> items = new List<MenuItem>();
|
|
|
|
|
|
|
|
if (score.Mods.Length > 0 && modsContainer.Any(s => s.IsHovered) && songSelect != null)
|
|
|
|
items.Add(new OsuMenuItem("Use these mods", MenuItemType.Highlighted, () => songSelect.Mods.Value = score.Mods));
|
|
|
|
|
|
|
|
if (score.Files.Count <= 0) return items.ToArray();
|
|
|
|
|
|
|
|
items.Add(new OsuMenuItem("Export", MenuItemType.Standard, () => new LegacyScoreExporter(storage).Export(score)));
|
|
|
|
items.Add(new OsuMenuItem(CommonStrings.ButtonsDelete, MenuItemType.Destructive, () => dialogOverlay?.Push(new LocalScoreDeleteDialog(score))));
|
|
|
|
|
|
|
|
return items.ToArray();
|
|
|
|
}
|
|
|
|
}
|
2023-01-16 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|