mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 19:22:56 +08:00
Handle mouse back button using OnMouseDown override instead of using GlobalAction
This commit is contained in:
parent
b08b24b6da
commit
44bbb8700e
@ -26,7 +26,7 @@ namespace osu.Game.Input.Bindings
|
||||
{
|
||||
new KeyBinding(InputKey.F8, GlobalAction.ToggleChat),
|
||||
new KeyBinding(InputKey.F9, GlobalAction.ToggleSocial),
|
||||
new KeyBinding(InputKey.F12, GlobalAction.TakeScreenshot),
|
||||
new KeyBinding(InputKey.F12,GlobalAction.TakeScreenshot),
|
||||
|
||||
new KeyBinding(new[] { InputKey.Control, InputKey.Alt, InputKey.R }, GlobalAction.ResetInputSettings),
|
||||
new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar),
|
||||
@ -36,9 +36,6 @@ namespace osu.Game.Input.Bindings
|
||||
new KeyBinding(InputKey.Down, GlobalAction.DecreaseVolume),
|
||||
new KeyBinding(InputKey.MouseWheelDown, GlobalAction.DecreaseVolume),
|
||||
new KeyBinding(InputKey.F4, GlobalAction.ToggleMute),
|
||||
|
||||
new KeyBinding(InputKey.Escape, GlobalAction.Back),
|
||||
new KeyBinding(InputKey.MouseButton1, GlobalAction.Back)
|
||||
};
|
||||
|
||||
public IEnumerable<KeyBinding> InGameKeyBindings => new[]
|
||||
@ -79,9 +76,6 @@ namespace osu.Game.Input.Bindings
|
||||
QuickRetry,
|
||||
|
||||
[Description("Take screenshot")]
|
||||
TakeScreenshot,
|
||||
|
||||
[Description("Go back")]
|
||||
Back
|
||||
TakeScreenshot
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace osu.Game.Screens
|
||||
private bool showDisclaimer;
|
||||
|
||||
public override bool ShowOverlaysOnEnter => false;
|
||||
protected override bool AllowBackButton => false;
|
||||
|
||||
public Loader()
|
||||
{
|
||||
|
@ -13,17 +13,15 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Input.Bindings;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
{
|
||||
public class ButtonSystem : Container, IStateful<MenuState>, IKeyBindingHandler<GlobalAction>
|
||||
public class ButtonSystem : Container, IStateful<MenuState>
|
||||
{
|
||||
public event Action<MenuState> StateChanged;
|
||||
|
||||
@ -148,43 +146,35 @@ namespace osu.Game.Screens.Menu
|
||||
case Key.Space:
|
||||
logo?.TriggerOnClick(state);
|
||||
return true;
|
||||
case Key.Escape:
|
||||
return handleBack();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.Back:
|
||||
switch (State)
|
||||
{
|
||||
case MenuState.TopLevel:
|
||||
State = MenuState.Initial;
|
||||
return true;
|
||||
case MenuState.Play:
|
||||
backButton.TriggerOnClick();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (state.Mouse.IsPressed(MouseButton.Button1))
|
||||
return handleBack();
|
||||
|
||||
return base.OnMouseDown(state, args);
|
||||
}
|
||||
|
||||
public bool OnReleased(GlobalAction action)
|
||||
private bool handleBack()
|
||||
{
|
||||
switch (action)
|
||||
switch (State)
|
||||
{
|
||||
case GlobalAction.Back:
|
||||
case MenuState.TopLevel:
|
||||
State = MenuState.Initial;
|
||||
return true;
|
||||
case MenuState.Play:
|
||||
backButton.TriggerOnClick();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onPlay()
|
||||
{
|
||||
|
@ -25,6 +25,7 @@ namespace osu.Game.Screens.Menu
|
||||
private readonly ButtonSystem buttons;
|
||||
|
||||
public override bool ShowOverlaysOnEnter => buttons.State != MenuState.Initial;
|
||||
protected override bool AllowBackButton => false;
|
||||
|
||||
private readonly BackgroundScreenDefault background;
|
||||
private Screen songSelect;
|
||||
|
@ -7,18 +7,18 @@ using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Menu;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Screens
|
||||
{
|
||||
public abstract class OsuScreen : Screen, IKeyBindingHandler<GlobalAction>
|
||||
public abstract class OsuScreen : Screen
|
||||
{
|
||||
public BackgroundScreen Background { get; private set; }
|
||||
|
||||
@ -92,19 +92,31 @@ namespace osu.Game.Screens
|
||||
sampleExit = audio.Sample.Get(@"UI/screen-back");
|
||||
}
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
if (action == GlobalAction.Back && AllowBackButton)
|
||||
if (args.Repeat || !IsCurrentScreen) return false;
|
||||
|
||||
switch (args.Key)
|
||||
{
|
||||
case Key.Escape:
|
||||
Exit();
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnKeyDown(state, args);
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||
{
|
||||
if (AllowBackButton && state.Mouse.IsPressed(MouseButton.Button1))
|
||||
{
|
||||
Exit();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return base.OnMouseDown(state, args);
|
||||
}
|
||||
|
||||
public bool OnReleased(GlobalAction action) => action == GlobalAction.Back && AllowBackButton;
|
||||
|
||||
protected override void OnResuming(Screen last)
|
||||
{
|
||||
sampleExit?.Play();
|
||||
|
@ -27,7 +27,6 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private bool showOverlays = true;
|
||||
public override bool ShowOverlaysOnEnter => showOverlays;
|
||||
protected override bool AllowBackButton => false;
|
||||
|
||||
private Task loadTask;
|
||||
|
||||
|
@ -17,6 +17,8 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
public override bool AllowBeatmapRulesetChange => false;
|
||||
|
||||
protected override bool AllowBackButton => false;
|
||||
|
||||
protected const float BACKGROUND_FADE_DURATION = 800;
|
||||
|
||||
protected float BackgroundOpacity => 1 - (float)DimLevel;
|
||||
|
Loading…
Reference in New Issue
Block a user