mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 12:53:11 +08:00
Tidy up UnrankedBadge
implementation
This commit is contained in:
parent
ac7598cb68
commit
a988bbd3cb
@ -7,7 +7,7 @@ using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
@ -97,15 +97,12 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
public void TestUnrankedBadge()
|
||||
{
|
||||
AddStep(@"Add unranked mod", () => changeMods(new[] { new OsuModDeflate() }));
|
||||
AddUntilStep("Unranked badge shown", () => footerButtonMods.UnrankedBadge.Alpha == 1);
|
||||
AddUntilStep("Unranked badge shown", () => footerButtonMods.ChildrenOfType<FooterButtonModsV2.UnrankedBadge>().Single().Alpha == 1);
|
||||
AddStep(@"Clear selected mod", () => changeMods(Array.Empty<Mod>()));
|
||||
AddUntilStep("Unranked badge not shown", () => footerButtonMods.UnrankedBadge.Alpha == 0);
|
||||
AddUntilStep("Unranked badge not shown", () => footerButtonMods.ChildrenOfType<FooterButtonModsV2.UnrankedBadge>().Single().Alpha == 0);
|
||||
}
|
||||
|
||||
private void changeMods(IReadOnlyList<Mod> mods)
|
||||
{
|
||||
footerButtonMods.Current.Value = mods;
|
||||
}
|
||||
private void changeMods(IReadOnlyList<Mod> mods) => footerButtonMods.Current.Value = mods;
|
||||
|
||||
private bool assertModsMultiplier(IEnumerable<Mod> mods)
|
||||
{
|
||||
@ -117,7 +114,6 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
private partial class TestFooterButtonModsV2 : FooterButtonModsV2
|
||||
{
|
||||
public new Container UnrankedBadge => base.UnrankedBadge;
|
||||
public new OsuSpriteText MultiplierText => base.MultiplierText;
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,11 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
{
|
||||
// todo: see https://github.com/ppy/osu-framework/issues/3271
|
||||
private const float torus_scale_factor = 1.2f;
|
||||
private const float bar_shear_width = 7f;
|
||||
private const float bar_height = 37f;
|
||||
private const float mod_display_portion = 0.65f;
|
||||
|
||||
private static readonly Vector2 bar_shear = new Vector2(bar_shear_width / bar_height, 0);
|
||||
|
||||
private readonly BindableWithCurrent<IReadOnlyList<Mod>> current = new BindableWithCurrent<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||
|
||||
@ -43,7 +48,7 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
|
||||
private Container modDisplayBar = null!;
|
||||
|
||||
protected Container UnrankedBadge { get; private set; } = null!;
|
||||
private Drawable unrankedBadge = null!;
|
||||
|
||||
private ModDisplay modDisplay = null!;
|
||||
private OsuSpriteText modCountText = null!;
|
||||
@ -59,58 +64,19 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
const float bar_shear_width = 7f;
|
||||
const float bar_height = 37f;
|
||||
const float mod_display_portion = 0.65f;
|
||||
|
||||
var barShear = new Vector2(bar_shear_width / bar_height, 0);
|
||||
|
||||
Text = "Mods";
|
||||
Icon = FontAwesome.Solid.ExchangeAlt;
|
||||
AccentColour = colours.Lime1;
|
||||
|
||||
AddRange(new[]
|
||||
{
|
||||
UnrankedBadge = new ContainerWithTooltip
|
||||
{
|
||||
Margin = new MarginPadding { Left = BUTTON_WIDTH + 5f },
|
||||
Y = -5f,
|
||||
Depth = float.MaxValue,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Shear = barShear,
|
||||
CornerRadius = CORNER_RADIUS,
|
||||
AutoSizeAxes = Axes.X,
|
||||
Height = bar_height,
|
||||
Masking = true,
|
||||
BorderColour = Color4.White,
|
||||
BorderThickness = 2f,
|
||||
TooltipText = ModSelectOverlayStrings.UnrankedExplanation,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = colours.Orange2,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Shear = -barShear,
|
||||
Text = ModSelectOverlayStrings.Unranked.ToUpper(),
|
||||
Margin = new MarginPadding { Horizontal = 15 },
|
||||
UseFullGlyphHeight = false,
|
||||
Font = OsuFont.Torus.With(size: 14 * torus_scale_factor, weight: FontWeight.Bold),
|
||||
Colour = Color4.Black,
|
||||
}
|
||||
}
|
||||
},
|
||||
unrankedBadge = new UnrankedBadge(),
|
||||
modDisplayBar = new Container
|
||||
{
|
||||
Y = -5f,
|
||||
Depth = float.MaxValue,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Shear = barShear,
|
||||
Shear = bar_shear,
|
||||
CornerRadius = CORNER_RADIUS,
|
||||
Size = new Vector2(BUTTON_WIDTH, bar_height),
|
||||
Masking = true,
|
||||
@ -140,7 +106,7 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Shear = -barShear,
|
||||
Shear = -bar_shear,
|
||||
UseFullGlyphHeight = false,
|
||||
Font = OsuFont.Torus.With(size: 14 * torus_scale_factor, weight: FontWeight.Bold)
|
||||
}
|
||||
@ -162,7 +128,7 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Shear = -barShear,
|
||||
Shear = -bar_shear,
|
||||
Scale = new Vector2(0.6f),
|
||||
Current = { BindTarget = Current },
|
||||
ExpansionMode = ExpansionMode.AlwaysContracted,
|
||||
@ -171,7 +137,7 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Shear = -barShear,
|
||||
Shear = -bar_shear,
|
||||
Font = OsuFont.Torus.With(size: 14 * torus_scale_factor, weight: FontWeight.Bold),
|
||||
Mods = { BindTarget = Current },
|
||||
}
|
||||
@ -216,8 +182,8 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
modDisplay.FadeOut(duration, easing);
|
||||
modCountText.FadeOut(duration, easing);
|
||||
|
||||
UnrankedBadge.MoveToY(20, duration, easing);
|
||||
UnrankedBadge.FadeOut(duration, easing);
|
||||
unrankedBadge.MoveToY(20, duration, easing);
|
||||
unrankedBadge.FadeOut(duration, easing);
|
||||
|
||||
// add delay to let unranked indicator hide first before resizing the button back to its original width.
|
||||
this.Delay(duration).ResizeWidthTo(BUTTON_WIDTH, duration, easing);
|
||||
@ -234,21 +200,21 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
|
||||
if (Current.Value.Any(m => !m.Ranked))
|
||||
{
|
||||
UnrankedBadge.MoveToX(0, duration, easing);
|
||||
UnrankedBadge.FadeIn(duration, easing);
|
||||
unrankedBadge.MoveToX(0, duration, easing);
|
||||
unrankedBadge.FadeIn(duration, easing);
|
||||
|
||||
this.ResizeWidthTo(BUTTON_WIDTH + 5 + UnrankedBadge.DrawWidth, duration, easing);
|
||||
this.ResizeWidthTo(BUTTON_WIDTH + 5 + unrankedBadge.DrawWidth, duration, easing);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnrankedBadge.MoveToX(-UnrankedBadge.DrawWidth, duration, easing);
|
||||
UnrankedBadge.FadeOut(duration, easing);
|
||||
unrankedBadge.MoveToX(-unrankedBadge.DrawWidth, duration, easing);
|
||||
unrankedBadge.FadeOut(duration, easing);
|
||||
|
||||
this.ResizeWidthTo(BUTTON_WIDTH, duration, easing);
|
||||
}
|
||||
|
||||
modDisplayBar.MoveToY(-5, duration, Easing.OutQuint);
|
||||
UnrankedBadge.MoveToY(-5, duration, easing);
|
||||
unrankedBadge.MoveToY(-5, duration, easing);
|
||||
modDisplayBar.FadeIn(duration, easing);
|
||||
}
|
||||
|
||||
@ -327,9 +293,49 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
}
|
||||
}
|
||||
|
||||
private partial class ContainerWithTooltip : Container, IHasTooltip
|
||||
internal partial class UnrankedBadge : CompositeDrawable, IHasTooltip
|
||||
{
|
||||
public LocalisableString TooltipText { get; set; }
|
||||
public LocalisableString TooltipText { get; }
|
||||
|
||||
public UnrankedBadge()
|
||||
{
|
||||
Margin = new MarginPadding { Left = BUTTON_WIDTH + 5f };
|
||||
Y = -5f;
|
||||
Depth = float.MaxValue;
|
||||
Origin = Anchor.BottomLeft;
|
||||
Shear = bar_shear;
|
||||
CornerRadius = CORNER_RADIUS;
|
||||
AutoSizeAxes = Axes.X;
|
||||
Height = bar_height;
|
||||
Masking = true;
|
||||
BorderColour = Color4.White;
|
||||
BorderThickness = 2f;
|
||||
TooltipText = ModSelectOverlayStrings.UnrankedExplanation;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = colours.Orange2,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Shear = -bar_shear,
|
||||
Text = ModSelectOverlayStrings.Unranked.ToUpper(),
|
||||
Margin = new MarginPadding { Horizontal = 15 },
|
||||
UseFullGlyphHeight = false,
|
||||
Font = OsuFont.Torus.With(size: 14 * torus_scale_factor, weight: FontWeight.Bold),
|
||||
Colour = Color4.Black,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user