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-04-13 09:19:50 +00:00
|
|
|
|
|
2016-08-26 03:28:23 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2016-11-14 08:23:33 +00:00
|
|
|
|
using osu.Framework;
|
2016-12-05 12:09:41 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-29 17:15:09 +00:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-03-26 08:18:35 +00:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2023-11-24 01:56:59 +00:00
|
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2016-08-26 03:28:23 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-05-14 17:27:05 +00:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2019-09-22 11:30:58 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-07-03 09:18:04 +00:00
|
|
|
|
using osu.Framework.Logging;
|
2019-02-25 00:56:00 +00:00
|
|
|
|
using osu.Framework.Platform;
|
2018-04-29 17:15:09 +00:00
|
|
|
|
using osu.Framework.Threading;
|
2016-08-26 03:28:23 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2019-03-26 08:18:35 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-11-19 17:48:59 +00:00
|
|
|
|
using osu.Game.Input;
|
2018-05-14 17:27:05 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2021-04-20 08:06:26 +00:00
|
|
|
|
using osu.Game.Localisation;
|
2018-12-04 08:43:27 +00:00
|
|
|
|
using osu.Game.Online.API;
|
2018-06-06 07:17:51 +00:00
|
|
|
|
using osu.Game.Overlays;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osuTK.Input;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2016-11-14 08:23:33 +00:00
|
|
|
|
namespace osu.Game.Screens.Menu
|
2016-08-26 03:28:23 +00:00
|
|
|
|
{
|
2018-07-03 09:18:04 +00:00
|
|
|
|
public partial class ButtonSystem : Container, IStateful<ButtonSystemState>, IKeyBindingHandler<GlobalAction>
|
2016-08-26 03:28:23 +00:00
|
|
|
|
{
|
2023-11-24 02:00:22 +00:00
|
|
|
|
public const float BUTTON_WIDTH = 140f;
|
|
|
|
|
public const float WEDGE_WIDTH = 20;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-11-24 02:00:22 +00:00
|
|
|
|
public event Action<ButtonSystemState>? StateChanged;
|
2018-11-26 07:32:59 +00:00
|
|
|
|
|
2023-11-24 02:00:22 +00:00
|
|
|
|
public Action? OnEditBeatmap;
|
|
|
|
|
public Action? OnEditSkin;
|
|
|
|
|
public Action? OnExit;
|
|
|
|
|
public Action? OnBeatmapListing;
|
|
|
|
|
public Action? OnSolo;
|
|
|
|
|
public Action? OnSettings;
|
|
|
|
|
public Action? OnMultiplayer;
|
|
|
|
|
public Action? OnPlaylists;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-11-24 02:00:22 +00:00
|
|
|
|
private readonly IBindable<bool> isIdle = new BindableBool();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-11-24 02:00:22 +00:00
|
|
|
|
private OsuLogo? logo;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-27 08:28:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Assign the <see cref="OsuLogo"/> that this ButtonSystem should manage the position of.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logo">The instance of the logo to be assigned. If null, we are suspending from the screen that uses this ButtonSystem.</param>
|
2023-11-24 06:06:51 +00:00
|
|
|
|
public void SetOsuLogo(OsuLogo? logo)
|
2017-11-01 11:54:58 +00:00
|
|
|
|
{
|
|
|
|
|
this.logo = logo;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-01 11:54:58 +00:00
|
|
|
|
if (this.logo != null)
|
|
|
|
|
{
|
|
|
|
|
this.logo.Action = onOsuLogo;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-01 11:54:58 +00:00
|
|
|
|
// osuLogo.SizeForFlow relies on loading to be complete.
|
2018-07-03 09:18:04 +00:00
|
|
|
|
buttonArea.Flow.Position = new Vector2(WEDGE_WIDTH * 2 - (BUTTON_WIDTH + this.logo.SizeForFlow / 4), 0);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-17 08:40:10 +00:00
|
|
|
|
updateLogoState();
|
2017-11-01 11:54:58 +00:00
|
|
|
|
}
|
2019-03-26 08:18:35 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-27 02:37:16 +00:00
|
|
|
|
// We should stop tracking as the facade is now out of scope.
|
2019-04-08 06:24:09 +00:00
|
|
|
|
logoTrackingContainer.StopTracking();
|
2019-03-26 08:18:35 +00:00
|
|
|
|
}
|
2017-11-01 11:54:58 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
private readonly ButtonArea buttonArea;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-03-25 06:12:39 +00:00
|
|
|
|
private readonly MainMenuButton backButton;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-03-25 06:12:39 +00:00
|
|
|
|
private readonly List<MainMenuButton> buttonsTopLevel = new List<MainMenuButton>();
|
|
|
|
|
private readonly List<MainMenuButton> buttonsPlay = new List<MainMenuButton>();
|
2023-11-24 01:56:59 +00:00
|
|
|
|
private readonly List<MainMenuButton> buttonsEdit = new List<MainMenuButton>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-11-24 02:00:22 +00:00
|
|
|
|
private Sample? sampleBackToLogo;
|
|
|
|
|
private Sample? sampleLogoSwoosh;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-04-05 03:02:47 +00:00
|
|
|
|
private readonly LogoTrackingContainer logoTrackingContainer;
|
2019-03-26 08:18:35 +00:00
|
|
|
|
|
2022-04-19 06:46:03 +00:00
|
|
|
|
public bool ReturnToTopOnIdle { get; set; } = true;
|
|
|
|
|
|
2016-10-01 09:40:14 +00:00
|
|
|
|
public ButtonSystem()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-04-05 03:02:47 +00:00
|
|
|
|
Child = logoTrackingContainer = new LogoTrackingContainer
|
2019-03-26 08:18:35 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Child = buttonArea = new ButtonArea()
|
|
|
|
|
};
|
2018-07-03 09:18:04 +00:00
|
|
|
|
|
2019-04-05 03:02:47 +00:00
|
|
|
|
buttonArea.AddRange(new Drawable[]
|
2016-08-26 03:28:23 +00:00
|
|
|
|
{
|
2023-12-27 14:40:48 +00:00
|
|
|
|
new MainMenuButton(ButtonSystemStrings.Settings, string.Empty, OsuIcon.Settings, new Color4(85, 85, 85, 255), () => OnSettings?.Invoke(), -WEDGE_WIDTH, Key.O),
|
|
|
|
|
backButton = new MainMenuButton(ButtonSystemStrings.Back, @"back-to-top", OsuIcon.PrevCircle, new Color4(51, 58, 94, 255), () => State = ButtonSystemState.TopLevel,
|
2023-11-24 01:56:59 +00:00
|
|
|
|
-WEDGE_WIDTH)
|
|
|
|
|
{
|
2023-11-24 02:15:18 +00:00
|
|
|
|
VisibleStateMin = ButtonSystemState.Play,
|
|
|
|
|
VisibleStateMax = ButtonSystemState.Edit,
|
2016-09-19 00:35:50 +00:00
|
|
|
|
},
|
2019-04-17 08:24:09 +00:00
|
|
|
|
logoTrackingContainer.LogoFacade.With(d => d.Scale = new Vector2(0.74f))
|
2018-07-03 09:18:04 +00:00
|
|
|
|
});
|
|
|
|
|
|
2019-04-05 03:02:47 +00:00
|
|
|
|
buttonArea.Flow.CentreTarget = logoTrackingContainer.LogoFacade;
|
2016-08-26 03:28:23 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-11-24 02:00:22 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2018-12-04 08:43:27 +00:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
2023-11-24 02:00:22 +00:00
|
|
|
|
private OsuGame? game { get; set; }
|
2018-12-04 08:43:27 +00:00
|
|
|
|
|
2023-11-24 02:00:22 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private LoginOverlay? loginOverlay { get; set; }
|
2019-04-06 16:05:13 +00:00
|
|
|
|
|
2023-11-24 02:00:22 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio, IdleTracker? idleTracker, GameHost host)
|
2016-12-05 12:09:41 +00:00
|
|
|
|
{
|
2023-12-27 14:40:48 +00:00
|
|
|
|
buttonsPlay.Add(new MainMenuButton(ButtonSystemStrings.Solo, @"button-default-select", OsuIcon.Player, new Color4(102, 68, 204, 255), () => OnSolo?.Invoke(), WEDGE_WIDTH, Key.P));
|
|
|
|
|
buttonsPlay.Add(new MainMenuButton(ButtonSystemStrings.Multi, @"button-default-select", OsuIcon.Online, new Color4(94, 63, 186, 255), onMultiplayer, 0, Key.M));
|
|
|
|
|
buttonsPlay.Add(new MainMenuButton(ButtonSystemStrings.Playlists, @"button-default-select", OsuIcon.Tournament, new Color4(94, 63, 186, 255), onPlaylists, 0, Key.L));
|
2019-02-25 12:41:41 +00:00
|
|
|
|
buttonsPlay.ForEach(b => b.VisibleState = ButtonSystemState.Play);
|
|
|
|
|
|
2023-12-27 14:40:48 +00:00
|
|
|
|
buttonsEdit.Add(new MainMenuButton(EditorStrings.BeatmapEditor.ToLower(), @"button-default-select", OsuIcon.Beatmap, new Color4(238, 170, 0, 255), () => OnEditBeatmap?.Invoke(), WEDGE_WIDTH, Key.B));
|
|
|
|
|
buttonsEdit.Add(new MainMenuButton(SkinEditorStrings.SkinEditor.ToLower(), @"button-default-select", OsuIcon.SkinB, new Color4(220, 160, 0, 255), () => OnEditSkin?.Invoke(), 0, Key.S));
|
2023-11-24 01:56:59 +00:00
|
|
|
|
buttonsEdit.ForEach(b => b.VisibleState = ButtonSystemState.Edit);
|
|
|
|
|
|
2023-10-20 09:47:00 +00:00
|
|
|
|
buttonsTopLevel.Add(new MainMenuButton(ButtonSystemStrings.Play, @"button-play-select", OsuIcon.Logo, new Color4(102, 68, 204, 255), () => State = ButtonSystemState.Play, WEDGE_WIDTH, Key.P));
|
2023-11-24 10:37:57 +00:00
|
|
|
|
buttonsTopLevel.Add(new MainMenuButton(ButtonSystemStrings.Edit, @"button-play-select", OsuIcon.EditCircle, new Color4(238, 170, 0, 255), () => State = ButtonSystemState.Edit, 0, Key.E));
|
2023-12-27 14:40:48 +00:00
|
|
|
|
buttonsTopLevel.Add(new MainMenuButton(ButtonSystemStrings.Browse, @"button-default-select", OsuIcon.Beatmap, new Color4(165, 204, 0, 255), () => OnBeatmapListing?.Invoke(), 0, Key.B, Key.D));
|
2019-02-25 12:41:41 +00:00
|
|
|
|
|
2019-02-25 00:56:00 +00:00
|
|
|
|
if (host.CanExit)
|
2022-03-25 06:12:39 +00:00
|
|
|
|
buttonsTopLevel.Add(new MainMenuButton(ButtonSystemStrings.Exit, string.Empty, OsuIcon.CrossCircle, new Color4(238, 51, 153, 255), () => OnExit?.Invoke(), 0, Key.Q));
|
2019-02-25 00:56:00 +00:00
|
|
|
|
|
|
|
|
|
buttonArea.AddRange(buttonsPlay);
|
2023-11-24 01:56:59 +00:00
|
|
|
|
buttonArea.AddRange(buttonsEdit);
|
2019-02-25 00:56:00 +00:00
|
|
|
|
buttonArea.AddRange(buttonsTopLevel);
|
|
|
|
|
|
2019-03-26 08:18:35 +00:00
|
|
|
|
buttonArea.ForEach(b =>
|
|
|
|
|
{
|
2022-03-25 06:12:39 +00:00
|
|
|
|
if (b is MainMenuButton)
|
2019-03-26 08:18:35 +00:00
|
|
|
|
{
|
|
|
|
|
b.Origin = Anchor.CentreLeft;
|
|
|
|
|
b.Anchor = Anchor.CentreLeft;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-02-22 08:51:39 +00:00
|
|
|
|
isIdle.ValueChanged += idle => updateIdleState(idle.NewValue);
|
2018-12-04 08:43:27 +00:00
|
|
|
|
|
2018-11-26 07:50:41 +00:00
|
|
|
|
if (idleTracker != null) isIdle.BindTo(idleTracker.IsIdle);
|
2018-11-26 07:32:59 +00:00
|
|
|
|
|
2023-11-08 13:08:05 +00:00
|
|
|
|
sampleBackToLogo = audio.Samples.Get(@"Menu/back-to-logo");
|
2023-11-08 13:13:35 +00:00
|
|
|
|
sampleLogoSwoosh = audio.Samples.Get(@"Menu/osu-logo-swoosh");
|
2016-12-05 12:09:41 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-12-22 05:55:25 +00:00
|
|
|
|
private void onMultiplayer()
|
2018-12-04 08:43:27 +00:00
|
|
|
|
{
|
2020-12-29 09:56:29 +00:00
|
|
|
|
if (api.State.Value != APIState.Online)
|
2018-12-04 08:43:27 +00:00
|
|
|
|
{
|
2022-04-19 08:44:20 +00:00
|
|
|
|
loginOverlay?.Show();
|
2018-12-04 08:43:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-12-26 04:18:36 +00:00
|
|
|
|
|
2020-12-22 05:55:25 +00:00
|
|
|
|
OnMultiplayer?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-25 04:11:21 +00:00
|
|
|
|
private void onPlaylists()
|
2020-12-22 05:55:25 +00:00
|
|
|
|
{
|
2020-12-29 09:56:29 +00:00
|
|
|
|
if (api.State.Value != APIState.Online)
|
2020-12-22 05:55:25 +00:00
|
|
|
|
{
|
2022-04-20 00:33:06 +00:00
|
|
|
|
loginOverlay?.Show();
|
2020-12-22 05:55:25 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-25 04:11:21 +00:00
|
|
|
|
OnPlaylists?.Invoke();
|
2018-12-04 08:43:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-26 07:32:59 +00:00
|
|
|
|
private void updateIdleState(bool isIdle)
|
|
|
|
|
{
|
2022-04-19 06:46:03 +00:00
|
|
|
|
if (!ReturnToTopOnIdle)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-05-31 05:06:13 +00:00
|
|
|
|
if (isIdle && State != ButtonSystemState.Exit && State != ButtonSystemState.EnteringMode)
|
2018-11-26 07:32:59 +00:00
|
|
|
|
State = ButtonSystemState.Initial;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 09:15:37 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Triggers the <see cref="logo"/> if the current <see cref="State"/> is <see cref="ButtonSystemState.Initial"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns><c>true</c> if the <see cref="logo"/> was triggered, <c>false</c> otherwise.</returns>
|
|
|
|
|
private bool triggerInitialOsuLogo()
|
2019-09-22 11:30:58 +00:00
|
|
|
|
{
|
|
|
|
|
if (State == ButtonSystemState.Initial)
|
|
|
|
|
{
|
2023-11-08 13:18:33 +00:00
|
|
|
|
StopSamplePlayback();
|
2022-04-20 20:00:37 +00:00
|
|
|
|
logo?.TriggerClick();
|
|
|
|
|
return true;
|
2019-09-22 11:30:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 09:15:37 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Repeat || e.ControlPressed || e.ShiftPressed || e.AltPressed || e.SuperPressed)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (triggerInitialOsuLogo())
|
|
|
|
|
return true;
|
|
|
|
|
|
2019-09-22 11:30:58 +00:00
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 22:38:18 +00:00
|
|
|
|
protected override bool OnJoystickPress(JoystickPressEvent e)
|
|
|
|
|
{
|
2022-07-05 09:15:37 +00:00
|
|
|
|
if (triggerInitialOsuLogo())
|
2022-07-04 22:38:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return base.OnJoystickPress(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMidiDown(MidiDownEvent e)
|
|
|
|
|
{
|
2022-07-05 09:15:37 +00:00
|
|
|
|
if (triggerInitialOsuLogo())
|
2022-07-04 22:38:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return base.OnMidiDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2018-04-29 17:15:09 +00:00
|
|
|
|
{
|
2021-11-18 03:35:47 +00:00
|
|
|
|
if (e.Repeat)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
switch (e.Action)
|
2018-05-14 17:27:05 +00:00
|
|
|
|
{
|
|
|
|
|
case GlobalAction.Back:
|
2018-05-21 14:09:00 +00:00
|
|
|
|
return goBack();
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-07-03 09:37:21 +00:00
|
|
|
|
case GlobalAction.Select:
|
2021-08-04 08:27:44 +00:00
|
|
|
|
logo?.TriggerClick();
|
2018-07-03 09:37:21 +00:00
|
|
|
|
return true;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-05-21 14:09:00 +00:00
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2020-01-22 04:22:34 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2018-07-03 09:18:04 +00:00
|
|
|
|
|
2018-05-21 14:09:00 +00:00
|
|
|
|
private bool goBack()
|
|
|
|
|
{
|
|
|
|
|
switch (State)
|
|
|
|
|
{
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.TopLevel:
|
|
|
|
|
State = ButtonSystemState.Initial;
|
2023-11-08 13:08:05 +00:00
|
|
|
|
|
|
|
|
|
// Samples are explicitly played here in response to user interaction and not when transitioning due to idle.
|
2023-11-08 13:18:33 +00:00
|
|
|
|
StopSamplePlayback();
|
2023-11-08 13:08:05 +00:00
|
|
|
|
sampleBackToLogo?.Play();
|
2023-11-08 13:13:35 +00:00
|
|
|
|
|
2018-05-21 14:09:00 +00:00
|
|
|
|
return true;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2023-11-24 01:56:59 +00:00
|
|
|
|
case ButtonSystemState.Edit:
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.Play:
|
2023-11-08 13:18:33 +00:00
|
|
|
|
StopSamplePlayback();
|
2021-08-04 08:27:44 +00:00
|
|
|
|
backButton.TriggerClick();
|
2018-05-21 14:09:00 +00:00
|
|
|
|
return true;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-05-14 17:27:05 +00:00
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-29 17:15:09 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-11-08 13:18:33 +00:00
|
|
|
|
public void StopSamplePlayback()
|
|
|
|
|
{
|
|
|
|
|
buttonsPlay.ForEach(button => button.StopSamplePlayback());
|
|
|
|
|
buttonsTopLevel.ForEach(button => button.StopSamplePlayback());
|
|
|
|
|
logo?.StopSamplePlayback();
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 14:29:08 +00:00
|
|
|
|
private bool onOsuLogo()
|
2016-08-26 03:28:23 +00:00
|
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
2017-11-25 14:29:08 +00:00
|
|
|
|
default:
|
2021-06-25 16:21:26 +00:00
|
|
|
|
return false;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.Initial:
|
|
|
|
|
State = ButtonSystemState.TopLevel;
|
2017-11-25 14:29:08 +00:00
|
|
|
|
return true;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.TopLevel:
|
2021-08-04 08:27:44 +00:00
|
|
|
|
buttonsTopLevel.First().TriggerClick();
|
2017-11-25 14:29:08 +00:00
|
|
|
|
return false;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.Play:
|
2021-08-04 08:27:44 +00:00
|
|
|
|
buttonsPlay.First().TriggerClick();
|
2017-11-25 14:29:08 +00:00
|
|
|
|
return false;
|
2023-11-24 15:53:25 +00:00
|
|
|
|
|
|
|
|
|
case ButtonSystemState.Edit:
|
|
|
|
|
buttonsEdit.First().TriggerClick();
|
|
|
|
|
return false;
|
2016-08-26 03:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
private ButtonSystemState state = ButtonSystemState.Initial;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-26 05:01:15 +00:00
|
|
|
|
public override bool HandleNonPositionalInput => state != ButtonSystemState.Exit;
|
|
|
|
|
public override bool HandlePositionalInput => state != ButtonSystemState.Exit;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
public ButtonSystemState State
|
2016-08-26 03:28:23 +00:00
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => state;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2016-08-26 03:28:23 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (state == value) return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
ButtonSystemState lastState = state;
|
2016-08-26 03:28:23 +00:00
|
|
|
|
state = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-17 08:40:10 +00:00
|
|
|
|
updateLogoState(lastState);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
Logger.Log($"{nameof(ButtonSystem)}'s state changed from {lastState} to {state}");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-11-24 02:02:30 +00:00
|
|
|
|
buttonArea.FinishTransforms(true);
|
|
|
|
|
|
2021-07-05 15:52:39 +00:00
|
|
|
|
using (buttonArea.BeginDelayedSequence(lastState == ButtonSystemState.Initial ? 150 : 0))
|
2018-07-03 09:18:04 +00:00
|
|
|
|
{
|
|
|
|
|
buttonArea.ButtonSystemState = state;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-03-25 06:12:39 +00:00
|
|
|
|
foreach (var b in buttonArea.Children.OfType<MainMenuButton>())
|
2018-07-03 09:18:04 +00:00
|
|
|
|
b.ButtonSystemState = state;
|
2016-08-26 03:28:23 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-09-04 00:10:04 +00:00
|
|
|
|
StateChanged?.Invoke(State);
|
2016-08-26 03:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-11-24 02:00:22 +00:00
|
|
|
|
private ScheduledDelegate? logoDelayedAction;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
private void updateLogoState(ButtonSystemState lastState = ButtonSystemState.Initial)
|
2017-11-17 08:40:10 +00:00
|
|
|
|
{
|
2017-11-18 02:19:15 +00:00
|
|
|
|
if (logo == null) return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-17 08:40:10 +00:00
|
|
|
|
switch (state)
|
|
|
|
|
{
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.Exit:
|
|
|
|
|
case ButtonSystemState.Initial:
|
2018-05-30 10:50:00 +00:00
|
|
|
|
logoDelayedAction?.Cancel();
|
2017-11-18 02:19:15 +00:00
|
|
|
|
logoDelayedAction = Scheduler.AddDelayed(() =>
|
2020-02-15 02:54:29 +00:00
|
|
|
|
{
|
|
|
|
|
logoTrackingContainer.StopTracking();
|
2018-05-21 15:24:57 +00:00
|
|
|
|
|
2020-02-15 02:54:29 +00:00
|
|
|
|
game?.Toolbar.Hide();
|
2018-06-06 07:17:51 +00:00
|
|
|
|
|
2022-01-27 07:39:36 +00:00
|
|
|
|
logo?.ClearTransforms(targetMember: nameof(Position));
|
|
|
|
|
logo?.MoveTo(new Vector2(0.5f), 800, Easing.OutExpo);
|
|
|
|
|
logo?.ScaleTo(1, 800, Easing.OutExpo);
|
2020-02-15 02:54:29 +00:00
|
|
|
|
}, buttonArea.Alpha * 150);
|
2023-11-09 05:01:33 +00:00
|
|
|
|
|
|
|
|
|
if (lastState == ButtonSystemState.TopLevel)
|
|
|
|
|
sampleLogoSwoosh?.Play();
|
2017-11-17 08:40:10 +00:00
|
|
|
|
break;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.TopLevel:
|
|
|
|
|
case ButtonSystemState.Play:
|
2017-11-17 08:40:10 +00:00
|
|
|
|
switch (lastState)
|
|
|
|
|
{
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.TopLevel: // coming from toplevel to play
|
2018-05-30 10:50:00 +00:00
|
|
|
|
break;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.Initial:
|
2018-05-30 10:50:00 +00:00
|
|
|
|
logo.ClearTransforms(targetMember: nameof(Position));
|
|
|
|
|
|
|
|
|
|
bool impact = logo.Scale.X > 0.6f;
|
|
|
|
|
|
2020-08-16 14:11:29 +00:00
|
|
|
|
logo.ScaleTo(0.5f, 200, Easing.In);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-08-16 14:11:29 +00:00
|
|
|
|
logoTrackingContainer.StartTracking(logo, 200, Easing.In);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-05-30 10:50:00 +00:00
|
|
|
|
logoDelayedAction?.Cancel();
|
2017-11-18 02:19:15 +00:00
|
|
|
|
logoDelayedAction = Scheduler.AddDelayed(() =>
|
|
|
|
|
{
|
2018-05-31 06:17:59 +00:00
|
|
|
|
if (impact)
|
2022-01-27 07:39:36 +00:00
|
|
|
|
logo?.Impact();
|
2018-06-06 07:17:51 +00:00
|
|
|
|
|
2018-08-23 02:20:20 +00:00
|
|
|
|
game?.Toolbar.Show();
|
2017-11-18 02:19:15 +00:00
|
|
|
|
}, 200);
|
2017-11-17 08:40:10 +00:00
|
|
|
|
break;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2017-11-17 08:40:10 +00:00
|
|
|
|
default:
|
2018-05-30 10:50:00 +00:00
|
|
|
|
logo.ClearTransforms(targetMember: nameof(Position));
|
2019-04-08 06:24:09 +00:00
|
|
|
|
logoTrackingContainer.StartTracking(logo, 0, Easing.In);
|
2017-11-17 08:40:10 +00:00
|
|
|
|
logo.ScaleTo(0.5f, 200, Easing.OutQuint);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-29 17:15:09 +00:00
|
|
|
|
|
2017-11-17 08:40:10 +00:00
|
|
|
|
break;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
case ButtonSystemState.EnteringMode:
|
2019-07-05 07:07:17 +00:00
|
|
|
|
logoTrackingContainer.StartTracking(logo, lastState == ButtonSystemState.Initial ? MainMenu.FADE_OUT_DURATION : 0, Easing.InSine);
|
2017-11-17 08:40:10 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-08 03:53:46 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
|
public enum ButtonSystemState
|
2016-10-08 03:53:46 +00:00
|
|
|
|
{
|
2018-07-03 09:18:04 +00:00
|
|
|
|
Exit,
|
2016-10-08 03:53:46 +00:00
|
|
|
|
Initial,
|
|
|
|
|
TopLevel,
|
|
|
|
|
Play,
|
2023-11-24 01:56:59 +00:00
|
|
|
|
Edit,
|
2016-10-08 03:53:46 +00:00
|
|
|
|
EnteringMode,
|
2016-08-26 03:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|