2022-02-01 13:51:00 +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.
|
|
|
|
|
2022-02-01 13:28:18 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osuTK;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Framework.Allocation;
|
2022-08-15 02:54:02 +08:00
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
|
|
|
using osu.Framework.Localisation;
|
2022-02-01 13:28:18 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.UI;
|
2022-09-17 03:36:17 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Game.Configuration;
|
2022-02-01 13:28:18 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Online.Leaderboards
|
|
|
|
{
|
|
|
|
public class LeaderboardScoreTooltip : VisibilityContainer, ITooltip<ScoreInfo>
|
|
|
|
{
|
2022-02-01 15:35:22 +08:00
|
|
|
private OsuSpriteText timestampLabel = null!;
|
|
|
|
private FillFlowContainer<HitResultCell> topScoreStatistics = null!;
|
|
|
|
private FillFlowContainer<HitResultCell> bottomScoreStatistics = null!;
|
|
|
|
private FillFlowContainer<ModCell> modStatistics = null!;
|
2022-09-17 03:36:17 +08:00
|
|
|
private readonly Bindable<bool> prefer24HourTime = new Bindable<bool>();
|
2022-09-17 21:22:56 +08:00
|
|
|
|
2022-02-01 13:28:18 +08:00
|
|
|
public LeaderboardScoreTooltip()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2022-02-01 15:35:22 +08:00
|
|
|
AutoSizeDuration = 200;
|
|
|
|
AutoSizeEasing = Easing.OutQuint;
|
|
|
|
|
2022-02-01 13:28:18 +08:00
|
|
|
Masking = true;
|
|
|
|
CornerRadius = 5;
|
2022-02-01 15:35:22 +08:00
|
|
|
}
|
2022-02-01 13:28:18 +08:00
|
|
|
|
2022-02-01 15:35:22 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2022-09-17 03:36:17 +08:00
|
|
|
private void load(OsuColour colours, OsuConfigManager configManager)
|
2022-02-01 15:35:22 +08:00
|
|
|
{
|
2022-09-17 03:36:17 +08:00
|
|
|
configManager.BindWith(OsuSetting.Prefer24HourTime, prefer24HourTime);
|
2022-02-01 13:28:18 +08:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-02-01 15:35:22 +08:00
|
|
|
Alpha = 0.9f,
|
|
|
|
Colour = colours.Gray3,
|
2022-02-01 13:28:18 +08:00
|
|
|
},
|
2022-02-01 15:43:26 +08:00
|
|
|
new FillFlowContainer
|
2022-02-01 13:28:18 +08:00
|
|
|
{
|
2022-02-02 03:26:52 +08:00
|
|
|
Margin = new MarginPadding(5),
|
2022-02-01 15:43:26 +08:00
|
|
|
Spacing = new Vector2(10),
|
2022-02-01 13:28:18 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
2022-02-01 15:43:26 +08:00
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
2022-02-01 13:28:18 +08:00
|
|
|
{
|
|
|
|
// Info row
|
2022-02-01 15:43:26 +08:00
|
|
|
timestampLabel = new OsuSpriteText
|
2022-02-01 13:28:18 +08:00
|
|
|
{
|
2022-02-01 15:43:26 +08:00
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
|
2022-02-01 13:28:18 +08:00
|
|
|
},
|
|
|
|
// Mods row
|
2022-02-01 15:43:26 +08:00
|
|
|
modStatistics = new FillFlowContainer<ModCell>
|
2022-02-01 13:28:18 +08:00
|
|
|
{
|
2022-02-02 08:13:19 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
2022-02-02 03:26:52 +08:00
|
|
|
Spacing = new Vector2(5, 0),
|
2022-02-01 13:28:18 +08:00
|
|
|
},
|
2022-02-01 15:43:26 +08:00
|
|
|
new FillFlowContainer
|
2022-02-01 13:28:18 +08:00
|
|
|
{
|
2022-02-01 15:43:26 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
2022-02-01 13:28:18 +08:00
|
|
|
{
|
2022-02-01 15:43:26 +08:00
|
|
|
// Actual stats rows
|
|
|
|
topScoreStatistics = new FillFlowContainer<HitResultCell>
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
2022-02-02 03:26:52 +08:00
|
|
|
Spacing = new Vector2(10, 0),
|
2022-02-01 15:43:26 +08:00
|
|
|
},
|
|
|
|
bottomScoreStatistics = new FillFlowContainer<HitResultCell>
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
2022-02-02 03:26:52 +08:00
|
|
|
Spacing = new Vector2(10, 0),
|
2022-02-01 15:43:26 +08:00
|
|
|
},
|
2022-02-01 13:28:18 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2022-09-17 21:22:56 +08:00
|
|
|
|
2022-09-17 18:58:23 +08:00
|
|
|
protected override void LoadComplete()
|
2022-09-17 03:36:17 +08:00
|
|
|
{
|
2022-09-17 18:58:23 +08:00
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
prefer24HourTime.BindValueChanged(_ => updateTimestampLabel(), true);
|
2022-09-17 03:36:17 +08:00
|
|
|
}
|
2022-09-17 21:22:56 +08:00
|
|
|
|
2022-02-01 15:13:27 +08:00
|
|
|
private ScoreInfo? displayedScore;
|
2022-02-01 13:28:18 +08:00
|
|
|
|
|
|
|
public void SetContent(ScoreInfo score)
|
|
|
|
{
|
2022-02-01 15:13:27 +08:00
|
|
|
if (displayedScore?.Equals(score) == true)
|
2022-02-01 13:28:18 +08:00
|
|
|
return;
|
2022-02-01 14:10:00 +08:00
|
|
|
|
2022-02-01 15:13:27 +08:00
|
|
|
displayedScore = score;
|
2022-02-01 13:28:18 +08:00
|
|
|
|
2022-09-17 18:58:23 +08:00
|
|
|
updateTimestampLabel();
|
2022-02-01 13:28:18 +08:00
|
|
|
|
|
|
|
modStatistics.Clear();
|
|
|
|
topScoreStatistics.Clear();
|
|
|
|
bottomScoreStatistics.Clear();
|
|
|
|
|
|
|
|
foreach (var mod in score.Mods)
|
|
|
|
{
|
|
|
|
modStatistics.Add(new ModCell(mod));
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var result in score.GetStatisticsForDisplay())
|
|
|
|
{
|
2022-02-01 15:35:22 +08:00
|
|
|
if (result.Result > HitResult.Perfect)
|
|
|
|
bottomScoreStatistics.Add(new HitResultCell(result));
|
|
|
|
else
|
|
|
|
topScoreStatistics.Add(new HitResultCell(result));
|
2022-02-01 13:28:18 +08:00
|
|
|
}
|
|
|
|
}
|
2022-09-17 21:22:56 +08:00
|
|
|
|
2022-09-17 18:58:23 +08:00
|
|
|
private void updateTimestampLabel()
|
|
|
|
{
|
|
|
|
if (displayedScore != null)
|
|
|
|
{
|
2022-09-17 21:22:56 +08:00
|
|
|
timestampLabel.Text = prefer24HourTime.Value
|
|
|
|
? $"Played on {displayedScore.Date.ToLocalTime():d MMMM yyyy HH:mm}"
|
|
|
|
: $"Played on {displayedScore.Date.ToLocalTime():d MMMM yyyy h:mm tt}";
|
2022-09-17 18:58:23 +08:00
|
|
|
}
|
|
|
|
}
|
2022-02-01 13:28:18 +08:00
|
|
|
|
|
|
|
protected override void PopIn() => this.FadeIn(20, Easing.OutQuint);
|
|
|
|
protected override void PopOut() => this.FadeOut(80, Easing.OutQuint);
|
|
|
|
|
|
|
|
public void Move(Vector2 pos) => Position = pos;
|
|
|
|
|
|
|
|
private class HitResultCell : CompositeDrawable
|
|
|
|
{
|
2022-08-15 02:54:02 +08:00
|
|
|
private readonly LocalisableString displayName;
|
2022-02-01 15:07:57 +08:00
|
|
|
private readonly HitResult result;
|
|
|
|
private readonly int count;
|
2022-02-01 13:28:18 +08:00
|
|
|
|
|
|
|
public HitResultCell(HitResultDisplayStatistic stat)
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
2022-08-15 02:54:02 +08:00
|
|
|
displayName = stat.DisplayName.ToUpper();
|
2022-02-01 15:07:57 +08:00
|
|
|
result = stat.Result;
|
|
|
|
count = stat.Count;
|
2022-02-01 13:28:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
{
|
|
|
|
Height = 12,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Direction = FillDirection.Horizontal,
|
2022-02-02 03:26:52 +08:00
|
|
|
Spacing = new Vector2(5f, 0f),
|
2022-02-01 13:28:18 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-02-02 03:26:52 +08:00
|
|
|
new OsuSpriteText
|
2022-02-01 13:28:18 +08:00
|
|
|
{
|
2022-02-02 03:26:52 +08:00
|
|
|
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.SemiBold),
|
2022-08-15 02:54:02 +08:00
|
|
|
Text = displayName.ToUpper(),
|
2022-02-02 03:26:52 +08:00
|
|
|
Colour = colours.ForHitResult(result),
|
2022-02-01 13:28:18 +08:00
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
|
2022-02-01 15:07:57 +08:00
|
|
|
Text = count.ToString(),
|
2022-02-01 13:28:18 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ModCell : CompositeDrawable
|
|
|
|
{
|
2022-02-01 15:07:57 +08:00
|
|
|
private readonly Mod mod;
|
2022-02-01 13:28:18 +08:00
|
|
|
|
|
|
|
public ModCell(Mod mod)
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2022-02-01 15:07:57 +08:00
|
|
|
this.mod = mod;
|
2022-02-01 13:28:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2022-02-01 13:45:59 +08:00
|
|
|
FillFlowContainer container;
|
|
|
|
InternalChild = container = new FillFlowContainer
|
2022-02-01 13:28:18 +08:00
|
|
|
{
|
|
|
|
Height = 15,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(2f, 0f),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-02-01 15:07:57 +08:00
|
|
|
new ModIcon(mod, showTooltip: false).With(icon =>
|
2022-02-01 13:28:18 +08:00
|
|
|
{
|
2022-02-01 13:45:59 +08:00
|
|
|
icon.Origin = Anchor.CentreLeft;
|
|
|
|
icon.Anchor = Anchor.CentreLeft;
|
2022-02-01 13:28:18 +08:00
|
|
|
icon.Scale = new Vector2(15f / icon.Height);
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
};
|
2022-02-01 13:45:59 +08:00
|
|
|
|
2022-02-01 15:07:57 +08:00
|
|
|
string description = mod.SettingDescription;
|
|
|
|
|
2022-02-01 13:45:59 +08:00
|
|
|
if (!string.IsNullOrEmpty(description))
|
|
|
|
{
|
|
|
|
container.Add(new OsuSpriteText
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
|
2022-02-01 15:07:57 +08:00
|
|
|
Text = mod.SettingDescription,
|
2022-02-01 13:45:59 +08:00
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
2022-02-02 03:26:52 +08:00
|
|
|
Margin = new MarginPadding { Top = 1 },
|
2022-02-01 13:45:59 +08:00
|
|
|
});
|
|
|
|
}
|
2022-02-01 13:28:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|