Revert "Handle mouse back button using OnMouseDown override instead of using GlobalAction"

This reverts commit 44bbb8700e.
This commit is contained in:
Roman Kapustin
2018-05-14 20:27:05 +03:00
parent 38d54f2a6c
commit e802b722f0
7 changed files with 48 additions and 47 deletions

View File

@ -26,7 +26,7 @@ namespace osu.Game.Input.Bindings
{ {
new KeyBinding(InputKey.F8, GlobalAction.ToggleChat), new KeyBinding(InputKey.F8, GlobalAction.ToggleChat),
new KeyBinding(InputKey.F9, GlobalAction.ToggleSocial), 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.Alt, InputKey.R }, GlobalAction.ResetInputSettings),
new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar), new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar),
@ -36,6 +36,9 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.Down, GlobalAction.DecreaseVolume), new KeyBinding(InputKey.Down, GlobalAction.DecreaseVolume),
new KeyBinding(InputKey.MouseWheelDown, GlobalAction.DecreaseVolume), new KeyBinding(InputKey.MouseWheelDown, GlobalAction.DecreaseVolume),
new KeyBinding(InputKey.F4, GlobalAction.ToggleMute), new KeyBinding(InputKey.F4, GlobalAction.ToggleMute),
new KeyBinding(InputKey.Escape, GlobalAction.Back),
new KeyBinding(InputKey.MouseButton1, GlobalAction.Back)
}; };
public IEnumerable<KeyBinding> InGameKeyBindings => new[] public IEnumerable<KeyBinding> InGameKeyBindings => new[]
@ -76,6 +79,9 @@ namespace osu.Game.Input.Bindings
QuickRetry, QuickRetry,
[Description("Take screenshot")] [Description("Take screenshot")]
TakeScreenshot TakeScreenshot,
[Description("Go back")]
Back
} }
} }

View File

@ -18,7 +18,6 @@ namespace osu.Game.Screens
private bool showDisclaimer; private bool showDisclaimer;
public override bool ShowOverlaysOnEnter => false; public override bool ShowOverlaysOnEnter => false;
protected override bool AllowBackButton => false;
public Loader() public Loader()
{ {

View File

@ -13,15 +13,17 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Input.Bindings;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Input; using OpenTK.Input;
namespace osu.Game.Screens.Menu namespace osu.Game.Screens.Menu
{ {
public class ButtonSystem : Container, IStateful<MenuState> public class ButtonSystem : Container, IStateful<MenuState>, IKeyBindingHandler<GlobalAction>
{ {
public event Action<MenuState> StateChanged; public event Action<MenuState> StateChanged;
@ -146,36 +148,44 @@ namespace osu.Game.Screens.Menu
case Key.Space: case Key.Space:
logo?.TriggerOnClick(state); logo?.TriggerOnClick(state);
return true; return true;
case Key.Escape:
return handleBack();
} }
return false; return false;
} }
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) public bool OnPressed(GlobalAction action)
{ {
if (state.Mouse.IsPressed(MouseButton.Button1)) switch (action)
return handleBack();
return base.OnMouseDown(state, args);
}
private bool handleBack()
{
switch (State)
{ {
case MenuState.TopLevel: case GlobalAction.Back:
State = MenuState.Initial; switch (State)
return true; {
case MenuState.Play: case MenuState.TopLevel:
backButton.TriggerOnClick(); State = MenuState.Initial;
return true; return true;
case MenuState.Play:
backButton.TriggerOnClick();
return true;
default:
return false;
}
default:
return false;
} }
return false;
} }
public bool OnReleased(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
return true;
default:
return false;
}
}
private void onPlay() private void onPlay()
{ {
State = MenuState.Play; State = MenuState.Play;

View File

@ -25,7 +25,6 @@ namespace osu.Game.Screens.Menu
private readonly ButtonSystem buttons; private readonly ButtonSystem buttons;
public override bool ShowOverlaysOnEnter => buttons.State != MenuState.Initial; public override bool ShowOverlaysOnEnter => buttons.State != MenuState.Initial;
protected override bool AllowBackButton => false;
private readonly BackgroundScreenDefault background; private readonly BackgroundScreenDefault background;
private Screen songSelect; private Screen songSelect;

View File

@ -7,18 +7,18 @@ using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input; using osu.Framework.Input.Bindings;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using OpenTK; using OpenTK;
using OpenTK.Input;
namespace osu.Game.Screens namespace osu.Game.Screens
{ {
public abstract class OsuScreen : Screen public abstract class OsuScreen : Screen, IKeyBindingHandler<GlobalAction>
{ {
public BackgroundScreen Background { get; private set; } public BackgroundScreen Background { get; private set; }
@ -92,31 +92,19 @@ namespace osu.Game.Screens
sampleExit = audio.Sample.Get(@"UI/screen-back"); sampleExit = audio.Sample.Get(@"UI/screen-back");
} }
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) public bool OnPressed(GlobalAction action)
{ {
if (args.Repeat || !IsCurrentScreen) return false; if (action == GlobalAction.Back && AllowBackButton)
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(); Exit();
return true; return true;
} }
return base.OnMouseDown(state, args); return false;
} }
public bool OnReleased(GlobalAction action) => action == GlobalAction.Back && AllowBackButton;
protected override void OnResuming(Screen last) protected override void OnResuming(Screen last)
{ {
sampleExit?.Play(); sampleExit?.Play();

View File

@ -27,6 +27,7 @@ namespace osu.Game.Screens.Play
private bool showOverlays = true; private bool showOverlays = true;
public override bool ShowOverlaysOnEnter => showOverlays; public override bool ShowOverlaysOnEnter => showOverlays;
protected override bool AllowBackButton => false;
private Task loadTask; private Task loadTask;

View File

@ -17,8 +17,6 @@ namespace osu.Game.Screens.Play
public override bool AllowBeatmapRulesetChange => false; public override bool AllowBeatmapRulesetChange => false;
protected override bool AllowBackButton => false;
protected const float BACKGROUND_FADE_DURATION = 800; protected const float BACKGROUND_FADE_DURATION = 800;
protected float BackgroundOpacity => 1 - (float)DimLevel; protected float BackgroundOpacity => 1 - (float)DimLevel;