move back logic into GameplayMenuOverlay

This commit is contained in:
Aergwyn
2018-06-09 09:28:02 +02:00
parent 792d3b8215
commit b9b04c1b6e
3 changed files with 28 additions and 35 deletions

View File

@ -1,38 +1,26 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Linq;
using osu.Game.Graphics;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using System.Linq;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
namespace osu.Game.Screens.Play
{
public class FailOverlay : GameplayMenuOverlay, IKeyBindingHandler<GlobalAction>
public class FailOverlay : GameplayMenuOverlay
{
public override string Header => "failed";
public override string Description => "you're dead, try again?";
protected override Action DefaultBackAction => () => InternalButtons.Children.Last().TriggerOnClick();
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AddButton("Retry", colours.YellowDark, () => OnRetry?.Invoke());
AddButton("Quit", new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
}
public bool OnPressed(GlobalAction action)
{
if (action == GlobalAction.Back)
{
InternalButtons.Children.Last().TriggerOnClick();
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => action == GlobalAction.Back;
}
}

View File

@ -15,10 +15,13 @@ using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.Shapes;
using OpenTK.Input;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
namespace osu.Game.Screens.Play
{
public abstract class GameplayMenuOverlay : OverlayContainer
public abstract class GameplayMenuOverlay : OverlayContainer, IKeyBindingHandler<GlobalAction>
{
private const int transition_duration = 200;
private const int button_height = 70;
@ -31,6 +34,11 @@ namespace osu.Game.Screens.Play
public Action OnRetry;
public Action OnQuit;
/// <summary>
/// Action that is invoked if <see cref="GlobalAction.Back"/> is triggered.
/// </summary>
protected virtual Action DefaultBackAction => () => InternalButtons.Children.First().TriggerOnClick();
public abstract string Header { get; }
public abstract string Description { get; }
@ -219,6 +227,19 @@ namespace osu.Game.Screens.Play
return base.OnKeyDown(state, args);
}
public bool OnPressed(GlobalAction action)
{
if (action == GlobalAction.Back)
{
DefaultBackAction.Invoke();
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => action == GlobalAction.Back;
private void buttonSelectionChanged(DialogButton button, bool isSelected)
{
if (!isSelected)

View File

@ -2,14 +2,11 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Framework.Timing;
using osu.Game.Graphics;
using osu.Game.Input.Bindings;
using OpenTK.Graphics;
namespace osu.Game.Screens.Play
@ -131,7 +128,7 @@ namespace osu.Game.Screens.Play
base.Update();
}
public class PauseOverlay : GameplayMenuOverlay, IKeyBindingHandler<GlobalAction>
public class PauseOverlay : GameplayMenuOverlay
{
public Action OnResume;
@ -145,19 +142,6 @@ namespace osu.Game.Screens.Play
AddButton("Retry", colours.YellowDark, () => OnRetry?.Invoke());
AddButton("Quit", new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
}
public bool OnPressed(GlobalAction action)
{
if (action == GlobalAction.Back)
{
InternalButtons.Children.First().TriggerOnClick();
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => action == GlobalAction.Back;
}
}
}