2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-07-03 09:18:04 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-07-03 09:18:04 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Menu
|
|
|
|
|
{
|
|
|
|
|
public partial class ButtonArea : Container, IStateful<Visibility>
|
|
|
|
|
{
|
|
|
|
|
public FlowContainerWithOrigin Flow;
|
|
|
|
|
|
|
|
|
|
protected override Container<Drawable> Content => Flow;
|
|
|
|
|
|
|
|
|
|
private readonly ButtonAreaBackground buttonAreaBackground;
|
|
|
|
|
private Visibility state;
|
|
|
|
|
|
|
|
|
|
public const float BUTTON_AREA_HEIGHT = 100;
|
|
|
|
|
|
|
|
|
|
public ButtonArea()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
InternalChild = new Container
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Size = new Vector2(1, BUTTON_AREA_HEIGHT),
|
|
|
|
|
Alpha = 0,
|
2019-04-17 08:02:47 +00:00
|
|
|
|
AlwaysPresent = true, // Always needs to be present for correct tracking on initial -> toplevel state change
|
2018-07-03 09:18:04 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
buttonAreaBackground = new ButtonAreaBackground(),
|
|
|
|
|
Flow = new FlowContainerWithOrigin
|
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(-ButtonSystem.WEDGE_WIDTH, 0),
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ButtonSystemState ButtonSystemState
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
switch (value)
|
|
|
|
|
{
|
|
|
|
|
case ButtonSystemState.Exit:
|
|
|
|
|
case ButtonSystemState.Initial:
|
|
|
|
|
case ButtonSystemState.EnteringMode:
|
2019-06-11 05:28:52 +00:00
|
|
|
|
Hide();
|
2018-07-03 09:18:04 +00:00
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.TopLevel:
|
|
|
|
|
case ButtonSystemState.Play:
|
2019-06-11 05:28:52 +00:00
|
|
|
|
Show();
|
2018-07-03 09:18:04 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buttonAreaBackground.ButtonSystemState = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Visibility State
|
|
|
|
|
{
|
|
|
|
|
get => state;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == state) return;
|
|
|
|
|
|
|
|
|
|
state = value;
|
|
|
|
|
InternalChild.FadeTo(state == Visibility.Hidden ? 0 : 1, 300);
|
|
|
|
|
StateChanged?.Invoke(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 05:28:52 +00:00
|
|
|
|
public override void Hide() => State = Visibility.Hidden;
|
|
|
|
|
|
|
|
|
|
public override void Show() => State = Visibility.Visible;
|
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
public event Action<Visibility> StateChanged;
|
|
|
|
|
|
|
|
|
|
private partial class ButtonAreaBackground : Box, IStateful<ButtonAreaBackgroundState>
|
|
|
|
|
{
|
|
|
|
|
private ButtonAreaBackgroundState state;
|
|
|
|
|
|
|
|
|
|
public ButtonAreaBackground()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
Size = new Vector2(2, 1);
|
|
|
|
|
Colour = OsuColour.Gray(50);
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ButtonAreaBackgroundState State
|
|
|
|
|
{
|
|
|
|
|
get => state;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == state) return;
|
|
|
|
|
|
|
|
|
|
state = value;
|
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case ButtonAreaBackgroundState.Flat:
|
|
|
|
|
this.ScaleTo(new Vector2(2, 0), 300, Easing.InSine);
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonAreaBackgroundState.Normal:
|
|
|
|
|
this.ScaleTo(Vector2.One, 400, Easing.OutQuint);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StateChanged?.Invoke(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ButtonSystemState ButtonSystemState
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
switch (value)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
State = ButtonAreaBackgroundState.Normal;
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.Initial:
|
|
|
|
|
case ButtonSystemState.Exit:
|
|
|
|
|
case ButtonSystemState.EnteringMode:
|
|
|
|
|
State = ButtonAreaBackgroundState.Flat;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event Action<ButtonAreaBackgroundState> StateChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ButtonAreaBackgroundState
|
|
|
|
|
{
|
|
|
|
|
Normal,
|
|
|
|
|
Flat
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|