From c931bae70ec13b10f45c89ad67d223c635046186 Mon Sep 17 00:00:00 2001 From: Shivam Date: Sat, 16 May 2020 03:07:27 +0200 Subject: [PATCH] Add back button to TournamentScreen and the inputhandler for it --- .../Screens/Editors/TournamentEditorScreen.cs | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tournament/Screens/Editors/TournamentEditorScreen.cs b/osu.Game.Tournament/Screens/Editors/TournamentEditorScreen.cs index 8e5df72cc8..11cb072c6b 100644 --- a/osu.Game.Tournament/Screens/Editors/TournamentEditorScreen.cs +++ b/osu.Game.Tournament/Screens/Editors/TournamentEditorScreen.cs @@ -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 : TournamentScreen, IProvideVideo + public abstract class TournamentEditorScreen : TournamentScreen, IProvideVideo, IKeyBindingHandler where TDrawable : Drawable, IModelBacked where TModel : class, new() { @@ -25,8 +28,19 @@ namespace osu.Game.Tournament.Screens.Editors private FillFlowContainer 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); } }