Introduce OsuScreen.AllowBackButton property

This commit is contained in:
Roman Kapustin 2018-05-04 21:18:48 +03:00
parent 804b59ee80
commit b08b24b6da
2 changed files with 9 additions and 16 deletions

View File

@ -22,6 +22,8 @@ namespace osu.Game.Screens
{ {
public BackgroundScreen Background { get; private set; } public BackgroundScreen Background { get; private set; }
protected virtual bool AllowBackButton => true;
/// <summary> /// <summary>
/// Override to create a BackgroundMode for the current screen. /// 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. /// Note that the instance created may not be the used instance if it matches the BackgroundMode equality clause.
@ -92,26 +94,16 @@ namespace osu.Game.Screens
public bool OnPressed(GlobalAction action) public bool OnPressed(GlobalAction action)
{ {
switch (action) if (action == GlobalAction.Back && AllowBackButton)
{ {
case GlobalAction.Back: Exit();
Exit(); return true;
return true;
default:
return false;
} }
return false;
} }
public bool OnReleased(GlobalAction action) public bool OnReleased(GlobalAction action) => action == GlobalAction.Back && AllowBackButton;
{
switch (action)
{
case GlobalAction.Back:
return true;
default:
return false;
}
}
protected override void OnResuming(Screen last) protected override void OnResuming(Screen last)
{ {

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;