mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 23:52:57 +08:00
Add basic button design and footer button addition flow
This commit is contained in:
parent
18b4317e99
commit
774eb178a1
@ -19,6 +19,8 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
};
|
||||
|
||||
footer.AddButton(new FooterButtonV2());
|
||||
});
|
||||
|
||||
[Test]
|
||||
|
65
osu.Game/Screens/Select/FooterV2/FooterButtonV2.cs
Normal file
65
osu.Game/Screens/Select/FooterV2/FooterButtonV2.cs
Normal file
@ -0,0 +1,65 @@
|
||||
// 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 System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Overlays;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Select.FooterV2
|
||||
{
|
||||
public partial class FooterButtonV2 : OsuClickableContainer, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
private const int button_height = 120;
|
||||
private const int button_width = 140;
|
||||
private const int corner_radius = 10;
|
||||
|
||||
public const float SHEAR_WIDTH = 16;
|
||||
|
||||
[Cached]
|
||||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
|
||||
|
||||
protected static readonly Vector2 SHEAR = new Vector2(SHEAR_WIDTH / button_height, 0);
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Shear = SHEAR;
|
||||
Size = new Vector2(button_width, button_height);
|
||||
Masking = true;
|
||||
CornerRadius = corner_radius;
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = colourProvider.Background3,
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
|
||||
//For elements that should not be sheared.
|
||||
new Container
|
||||
{
|
||||
Shear = -SHEAR
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Action Hovered = null!;
|
||||
public Action HoverLost = null!;
|
||||
public GlobalAction? Hotkey;
|
||||
|
||||
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) { }
|
||||
}
|
||||
}
|
@ -1,12 +1,15 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Select.FooterV2
|
||||
{
|
||||
@ -14,6 +17,33 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
{
|
||||
//Should be 60, setting to 50 for now for the sake of matching the current BackButton height.
|
||||
private const int height = 50;
|
||||
private const int padding = 80;
|
||||
|
||||
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>();
|
||||
|
||||
public void AddButton(FooterButtonV2 button, OverlayContainer? overlay = null)
|
||||
{
|
||||
if (overlay != null)
|
||||
{
|
||||
overlays.Add(overlay);
|
||||
button.Action = () => showOverlay(overlay);
|
||||
}
|
||||
|
||||
buttons.Add(button);
|
||||
}
|
||||
|
||||
private void showOverlay(OverlayContainer overlay)
|
||||
{
|
||||
foreach (var o in overlays)
|
||||
{
|
||||
if (o == overlay)
|
||||
o.ToggleVisibility();
|
||||
else
|
||||
o.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private FillFlowContainer<FooterButtonV2> buttons = null!;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colour)
|
||||
@ -26,6 +56,27 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colour.B5
|
||||
},
|
||||
new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Position = new Vector2(TwoLayerButton.SIZE_EXTENDED.X + padding, 40),
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
AutoSizeAxes = Axes.X,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(padding, 0),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
buttons = new FillFlowContainer<FooterButtonV2>
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(-FooterButtonV2.SHEAR_WIDTH, 5),
|
||||
AutoSizeAxes = Axes.Both
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user