1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 19:27:24 +08:00

Add localisation and tooltip for mods count text

This commit is contained in:
Salman Ahmed 2024-05-10 06:38:48 +03:00
parent 49692e168e
commit bff34a1c04
4 changed files with 87 additions and 4 deletions

View File

@ -78,6 +78,12 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("four mods", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime(), new OsuModClassic() });
AddStep("five mods", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime(), new OsuModClassic(), new OsuModDifficultyAdjust() });
AddStep("modified", () => SelectedMods.Value = new List<Mod> { new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } });
AddStep("modified + one", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } });
AddStep("modified + two", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } });
AddStep("modified + three", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModClassic(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } });
AddStep("modified + four", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModClassic(), new OsuModDifficultyAdjust(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } });
AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
AddWaitStep("wait", 3);
AddStep("one mod", () => SelectedMods.Value = new List<Mod> { new OsuModHidden() });

View File

@ -44,6 +44,10 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("four mods", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime(), new OsuModClassic() }));
AddStep("five mods", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime(), new OsuModClassic(), new OsuModDifficultyAdjust() }));
AddStep("modified", () => changeMods(new List<Mod> { new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } }));
AddStep("modified + one", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } }));
AddStep("modified + two", () => changeMods(new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } }));
AddStep("clear mods", () => changeMods(Array.Empty<Mod>()));
AddWaitStep("wait", 3);
AddStep("one mod", () => changeMods(new List<Mod> { new OsuModHidden() }));

View File

@ -0,0 +1,19 @@
// 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.Localisation;
namespace osu.Game.Localisation
{
public static class FooterButtonModsV2Strings
{
private const string prefix = @"osu.Game.Resources.Localisation.FooterButtonModsV2";
/// <summary>
/// "{0} mods"
/// </summary>
public static LocalisableString Mods(int count) => new TranslatableString(getKey(@"mods"), @"{0} mods", count);
private static string getKey(string key) => $@"{prefix}:{key}";
}
}

View File

@ -9,12 +9,14 @@ using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Localisation;
using osu.Game.Overlays;
@ -155,15 +157,16 @@ namespace osu.Game.Screens.Select.FooterV2
Origin = Anchor.Centre,
Shear = -barShear,
Scale = new Vector2(0.6f),
Current = { Value = new List<Mod> { new ModCinema() } },
Current = { BindTarget = Current },
ExpansionMode = ExpansionMode.AlwaysContracted,
},
modCountText = new OsuSpriteText
modCountText = new ModCountText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Shear = -barShear,
Font = OsuFont.Torus.With(size: 14 * torus_scale_factor, weight: FontWeight.Bold),
Mods = { BindTarget = Current },
}
}
},
@ -216,13 +219,11 @@ namespace osu.Game.Screens.Select.FooterV2
{
if (Current.Value.Count >= 5)
{
modCountText.Text = $"{Current.Value.Count} MODS";
modCountText.FadeIn(duration, easing);
modDisplay.FadeOut(duration, easing);
}
else
{
modDisplay.Current.Value = Current.Value;
modDisplay.FadeIn(duration, easing);
modCountText.FadeOut(duration, easing);
}
@ -257,5 +258,58 @@ namespace osu.Game.Screens.Select.FooterV2
else
MultiplierText.FadeColour(Color4.White, duration, easing);
}
private partial class ModCountText : OsuSpriteText, IHasCustomTooltip<IReadOnlyList<Mod>>
{
public readonly Bindable<IReadOnlyList<Mod>> Mods = new Bindable<IReadOnlyList<Mod>>();
protected override void LoadComplete()
{
base.LoadComplete();
Mods.BindValueChanged(v => Text = FooterButtonModsV2Strings.Mods(v.NewValue.Count).ToUpper(), true);
}
public ITooltip<IReadOnlyList<Mod>> GetCustomTooltip() => new ModTooltip();
public IReadOnlyList<Mod>? TooltipContent => Mods.Value;
public partial class ModTooltip : VisibilityContainer, ITooltip<IReadOnlyList<Mod>>
{
private ModDisplay extendedModDisplay = null!;
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
AutoSizeAxes = Axes.Both;
CornerRadius = CORNER_RADIUS;
Masking = true;
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5,
},
extendedModDisplay = new ModDisplay
{
Margin = new MarginPadding { Vertical = 2f, Horizontal = 10f },
Scale = new Vector2(0.6f),
ExpansionMode = ExpansionMode.AlwaysExpanded,
},
};
}
public void SetContent(IReadOnlyList<Mod> content)
{
extendedModDisplay.Current.Value = content;
}
public void Move(Vector2 pos) => Position = pos;
protected override void PopIn() => this.FadeIn(240, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(240, Easing.OutQuint);
}
}
}
}