mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Merge remote-tracking branch 'Joehuu/master' into drawnode-composability
# Conflicts: # osu.Game.Rulesets.Osu/UI/Cursor/OsuCursorContainer.cs
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
// 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 osuTK;
|
||||
using osuTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -11,230 +9,117 @@ using osu.Framework.Graphics.Effects;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.Leaderboards;
|
||||
using osu.Game.Overlays.Profile.Sections.Ranks;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Users;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
{
|
||||
public class DrawableTopScore : Container
|
||||
public class DrawableTopScore : CompositeDrawable
|
||||
{
|
||||
private const float fade_duration = 100;
|
||||
private const float height = 200;
|
||||
private const float avatar_size = 80;
|
||||
private const float margin = 10;
|
||||
|
||||
private Color4 backgroundIdleColour;
|
||||
private Color4 backgroundHoveredColour;
|
||||
|
||||
private readonly Box background;
|
||||
private readonly Box bottomBackground;
|
||||
private readonly Box middleLine;
|
||||
private readonly UpdateableAvatar avatar;
|
||||
private readonly DrawableFlag flag;
|
||||
private readonly ClickableUsername username;
|
||||
private readonly OsuSpriteText rankText;
|
||||
private readonly OsuSpriteText date;
|
||||
private readonly DrawableRank rank;
|
||||
private readonly InfoColumn totalScore;
|
||||
private readonly InfoColumn accuracy;
|
||||
private readonly InfoColumn statistics;
|
||||
private readonly ScoreModsContainer modsContainer;
|
||||
|
||||
private ScoreInfo score;
|
||||
|
||||
public ScoreInfo Score
|
||||
{
|
||||
get => score;
|
||||
set
|
||||
{
|
||||
if (score == value) return;
|
||||
|
||||
score = value;
|
||||
|
||||
avatar.User = username.User = score.User;
|
||||
flag.Country = score.User.Country;
|
||||
date.Text = $@"achieved {score.Date:MMM d, yyyy}";
|
||||
rank.UpdateRank(score.Rank);
|
||||
|
||||
totalScore.Value = $@"{score.TotalScore:N0}";
|
||||
accuracy.Value = $@"{score.Accuracy:P2}";
|
||||
statistics.Value = $"{score.Statistics[HitResult.Great]}/{score.Statistics[HitResult.Good]}/{score.Statistics[HitResult.Meh]}";
|
||||
|
||||
modsContainer.Clear();
|
||||
foreach (Mod mod in score.Mods)
|
||||
modsContainer.Add(new ModIcon(mod)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Scale = new Vector2(0.45f),
|
||||
});
|
||||
}
|
||||
}
|
||||
private readonly TopScoreUserSection userSection;
|
||||
private readonly TopScoreStatisticsSection statisticsSection;
|
||||
|
||||
public DrawableTopScore()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = height;
|
||||
CornerRadius = 5;
|
||||
BorderThickness = 4;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
Masking = true;
|
||||
Children = new Drawable[]
|
||||
CornerRadius = 10;
|
||||
EdgeEffect = new EdgeEffectParameters
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Colour = Color4.Black.Opacity(0.2f),
|
||||
Radius = 1,
|
||||
Offset = new Vector2(0, 1),
|
||||
};
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0,
|
||||
AlwaysPresent = true, //used for correct border representation
|
||||
},
|
||||
avatar = new UpdateableAvatar
|
||||
{
|
||||
Size = new Vector2(avatar_size),
|
||||
Masking = true,
|
||||
CornerRadius = 5,
|
||||
EdgeEffect = new EdgeEffectParameters
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Colour = Color4.Black.Opacity(0.25f),
|
||||
Offset = new Vector2(0, 2),
|
||||
Radius = 1,
|
||||
},
|
||||
Margin = new MarginPadding { Top = margin, Left = margin }
|
||||
},
|
||||
flag = new DrawableFlag
|
||||
{
|
||||
Size = new Vector2(30, 20),
|
||||
Position = new Vector2(margin * 2 + avatar_size, height / 4),
|
||||
},
|
||||
username = new ClickableUsername
|
||||
{
|
||||
Origin = Anchor.BottomLeft,
|
||||
TextSize = 30,
|
||||
Position = new Vector2(margin * 2 + avatar_size, height / 4),
|
||||
Margin = new MarginPadding { Bottom = 4 }
|
||||
},
|
||||
rankText = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.BottomRight,
|
||||
Text = "#1",
|
||||
Font = OsuFont.GetFont(size: 40, weight: FontWeight.Bold, italics: true),
|
||||
Y = height / 4,
|
||||
Margin = new MarginPadding { Right = margin }
|
||||
},
|
||||
date = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
Y = height / 4,
|
||||
Margin = new MarginPadding { Right = margin }
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Height = 0.5f,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding(10),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
bottomBackground = new Box { RelativeSizeAxes = Axes.Both },
|
||||
middleLine = new Box
|
||||
new AutoSizingGrid
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 1,
|
||||
},
|
||||
rank = new DrawableRank(ScoreRank.F)
|
||||
{
|
||||
Origin = Anchor.BottomLeft,
|
||||
Size = new Vector2(avatar_size, 40),
|
||||
FillMode = FillMode.Fit,
|
||||
Y = height / 4,
|
||||
Margin = new MarginPadding { Left = margin }
|
||||
},
|
||||
new FillFlowContainer<InfoColumn>
|
||||
{
|
||||
Origin = Anchor.BottomLeft,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Position = new Vector2(height / 2, height / 4),
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(15, 0),
|
||||
Children = new[]
|
||||
Content = new[]
|
||||
{
|
||||
totalScore = new InfoColumn("Score"),
|
||||
accuracy = new InfoColumn("Accuracy"),
|
||||
statistics = new InfoColumn("300/100/50"),
|
||||
new Drawable[]
|
||||
{
|
||||
userSection = new TopScoreUserSection
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
},
|
||||
null,
|
||||
statisticsSection = new TopScoreStatisticsSection
|
||||
{
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
modsContainer = new ScoreModsContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Width = 80,
|
||||
Position = new Vector2(height / 2, height / 4),
|
||||
ColumnDimensions = new[] { new Dimension(GridSizeMode.AutoSize), new Dimension(GridSizeMode.Absolute, 20) },
|
||||
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
background.Colour = bottomBackground.Colour = colours.Gray4;
|
||||
middleLine.Colour = colours.Gray2;
|
||||
date.Colour = colours.Gray9;
|
||||
BorderColour = rankText.Colour = colours.Yellow;
|
||||
backgroundIdleColour = colours.Gray3;
|
||||
backgroundHoveredColour = colours.Gray4;
|
||||
|
||||
background.Colour = backgroundIdleColour;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the score to be displayed.
|
||||
/// </summary>
|
||||
public ScoreInfo Score
|
||||
{
|
||||
set
|
||||
{
|
||||
userSection.Score = value;
|
||||
statisticsSection.Score = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
background.FadeIn(fade_duration, Easing.OutQuint);
|
||||
background.FadeColour(backgroundHoveredColour, fade_duration, Easing.OutQuint);
|
||||
return base.OnHover(e);
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
background.FadeOut(fade_duration, Easing.OutQuint);
|
||||
background.FadeColour(backgroundIdleColour, fade_duration, Easing.OutQuint);
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
|
||||
private class InfoColumn : FillFlowContainer
|
||||
private class AutoSizingGrid : GridContainer
|
||||
{
|
||||
private readonly OsuSpriteText headerText;
|
||||
private readonly OsuSpriteText valueText;
|
||||
|
||||
public string Value
|
||||
public AutoSizingGrid()
|
||||
{
|
||||
set
|
||||
{
|
||||
if (valueText.Text == value)
|
||||
return;
|
||||
|
||||
valueText.Text = value;
|
||||
}
|
||||
get => valueText.Text;
|
||||
}
|
||||
|
||||
public InfoColumn(string header)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Direction = FillDirection.Vertical;
|
||||
Spacing = new Vector2(0, 3);
|
||||
Children = new Drawable[]
|
||||
{
|
||||
headerText = new OsuSpriteText
|
||||
{
|
||||
Text = header,
|
||||
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold)
|
||||
},
|
||||
valueText = new OsuSpriteText { Font = OsuFont.GetFont(size: 25, weight: FontWeight.Regular, italics: true) }
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
headerText.Colour = colours.Gray9;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user