2017-03-04 15:37:34 +08:00
|
|
|
|
// 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.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Transforms;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-03-04 17:01:55 +08:00
|
|
|
|
using osu.Game.Modes;
|
2017-03-13 20:44:22 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-03-14 21:11:38 +08:00
|
|
|
|
using osu.Game.Modes.Mods;
|
2017-03-14 21:58:28 +08:00
|
|
|
|
using osu.Game.Users;
|
2017-03-15 19:44:29 +08:00
|
|
|
|
using osu.Framework;
|
2017-03-04 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.Leaderboards
|
|
|
|
|
{
|
2017-03-15 19:44:29 +08:00
|
|
|
|
public class LeaderboardScore : Container, IStateful<Visibility>
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
|
|
|
|
private const float height = 70;
|
|
|
|
|
private const float corner_radius = 5;
|
|
|
|
|
private const float edge_margin = 10;
|
2017-03-13 20:33:25 +08:00
|
|
|
|
private const float background_alpha = 0.25f;
|
2017-03-14 21:04:42 +08:00
|
|
|
|
private const float score_rank_size = 40f;
|
2017-03-04 15:37:34 +08:00
|
|
|
|
|
2017-03-05 10:29:52 +08:00
|
|
|
|
private readonly EdgeEffect imageShadow = new EdgeEffect
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Radius = 1,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.2f),
|
|
|
|
|
};
|
|
|
|
|
|
2017-03-04 15:37:34 +08:00
|
|
|
|
private Box background;
|
2017-03-15 14:22:28 +08:00
|
|
|
|
private Container content, avatar;
|
2017-03-14 21:58:28 +08:00
|
|
|
|
private DrawableRank scoreRank;
|
2017-03-13 23:31:46 +08:00
|
|
|
|
private OsuSpriteText nameLabel;
|
|
|
|
|
private GlowingSpriteText scoreLabel;
|
|
|
|
|
private ScoreComponentLabel maxCombo, accuracy;
|
|
|
|
|
private Container flagBadgeContainer;
|
2017-03-04 17:01:55 +08:00
|
|
|
|
private FillFlowContainer<ScoreModIcon> modsContainer;
|
2017-03-04 15:37:34 +08:00
|
|
|
|
|
2017-03-04 17:01:55 +08:00
|
|
|
|
private readonly int index;
|
2017-03-05 10:29:52 +08:00
|
|
|
|
public readonly Score Score;
|
|
|
|
|
|
2017-03-15 19:44:29 +08:00
|
|
|
|
private Visibility state;
|
|
|
|
|
public Visibility State
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
2017-03-15 19:44:29 +08:00
|
|
|
|
get { return state; }
|
|
|
|
|
set
|
2017-03-13 23:31:46 +08:00
|
|
|
|
{
|
2017-03-15 19:44:29 +08:00
|
|
|
|
state = value;
|
2017-03-15 16:07:56 +08:00
|
|
|
|
|
2017-03-15 19:44:29 +08:00
|
|
|
|
switch (state)
|
2017-03-13 23:31:46 +08:00
|
|
|
|
{
|
2017-03-15 19:44:29 +08:00
|
|
|
|
case Visibility.Hidden:
|
|
|
|
|
foreach (Drawable d in new Drawable[] { avatar, nameLabel, scoreLabel, scoreRank, flagBadgeContainer, maxCombo, accuracy, modsContainer, })
|
|
|
|
|
{
|
|
|
|
|
d.FadeOut();
|
|
|
|
|
}
|
2017-03-13 23:31:46 +08:00
|
|
|
|
|
2017-03-15 19:44:29 +08:00
|
|
|
|
Alpha = 0;
|
2017-03-13 23:31:46 +08:00
|
|
|
|
|
2017-03-15 19:44:29 +08:00
|
|
|
|
content.MoveToY(75);
|
|
|
|
|
avatar.MoveToX(75);
|
|
|
|
|
nameLabel.MoveToX(150);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Visibility.Visible:
|
|
|
|
|
FadeIn(200);
|
|
|
|
|
content.MoveToY(0, 800, EasingTypes.OutQuint);
|
2017-03-13 23:31:46 +08:00
|
|
|
|
|
2017-03-15 19:44:29 +08:00
|
|
|
|
Delay(100);
|
2017-03-13 23:31:46 +08:00
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
2017-03-15 19:44:29 +08:00
|
|
|
|
avatar.FadeIn(300, EasingTypes.OutQuint);
|
|
|
|
|
nameLabel.FadeIn(350, EasingTypes.OutQuint);
|
|
|
|
|
|
|
|
|
|
avatar.MoveToX(0, 300, EasingTypes.OutQuint);
|
|
|
|
|
nameLabel.MoveToX(0, 350, EasingTypes.OutQuint);
|
2017-03-13 23:31:46 +08:00
|
|
|
|
|
2017-03-15 19:44:29 +08:00
|
|
|
|
Delay(250);
|
|
|
|
|
Schedule(() =>
|
2017-03-13 23:31:46 +08:00
|
|
|
|
{
|
2017-03-15 19:44:29 +08:00
|
|
|
|
scoreLabel.FadeIn(200);
|
|
|
|
|
scoreRank.FadeIn(200);
|
|
|
|
|
|
|
|
|
|
Delay(50);
|
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
var drawables = new Drawable[] { flagBadgeContainer, maxCombo, accuracy, modsContainer, };
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < drawables.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
drawables[i].FadeIn(100 + i * 50);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-03-13 23:31:46 +08:00
|
|
|
|
});
|
2017-03-15 19:44:29 +08:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Hide() => State = Visibility.Hidden;
|
|
|
|
|
public override void Show() => State = Visibility.Visible;
|
|
|
|
|
public void ToggleVisibility() => State = State == Visibility.Visible ? Visibility.Hidden : Visibility.Visible;
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(Framework.Input.InputState state)
|
|
|
|
|
{
|
|
|
|
|
background.FadeTo(0.5f, 300, EasingTypes.OutQuint);
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(Framework.Input.InputState state)
|
|
|
|
|
{
|
|
|
|
|
background.FadeTo(background_alpha, 200, EasingTypes.OutQuint);
|
|
|
|
|
base.OnHoverLost(state);
|
2017-03-04 17:01:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-13 20:33:25 +08:00
|
|
|
|
public LeaderboardScore(Score score, int i)
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
|
|
|
|
Score = score;
|
2017-03-04 17:01:55 +08:00
|
|
|
|
index = i;
|
2017-03-04 15:37:34 +08:00
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Height = height;
|
|
|
|
|
|
2017-03-15 14:22:46 +08:00
|
|
|
|
var flag = Score.User?.Region.CreateDrawable() ?? new DrawableFlag();
|
2017-03-13 20:33:25 +08:00
|
|
|
|
flag.Width = 30;
|
|
|
|
|
flag.RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
2017-03-04 15:37:34 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Width = 40,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Font = @"Exo2.0-MediumItalic",
|
|
|
|
|
TextSize = 22,
|
|
|
|
|
Text = index.ToString(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-03-04 17:01:55 +08:00
|
|
|
|
content = new Container
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Left = 40, },
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
CornerRadius = corner_radius,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-03-13 20:33:25 +08:00
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
Alpha = background_alpha,
|
2017-03-04 15:37:34 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding(edge_margin),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-15 14:22:28 +08:00
|
|
|
|
avatar = new Avatar
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(height - edge_margin * 2, height - edge_margin * 2),
|
|
|
|
|
CornerRadius = corner_radius,
|
|
|
|
|
Masking = true,
|
2017-03-05 10:29:52 +08:00
|
|
|
|
EdgeEffect = imageShadow,
|
2017-03-15 14:22:28 +08:00
|
|
|
|
UserId = Score.User?.Id ?? Score.UserID,
|
2017-03-04 15:37:34 +08:00
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
Position = new Vector2(height - edge_margin, 0f),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-13 23:31:46 +08:00
|
|
|
|
nameLabel = new OsuSpriteText
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
2017-03-15 14:22:46 +08:00
|
|
|
|
Text = Score.User?.Username ?? Score.Username,
|
2017-03-04 15:37:34 +08:00
|
|
|
|
Font = @"Exo2.0-BoldItalic",
|
|
|
|
|
TextSize = 23,
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2017-03-05 10:38:01 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
2017-03-04 15:37:34 +08:00
|
|
|
|
Spacing = new Vector2(10f, 0f),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-13 23:31:46 +08:00
|
|
|
|
flagBadgeContainer = new Container
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(87f, 20f),
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-13 20:33:25 +08:00
|
|
|
|
flag,
|
2017-03-04 15:37:34 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2017-03-05 10:38:01 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
2017-03-04 15:37:34 +08:00
|
|
|
|
Spacing = new Vector2(10f, 0f),
|
|
|
|
|
Margin = new MarginPadding { Left = 10, },
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-14 23:58:22 +08:00
|
|
|
|
maxCombo = new ScoreComponentLabel(FontAwesome.fa_link, Score.MaxCombo.ToString()),
|
2017-03-15 18:21:55 +08:00
|
|
|
|
accuracy = new ScoreComponentLabel(FontAwesome.fa_crosshairs, string.Format(Score.Accuracy % 1 == 0 ? @"{0:0}" : @"{0:0.00}", Score.Accuracy)),
|
2017-03-04 15:37:34 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-03-14 21:58:28 +08:00
|
|
|
|
scoreRank = new DrawableRank(Score.Rank)
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
2017-03-14 05:34:43 +08:00
|
|
|
|
Size = new Vector2(score_rank_size),
|
2017-03-14 21:04:42 +08:00
|
|
|
|
Position = new Vector2(0f, -10f),
|
2017-03-04 15:37:34 +08:00
|
|
|
|
},
|
2017-03-15 18:21:55 +08:00
|
|
|
|
scoreLabel = new GlowingSpriteText(Score.TotalScore.ToString(@"N0"), @"Venera", 23, Color4.White, OsuColour.FromHex(@"83ccfa"))
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
2017-03-14 05:34:43 +08:00
|
|
|
|
Position = new Vector2(-score_rank_size - 5f, 0f),
|
2017-03-04 15:37:34 +08:00
|
|
|
|
},
|
2017-03-04 17:01:55 +08:00
|
|
|
|
modsContainer = new FillFlowContainer<ScoreModIcon>
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
// TODO: Probably remove? Seems like others don't like this kind of thing
|
|
|
|
|
Position = new Vector2(0f, 4f), //properly align the mod icons
|
2017-03-05 10:38:01 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
2017-03-04 15:37:34 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2017-03-04 17:01:55 +08:00
|
|
|
|
|
2017-03-15 14:22:46 +08:00
|
|
|
|
if (Score.Mods != null)
|
2017-03-04 17:01:55 +08:00
|
|
|
|
{
|
2017-03-15 14:22:46 +08:00
|
|
|
|
foreach (Mod mod in Score.Mods)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Get actual mod colours
|
|
|
|
|
modsContainer.Add(new ScoreModIcon(mod.Icon, OsuColour.FromHex(@"ffcc22")));
|
|
|
|
|
}
|
2017-03-04 17:01:55 +08:00
|
|
|
|
}
|
2017-03-04 15:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 22:55:19 +08:00
|
|
|
|
private class GlowingSpriteText : Container
|
2017-03-05 10:29:52 +08:00
|
|
|
|
{
|
|
|
|
|
public GlowingSpriteText(string text, string font, int textSize, Color4 textColour, Color4 glowColour)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new BufferedContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
BlurSigma = new Vector2(4),
|
|
|
|
|
CacheDrawnFrameBuffer = true,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
BlendingMode = BlendingMode.Additive,
|
|
|
|
|
Size = new Vector2(3f),
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Font = font,
|
|
|
|
|
TextSize = textSize,
|
2017-03-15 14:21:07 +08:00
|
|
|
|
FixedWidth = true,
|
2017-03-05 10:29:52 +08:00
|
|
|
|
Text = text,
|
|
|
|
|
Colour = glowColour,
|
|
|
|
|
Shadow = false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Font = font,
|
2017-03-15 14:21:07 +08:00
|
|
|
|
FixedWidth = true,
|
2017-03-05 10:29:52 +08:00
|
|
|
|
TextSize = textSize,
|
|
|
|
|
Text = text,
|
|
|
|
|
Colour = textColour,
|
|
|
|
|
Shadow = false,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 22:55:19 +08:00
|
|
|
|
private class ScoreModIcon : Container
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
|
|
|
|
public ScoreModIcon(FontAwesome icon, Color4 colour)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Icon = FontAwesome.fa_osu_mod_bg,
|
|
|
|
|
Colour = colour,
|
|
|
|
|
Shadow = true,
|
|
|
|
|
TextSize = 30,
|
|
|
|
|
},
|
|
|
|
|
new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Icon = icon,
|
|
|
|
|
Colour = OsuColour.Gray(84),
|
|
|
|
|
TextSize = 18,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 22:55:19 +08:00
|
|
|
|
private class ScoreComponentLabel : Container
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
|
|
|
|
public ScoreComponentLabel(FontAwesome icon, string value)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft;
|
|
|
|
|
Origin = Anchor.CentreLeft;
|
|
|
|
|
Size = new Vector2(60f, 20f);
|
|
|
|
|
Padding = new MarginPadding { Top = 10f, };
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new TextAwesome
|
|
|
|
|
{
|
2017-03-13 23:31:46 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
2017-03-04 15:37:34 +08:00
|
|
|
|
Icon = FontAwesome.fa_square,
|
|
|
|
|
Colour = OsuColour.FromHex(@"3087ac"),
|
|
|
|
|
Rotation = 45,
|
|
|
|
|
Shadow = true,
|
|
|
|
|
},
|
|
|
|
|
new TextAwesome
|
|
|
|
|
{
|
2017-03-13 23:31:46 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
2017-03-04 15:37:34 +08:00
|
|
|
|
Icon = icon,
|
|
|
|
|
Colour = OsuColour.FromHex(@"a4edff"),
|
|
|
|
|
Scale = new Vector2(0.8f),
|
|
|
|
|
},
|
2017-03-05 10:29:52 +08:00
|
|
|
|
new GlowingSpriteText(value, @"Exo2.0-Bold", 17, Color4.White, OsuColour.FromHex(@"83ccfa"))
|
2017-03-04 15:37:34 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Margin = new MarginPadding { Left = 15, },
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|