From 650fc7563d1c2a09c331798f47ab18d3aef94118 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Tue, 14 Mar 2017 10:58:28 -0300 Subject: [PATCH] ScoreRank, Avatar to own files, +DrawableRank --- osu.Game/Modes/Score.cs | 31 ------ osu.Game/Modes/ScoreRank.cs | 37 +++++++ .../Overlays/Toolbar/ToolbarUserButton.cs | 92 +---------------- .../Select/Leaderboards/DrawableRank.cs | 51 ++++++++++ .../Select/Leaderboards/LeaderboardScore.cs | 14 +-- osu.Game/Users/Avatar.cs | 99 +++++++++++++++++++ osu.Game/osu.Game.csproj | 3 + 7 files changed, 195 insertions(+), 132 deletions(-) create mode 100644 osu.Game/Modes/ScoreRank.cs create mode 100644 osu.Game/Screens/Select/Leaderboards/DrawableRank.cs create mode 100644 osu.Game/Users/Avatar.cs diff --git a/osu.Game/Modes/Score.cs b/osu.Game/Modes/Score.cs index 025eca9ab8..f42dc7f7d4 100644 --- a/osu.Game/Modes/Score.cs +++ b/osu.Game/Modes/Score.cs @@ -3,7 +3,6 @@ using osu.Game.Users; using osu.Game.Database; -using System.ComponentModel; using osu.Game.Modes.Mods; namespace osu.Game.Modes @@ -22,34 +21,4 @@ namespace osu.Game.Modes public Replay Replay; public BeatmapInfo Beatmap; } - - public enum ScoreRank - { - [Description(@"F")] - F, - - [Description(@"F")] - D, - - [Description(@"C")] - C, - - [Description(@"B")] - B, - - [Description(@"A")] - A, - - [Description(@"S")] - S, - - [Description(@"SPlus")] - SPlus, - - [Description(@"SS")] - SS, - - [Description(@"SSPlus")] - SSPlus, - } } diff --git a/osu.Game/Modes/ScoreRank.cs b/osu.Game/Modes/ScoreRank.cs new file mode 100644 index 0000000000..d25fe8ab1f --- /dev/null +++ b/osu.Game/Modes/ScoreRank.cs @@ -0,0 +1,37 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.ComponentModel; + +namespace osu.Game.Modes +{ + public enum ScoreRank + { + [Description(@"F")] + F, + + [Description(@"F")] + D, + + [Description(@"C")] + C, + + [Description(@"B")] + B, + + [Description(@"A")] + A, + + [Description(@"S")] + S, + + [Description(@"SPlus")] + SPlus, + + [Description(@"SS")] + SS, + + [Description(@"SSPlus")] + SSPlus, + } +} diff --git a/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs b/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs index 30dd70ce03..e8fc40825d 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarUserButton.cs @@ -1,16 +1,10 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Diagnostics; using osu.Framework.Allocation; -using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Textures; using osu.Game.Online.API; -using OpenTK; -using OpenTK.Graphics; +using osu.Game.Users; namespace osu.Game.Overlays.Toolbar { @@ -49,89 +43,5 @@ namespace osu.Game.Overlays.Toolbar break; } } - - public class Avatar : Container - { - public Drawable Sprite; - - private int userId; - private OsuGame game; - private Texture guestTexture; - - public Avatar() - { - Size = new Vector2(32); - Anchor = Anchor.CentreLeft; - Origin = Anchor.CentreLeft; - - CornerRadius = Size.X / 8; - - EdgeEffect = new EdgeEffect - { - Type = EdgeEffectType.Shadow, - Radius = 4, - Colour = Color4.Black.Opacity(0.1f), - }; - - Masking = true; - } - - [BackgroundDependencyLoader(permitNulls:true)] - private void load(OsuGame game, TextureStore textures) - { - this.game = game; - - guestTexture = textures.Get(@"Online/avatar-guest"); - } - - public int UserId - { - get { return userId; } - set - { - if (userId == value) - return; - - userId = value; - - var newSprite = userId > 1 ? new OnlineSprite($@"https://a.ppy.sh/{userId}") : new Sprite { Texture = guestTexture }; - - newSprite.FillMode = FillMode.Fit; - - if (game != null) - { - newSprite.LoadAsync(game, s => - { - Sprite?.FadeOut(); - Sprite?.Expire(); - Sprite = s; - - Add(s); - - //todo: fix this... clock dependencies are a pain - if (s.Clock != null) - s.FadeInFromZero(200); - }); - } - } - } - - public class OnlineSprite : Sprite - { - private readonly string url; - - public OnlineSprite(string url) - { - Debug.Assert(url != null); - this.url = url; - } - - [BackgroundDependencyLoader] - private void load(TextureStore textures) - { - Texture = textures.Get(url); - } - } - } } } diff --git a/osu.Game/Screens/Select/Leaderboards/DrawableRank.cs b/osu.Game/Screens/Select/Leaderboards/DrawableRank.cs new file mode 100644 index 0000000000..23f33a205b --- /dev/null +++ b/osu.Game/Screens/Select/Leaderboards/DrawableRank.cs @@ -0,0 +1,51 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Framework.Extensions; +using osu.Game.Modes; + +namespace osu.Game.Screens.Select.Leaderboards +{ + public class DrawableRank : Container + { + private Sprite sprite; + private TextureStore textures; + + private ScoreRank rank; + public ScoreRank Rank + { + get { return rank; } + set + { + if (value == rank) return; + rank = value; + sprite.Texture = textures.Get($@"Badges/ScoreRanks/{rank.GetDescription()}"); + } + } + + [BackgroundDependencyLoader] + private void load(TextureStore ts) + { + textures = ts; + sprite.Texture = textures.Get($@"Badges/ScoreRanks/{rank.GetDescription()}"); + } + + public DrawableRank(ScoreRank rank) + { + this.rank = rank; + + Children = new Drawable[] + { + sprite = new Sprite + { + RelativeSizeAxes = Axes.Both, + }, + }; + } + } +} diff --git a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs index 90d28bc0bf..573365cdd2 100644 --- a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs @@ -13,10 +13,10 @@ using osu.Game.Graphics.Sprites; using osu.Game.Modes; using osu.Framework.Graphics.Textures; using osu.Framework.Allocation; -using System.Linq; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions; using osu.Game.Modes.Mods; +using osu.Game.Users; namespace osu.Game.Screens.Select.Leaderboards { @@ -37,7 +37,7 @@ namespace osu.Game.Screens.Select.Leaderboards private Box background; private Container content, avatarContainer; - private Sprite scoreRank; + private DrawableRank scoreRank; private OsuSpriteText nameLabel; private GlowingSpriteText scoreLabel; private ScoreComponentLabel maxCombo, accuracy; @@ -59,12 +59,6 @@ namespace osu.Game.Screens.Select.Leaderboards base.OnHoverLost(state); } - [BackgroundDependencyLoader] - private void load(TextureStore textures) - { - scoreRank.Texture = textures.Get($@"Badges/ScoreRanks/{Score.Rank.GetDescription()}"); - } - protected override void LoadComplete() { base.LoadComplete(); @@ -182,7 +176,7 @@ namespace osu.Game.Screens.Select.Leaderboards EdgeEffect = imageShadow, Children = new Drawable[] { - new Overlays.Toolbar.ToolbarUserButton.Avatar + new Avatar { RelativeSizeAxes = Axes.Both, UserId = Score.User.Id, @@ -237,7 +231,7 @@ namespace osu.Game.Screens.Select.Leaderboards }, }, }, - scoreRank = new Sprite + scoreRank = new DrawableRank(Score.Rank) { Anchor = Anchor.TopRight, Origin = Anchor.TopRight, diff --git a/osu.Game/Users/Avatar.cs b/osu.Game/Users/Avatar.cs new file mode 100644 index 0000000000..7a44d8601c --- /dev/null +++ b/osu.Game/Users/Avatar.cs @@ -0,0 +1,99 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Diagnostics; +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.Sprites; +using osu.Framework.Graphics.Textures; + +namespace osu.Game.Users +{ + public class Avatar : Container + { + public Drawable Sprite; + + private int userId; + private OsuGame game; + private Texture guestTexture; + + public Avatar() + { + Size = new Vector2(32); + Anchor = Anchor.CentreLeft; + Origin = Anchor.CentreLeft; + + CornerRadius = Size.X / 8; + + EdgeEffect = new EdgeEffect + { + Type = EdgeEffectType.Shadow, + Radius = 4, + Colour = Color4.Black.Opacity(0.1f), + }; + + Masking = true; + } + + [BackgroundDependencyLoader(permitNulls: true)] + private void load(OsuGame game, TextureStore textures) + { + this.game = game; + + guestTexture = textures.Get(@"Online/avatar-guest"); + } + + public int UserId + { + get { return userId; } + set + { + if (userId == value) + return; + + userId = value; + + var newSprite = userId > 1 ? new OnlineSprite($@"https://a.ppy.sh/{userId}") : new Sprite { Texture = guestTexture }; + + newSprite.FillMode = FillMode.Fit; + + if (game != null) + { + newSprite.LoadAsync(game, s => + { + Sprite?.FadeOut(); + Sprite?.Expire(); + Sprite = s; + + Add(s); + + //todo: fix this... clock dependencies are a pain + if (s.Clock != null) + s.FadeInFromZero(200); + }); + } + } + } + + public class OnlineSprite : Sprite + { + private readonly string url; + + public OnlineSprite(string url) + { + Debug.Assert(url != null); + this.url = url; + } + + [BackgroundDependencyLoader] + private void load(TextureStore textures) + { + Texture = textures.Get(url); + } + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index a14398d367..0d8ce9d4b9 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -333,6 +333,9 @@ + + +