mirror of
https://github.com/ppy/osu
synced 2025-01-09 07:39:46 +00:00
Implement HeaderFlag component for rankings overlay
This commit is contained in:
parent
0551a5da32
commit
95828b07ef
55
osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs
Normal file
55
osu.Game.Tests/Visual/Online/TestSceneRankingsHeaderFlag.cs
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
68
osu.Game/Overlays/Rankings/HeaderFlag.cs
Normal file
68
osu.Game/Overlays/Rankings/HeaderFlag.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user