1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 18:27:26 +08:00

Implement HeaderFlag component for rankings overlay

This commit is contained in:
Andrei Zavatski 2019-09-11 10:40:58 +03:00
parent 0551a5da32
commit 95828b07ef
2 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,55 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Overlays.Rankings;
using osu.Game.Users;
using osuTK;
namespace osu.Game.Tests.Visual.Online
{
public class TestSceneRankingsHeaderFlag : OsuTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(HeaderFlag),
};
public TestSceneRankingsHeaderFlag()
{
HeaderFlag flag;
SpriteText text;
AddRange(new Drawable[]
{
flag = new HeaderFlag
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(30, 20),
Country = new Country
{
FlagName = "BY",
FullName = "Belarus"
}
},
text = new SpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = "Invoked",
Font = OsuFont.GetFont(size: 30),
Alpha = 0,
}
});
flag.Action += () => text.FadeIn().Then().FadeOut(1000, Easing.OutQuint);
AddStep("Trigger click", () => flag.Click());
}
}
}

View File

@ -0,0 +1,68 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Users.Drawables;
using osuTK.Graphics;
using osuTK;
using osu.Framework.Input.Events;
using osu.Framework.Extensions.Color4Extensions;
using System;
namespace osu.Game.Overlays.Rankings
{
public class HeaderFlag : UpdateableFlag
{
private const int duration = 200;
public Action Action;
private readonly Container hoverContainer;
public HeaderFlag()
{
AddInternal(hoverContainer = new Container
{
Alpha = 0,
Depth = -1,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(15),
Icon = FontAwesome.Solid.Times,
},
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black.Opacity(100),
}
}
});
}
protected override bool OnHover(HoverEvent e)
{
hoverContainer.FadeIn(duration, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
hoverContainer.FadeOut(duration, Easing.OutQuint);
}
protected override bool OnClick(ClickEvent e)
{
Action?.Invoke();
return base.OnClick(e);
}
}
}