1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Merge pull request #2472 from UselessToucan/back_mouse_button_support

Add ability to bind "back" action; add default mouse binding
This commit is contained in:
Dean Herbert 2018-05-18 13:53:45 +09:00 committed by GitHub
commit cdd43f7909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 15 deletions

View File

@ -37,6 +37,9 @@ 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[]
@ -80,5 +83,8 @@ namespace osu.Game.Input.Bindings
TakeScreenshot,
[Description("Toggle gameplay mouse buttons")]
ToggleGameplayMouseButtons,
[Description("Go back")]
Back
}
}

View File

@ -6,9 +6,11 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Input.Bindings;
using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections;
using osu.Game.Screens.Ranking;
@ -96,7 +98,7 @@ namespace osu.Game.Overlays
});
}
private class BackButton : OsuClickableContainer
private class BackButton : OsuClickableContainer, IKeyBindingHandler<GlobalAction>
{
private AspectContainer aspect;
@ -146,6 +148,20 @@ namespace osu.Game.Overlays
aspect.ScaleTo(1, 1000, Easing.OutElastic);
return base.OnMouseUp(state, args);
}
public bool OnPressed(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
TriggerOnClick();
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => false;
}
}
}

View File

@ -19,6 +19,8 @@ namespace osu.Game.Screens
public override bool ShowOverlaysOnEnter => false;
protected override bool AllowBackButton => false;
public Loader()
{
ValidForResume = false;

View File

@ -6,22 +6,24 @@ using System.Collections.Generic;
using System.Linq;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Configuration;
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;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio;
using osu.Framework.Configuration;
using osu.Framework.Threading;
namespace osu.Game.Screens.Menu
{
public class ButtonSystem : Container, IStateful<MenuState>
public class ButtonSystem : Container, IStateful<MenuState>, IKeyBindingHandler<GlobalAction>
{
public event Action<MenuState> StateChanged;
@ -146,7 +148,16 @@ namespace osu.Game.Screens.Menu
case Key.Space:
logo?.TriggerOnClick(state);
return true;
case Key.Escape:
}
return false;
}
public bool OnPressed(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
switch (State)
{
case MenuState.TopLevel:
@ -155,12 +166,23 @@ namespace osu.Game.Screens.Menu
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()
@ -337,6 +359,7 @@ namespace osu.Game.Screens.Menu
logo.ScaleTo(0.5f, 200, Easing.OutQuint);
break;
}
break;
case MenuState.EnteringMode:
logoTracking = true;

View File

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

View File

@ -3,25 +3,29 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
using OpenTK;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets;
using osu.Game.Screens.Menu;
using osu.Framework.Input;
using OpenTK;
using OpenTK.Input;
namespace osu.Game.Screens
{
public abstract class OsuScreen : Screen
public abstract class OsuScreen : Screen, IKeyBindingHandler<GlobalAction>
{
public BackgroundScreen Background { get; private set; }
protected virtual bool AllowBackButton => true;
/// <summary>
/// Override to create a BackgroundMode for the current screen.
/// Note that the instance created may not be the used instance if it matches the BackgroundMode equality clause.
@ -90,6 +94,19 @@ namespace osu.Game.Screens
sampleExit = audio.Sample.Get(@"UI/screen-back");
}
public bool OnPressed(GlobalAction action)
{
if (action == GlobalAction.Back && AllowBackButton)
{
Exit();
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => action == GlobalAction.Back && AllowBackButton;
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (args.Repeat || !IsCurrentScreen) return false;

View File

@ -45,6 +45,8 @@ namespace osu.Game.Screens.Play
public bool AllowLeadIn { get; set; } = true;
public bool AllowResults { get; set; } = true;
protected override bool AllowBackButton => false;
private Bindable<bool> mouseWheelDisabled;
private Bindable<double> userAudioOffset;