Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 26 additions & 65 deletions osu.Game/Screens/OnlinePlay/FooterButtonFreeModsV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
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>();

Expand All @@ -44,7 +44,7 @@ public partial class FooterButtonFreeModsV2 : ScreenFooterButton
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)
Expand All @@ -65,7 +65,7 @@ private void load()
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
{
Expand All @@ -90,11 +90,6 @@ private void load()
Masking = true,
Children = new Drawable[]
{
new Box
{
Colour = colourProvider.Background3,
RelativeSizeAxes = Axes.Both,
},
modDisplay = new ModDisplay(showExtendedInformation: true)
{
Anchor = Anchor.Centre,
Expand All @@ -104,10 +99,9 @@ private void load()
Current = { BindTarget = FreeMods },
ExpansionMode = ExpansionMode.AlwaysContracted,
},
overflowModCountDisplay = new ModCountText
overflowModCountDisplay = new FooterButtonMods.ModCountText
{
Mods = { BindTarget = FreeMods },
Freestyle = { BindTarget = Freestyle }
},
}
},
Expand All @@ -119,72 +113,39 @@ protected override void LoadComplete()
{
base.LoadComplete();

Freestyle.BindValueChanged(f => Enabled.Value = !f.NewValue, true);
Freestyle.BindValueChanged(f =>
{
Enabled.Value = !f.NewValue;
overflowModCountDisplay.CustomText = f.NewValue ? ModSelectOverlayStrings.AllMods.ToUpper() : (LocalisableString?)null;
}, true);
FreeMods.BindValueChanged(m =>
{
if (m.NewValue.Count == 0)
modsWedge.FadeOut(200);
if (m.NewValue.Count == 0 && !Freestyle.Value)
modsWedge.FadeOut(300, Easing.OutExpo);
else
modsWedge.FadeIn(200);
modsWedge.FadeIn(300, Easing.OutExpo);
}, true);
}

protected override void Update()
{
base.Update();

if (modDisplay.DrawWidth * modDisplay.Scale.X > modContainer.DrawWidth)
// If there are freemods selected but the display has no width, it's still loading.
// Don't update visibility in this state or we will cause an awkward flash.
if (FreeMods.Value.Count > 0 && Precision.AlmostEquals(modDisplay.DrawWidth, 0))
return;

bool showCountText =
// When freestyle is enabled this text shows "ALL MODS"
Freestyle.Value
// Standard flow where mods are overflowing so we show count text.
|| modDisplay.DrawWidth * modDisplay.Scale.X > modContainer.DrawWidth;

if (showCountText)
overflowModCountDisplay.Show();
else
overflowModCountDisplay.Hide();
}

private partial class ModCountText : CompositeDrawable
{
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();
}

private void updateText()
{
if (Freestyle.Value)
text.Text = ModSelectOverlayStrings.AllMods.ToUpper();
else
text.Text = ModSelectOverlayStrings.Mods(Mods.Value.Count).ToUpper();
}
}
}
}
45 changes: 37 additions & 8 deletions osu.Game/Screens/SelectV2/FooterButtonMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public partial class FooterButtonMods : ScreenFooterButton, IHasCurrentValue<IRe
{
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>());
Expand Down Expand Up @@ -92,7 +93,7 @@ private void load()
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
{
Expand Down Expand Up @@ -257,10 +258,26 @@ protected override void Update()
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>>();

private LocalisableString? customText;

/// <summary>
/// When set, this will be shown instead of a mod count.
/// </summary>
public LocalisableString? CustomText
{
get => customText;
set
{
customText = value;
if (IsLoaded)
updateText();
}
}

private OsuSpriteText text = null!;

[Resolved]
Expand Down Expand Up @@ -289,16 +306,27 @@ protected override void LoadComplete()
}
};

Mods.BindValueChanged(v => text.Text = ModSelectOverlayStrings.Mods(v.NewValue.Count).ToUpper(), true);
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 (CustomText != null)
text.Text = CustomText.Value;
else
text.Text = ModSelectOverlayStrings.Mods(Mods.Value.Count).ToUpper();
}

public partial class ModOverflowTooltip : VisibilityContainer, ITooltip<IReadOnlyList<Mod>>
{
private ModDisplay extendedModDisplay = null!;
private ModFlowDisplay extendedModDisplay = null!;

[Cached]
private OverlayColourProvider colourProvider;
Expand All @@ -322,11 +350,12 @@ private void load()
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5,
},
extendedModDisplay = new ModDisplay
extendedModDisplay = new ModFlowDisplay
{
AutoSizeAxes = Axes.Both,
MaximumSize = new Vector2(400, 0),
Margin = new MarginPadding { Vertical = 2f, Horizontal = 10f },
Scale = new Vector2(0.6f),
ExpansionMode = ExpansionMode.AlwaysExpanded,
},
};
}
Expand Down Expand Up @@ -356,7 +385,7 @@ public UnrankedBadge()
Shear = OsuGame.SHEAR;
CornerRadius = CORNER_RADIUS;
AutoSizeAxes = Axes.X;
Height = bar_height;
Height = BAR_HEIGHT;
Masking = true;
BorderColour = Color4.White;
BorderThickness = 2f;
Expand Down