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;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; 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;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
@ -17,7 +20,7 @@ using osuTK;
namespace osu.Game.Tournament.Screens.Editors 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 TDrawable : Drawable, IModelBacked<TModel>
where TModel : class, new() where TModel : class, new()
{ {
@ -25,8 +28,19 @@ namespace osu.Game.Tournament.Screens.Editors
private FillFlowContainer<TDrawable> flow; private FillFlowContainer<TDrawable> flow;
[Resolved(canBeNull: true)]
private TournamentSceneManager sceneManager { get; set; }
protected ControlPanel ControlPanel; 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] [BackgroundDependencyLoader]
private void load() 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) => Storage.CollectionChanged += (_, args) =>
{ {
switch (args.Action) switch (args.Action)
@ -88,6 +115,22 @@ namespace osu.Game.Tournament.Screens.Editors
flow.Add(CreateDrawable(model)); 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); protected abstract TDrawable CreateDrawable(TModel model);
} }
} }