1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 16:12:54 +08:00

Add back button to TournamentScreen and the inputhandler for it

This commit is contained in:
Shivam 2020-05-16 03:07:27 +02:00
parent 43c42cdf31
commit c931bae70e

View File

@ -9,6 +9,9 @@ using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Framework.Input.Bindings;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays.Settings;
@ -17,7 +20,7 @@ using osuTK;
namespace osu.Game.Tournament.Screens.Editors
{
public abstract class TournamentEditorScreen<TDrawable, TModel> : TournamentScreen, IProvideVideo
public abstract class TournamentEditorScreen<TDrawable, TModel> : TournamentScreen, IProvideVideo, IKeyBindingHandler<GlobalAction>
where TDrawable : Drawable, IModelBacked<TModel>
where TModel : class, new()
{
@ -25,8 +28,19 @@ namespace osu.Game.Tournament.Screens.Editors
private FillFlowContainer<TDrawable> flow;
[Resolved(canBeNull: true)]
private TournamentSceneManager sceneManager { get; set; }
protected ControlPanel ControlPanel;
protected virtual bool IsSubScreen => false;
protected virtual System.Type ParentScreen { get; set; }
private BackButton backButton;
private System.Action backAction => () => sceneManager?.SetScreen(ParentScreen);
[BackgroundDependencyLoader]
private void load()
{
@ -70,6 +84,19 @@ namespace osu.Game.Tournament.Screens.Editors
}
});
if (IsSubScreen)
{
BackButton.Receptor receptor = new BackButton.Receptor();
backButton = new BackButton(receptor)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Action = () => { backAction.Invoke(); }
};
AddInternal(backButton);
backButton.Show();
}
Storage.CollectionChanged += (_, args) =>
{
switch (args.Action)
@ -88,6 +115,22 @@ namespace osu.Game.Tournament.Screens.Editors
flow.Add(CreateDrawable(model));
}
public bool OnPressed(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
backAction.Invoke();
return true;
}
return false;
}
public void OnReleased(GlobalAction action)
{
}
protected abstract TDrawable CreateDrawable(TModel model);
}
}