2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework;
|
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-30 01:15:09 +08:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-05-15 01:27:05 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
using osu.Framework.Logging;
|
2018-04-30 01:15:09 +08:00
|
|
|
|
using osu.Framework.Threading;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2018-05-15 01:27:05 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2018-06-06 15:17:51 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Menu
|
|
|
|
|
{
|
2018-07-03 17:18:04 +08:00
|
|
|
|
public class ButtonSystem : Container, IStateful<ButtonSystemState>, IKeyBindingHandler<GlobalAction>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-07-03 17:18:04 +08:00
|
|
|
|
public event Action<ButtonSystemState> StateChanged;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public Action OnEdit;
|
|
|
|
|
public Action OnExit;
|
|
|
|
|
public Action OnDirect;
|
|
|
|
|
public Action OnSolo;
|
|
|
|
|
public Action OnSettings;
|
|
|
|
|
public Action OnMulti;
|
|
|
|
|
public Action OnChart;
|
|
|
|
|
|
|
|
|
|
public const float BUTTON_WIDTH = 140f;
|
|
|
|
|
public const float WEDGE_WIDTH = 20;
|
|
|
|
|
|
|
|
|
|
private OsuLogo logo;
|
|
|
|
|
|
|
|
|
|
public void SetOsuLogo(OsuLogo logo)
|
|
|
|
|
{
|
|
|
|
|
this.logo = logo;
|
|
|
|
|
|
|
|
|
|
if (this.logo != null)
|
|
|
|
|
{
|
|
|
|
|
this.logo.Action = onOsuLogo;
|
|
|
|
|
|
|
|
|
|
// osuLogo.SizeForFlow relies on loading to be complete.
|
2018-07-03 17:18:04 +08:00
|
|
|
|
buttonArea.Flow.Position = new Vector2(WEDGE_WIDTH * 2 - (BUTTON_WIDTH + this.logo.SizeForFlow / 4), 0);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
updateLogoState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly Drawable iconFacade;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
private readonly ButtonArea buttonArea;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private readonly Button backButton;
|
|
|
|
|
|
|
|
|
|
private readonly List<Button> buttonsTopLevel = new List<Button>();
|
|
|
|
|
private readonly List<Button> buttonsPlay = new List<Button>();
|
|
|
|
|
|
|
|
|
|
private SampleChannel sampleBack;
|
|
|
|
|
|
|
|
|
|
public ButtonSystem()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
Child = buttonArea = new ButtonArea();
|
|
|
|
|
|
|
|
|
|
buttonArea.AddRange(new[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-07-06 16:53:01 +08:00
|
|
|
|
new Button(@"settings", string.Empty, FontAwesome.fa_gear, new Color4(85, 85, 85, 255), () => OnSettings?.Invoke(), -WEDGE_WIDTH, Key.O),
|
2018-07-03 17:18:04 +08:00
|
|
|
|
backButton = new Button(@"back", @"button-back-select", FontAwesome.fa_osu_left_o, new Color4(51, 58, 94, 255), () => State = ButtonSystemState.TopLevel, -WEDGE_WIDTH)
|
|
|
|
|
{
|
|
|
|
|
VisibleState = ButtonSystemState.Play,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2018-07-03 17:18:04 +08:00
|
|
|
|
iconFacade = new Container //need a container to make the osu! icon flow properly.
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(0, ButtonArea.BUTTON_AREA_HEIGHT)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
buttonArea.Flow.CentreTarget = iconFacade;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
buttonsPlay.Add(new Button(@"solo", @"button-solo-select", FontAwesome.fa_user, new Color4(102, 68, 204, 255), () => OnSolo?.Invoke(), WEDGE_WIDTH, Key.P));
|
|
|
|
|
buttonsPlay.Add(new Button(@"multi", @"button-generic-select", FontAwesome.fa_users, new Color4(94, 63, 186, 255), () => OnMulti?.Invoke(), 0, Key.M));
|
|
|
|
|
buttonsPlay.Add(new Button(@"chart", @"button-generic-select", FontAwesome.fa_osu_charts, new Color4(80, 53, 160, 255), () => OnChart?.Invoke()));
|
2018-07-03 17:18:04 +08:00
|
|
|
|
buttonsPlay.ForEach(b => b.VisibleState = ButtonSystemState.Play);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
buttonsTopLevel.Add(new Button(@"play", @"button-play-select", FontAwesome.fa_osu_logo, new Color4(102, 68, 204, 255), () => State = ButtonSystemState.Play, WEDGE_WIDTH, Key.P));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
buttonsTopLevel.Add(new Button(@"osu!editor", @"button-generic-select", FontAwesome.fa_osu_edit_o, new Color4(238, 170, 0, 255), () => OnEdit?.Invoke(), 0, Key.E));
|
|
|
|
|
buttonsTopLevel.Add(new Button(@"osu!direct", @"button-direct-select", FontAwesome.fa_osu_chevron_down_o, new Color4(165, 204, 0, 255), () => OnDirect?.Invoke(), 0, Key.D));
|
2018-07-03 17:18:04 +08:00
|
|
|
|
buttonsTopLevel.Add(new Button(@"exit", string.Empty, FontAwesome.fa_osu_cross_o, new Color4(238, 51, 153, 255), () => OnExit?.Invoke(), 0, Key.Q));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
buttonArea.AddRange(buttonsPlay);
|
|
|
|
|
buttonArea.AddRange(buttonsTopLevel);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 15:17:51 +08:00
|
|
|
|
private OsuGame game;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2018-08-31 06:04:40 +08:00
|
|
|
|
private void load(AudioManager audio, OsuGame game)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-06 15:17:51 +08:00
|
|
|
|
this.game = game;
|
2018-08-31 06:04:40 +08:00
|
|
|
|
sampleBack = audio.Sample.Get(@"Menu/button-back-select");
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 01:27:05 +08:00
|
|
|
|
public bool OnPressed(GlobalAction action)
|
2018-04-30 01:15:09 +08:00
|
|
|
|
{
|
2018-05-15 01:27:05 +08:00
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case GlobalAction.Back:
|
2018-05-21 22:09:00 +08:00
|
|
|
|
return goBack();
|
2018-07-03 17:37:21 +08:00
|
|
|
|
case GlobalAction.Select:
|
|
|
|
|
logo?.TriggerOnClick();
|
|
|
|
|
return true;
|
2018-05-21 22:09:00 +08:00
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
public bool OnReleased(GlobalAction action) => false;
|
|
|
|
|
|
2018-05-21 22:09:00 +08:00
|
|
|
|
private bool goBack()
|
|
|
|
|
{
|
|
|
|
|
switch (State)
|
|
|
|
|
{
|
2018-07-03 17:18:04 +08:00
|
|
|
|
case ButtonSystemState.TopLevel:
|
|
|
|
|
State = ButtonSystemState.Initial;
|
|
|
|
|
sampleBack?.Play();
|
2018-05-21 22:09:00 +08:00
|
|
|
|
return true;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
case ButtonSystemState.Play:
|
2018-05-21 22:09:00 +08:00
|
|
|
|
backButton.TriggerOnClick();
|
|
|
|
|
return true;
|
2018-05-15 01:27:05 +08:00
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-30 01:15:09 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private bool onOsuLogo()
|
|
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
return true;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
case ButtonSystemState.Initial:
|
|
|
|
|
State = ButtonSystemState.TopLevel;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return true;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
case ButtonSystemState.TopLevel:
|
2018-04-13 17:19:50 +08:00
|
|
|
|
buttonsTopLevel.First().TriggerOnClick();
|
|
|
|
|
return false;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
case ButtonSystemState.Play:
|
2018-04-13 17:19:50 +08:00
|
|
|
|
buttonsPlay.First().TriggerOnClick();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
private ButtonSystemState state = ButtonSystemState.Initial;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
public override bool HandleKeyboardInput => state != ButtonSystemState.Exit;
|
|
|
|
|
public override bool HandleMouseInput => state != ButtonSystemState.Exit;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
public ButtonSystemState State
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
get { return state; }
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (state == value) return;
|
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
ButtonSystemState lastState = state;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
state = value;
|
|
|
|
|
|
2018-08-23 10:20:20 +08:00
|
|
|
|
if (game != null)
|
|
|
|
|
game.OverlayActivationMode.Value = state == ButtonSystemState.Exit ? OverlayActivation.Disabled : OverlayActivation.All;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
updateLogoState(lastState);
|
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
Logger.Log($"{nameof(ButtonSystem)}'s state changed from {lastState} to {state}");
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
using (buttonArea.BeginDelayedSequence(lastState == ButtonSystemState.Initial ? 150 : 0, true))
|
|
|
|
|
{
|
|
|
|
|
buttonArea.ButtonSystemState = state;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
foreach (var b in buttonArea.Children.OfType<Button>())
|
|
|
|
|
b.ButtonSystemState = state;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StateChanged?.Invoke(State);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ScheduledDelegate logoDelayedAction;
|
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
private void updateLogoState(ButtonSystemState lastState = ButtonSystemState.Initial)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
if (logo == null) return;
|
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
2018-07-03 17:18:04 +08:00
|
|
|
|
case ButtonSystemState.Exit:
|
|
|
|
|
case ButtonSystemState.Initial:
|
2018-05-30 18:50:00 +08:00
|
|
|
|
logoDelayedAction?.Cancel();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
logoDelayedAction = Scheduler.AddDelayed(() =>
|
2018-06-06 17:21:03 +08:00
|
|
|
|
{
|
|
|
|
|
logoTracking = false;
|
2018-05-21 23:24:57 +08:00
|
|
|
|
|
2018-08-23 10:20:20 +08:00
|
|
|
|
game?.Toolbar.Hide();
|
2018-06-06 15:17:51 +08:00
|
|
|
|
|
2018-06-06 17:21:03 +08:00
|
|
|
|
logo.ClearTransforms(targetMember: nameof(Position));
|
|
|
|
|
logo.RelativePositionAxes = Axes.Both;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-06 17:21:03 +08:00
|
|
|
|
logo.MoveTo(new Vector2(0.5f), 800, Easing.OutExpo);
|
|
|
|
|
logo.ScaleTo(1, 800, Easing.OutExpo);
|
|
|
|
|
}, buttonArea.Alpha * 150);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
case ButtonSystemState.TopLevel:
|
|
|
|
|
case ButtonSystemState.Play:
|
2018-04-13 17:19:50 +08:00
|
|
|
|
switch (lastState)
|
|
|
|
|
{
|
2018-07-03 17:18:04 +08:00
|
|
|
|
case ButtonSystemState.TopLevel: // coming from toplevel to play
|
2018-05-30 18:50:00 +08:00
|
|
|
|
break;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
case ButtonSystemState.Initial:
|
2018-05-30 18:50:00 +08:00
|
|
|
|
logo.ClearTransforms(targetMember: nameof(Position));
|
|
|
|
|
logo.RelativePositionAxes = Axes.None;
|
|
|
|
|
|
|
|
|
|
bool impact = logo.Scale.X > 0.6f;
|
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
if (lastState == ButtonSystemState.Initial)
|
2018-05-30 18:50:00 +08:00
|
|
|
|
logo.ScaleTo(0.5f, 200, Easing.In);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
logo.MoveTo(logoTrackingPosition, lastState == ButtonSystemState.EnteringMode ? 0 : 200, Easing.In);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-05-30 18:50:00 +08:00
|
|
|
|
logoDelayedAction?.Cancel();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
logoDelayedAction = Scheduler.AddDelayed(() =>
|
|
|
|
|
{
|
|
|
|
|
logoTracking = true;
|
|
|
|
|
|
2018-05-31 14:17:59 +08:00
|
|
|
|
if (impact)
|
|
|
|
|
logo.Impact();
|
2018-06-06 15:17:51 +08:00
|
|
|
|
|
2018-08-23 10:20:20 +08:00
|
|
|
|
game?.Toolbar.Show();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}, 200);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2018-05-30 18:50:00 +08:00
|
|
|
|
logo.ClearTransforms(targetMember: nameof(Position));
|
|
|
|
|
logo.RelativePositionAxes = Axes.None;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
logoTracking = true;
|
|
|
|
|
logo.ScaleTo(0.5f, 200, Easing.OutQuint);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-30 01:15:09 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
case ButtonSystemState.EnteringMode:
|
2018-04-13 17:19:50 +08:00
|
|
|
|
logoTracking = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Vector2 logoTrackingPosition => logo.Parent.ToLocalSpace(iconFacade.ScreenSpaceDrawQuad.Centre);
|
|
|
|
|
|
|
|
|
|
private bool logoTracking;
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
2018-09-12 23:09:19 +08:00
|
|
|
|
if (game.IdleTime > 6000 && State != ButtonSystemState.Exit)
|
|
|
|
|
State = ButtonSystemState.Initial;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (logo != null)
|
|
|
|
|
{
|
2018-08-20 13:58:02 +08:00
|
|
|
|
if (logoTracking && logo.RelativePositionAxes == Axes.None && iconFacade.IsLoaded)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
logo.Position = logoTrackingPosition;
|
|
|
|
|
|
|
|
|
|
iconFacade.Width = logo.SizeForFlow * 0.5f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
public enum ButtonSystemState
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-07-03 17:18:04 +08:00
|
|
|
|
Exit,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Initial,
|
|
|
|
|
TopLevel,
|
|
|
|
|
Play,
|
|
|
|
|
EnteringMode,
|
|
|
|
|
}
|
|
|
|
|
}
|