1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-07 02:53:38 +08:00

Combine implementation of mods text drawable

I don't want to have to update things in multiple places with different
code in each place.

This also closes https://github.com/ppy/osu/issues/36412.
This commit is contained in:
Dean Herbert
2026-01-28 15:58:55 +09:00
Unverified
parent 0c90cf3cef
commit c8c91cedfa
2 changed files with 23 additions and 63 deletions
@@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
@@ -13,21 +12,19 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Utils;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Localisation;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Footer;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.SelectV2;
using osuTK;
namespace osu.Game.Screens.OnlinePlay
{
public partial class FooterButtonFreeModsV2 : ScreenFooterButton
{
private const float bar_height = 30f;
public readonly Bindable<IReadOnlyList<Mod>> FreeMods = new Bindable<IReadOnlyList<Mod>>([]);
public readonly Bindable<bool> Freestyle = new Bindable<bool>();
@@ -45,7 +42,7 @@ namespace osu.Game.Screens.OnlinePlay
private Container modsWedge = null!;
private ModDisplay modDisplay = null!;
private Container modContainer = null!;
private ModCountText overflowModCountDisplay = null!;
private FooterButtonMods.ModCountText overflowModCountDisplay = null!;
public FooterButtonFreeModsV2(ModSelectOverlay overlay)
: base(overlay)
@@ -66,7 +63,7 @@ namespace osu.Game.Screens.OnlinePlay
Origin = Anchor.BottomLeft,
Shear = OsuGame.SHEAR,
CornerRadius = CORNER_RADIUS,
Size = new Vector2(BUTTON_WIDTH, bar_height),
Size = new Vector2(BUTTON_WIDTH, FooterButtonMods.BAR_HEIGHT),
Masking = true,
EdgeEffect = new EdgeEffectParameters
{
@@ -100,7 +97,7 @@ namespace osu.Game.Screens.OnlinePlay
Current = { BindTarget = FreeMods },
ExpansionMode = ExpansionMode.AlwaysContracted,
},
overflowModCountDisplay = new ModCountText
overflowModCountDisplay = new FooterButtonMods.ModCountText
{
Mods = { BindTarget = FreeMods },
Freestyle = { BindTarget = Freestyle }
@@ -145,56 +142,5 @@ namespace osu.Game.Screens.OnlinePlay
else
overflowModCountDisplay.Hide();
}
private partial class ModCountText : VisibilityContainer
{
public readonly Bindable<IReadOnlyList<Mod>> Mods = new Bindable<IReadOnlyList<Mod>>();
public readonly Bindable<bool> Freestyle = new Bindable<bool>();
private OsuSpriteText text = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
protected override void LoadComplete()
{
base.LoadComplete();
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
new Box
{
Colour = colourProvider.Background3,
Alpha = 0.8f,
RelativeSizeAxes = Axes.Both,
},
text = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Torus.With(size: 14f, weight: FontWeight.Bold),
Shear = -OsuGame.SHEAR,
}
};
Mods.BindValueChanged(_ => updateText());
Freestyle.BindValueChanged(_ => updateText());
updateText();
}
protected override void PopIn() => this.FadeIn(300, Easing.OutExpo);
protected override void PopOut() => this.FadeOut(300, Easing.OutExpo);
private void updateText()
{
if (Freestyle.Value)
text.Text = ModSelectOverlayStrings.AllMods.ToUpper();
else
text.Text = ModSelectOverlayStrings.Mods(Mods.Value.Count).ToUpper();
}
}
}
}
+19 -5
View File
@@ -36,7 +36,8 @@ namespace osu.Game.Screens.SelectV2
{
public Action? RequestDeselectAllMods { get; init; }
private const float bar_height = 30f;
public const float BAR_HEIGHT = 30f;
private const float mod_display_portion = 0.65f;
private readonly BindableWithCurrent<IReadOnlyList<Mod>> current = new BindableWithCurrent<IReadOnlyList<Mod>>(Array.Empty<Mod>());
@@ -92,7 +93,7 @@ namespace osu.Game.Screens.SelectV2
Origin = Anchor.BottomLeft,
Shear = OsuGame.SHEAR,
CornerRadius = CORNER_RADIUS,
Size = new Vector2(BUTTON_WIDTH, bar_height),
Size = new Vector2(BUTTON_WIDTH, BAR_HEIGHT),
Masking = true,
EdgeEffect = new EdgeEffectParameters
{
@@ -257,9 +258,10 @@ namespace osu.Game.Screens.SelectV2
overflowModCountDisplay.Hide();
}
private partial class ModCountText : CompositeDrawable, IHasCustomTooltip<IReadOnlyList<Mod>>
public partial class ModCountText : VisibilityContainer, IHasCustomTooltip<IReadOnlyList<Mod>>
{
public readonly Bindable<IReadOnlyList<Mod>> Mods = new Bindable<IReadOnlyList<Mod>>();
public readonly Bindable<bool> Freestyle = new Bindable<bool>();
private OsuSpriteText text = null!;
@@ -289,13 +291,25 @@ namespace osu.Game.Screens.SelectV2
}
};
Mods.BindValueChanged(v => text.Text = ModSelectOverlayStrings.Mods(v.NewValue.Count).ToUpper(), true);
Freestyle.BindValueChanged(_ => updateText());
Mods.BindValueChanged(_ => updateText(), true);
}
public ITooltip<IReadOnlyList<Mod>> GetCustomTooltip() => new ModOverflowTooltip(colourProvider);
public IReadOnlyList<Mod>? TooltipContent => Mods.Value;
protected override void PopIn() => this.FadeIn(300, Easing.OutExpo);
protected override void PopOut() => this.FadeOut(300, Easing.OutExpo);
private void updateText()
{
if (Freestyle.Value)
text.Text = ModSelectOverlayStrings.AllMods.ToUpper();
else
text.Text = ModSelectOverlayStrings.Mods(Mods.Value.Count).ToUpper();
}
public partial class ModOverflowTooltip : VisibilityContainer, ITooltip<IReadOnlyList<Mod>>
{
private ModDisplay extendedModDisplay = null!;
@@ -356,7 +370,7 @@ namespace osu.Game.Screens.SelectV2
Shear = OsuGame.SHEAR;
CornerRadius = CORNER_RADIUS;
AutoSizeAxes = Axes.X;
Height = bar_height;
Height = BAR_HEIGHT;
Masking = true;
BorderColour = Color4.White;
BorderThickness = 2f;