osu/osu.Game/Screens/Select/Leaderboards/LeaderboardScoreDisplay.cs

290 lines
13 KiB
C#
Raw Normal View History

2017-03-04 07:37:34 +00: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;
using osu.Game.Modes;
2017-03-04 07:37:34 +00:00
namespace osu.Game.Screens.Select.Leaderboards
{
public class LeaderboardScoreDisplay : Container
{
private const float height = 70;
private const float corner_radius = 5;
private const float edge_margin = 10;
private const float background_opacity = 0.25f;
private const float score_letter_size = 20f;
private Box background;
private Container content;
private FillFlowContainer<ScoreModIcon> modsContainer;
2017-03-04 07:37:34 +00:00
private readonly int index;
2017-03-04 07:37:34 +00:00
public readonly LeaderboardScore Score;
protected override bool OnHover(Framework.Input.InputState state)
{
background.FadeColour(Color4.Black.Opacity(0.5f), 300, EasingTypes.OutQuint);
return base.OnHover(state);
}
protected override void OnHoverLost(Framework.Input.InputState state)
{
background.FadeColour(Color4.Black.Opacity(background_opacity), 200, EasingTypes.OutQuint);
base.OnHoverLost(state);
}
protected override void LoadComplete()
{
base.LoadComplete();
FadeTo(0.01f); // TODO: This is hacky, find a better way
Delay(index * 50);
Schedule(() =>
{
FadeInFromZero(200);
content.MoveToX(DrawSize.X);
content.MoveToX(0, 500, EasingTypes.OutQuint);
});
}
public LeaderboardScoreDisplay(LeaderboardScore score, int i)
2017-03-04 07:37:34 +00:00
{
Score = score;
index = i;
2017-03-04 07:37:34 +00:00
RelativeSizeAxes = Axes.X;
Height = height;
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(),
},
},
},
content = new Container
2017-03-04 07:37:34 +00: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,
Colour = Color4.Black.Opacity(background_opacity),
},
},
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(edge_margin),
Children = new Drawable[]
{
new Container
{
Size = new Vector2(height - edge_margin * 2, height - edge_margin * 2),
CornerRadius = corner_radius,
Masking = true,
Children = new Drawable[]
{
new Sprite
{
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill,
Texture = Score.Avatar,
},
},
},
new Container
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Position = new Vector2(height - edge_margin, 0f),
Children = new Drawable[]
{
new OsuSpriteText
{
Text = Score.Name,
Font = @"Exo2.0-BoldItalic",
TextSize = 23,
},
new FillFlowContainer
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Right,
Spacing = new Vector2(10f, 0f),
Children = new Drawable[]
{
new Container
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Size = new Vector2(87f, 20f),
Masking = true,
Children = new Drawable[]
{
new Sprite
{
RelativeSizeAxes = Axes.Y,
Width = 30f,
Texture = Score.Flag,
},
new Sprite
{
Origin = Anchor.BottomRight,
Anchor = Anchor.BottomRight,
RelativeSizeAxes = Axes.Y,
Width = 50f,
Texture = Score.Badge,
},
},
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Right,
Spacing = new Vector2(10f, 0f),
Margin = new MarginPadding { Left = 10, },
Children = new Drawable[]
{
new ScoreComponentLabel(FontAwesome.fa_circle_o, Score.MaxCombo.ToString()),
new ScoreComponentLabel(FontAwesome.fa_circle_o, Score.Accuracy.ToString()),
},
},
},
},
},
},
new Sprite
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Size = new Vector2(score_letter_size),
},
new OsuSpriteText
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Position = new Vector2(-score_letter_size - 5f, 0f),
Font = @"Venera",
Text = Score.Score.ToString(),
TextSize = 23,
},
modsContainer = new FillFlowContainer<ScoreModIcon>
2017-03-04 07:37:34 +00: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
Direction = FillDirection.Left,
},
},
},
},
},
};
foreach (Mod mod in Score.Mods)
{
// TODO: Get actual mod colours
modsContainer.Add(new ScoreModIcon(mod.Icon, OsuColour.FromHex(@"ffcc22")));
}
2017-03-04 07:37:34 +00:00
}
class ScoreModIcon : Container
{
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,
},
};
}
}
class ScoreComponentLabel : Container
{
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
{
Icon = FontAwesome.fa_square,
Colour = OsuColour.FromHex(@"3087ac"),
Rotation = 45,
Shadow = true,
},
new TextAwesome
{
Icon = icon,
Colour = OsuColour.FromHex(@"a4edff"),
Scale = new Vector2(0.8f),
},
new OsuSpriteText
{
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Left = 15, },
Font = @"Exo2.0-Bold",
Text = value,
TextSize = 17,
},
};
}
}
}
}