ScoreRank, Avatar to own files, +DrawableRank

This commit is contained in:
DrabWeb 2017-03-14 10:58:28 -03:00
parent 8176b4ef77
commit 650fc7563d
7 changed files with 195 additions and 132 deletions

View File

@ -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 @@ public class Score
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,
}
}

View File

@ -0,0 +1,37 @@
// 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.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,
}
}

View File

@ -1,16 +1,10 @@
// 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.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 @@ public void APIStateChanged(APIAccess api, APIState state)
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);
}
}
}
}
}

View File

@ -0,0 +1,51 @@
// 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.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,
},
};
}
}
}

View File

@ -13,10 +13,10 @@
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 @@ public class LeaderboardScore : Container
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 @@ protected override void OnHoverLost(Framework.Input.InputState state)
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 @@ public LeaderboardScore(Score score, int i)
EdgeEffect = imageShadow,
Children = new Drawable[]
{
new Overlays.Toolbar.ToolbarUserButton.Avatar
new Avatar
{
RelativeSizeAxes = Axes.Both,
UserId = Score.User.Id,
@ -237,7 +231,7 @@ public LeaderboardScore(Score score, int i)
},
},
},
scoreRank = new Sprite
scoreRank = new DrawableRank(Score.Rank)
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,

99
osu.Game/Users/Avatar.cs Normal file
View File

@ -0,0 +1,99 @@
// 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.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);
}
}
}
}

View File

@ -333,6 +333,9 @@
<Compile Include="Graphics\UserInterface\IHasDrawableRepresentation.cs" />
<Compile Include="Users\Region.cs" />
<Compile Include="Users\Badge.cs" />
<Compile Include="Modes\ScoreRank.cs" />
<Compile Include="Users\Avatar.cs" />
<Compile Include="Screens\Select\Leaderboards\DrawableRank.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">