1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 09:02:58 +08:00

Add DrawableTopScore

This commit is contained in:
EVAST9919 2017-11-11 06:54:52 +03:00
parent 3261af5200
commit 5bf756c3c6
7 changed files with 436 additions and 42 deletions

View File

@ -0,0 +1,64 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Users;
using System;
using osu.Framework.Input;
namespace osu.Game.Overlays.BeatmapSet.Scores
{
public class ClickableUsername : OsuHoverContainer
{
private readonly OsuSpriteText text;
private Action clickAction;
private UserProfileOverlay profile;
private User user;
public User User
{
set
{
if (user == value) return;
user = value;
text.Text = user.Username;
}
get { return user; }
}
public float TextSize
{
set
{
if (text.TextSize == value) return;
text.TextSize = value;
}
get { return text.TextSize; }
}
public ClickableUsername()
{
AutoSizeAxes = Axes.Both;
Child = text = new OsuSpriteText
{
Font = @"Exo2.0-BoldItalic",
};
}
[BackgroundDependencyLoader]
private void load(UserProfileOverlay profile)
{
this.profile = profile;
}
protected override bool OnClick(InputState state)
{
profile.ShowUser(user);
return base.OnClick(state);
}
}
}

View File

@ -8,7 +8,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests;
using osu.Game.Overlays.Profile.Sections.Ranks;
@ -58,10 +57,11 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
RelativePositionAxes = Axes.X,
X = 0.06f
},
new ClickableUsername(score.User.Username)
new ClickableUsername
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
User = score.User,
RelativePositionAxes = Axes.X,
X = 0.1f
},
@ -140,18 +140,5 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
}
protected override bool OnClick(InputState state) => true;
private class ClickableUsername : OsuHoverContainer
{
public ClickableUsername(string username)
{
AutoSizeAxes = Axes.Both;
Child = new OsuSpriteText
{
Text = username,
Font = @"Exo2.0-BoldItalic",
};
}
}
}
}

View File

@ -0,0 +1,254 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests;
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.Screens.Select.Leaderboards;
using osu.Game.Users;
namespace osu.Game.Overlays.BeatmapSet.Scores
{
public class DrawableTopScore : Container
{
private const int fade_duration = 100;
private const int height = 200;
private const int avatar_size = 80;
private const int margin = 10;
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 OnlineScore score;
public OnlineScore Score
{
set
{
if (score == value) return;
score = value;
setScore();
}
get { return score; }
}
public DrawableTopScore()
{
RelativeSizeAxes = Axes.X;
Height = height;
CornerRadius = 5;
BorderThickness = 4;
Masking = true;
Children = 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
{
Width = 30,
Height = 20,
Y = height / 4,
X = height / 2,
},
username = new ClickableUsername
{
Origin = Anchor.BottomLeft,
TextSize = 30,
Y = height / 4,
X = height / 2,
Margin = new MarginPadding { Bottom = 4 },
},
rankText = new OsuSpriteText
{
Anchor = Anchor.TopRight,
Origin = Anchor.BottomRight,
Text = "#1",
TextSize = 40,
Font = @"Exo2.0-BoldItalic",
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,
Children = new Drawable[]
{
bottomBackground = new Box { RelativeSizeAxes = Axes.Both },
middleLine = new Box
{
RelativeSizeAxes = Axes.X,
Height = 1,
},
rank = new DrawableRank(ScoreRank.F)
{
Origin = Anchor.BottomLeft,
Width = avatar_size,
Height = 40,
FillMode = FillMode.Fit,
Y = height / 4,
Margin = new MarginPadding { Left = margin }
},
new FillFlowContainer<InfoColumn>
{
Origin = Anchor.BottomLeft,
AutoSizeAxes = Axes.Both,
X = height / 2,
Y = height / 4,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(15, 0),
Children = new[]
{
totalScore = new InfoColumn("Score"),
accuracy = new InfoColumn("Accuracy"),
statistics = new InfoColumn("300/100/50"),
},
},
modsContainer = new ScoreModsContainer
{
AutoSizeAxes = Axes.Y,
Width = 80,
X = height / 2,
Y = height / 4,
}
}
},
};
}
[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;
}
private void setScore()
{
avatar.User = username.User = score.User;
flag.FlagName = score.User.Country?.FlagName;
date.Text = $"achieved {score.Date:MMM d, yyyy}";
rank.UpdateRank(score.Rank);
totalScore.Value = score.TotalScore.ToString();
accuracy.Value = $@"{score.Accuracy:P2}";
statistics.Value = $"{score.Statistics["300"]}/{score.Statistics["100"]}/{score.Statistics["50"]}";
modsContainer.Clear();
foreach (Mod mod in score.Mods)
modsContainer.Add(new ModIcon(mod)
{
AutoSizeAxes = Axes.Both,
Scale = new Vector2(0.45f),
});
}
protected override bool OnHover(InputState state)
{
background.FadeIn(fade_duration, Easing.OutQuint);
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
background.FadeOut(fade_duration, Easing.OutQuint);
base.OnHoverLost(state);
}
private class InfoColumn : FillFlowContainer
{
private readonly OsuSpriteText headerText;
private readonly OsuSpriteText valueText;
public string Value
{
set
{
if (valueText.Text == value)
return;
valueText.Text = value;
}
get { return valueText.Text; }
}
public InfoColumn(string header)
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Vertical;
Spacing = new Vector2(0, 3);
Children = new Drawable[]
{
headerText = new OsuSpriteText
{
TextSize = 14,
Text = header,
Font = @"Exo2.0-Bold",
},
valueText = new OsuSpriteText
{
TextSize = 25,
Font = @"Exo2.0-RegularItalic",
}
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
headerText.Colour = colours.Gray9;
}
}
}
}

View File

@ -2,11 +2,14 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using System.Linq;
@ -15,9 +18,25 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{
public class ScoresContainer : Container
{
private const int spacing = 15;
private const int fade_duration = 200;
private readonly FillFlowContainer flow;
private readonly DrawableTopScore topScore;
private readonly LoadingAnimation loadingAnimation;
private readonly Box foreground;
private GetScoresRequest request;
private APIAccess api;
private bool isLoading
{
set
{
foreground.FadeTo(value ? 1 : 0, fade_duration);
loadingAnimation.FadeTo(value ? 1 : 0, fade_duration);
}
}
private BeatmapInfo beatmap;
public BeatmapInfo Beatmap
{
@ -26,7 +45,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
if (beatmap == value) return;
beatmap = value;
getScores();
updateScores();
}
get { return beatmap; }
}
@ -35,15 +54,44 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Child = flow = new FillFlowContainer
Children = new Drawable[]
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Width = 0.95f,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 1),
new FillFlowContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Width = 0.95f,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, spacing),
Margin = new MarginPadding { Top = spacing },
Children = new Drawable[]
{
topScore = new DrawableTopScore(),
flow = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 1),
},
}
},
foreground = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black.Opacity(0.7f),
Alpha = 0,
},
loadingAnimation = new LoadingAnimation
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Size = new Vector2(20),
Margin = new MarginPadding { Top = 10 },
Alpha = 0,
},
};
}
@ -53,21 +101,52 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
this.api = api;
}
private void getScores()
private void updateScores()
{
flow.Clear();
request?.Cancel();
var req = new GetScoresRequest(beatmap);
req.Success += scores =>
if (beatmap == null)
{
int i = 0;
foreach(var s in scores.Scores)
clearAllScores();
return;
}
isLoading = true;
request = new GetScoresRequest(beatmap);
request.Success += scores =>
{
var scoresAmount = scores.Scores.Count();
if (scoresAmount == 0)
{
flow.Add(new DrawableScore(i, s));
i++;
clearAllScores();
return;
}
topScore.Score = scores.Scores.FirstOrDefault();
topScore.Show();
flow.Clear();
if (scoresAmount < 2)
{
isLoading = false;
return;
}
for (int i = 1; i < scoresAmount; i++)
flow.Add(new DrawableScore(i, scores.Scores.ElementAt(i)));
isLoading = false;
};
api.Queue(req);
api.Queue(request);
}
private void clearAllScores()
{
topScore.Hide();
flow.Clear();
isLoading = false;
}
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
@ -11,7 +10,6 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Select.Leaderboards;
using System.Linq;
using osu.Framework.Localisation;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;

View File

@ -14,15 +14,10 @@ namespace osu.Game.Screens.Select.Leaderboards
public class DrawableRank : Container
{
private readonly Sprite rankSprite;
private TextureStore textures;
public ScoreRank Rank { get; private set; }
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
rankSprite.Texture = textures.Get($@"Grades/{Rank.GetDescription()}");
}
public DrawableRank(ScoreRank rank)
{
Rank = rank;
@ -38,5 +33,20 @@ namespace osu.Game.Screens.Select.Leaderboards
},
};
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
this.textures = textures;
updateTexture();
}
private void updateTexture() => rankSprite.Texture = textures.Get($@"Grades/{Rank.GetDescription()}");
public void UpdateRank(ScoreRank newRank)
{
Rank = newRank;
updateTexture();
}
}
}

View File

@ -279,7 +279,9 @@
<Compile Include="Migrations\OsuDbContextModelSnapshot.cs" />
<Compile Include="Online\API\Requests\GetBeatmapSetRequest.cs" />
<Compile Include="Online\API\Requests\GetBeatmapSetsResponse.cs" />
<Compile Include="Overlays\BeatmapSet\Scores\ClickableUsername.cs" />
<Compile Include="Overlays\BeatmapSet\Scores\DrawableScore.cs" />
<Compile Include="Overlays\BeatmapSet\Scores\DrawableTopScore.cs" />
<Compile Include="Overlays\BeatmapSet\Scores\ScoresContainer.cs" />
<Compile Include="Overlays\Profile\Sections\Ranks\DrawablePerformanceScore.cs" />
<Compile Include="Overlays\Profile\Sections\Ranks\PaginatedScoreContainer.cs" />