2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-08-26 11:28:23 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2016-11-14 16:23:33 +08:00
|
|
|
|
using osu.Framework;
|
2016-12-05 20:09:41 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-02-25 20:12:39 +08:00
|
|
|
|
using osu.Framework.Graphics.Transforms;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Graphics;
|
2017-02-08 18:46:05 +08:00
|
|
|
|
using osu.Game.Overlays.Toolbar;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
|
2016-11-14 16:23:33 +08:00
|
|
|
|
namespace osu.Game.Screens.Menu
|
2016-08-26 11:28:23 +08:00
|
|
|
|
{
|
2016-10-08 11:53:46 +08:00
|
|
|
|
public partial class ButtonSystem : Container, IStateful<MenuState>
|
2016-08-26 11:28:23 +08:00
|
|
|
|
{
|
2016-09-29 19:13:58 +08:00
|
|
|
|
public Action OnEdit;
|
|
|
|
|
public Action OnExit;
|
|
|
|
|
public Action OnDirect;
|
|
|
|
|
public Action OnSolo;
|
|
|
|
|
public Action OnSettings;
|
|
|
|
|
public Action OnMulti;
|
|
|
|
|
public Action OnChart;
|
|
|
|
|
public Action OnTest;
|
|
|
|
|
|
2017-02-08 18:46:05 +08:00
|
|
|
|
private Toolbar toolbar;
|
|
|
|
|
|
2016-08-26 11:28:23 +08:00
|
|
|
|
private FlowContainerWithOrigin buttonFlow;
|
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
//todo: make these non-internal somehow.
|
2017-02-07 15:15:45 +08:00
|
|
|
|
internal const float BUTTON_AREA_HEIGHT = 100;
|
|
|
|
|
internal const float BUTTON_WIDTH = 140f;
|
|
|
|
|
internal const float WEDGE_WIDTH = 20;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
|
2016-09-30 12:31:05 +08:00
|
|
|
|
public const int EXIT_DELAY = 3000;
|
|
|
|
|
|
2016-08-26 11:28:23 +08:00
|
|
|
|
private OsuLogo osuLogo;
|
|
|
|
|
private Drawable iconFacade;
|
|
|
|
|
private Container buttonArea;
|
2016-10-01 16:01:29 +08:00
|
|
|
|
private Box buttonAreaBackground;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
|
|
|
|
|
private Button backButton;
|
|
|
|
|
private Button settingsButton;
|
|
|
|
|
|
|
|
|
|
List<Button> buttonsTopLevel = new List<Button>();
|
|
|
|
|
List<Button> buttonsPlay = new List<Button>();
|
|
|
|
|
|
2016-10-01 17:40:14 +08:00
|
|
|
|
public ButtonSystem()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2016-09-19 03:41:53 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-08-26 11:28:23 +08:00
|
|
|
|
{
|
2016-09-19 03:41:53 +08:00
|
|
|
|
buttonArea = new Container
|
2016-09-18 04:33:46 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2016-10-01 17:40:14 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-02-07 15:15:45 +08:00
|
|
|
|
Size = new Vector2(1, BUTTON_AREA_HEIGHT),
|
2016-09-18 04:33:46 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2016-10-01 16:01:29 +08:00
|
|
|
|
buttonAreaBackground = new Box
|
2016-09-18 04:33:46 +08:00
|
|
|
|
{
|
2016-10-01 17:40:14 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-10-01 16:01:29 +08:00
|
|
|
|
Size = new Vector2(2, 1),
|
2017-01-13 05:38:27 +08:00
|
|
|
|
Colour = OsuColour.Gray(50),
|
2016-10-01 16:01:29 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2016-09-18 04:33:46 +08:00
|
|
|
|
},
|
2016-09-19 03:41:53 +08:00
|
|
|
|
buttonFlow = new FlowContainerWithOrigin
|
2016-09-18 04:33:46 +08:00
|
|
|
|
{
|
2017-03-02 03:15:38 +08:00
|
|
|
|
Direction = FillDirection.Right,
|
2017-03-02 02:33:01 +08:00
|
|
|
|
Spacing = new Vector2(-WEDGE_WIDTH, 0),
|
2016-09-18 04:33:46 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
2016-10-22 17:05:46 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Children = new[]
|
2016-09-18 04:33:46 +08:00
|
|
|
|
{
|
2017-02-07 15:15:45 +08:00
|
|
|
|
settingsButton = new Button(@"settings", @"options", FontAwesome.fa_gear, new Color4(85, 85, 85, 255), () => OnSettings?.Invoke(), -WEDGE_WIDTH, Key.O),
|
2017-02-07 20:53:40 +08:00
|
|
|
|
backButton = new Button(@"back", @"back", FontAwesome.fa_osu_left_o, new Color4(51, 58, 94, 255), onBack, -WEDGE_WIDTH),
|
2016-09-19 03:41:53 +08:00
|
|
|
|
iconFacade = new Container //need a container to make the osu! icon flow properly.
|
2017-02-27 04:32:43 +08:00
|
|
|
|
{
|
2017-02-07 15:15:45 +08:00
|
|
|
|
Size = new Vector2(0, BUTTON_AREA_HEIGHT)
|
2016-09-24 14:35:27 +08:00
|
|
|
|
}
|
2016-09-18 04:33:46 +08:00
|
|
|
|
},
|
|
|
|
|
CentreTarget = iconFacade
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-19 08:35:50 +08:00
|
|
|
|
},
|
2016-10-07 16:07:23 +08:00
|
|
|
|
osuLogo = new OsuLogo
|
2016-09-24 14:35:27 +08:00
|
|
|
|
{
|
2016-10-07 16:07:23 +08:00
|
|
|
|
Action = onOsuLogo,
|
2016-09-24 14:35:27 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
2017-01-27 10:31:28 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
2016-09-24 14:35:27 +08:00
|
|
|
|
}
|
2016-09-19 03:41:53 +08:00
|
|
|
|
};
|
2016-08-26 11:28:23 +08:00
|
|
|
|
|
2017-02-07 15:15:45 +08:00
|
|
|
|
buttonsPlay.Add(new Button(@"solo", @"freeplay", FontAwesome.fa_user, new Color4(102, 68, 204, 255), () => OnSolo?.Invoke(), WEDGE_WIDTH, Key.P));
|
2016-11-13 01:34:36 +08:00
|
|
|
|
buttonsPlay.Add(new Button(@"multi", @"multiplayer", FontAwesome.fa_users, new Color4(94, 63, 186, 255), () => OnMulti?.Invoke(), 0, Key.M));
|
|
|
|
|
buttonsPlay.Add(new Button(@"chart", @"charts", FontAwesome.fa_osu_charts, new Color4(80, 53, 160, 255), () => OnChart?.Invoke()));
|
2016-10-09 17:55:52 +08:00
|
|
|
|
|
2017-02-07 15:15:45 +08:00
|
|
|
|
buttonsTopLevel.Add(new Button(@"play", @"play", FontAwesome.fa_osu_logo, new Color4(102, 68, 204, 255), onPlay, WEDGE_WIDTH, Key.P));
|
2016-11-13 01:34:36 +08:00
|
|
|
|
buttonsTopLevel.Add(new Button(@"osu!editor", @"edit", FontAwesome.fa_osu_edit_o, new Color4(238, 170, 0, 255), () => OnEdit?.Invoke(), 0, Key.E));
|
|
|
|
|
buttonsTopLevel.Add(new Button(@"osu!direct", @"direct", FontAwesome.fa_osu_chevron_down_o, new Color4(165, 204, 0, 255), () => OnDirect?.Invoke(), 0, Key.D));
|
2016-10-09 17:55:52 +08:00
|
|
|
|
buttonsTopLevel.Add(new Button(@"exit", @"exit", FontAwesome.fa_osu_cross_o, new Color4(238, 51, 153, 255), onExit, 0, Key.Q));
|
|
|
|
|
|
|
|
|
|
buttonFlow.Add(buttonsPlay);
|
|
|
|
|
buttonFlow.Add(buttonsTopLevel);
|
2016-08-26 11:28:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-09 16:47:11 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2017-02-27 22:32:32 +08:00
|
|
|
|
private void load(OsuGame game = null)
|
2016-12-05 20:09:41 +08:00
|
|
|
|
{
|
2017-02-09 16:47:11 +08:00
|
|
|
|
toolbar = game?.Toolbar;
|
2016-12-05 20:09:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 02:18:16 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
// osuLogo.SizeForFlow relies on loading to be complete.
|
2017-02-07 15:15:45 +08:00
|
|
|
|
buttonFlow.Position = new Vector2(WEDGE_WIDTH * 2 - (BUTTON_WIDTH + osuLogo.SizeForFlow / 4), 0);
|
2016-11-15 02:18:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 11:28:23 +08:00
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
|
{
|
2017-02-07 20:46:13 +08:00
|
|
|
|
if (args.Repeat) return false;
|
|
|
|
|
|
2016-10-07 23:41:44 +08:00
|
|
|
|
switch (args.Key)
|
2016-10-07 17:34:37 +08:00
|
|
|
|
{
|
2016-10-07 23:41:44 +08:00
|
|
|
|
case Key.Space:
|
|
|
|
|
osuLogo.TriggerClick(state);
|
|
|
|
|
return true;
|
|
|
|
|
case Key.Escape:
|
2017-02-07 20:53:40 +08:00
|
|
|
|
switch (State)
|
|
|
|
|
{
|
|
|
|
|
case MenuState.TopLevel:
|
|
|
|
|
State = MenuState.Initial;
|
|
|
|
|
return true;
|
|
|
|
|
case MenuState.Play:
|
2017-02-07 21:19:36 +08:00
|
|
|
|
backButton.TriggerClick();
|
2017-02-07 20:53:40 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-10-07 17:34:37 +08:00
|
|
|
|
|
2017-02-08 18:46:05 +08:00
|
|
|
|
|
2017-02-07 20:53:40 +08:00
|
|
|
|
return false;
|
2016-10-07 17:34:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 17:45:48 +08:00
|
|
|
|
return false;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onPlay()
|
|
|
|
|
{
|
|
|
|
|
State = MenuState.Play;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onExit()
|
|
|
|
|
{
|
2016-09-29 19:13:58 +08:00
|
|
|
|
OnExit?.Invoke();
|
2016-08-26 11:28:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onBack()
|
|
|
|
|
{
|
|
|
|
|
State = MenuState.TopLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onOsuLogo()
|
|
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case MenuState.Initial:
|
|
|
|
|
State = MenuState.TopLevel;
|
|
|
|
|
return;
|
|
|
|
|
case MenuState.TopLevel:
|
2017-02-07 19:29:26 +08:00
|
|
|
|
buttonsTopLevel.First().TriggerClick();
|
2016-08-26 11:28:23 +08:00
|
|
|
|
return;
|
|
|
|
|
case MenuState.Play:
|
2017-02-07 19:29:26 +08:00
|
|
|
|
buttonsPlay.First().TriggerClick();
|
2016-08-26 11:28:23 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MenuState state;
|
|
|
|
|
|
2016-09-20 13:41:55 +08:00
|
|
|
|
public override bool HandleInput => state != MenuState.Exit;
|
|
|
|
|
|
2016-08-26 11:28:23 +08:00
|
|
|
|
public MenuState State
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (state == value) return;
|
|
|
|
|
|
|
|
|
|
MenuState lastState = state;
|
|
|
|
|
state = value;
|
|
|
|
|
|
2016-10-01 16:01:29 +08:00
|
|
|
|
//todo: figure a more elegant way of doing this.
|
|
|
|
|
buttonsTopLevel.ForEach(b => b.ContractStyle = 0);
|
|
|
|
|
buttonsPlay.ForEach(b => b.ContractStyle = 0);
|
|
|
|
|
backButton.ContractStyle = 0;
|
|
|
|
|
settingsButton.ContractStyle = 0;
|
|
|
|
|
|
2016-08-26 11:28:23 +08:00
|
|
|
|
switch (state)
|
|
|
|
|
{
|
2017-02-17 14:33:08 +08:00
|
|
|
|
case MenuState.Exit:
|
2016-08-26 11:28:23 +08:00
|
|
|
|
case MenuState.Initial:
|
2017-02-08 18:46:05 +08:00
|
|
|
|
toolbar?.Hide();
|
|
|
|
|
|
2016-10-01 16:01:29 +08:00
|
|
|
|
buttonAreaBackground.ScaleTo(Vector2.One, 500, EasingTypes.Out);
|
2017-02-07 21:19:36 +08:00
|
|
|
|
buttonArea.FadeOut(300);
|
2016-08-26 11:28:23 +08:00
|
|
|
|
|
|
|
|
|
osuLogo.Delay(150);
|
|
|
|
|
osuLogo.MoveTo(Vector2.Zero, 800, EasingTypes.OutExpo);
|
|
|
|
|
osuLogo.ScaleTo(1, 800, EasingTypes.OutExpo);
|
|
|
|
|
|
|
|
|
|
foreach (Button b in buttonsTopLevel)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
b.State = ButtonState.Contracted;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
|
|
|
|
|
foreach (Button b in buttonsPlay)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
b.State = ButtonState.Contracted;
|
2017-02-17 14:33:08 +08:00
|
|
|
|
|
|
|
|
|
if (state == MenuState.Exit)
|
|
|
|
|
{
|
|
|
|
|
osuLogo.RotateTo(20, EXIT_DELAY * 1.5f);
|
|
|
|
|
osuLogo.FadeOut(EXIT_DELAY);
|
|
|
|
|
}
|
2016-08-26 11:28:23 +08:00
|
|
|
|
break;
|
|
|
|
|
case MenuState.TopLevel:
|
2017-02-07 21:19:36 +08:00
|
|
|
|
buttonArea.Flush(true);
|
|
|
|
|
|
2016-10-01 16:01:29 +08:00
|
|
|
|
buttonAreaBackground.ScaleTo(Vector2.One, 200, EasingTypes.Out);
|
2016-08-26 11:28:23 +08:00
|
|
|
|
|
2016-10-19 00:53:31 +08:00
|
|
|
|
osuLogo.MoveTo(buttonFlow.DrawPosition, 200, EasingTypes.In);
|
2016-08-26 11:28:23 +08:00
|
|
|
|
osuLogo.ScaleTo(0.5f, 200, EasingTypes.In);
|
|
|
|
|
|
|
|
|
|
buttonArea.FadeIn(300);
|
|
|
|
|
|
|
|
|
|
if (lastState == MenuState.Initial)
|
|
|
|
|
buttonArea.Delay(150, true);
|
|
|
|
|
|
2017-02-08 18:46:05 +08:00
|
|
|
|
Scheduler.AddDelayed(() => toolbar?.Show(), 150);
|
|
|
|
|
|
2016-08-26 11:28:23 +08:00
|
|
|
|
foreach (Button b in buttonsTopLevel)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
b.State = ButtonState.Expanded;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
|
|
|
|
|
foreach (Button b in buttonsPlay)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
b.State = ButtonState.Contracted;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
break;
|
|
|
|
|
case MenuState.Play:
|
|
|
|
|
foreach (Button b in buttonsTopLevel)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
b.State = ButtonState.Exploded;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
|
|
|
|
|
foreach (Button b in buttonsPlay)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
b.State = ButtonState.Expanded;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
break;
|
2016-10-01 16:01:29 +08:00
|
|
|
|
case MenuState.EnteringMode:
|
|
|
|
|
buttonAreaBackground.ScaleTo(new Vector2(2, 0), 300, EasingTypes.InSine);
|
|
|
|
|
|
|
|
|
|
buttonsTopLevel.ForEach(b => b.ContractStyle = 1);
|
|
|
|
|
buttonsPlay.ForEach(b => b.ContractStyle = 1);
|
|
|
|
|
backButton.ContractStyle = 1;
|
|
|
|
|
settingsButton.ContractStyle = 1;
|
|
|
|
|
|
|
|
|
|
foreach (Button b in buttonsTopLevel)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
b.State = ButtonState.Contracted;
|
2016-10-01 16:01:29 +08:00
|
|
|
|
|
|
|
|
|
foreach (Button b in buttonsPlay)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
b.State = ButtonState.Contracted;
|
2016-10-01 16:01:29 +08:00
|
|
|
|
break;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
backButton.State = state == MenuState.Play ? ButtonState.Expanded : ButtonState.Contracted;
|
|
|
|
|
settingsButton.State = state == MenuState.TopLevel ? ButtonState.Expanded : ButtonState.Contracted;
|
2016-08-26 11:28:23 +08:00
|
|
|
|
|
|
|
|
|
if (lastState == MenuState.Initial)
|
|
|
|
|
buttonArea.DelayReset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
//if (OsuGame.IdleTime > 6000 && State != MenuState.Exit)
|
|
|
|
|
// State = MenuState.Initial;
|
|
|
|
|
|
2017-02-07 20:46:13 +08:00
|
|
|
|
osuLogo.Interactive = Alpha > 0.2f;
|
2017-02-07 20:37:34 +08:00
|
|
|
|
|
2016-08-26 11:28:23 +08:00
|
|
|
|
iconFacade.Width = osuLogo.SizeForFlow * 0.5f;
|
|
|
|
|
base.Update();
|
|
|
|
|
}
|
2016-10-08 11:53:46 +08:00
|
|
|
|
}
|
2016-08-26 11:28:23 +08:00
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
public enum MenuState
|
|
|
|
|
{
|
|
|
|
|
Initial,
|
|
|
|
|
TopLevel,
|
|
|
|
|
Play,
|
|
|
|
|
EnteringMode,
|
|
|
|
|
Exit,
|
2016-08-26 11:28:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|