Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new footer back button and fix shearing being different between components #28183

Merged
merged 10 commits into from
May 28, 2024
51 changes: 47 additions & 4 deletions osu.Game.Tests/Visual/UserInterface/TestSceneShearedButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osuTK;
using osuTK.Input;

namespace osu.Game.Tests.Visual.UserInterface
Expand All @@ -35,7 +37,7 @@ public void TestShearedButton(bool bigButton)

if (bigButton)
{
Child = button = new ShearedButton(400)
Child = button = new ShearedButton(400, 80)
{
LighterColour = Colour4.FromHex("#FFFFFF"),
DarkerColour = Colour4.FromHex("#FFCC22"),
Expand All @@ -44,21 +46,19 @@ public void TestShearedButton(bool bigButton)
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Let's GO!",
Height = 80,
Action = () => actionFired = true,
};
}
else
{
Child = button = new ShearedButton(200)
Child = button = new ShearedButton(200, 80)
{
LighterColour = Colour4.FromHex("#FF86DD"),
DarkerColour = Colour4.FromHex("#DE31AE"),
TextColour = Colour4.White,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Press me",
Height = 80,
Action = () => actionFired = true,
};
}
Expand Down Expand Up @@ -171,5 +171,48 @@ void clickToggle() => AddStep("click toggle", () =>

void setToggleDisabledState(bool disabled) => AddStep($"{(disabled ? "disable" : "enable")} toggle", () => button.Active.Disabled = disabled);
}

[Test]
public void TestButtons()
{
AddStep("create buttons", () => Children = new[]
{
new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Scale = new Vector2(2.5f),
Children = new Drawable[]
{
new ShearedButton(120)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = "Test",
Action = () => { },
Padding = new MarginPadding(),
},
new ShearedButton(120, 40)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = "Test",
Action = () => { },
Padding = new MarginPadding { Left = -1f },
},
new ShearedButton(120, 70)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = "Test",
Action = () => { },
Padding = new MarginPadding { Left = 3f },
},
}
}
});
}
}
}
29 changes: 18 additions & 11 deletions osu.Game/Graphics/UserInterface/ShearedButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace osu.Game.Graphics.UserInterface
{
public partial class ShearedButton : OsuClickableContainer
{
public const float HEIGHT = 50;
public const float DEFAULT_HEIGHT = 50;
public const float CORNER_RADIUS = 7;
public const float BORDER_THICKNESS = 2;

Expand Down Expand Up @@ -66,7 +66,7 @@ public Colour4 TextColour
private readonly Box background;
private readonly OsuSpriteText text;

private const float shear = 0.2f;
private const float shear = OsuGame.SHEAR;

private Colour4? darkerColour;
private Colour4? lighterColour;
Expand All @@ -75,6 +75,8 @@ public Colour4 TextColour
private readonly Container backgroundLayer;
private readonly Box flashLayer;

protected readonly Container ButtonContent;

/// <summary>
/// Creates a new <see cref="ShearedToggleButton"/>
/// </summary>
Expand All @@ -85,10 +87,11 @@ public Colour4 TextColour
/// <item>If a <see langword="null"/> value is provided (or the argument is omitted entirely), the button will autosize in width to fit the text.</item>
/// </list>
/// </param>
public ShearedButton(float? width = null)
/// <param name="height">The height of the button.</param>
public ShearedButton(float? width = null, float height = DEFAULT_HEIGHT)
{
Height = HEIGHT;
Padding = new MarginPadding { Horizontal = shear * 50 };
Height = height;
Padding = new MarginPadding { Horizontal = shear * height };

Content.CornerRadius = CORNER_RADIUS;
Content.Shear = new Vector2(shear, 0);
Expand All @@ -109,12 +112,16 @@ public ShearedButton(float? width = null)
{
RelativeSizeAxes = Axes.Both
},
text = new OsuSpriteText
ButtonContent = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.TorusAlternate.With(size: 17),
Shear = new Vector2(-shear, 0)
AutoSizeAxes = Axes.Both,
Shear = new Vector2(-shear, 0),
Child = text = new OsuSpriteText
{
Font = OsuFont.TorusAlternate.With(size: 17),
}
},
}
},
Expand Down Expand Up @@ -188,7 +195,7 @@ private void updateState()
{
var colourDark = darkerColour ?? ColourProvider.Background3;
var colourLight = lighterColour ?? ColourProvider.Background1;
var colourText = textColour ?? ColourProvider.Content1;
var colourContent = textColour ?? ColourProvider.Content1;

if (!Enabled.Value)
{
Expand All @@ -205,9 +212,9 @@ private void updateState()
backgroundLayer.TransformTo(nameof(BorderColour), ColourInfo.GradientVertical(colourDark, colourLight), 150, Easing.OutQuint);

if (!Enabled.Value)
colourText = colourText.Opacity(0.6f);
colourContent = colourContent.Opacity(0.6f);

text.FadeColour(colourText, 150, Easing.OutQuint);
ButtonContent.FadeColour(colourContent, 150, Easing.OutQuint);
}
}
}
5 changes: 2 additions & 3 deletions osu.Game/Graphics/UserInterface/ShearedSearchTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using osu.Framework.Localisation;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
using osu.Game.Resources.Localisation.Web;
using osuTK;

Expand Down Expand Up @@ -53,7 +52,7 @@ public LocalisableString PlaceholderText
public ShearedSearchTextBox()
{
Height = 42;
Shear = new Vector2(ShearedOverlayContainer.SHEAR, 0);
Shear = new Vector2(OsuGame.SHEAR, 0);
Masking = true;
CornerRadius = corner_radius;

Expand Down Expand Up @@ -116,7 +115,7 @@ private void load(OverlayColourProvider colourProvider)
PlaceholderText = CommonStrings.InputSearch;

CornerRadius = corner_radius;
TextContainer.Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0);
TextContainer.Shear = new Vector2(-OsuGame.SHEAR, 0);
}

protected override SpriteText CreatePlaceholder() => new SearchPlaceholder();
Expand Down
5 changes: 5 additions & 0 deletions osu.Game/OsuGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public partial class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>, IL
/// </summary>
protected const float SIDE_OVERLAY_OFFSET_RATIO = 0.05f;

/// <summary>
/// A common shear factor applied to most components of the game.
/// </summary>
public const float SHEAR = 0.2f;

public Toolbar Toolbar { get; private set; }

private ChatOverlay chatOverlay;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Overlays/Mods/BeatmapAttributesDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public partial class BeatmapAttributesDisplay : ModFooterInformationDisplay, IHa
[BackgroundDependencyLoader]
private void load()
{
const float shear = ShearedOverlayContainer.SHEAR;
const float shear = OsuGame.SHEAR;

LeftContent.AddRange(new Drawable[]
{
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Overlays/Mods/ModColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public ModColumn(ModType modType, bool allowIncompatibleSelection)
Origin = Anchor.CentreLeft,
Scale = new Vector2(0.8f),
RelativeSizeAxes = Axes.X,
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0)
Shear = new Vector2(-OsuGame.SHEAR, 0)
});
ItemsFlow.Padding = new MarginPadding
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Overlays/Mods/ModFooterInformationDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ private void load()
Origin = Anchor.BottomRight,
Anchor = Anchor.BottomRight,
AutoSizeAxes = Axes.X,
Height = ShearedButton.HEIGHT,
Shear = new Vector2(ShearedOverlayContainer.SHEAR, 0),
Height = ShearedButton.DEFAULT_HEIGHT,
Shear = new Vector2(OsuGame.SHEAR, 0),
CornerRadius = ShearedButton.CORNER_RADIUS,
BorderThickness = ShearedButton.BORDER_THICKNESS,
Masking = true,
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Overlays/Mods/ModPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ModPanel(ModState modState)
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Active = { BindTarget = Active },
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Shear = new Vector2(-OsuGame.SHEAR, 0),
Scale = new Vector2(HEIGHT / ModSwitchSmall.DEFAULT_SIZE)
};
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Game/Overlays/Mods/ModSelectColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected ModSelectColumn()
{
Width = WIDTH;
RelativeSizeAxes = Axes.Y;
Shear = new Vector2(ShearedOverlayContainer.SHEAR, 0);
Shear = new Vector2(OsuGame.SHEAR, 0);

InternalChildren = new Drawable[]
{
Expand All @@ -96,7 +96,7 @@ protected ModSelectColumn()
{
RelativeSizeAxes = Axes.X,
Height = header_height,
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Shear = new Vector2(-OsuGame.SHEAR, 0),
Velocity = 0.7f,
ClampAxes = Axes.Y
},
Expand All @@ -111,7 +111,7 @@ protected ModSelectColumn()
AutoSizeAxes = Axes.Y,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Shear = new Vector2(-OsuGame.SHEAR, 0),
Padding = new MarginPadding
{
Horizontal = 17,
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Overlays/Mods/ModSelectOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private void load(OsuGameBase game, OsuColour colours, AudioManager audio, OsuCo
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Direction = FillDirection.Horizontal,
Shear = new Vector2(SHEAR, 0),
Shear = new Vector2(OsuGame.SHEAR, 0),
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Margin = new MarginPadding { Horizontal = 70 },
Expand Down Expand Up @@ -847,7 +847,7 @@ protected override void Update()
// DrawWidth/DrawPosition do not include shear effects, and we want to know the full extents of the columns post-shear,
// so we have to manually compensate.
var topLeft = column.ToSpaceOfOtherDrawable(Vector2.Zero, ScrollContent);
var bottomRight = column.ToSpaceOfOtherDrawable(new Vector2(column.DrawWidth - column.DrawHeight * SHEAR, 0), ScrollContent);
var bottomRight = column.ToSpaceOfOtherDrawable(new Vector2(column.DrawWidth - column.DrawHeight * OsuGame.SHEAR, 0), ScrollContent);

bool isCurrentlyVisible = Precision.AlmostBigger(topLeft.X, leftVisibleBound)
&& Precision.DefinitelyBigger(rightVisibleBound, bottomRight.X);
Expand Down
8 changes: 4 additions & 4 deletions osu.Game/Overlays/Mods/ModSelectPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected ModSelectPanel()
Content.CornerRadius = CORNER_RADIUS;
Content.BorderThickness = 2;

Shear = new Vector2(ShearedOverlayContainer.SHEAR, 0);
Shear = new Vector2(OsuGame.SHEAR, 0);

Children = new Drawable[]
{
Expand Down Expand Up @@ -128,18 +128,18 @@ protected ModSelectPanel()
{
Font = OsuFont.TorusAlternate.With(size: 18, weight: FontWeight.SemiBold),
RelativeSizeAxes = Axes.X,
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Shear = new Vector2(-OsuGame.SHEAR, 0),
Margin = new MarginPadding
{
Left = -18 * ShearedOverlayContainer.SHEAR
Left = -18 * OsuGame.SHEAR
},
ShowTooltip = false, // Tooltip is handled by `IncompatibilityDisplayingModPanel`.
},
descriptionText = new TruncatingSpriteText
{
Font = OsuFont.Default.With(size: 12),
RelativeSizeAxes = Axes.X,
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Shear = new Vector2(-OsuGame.SHEAR, 0),
ShowTooltip = false, // Tooltip is handled by `IncompatibilityDisplayingModPanel`.
}
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Game/Overlays/Mods/RankingInformationDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void load()
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(ShearedOverlayContainer.SHEAR, 0),
Shear = new Vector2(OsuGame.SHEAR, 0),
CornerRadius = ShearedButton.CORNER_RADIUS,
Masking = true,
Children = new Drawable[]
Expand All @@ -79,7 +79,7 @@ private void load()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Shear = new Vector2(-OsuGame.SHEAR, 0),
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
}
}
Expand All @@ -94,7 +94,7 @@ private void load()
Origin = Anchor.Centre,
Child = counter = new EffectCounter
{
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Shear = new Vector2(-OsuGame.SHEAR, 0),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Current = { BindTarget = ModMultiplier }
Expand Down
2 changes: 0 additions & 2 deletions osu.Game/Overlays/Mods/ShearedOverlayContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public abstract partial class ShearedOverlayContainer : OsuFocusedOverlayContain
{
protected const float PADDING = 14;

public const float SHEAR = 0.2f;

[Cached]
protected readonly OverlayColourProvider ColourProvider;

Expand Down
Loading
Loading