mirror of
https://github.com/ppy/osu.git
synced 2025-02-19 15:23:09 +08:00
Implement DismissableFlag component for rankings overlay (#6065)
Implement DismissableFlag component for rankings overlay Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
586503222f
@ -0,0 +1,65 @@
|
|||||||
|
// 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 TestSceneRankingsDismissableFlag : OsuTestScene
|
||||||
|
{
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(DismissableFlag),
|
||||||
|
};
|
||||||
|
|
||||||
|
public TestSceneRankingsDismissableFlag()
|
||||||
|
{
|
||||||
|
DismissableFlag flag;
|
||||||
|
SpriteText text;
|
||||||
|
|
||||||
|
var countryA = new Country
|
||||||
|
{
|
||||||
|
FlagName = "BY",
|
||||||
|
FullName = "Belarus"
|
||||||
|
};
|
||||||
|
|
||||||
|
var countryB = new Country
|
||||||
|
{
|
||||||
|
FlagName = "US",
|
||||||
|
FullName = "United States"
|
||||||
|
};
|
||||||
|
|
||||||
|
AddRange(new Drawable[]
|
||||||
|
{
|
||||||
|
flag = new DismissableFlag
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Size = new Vector2(30, 20),
|
||||||
|
Country = countryA,
|
||||||
|
},
|
||||||
|
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());
|
||||||
|
AddStep("Change to country 2", () => flag.Country = countryB);
|
||||||
|
AddStep("Change to country 1", () => flag.Country = countryA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
osu.Game/Overlays/Rankings/DismissableFlag.cs
Normal file
55
osu.Game/Overlays/Rankings/DismissableFlag.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 osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Users.Drawables;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
using osuTK;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Rankings
|
||||||
|
{
|
||||||
|
public class DismissableFlag : UpdateableFlag
|
||||||
|
{
|
||||||
|
private const int duration = 200;
|
||||||
|
|
||||||
|
public Action Action;
|
||||||
|
|
||||||
|
private readonly SpriteIcon hoverIcon;
|
||||||
|
|
||||||
|
public DismissableFlag()
|
||||||
|
{
|
||||||
|
AddInternal(hoverIcon = new SpriteIcon
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Depth = -1,
|
||||||
|
Alpha = 0,
|
||||||
|
Size = new Vector2(10),
|
||||||
|
Icon = FontAwesome.Solid.Times,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnHover(HoverEvent e)
|
||||||
|
{
|
||||||
|
hoverIcon.FadeIn(duration, Easing.OutQuint);
|
||||||
|
this.FadeColour(Color4.Gray, duration, Easing.OutQuint);
|
||||||
|
return base.OnHover(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
|
{
|
||||||
|
base.OnHoverLost(e);
|
||||||
|
hoverIcon.FadeOut(duration, Easing.OutQuint);
|
||||||
|
this.FadeColour(Color4.White, duration, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnClick(ClickEvent e)
|
||||||
|
{
|
||||||
|
Action?.Invoke();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user