Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ private void load()
AutoSizeAxes = Axes.Both,
Children = new[]
{
new ShearedButton(200) { Text = "Action #1", Action = () => { } },
new ShearedButton(140) { Text = "Action #2", Action = () => { } },
new ShearedButton { Width = 200, Text = "Action #1", Action = () => { } },
new ShearedButton { Width = 140, Text = "Action #2", Action = () => { } },
}
};
}
Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Tests/Visual/UserInterface/TestSceneButtonsInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ public TestSceneButtonsInput()
Enabled = { Value = true },
Text = "Rounded button"
},
shearedButton = new ShearedButton(width)
shearedButton = new ShearedButton
{
Text = "Sheared button",
LighterColour = Colour4.FromHex("#FFFFFF"),
DarkerColour = Colour4.FromHex("#FFCC22"),
TextColour = Colour4.Black,
Width = width,
Height = 40,
Enabled = { Value = true },
Padding = new MarginPadding(0)
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Tests/Visual/UserInterface/TestSceneScreenFooter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ private void load()
AutoSizeAxes = Axes.Both,
Children = new[]
{
new ShearedButton(200) { Text = "Action #1", Action = () => { } },
new ShearedButton(140) { Text = "Action #2", Action = () => { } },
new ShearedButton { Width = 200, Text = "Action #1", Action = () => { } },
new ShearedButton { Width = 140, Text = "Action #2", Action = () => { } },
}
};
}
Expand Down
58 changes: 53 additions & 5 deletions osu.Game.Tests/Visual/UserInterface/TestSceneShearedButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Screens.Footer;
using osuTK.Input;

namespace osu.Game.Tests.Visual.UserInterface
Expand All @@ -36,8 +38,10 @@ public void TestShearedButton(bool bigButton)

if (bigButton)
{
Child = button = new ShearedButton(400, 80)
Child = button = new ShearedButton
{
Width = 400,
Height = 80,
LighterColour = Colour4.FromHex("#FFFFFF"),
DarkerColour = Colour4.FromHex("#FFCC22"),
TextColour = Colour4.Black,
Expand All @@ -50,8 +54,10 @@ public void TestShearedButton(bool bigButton)
}
else
{
Child = button = new ShearedButton(200, 80)
Child = button = new ShearedButton
{
Width = 200,
Height = 80,
LighterColour = Colour4.FromHex("#FF86DD"),
DarkerColour = Colour4.FromHex("#DE31AE"),
TextColour = Colour4.White,
Expand Down Expand Up @@ -79,8 +85,9 @@ public void TestShearedToggleButton()

AddStep("create button", () =>
{
Child = button = new ShearedToggleButton(200)
Child = button = new ShearedToggleButton
{
Width = 200,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Toggle me",
Expand All @@ -91,13 +98,49 @@ public void TestShearedToggleButton()
AddToggleStep("toggle disabled", disabled => button.Active.Disabled = disabled);
}

[TestCase(true)]
[TestCase(false)]
public void TestShearedFooterButton(bool withIcon)
{
var colours = new OsuColour();

ShearedFooterButton button = null!;
bool actionFired = false;

AddStep("create button", () =>
{
Child = button = new ShearedFooterButton
{
Width = 220,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
LighterColour = colours.Blue1,
DarkerColour = colours.Blue3,
Text = "Add to playlist",
Action = () => actionFired = true,
};

if (withIcon)
button.Icon = OsuIcon.Add;
});

AddStep("set disabled", () => button.Enabled.Value = false);
AddStep("press button", () => button.TriggerClick());
AddAssert("action not fired", () => !actionFired);

AddStep("set enabled", () => button.Enabled.Value = true);
AddStep("press button", () => button.TriggerClick());
AddAssert("action fired", () => actionFired);
}

[Test]
public void TestSizing()
{
ShearedToggleButton toggleButton = null;

AddStep("create fixed width button", () => Child = toggleButton = new ShearedToggleButton(200)
AddStep("create fixed width button", () => Child = toggleButton = new ShearedToggleButton
{
Width = 200,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Fixed width"
Expand All @@ -109,6 +152,7 @@ public void TestSizing()

AddStep("create auto-sizing button", () => Child = toggleButton = new ShearedToggleButton
{
AutoSizeAxes = Axes.X,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "This button autosizes to its text!"
Expand All @@ -130,8 +174,9 @@ public void TestDisabledState()

AddStep("create button", () =>
{
Child = button = new ShearedToggleButton(200)
Child = button = new ShearedToggleButton
{
Width = 200,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Toggle me",
Expand Down Expand Up @@ -186,6 +231,7 @@ public void TestButtons()
{
new ShearedButton
{
AutoSizeAxes = Axes.X,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = "Button",
Expand All @@ -194,6 +240,7 @@ public void TestButtons()
},
new ShearedButton
{
AutoSizeAxes = Axes.X,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = "Button",
Expand All @@ -202,6 +249,7 @@ public void TestButtons()
},
new ShearedButton
{
AutoSizeAxes = Axes.X,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = "Button",
Expand Down
8 changes: 8 additions & 0 deletions osu.Game/Graphics/OsuIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public static class OsuIcon
public static IconUsage Twitter => get(OsuIconMapping.Twitter);
public static IconUsage UserInterface => get(OsuIconMapping.UserInterface);
public static IconUsage Wiki => get(OsuIconMapping.Wiki);
public static IconUsage Add => get(OsuIconMapping.Add);
public static IconUsage Remove => get(OsuIconMapping.Remove);
public static IconUsage EditorAddControlPoint => get(OsuIconMapping.EditorAddControlPoint);
public static IconUsage EditorConvertToStream => get(OsuIconMapping.EditorConvertToStream);
public static IconUsage EditorDistanceSnap => get(OsuIconMapping.EditorDistanceSnap);
Expand Down Expand Up @@ -396,6 +398,12 @@ private enum OsuIconMapping
[Description(@"wiki")]
Wiki,

[Description(@"add")]
Add,

[Description(@"remove")]
Remove,

[Description(@"Editor/add-control-point")]
EditorAddControlPoint = 1000,

Expand Down
58 changes: 18 additions & 40 deletions osu.Game/Graphics/UserInterface/ShearedButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,11 @@ public Colour4 TextColour
protected readonly Container ButtonContent;

/// <summary>
/// Creates a new <see cref="ShearedToggleButton"/>
/// Creates a new <see cref="ShearedButton"/>
/// </summary>
/// <param name="width">
/// The width of the button.
/// <list type="bullet">
/// <item>If a non-<see langword="null"/> value is provided, this button will have a fixed width equal to the provided value.</item>
/// <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>
/// <param name="height">The height of the button.</param>
public ShearedButton(float? width = null, float height = DEFAULT_HEIGHT)
public ShearedButton()
{
Height = height;
Height = DEFAULT_HEIGHT;

Shear = OsuGame.SHEAR;

Expand All @@ -99,27 +91,25 @@ public ShearedButton(float? width = null, float height = DEFAULT_HEIGHT)
{
backgroundLayer = new Container
{
RelativeSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.Both,
CornerRadius = CORNER_RADIUS,
Masking = true,
BorderThickness = BORDER_THICKNESS,
Children = new Drawable[]
Child = background = new Box
{
background = new Box
{
RelativeSizeAxes = Axes.Both
},
ButtonContent = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Shear = -OsuGame.SHEAR,
Child = text = new OsuSpriteText
{
Font = OsuFont.TorusAlternate.With(size: 17),
}
},
RelativeSizeAxes = Axes.Both,
},
},
ButtonContent = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Shear = -OsuGame.SHEAR,
Child = text = new OsuSpriteText
{
Font = OsuFont.TorusAlternate.With(size: 17),
Margin = new MarginPadding { Horizontal = 15 },
}
},
flashLayer = new Box
Expand All @@ -130,18 +120,6 @@ public ShearedButton(float? width = null, float height = DEFAULT_HEIGHT)
Alpha = 0,
},
};

if (width != null)
{
Width = width.Value;
backgroundLayer.RelativeSizeAxes = Axes.Both;
}
else
{
AutoSizeAxes = Axes.X;
backgroundLayer.AutoSizeAxes = Axes.X;
text.Margin = new MarginPadding { Horizontal = 15 };
}
}

protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverClickSounds(sampleSet) { Enabled = { BindTarget = Enabled } };
Expand Down
15 changes: 0 additions & 15 deletions osu.Game/Graphics/UserInterface/ShearedToggleButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,6 @@ public partial class ShearedToggleButton : ShearedButton
/// </summary>
public BindableBool Active { get; } = new BindableBool();

/// <summary>
/// Creates a new <see cref="ShearedToggleButton"/>
/// </summary>
/// <param name="width">
/// The width of the button.
/// <list type="bullet">
/// <item>If a non-<see langword="null"/> value is provided, this button will have a fixed width equal to the provided value.</item>
/// <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 ShearedToggleButton(float? width = null)
: base(width)
{
}

[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
Expand Down
1 change: 0 additions & 1 deletion osu.Game/Overlays/Mods/AddPresetButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public partial class AddPresetButton : ShearedToggleButton, IHasPopover
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;

public AddPresetButton()
: base(1)
{
RelativeSizeAxes = Axes.X;
Height = ModSelectPanel.HEIGHT;
Expand Down
3 changes: 2 additions & 1 deletion osu.Game/Overlays/Mods/AddPresetPopover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ public AddPresetPopover(AddPresetButton addPresetButton)
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
createButton = new ShearedButton(content_width)
createButton = new ShearedButton
{
// todo: for some very odd reason, this needs to be anchored to topright for the fill flow to be correctly sized to the AABB of the sheared button
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Width = content_width,
Text = ModSelectOverlayStrings.AddPreset,
Action = createPreset
}
Expand Down
3 changes: 2 additions & 1 deletion osu.Game/Overlays/Mods/DeselectAllModsButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public partial class DeselectAllModsButton : ShearedButton
private readonly Bindable<IReadOnlyList<Mod>> selectedMods = new Bindable<IReadOnlyList<Mod>>();

public DeselectAllModsButton(ModSelectOverlay modSelectOverlay)
: base(ModSelectOverlay.BUTTON_WIDTH)
{
Width = ModSelectOverlay.BUTTON_WIDTH;

Text = CommonStrings.DeselectAll;
Action = modSelectOverlay.DeselectAll;

Expand Down
6 changes: 4 additions & 2 deletions osu.Game/Overlays/Mods/EditPresetPopover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,24 @@ private void load()
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
useCurrentModsButton = new ShearedButton(content_width)
useCurrentModsButton = new ShearedButton
{
// todo: for some very odd reason, this needs to be anchored to topright for the fill flow to be correctly sized to the AABB of the sheared button
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Width = content_width,
Text = ModSelectOverlayStrings.UseCurrentMods,
DarkerColour = colours.Blue1,
LighterColour = colours.Blue0,
TextColour = colourProvider.Background6,
Action = useCurrentMods,
},
saveButton = new ShearedButton(content_width)
saveButton = new ShearedButton
{
// todo: for some very odd reason, this needs to be anchored to topright for the fill flow to be correctly sized to the AABB of the sheared button
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Width = content_width,
Text = Resources.Localisation.Web.CommonStrings.ButtonsSave,
DarkerColour = colours.Orange1,
LighterColour = colours.Orange0,
Expand Down
3 changes: 2 additions & 1 deletion osu.Game/Overlays/Mods/SelectAllModsButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public partial class SelectAllModsButton : ShearedButton
private readonly Bindable<string> searchTerm = new Bindable<string>();

public SelectAllModsButton(FreeModSelectOverlay modSelectOverlay)
: base(ModSelectOverlay.BUTTON_WIDTH)
{
Width = ModSelectOverlay.BUTTON_WIDTH;

Text = CommonStrings.SelectAll;
Action = modSelectOverlay.SelectAll;

Expand Down
3 changes: 1 addition & 2 deletions osu.Game/Overlays/WizardOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,9 @@ private void load(OverlayColourProvider colourProvider)

Padding = new MarginPadding { Right = OsuGame.SCREEN_EDGE_MARGIN };

InternalChild = NextButton = new ShearedButton(0)
InternalChild = NextButton = new ShearedButton
{
RelativeSizeAxes = Axes.X,
Width = 1,
Text = FirstRunSetupOverlayStrings.GetStarted,
DarkerColour = colourProvider.Colour3,
LighterColour = colourProvider.Colour2,
Expand Down
Loading