From add8b8e9c456bf2684284dc13a4cbd55a5316dcc Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Mon, 25 Feb 2019 09:56:00 +0900 Subject: [PATCH 1/4] Only add Exit button if the GameHost supports it --- osu.Game/Screens/Menu/ButtonSystem.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Menu/ButtonSystem.cs b/osu.Game/Screens/Menu/ButtonSystem.cs index 2669bb9342..76185e328b 100644 --- a/osu.Game/Screens/Menu/ButtonSystem.cs +++ b/osu.Game/Screens/Menu/ButtonSystem.cs @@ -13,6 +13,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input.Bindings; using osu.Framework.Logging; +using osu.Framework.Platform; using osu.Framework.Threading; using osu.Game.Graphics; using osu.Game.Input; @@ -99,10 +100,6 @@ namespace osu.Game.Screens.Menu buttonsTopLevel.Add(new Button(@"play", @"button-play-select", FontAwesome.fa_osu_logo, new Color4(102, 68, 204, 255), () => State = ButtonSystemState.Play, WEDGE_WIDTH, Key.P)); buttonsTopLevel.Add(new Button(@"osu!editor", @"button-generic-select", FontAwesome.fa_osu_edit_o, new Color4(238, 170, 0, 255), () => OnEdit?.Invoke(), 0, Key.E)); buttonsTopLevel.Add(new Button(@"osu!direct", @"button-direct-select", FontAwesome.fa_osu_chevron_down_o, new Color4(165, 204, 0, 255), () => OnDirect?.Invoke(), 0, Key.D)); - buttonsTopLevel.Add(new Button(@"exit", string.Empty, FontAwesome.fa_osu_cross_o, new Color4(238, 51, 153, 255), () => OnExit?.Invoke(), 0, Key.Q)); - - buttonArea.AddRange(buttonsPlay); - buttonArea.AddRange(buttonsTopLevel); } [Resolved(CanBeNull = true)] @@ -115,8 +112,14 @@ namespace osu.Game.Screens.Menu private NotificationOverlay notifications { get; set; } [BackgroundDependencyLoader(true)] - private void load(AudioManager audio, IdleTracker idleTracker) + private void load(AudioManager audio, IdleTracker idleTracker, GameHost host) { + if (host.CanExit) + buttonsTopLevel.Add(new Button(@"exit", string.Empty, FontAwesome.fa_osu_cross_o, new Color4(238, 51, 153, 255), () => OnExit?.Invoke(), 0, Key.Q)); + + buttonArea.AddRange(buttonsPlay); + buttonArea.AddRange(buttonsTopLevel); + isIdle.ValueChanged += idle => updateIdleState(idle.NewValue); if (idleTracker != null) isIdle.BindTo(idleTracker.IsIdle); From 61be4f26951c051aaafce7fee171c8da0476705e Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Mon, 25 Feb 2019 10:42:36 +0900 Subject: [PATCH 2/4] Conditionally add ExitConfirmOverlay and disable back action --- osu.Game/Screens/Menu/MainMenu.cs | 53 +++++++++++++++++-------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index d6e3d378e0..315be92141 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -19,6 +19,7 @@ using osu.Game.Screens.Edit; using osu.Game.Screens.Multi; using osu.Game.Screens.Select; using osu.Game.Screens.Tournament; +using osu.Framework.Platform; namespace osu.Game.Screens.Menu { @@ -28,7 +29,7 @@ namespace osu.Game.Screens.Menu public override bool HideOverlaysOnEnter => buttons.State == ButtonSystemState.Initial; - protected override bool AllowBackButton => buttons.State != ButtonSystemState.Initial; + protected override bool AllowBackButton => buttons.State != ButtonSystemState.Initial && host.CanExit; public override bool AllowExternalScreenChange => true; @@ -36,33 +37,23 @@ namespace osu.Game.Screens.Menu private readonly MenuSideFlashes sideFlashes; + [Resolved] + private GameHost host { get; set; } + protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault(); public MainMenu() { - InternalChildren = new Drawable[] + sideFlashes = new MenuSideFlashes(); + + buttons = new ButtonSystem { - new ExitConfirmOverlay - { - Action = this.Exit, - }, - new ParallaxContainer - { - ParallaxAmount = 0.01f, - Children = new Drawable[] - { - buttons = new ButtonSystem - { - OnChart = delegate { this.Push(new ChartListing()); }, - OnDirect = delegate {this.Push(new OnlineListing()); }, - OnEdit = delegate {this.Push(new Editor()); }, - OnSolo = onSolo, - OnMulti = delegate {this.Push(new Multiplayer()); }, - OnExit = this.Exit, - } - } - }, - sideFlashes = new MenuSideFlashes(), + OnChart = delegate { this.Push(new ChartListing()); }, + OnDirect = delegate { this.Push(new OnlineListing()); }, + OnEdit = delegate { this.Push(new Editor()); }, + OnSolo = onSolo, + OnMulti = delegate { this.Push(new Multiplayer()); }, + OnExit = this.Exit, }; buttons.StateChanged += state => @@ -83,6 +74,22 @@ namespace osu.Game.Screens.Menu [BackgroundDependencyLoader(true)] private void load(OsuGame game = null) { + if (host.CanExit) + { + AddInternal(new ExitConfirmOverlay + { + Action = this.Exit, + }); + } + + AddInternal(new ParallaxContainer + { + ParallaxAmount = 0.01f, + Child = buttons, + }); + + AddInternal(sideFlashes); + if (game != null) { buttons.OnSettings = game.ToggleSettings; From 2bd5bb3f69eb62fcba48f26274dd966fdd14d093 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Mon, 25 Feb 2019 21:41:41 +0900 Subject: [PATCH 3/4] Move all MainMenu button creation into load --- osu.Game/Screens/Menu/ButtonSystem.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Game/Screens/Menu/ButtonSystem.cs b/osu.Game/Screens/Menu/ButtonSystem.cs index 76185e328b..42d67ceffc 100644 --- a/osu.Game/Screens/Menu/ButtonSystem.cs +++ b/osu.Game/Screens/Menu/ButtonSystem.cs @@ -91,15 +91,6 @@ namespace osu.Game.Screens.Menu }); buttonArea.Flow.CentreTarget = iconFacade; - - buttonsPlay.Add(new Button(@"solo", @"button-solo-select", FontAwesome.fa_user, new Color4(102, 68, 204, 255), () => OnSolo?.Invoke(), WEDGE_WIDTH, Key.P)); - buttonsPlay.Add(new Button(@"multi", @"button-generic-select", FontAwesome.fa_users, new Color4(94, 63, 186, 255), onMulti, 0, Key.M)); - buttonsPlay.Add(new Button(@"chart", @"button-generic-select", FontAwesome.fa_osu_charts, new Color4(80, 53, 160, 255), () => OnChart?.Invoke())); - buttonsPlay.ForEach(b => b.VisibleState = ButtonSystemState.Play); - - buttonsTopLevel.Add(new Button(@"play", @"button-play-select", FontAwesome.fa_osu_logo, new Color4(102, 68, 204, 255), () => State = ButtonSystemState.Play, WEDGE_WIDTH, Key.P)); - buttonsTopLevel.Add(new Button(@"osu!editor", @"button-generic-select", FontAwesome.fa_osu_edit_o, new Color4(238, 170, 0, 255), () => OnEdit?.Invoke(), 0, Key.E)); - buttonsTopLevel.Add(new Button(@"osu!direct", @"button-direct-select", FontAwesome.fa_osu_chevron_down_o, new Color4(165, 204, 0, 255), () => OnDirect?.Invoke(), 0, Key.D)); } [Resolved(CanBeNull = true)] @@ -114,6 +105,15 @@ namespace osu.Game.Screens.Menu [BackgroundDependencyLoader(true)] private void load(AudioManager audio, IdleTracker idleTracker, GameHost host) { + buttonsPlay.Add(new Button(@"solo", @"button-solo-select", FontAwesome.fa_user, new Color4(102, 68, 204, 255), () => OnSolo?.Invoke(), WEDGE_WIDTH, Key.P)); + buttonsPlay.Add(new Button(@"multi", @"button-generic-select", FontAwesome.fa_users, new Color4(94, 63, 186, 255), onMulti, 0, Key.M)); + buttonsPlay.Add(new Button(@"chart", @"button-generic-select", FontAwesome.fa_osu_charts, new Color4(80, 53, 160, 255), () => OnChart?.Invoke())); + buttonsPlay.ForEach(b => b.VisibleState = ButtonSystemState.Play); + + buttonsTopLevel.Add(new Button(@"play", @"button-play-select", FontAwesome.fa_osu_logo, new Color4(102, 68, 204, 255), () => State = ButtonSystemState.Play, WEDGE_WIDTH, Key.P)); + buttonsTopLevel.Add(new Button(@"osu!editor", @"button-generic-select", FontAwesome.fa_osu_edit_o, new Color4(238, 170, 0, 255), () => OnEdit?.Invoke(), 0, Key.E)); + buttonsTopLevel.Add(new Button(@"osu!direct", @"button-direct-select", FontAwesome.fa_osu_chevron_down_o, new Color4(165, 204, 0, 255), () => OnDirect?.Invoke(), 0, Key.D)); + if (host.CanExit) buttonsTopLevel.Add(new Button(@"exit", string.Empty, FontAwesome.fa_osu_cross_o, new Color4(238, 51, 153, 255), () => OnExit?.Invoke(), 0, Key.Q)); From e91c07209ffc948c0934defd23b79afffffcefcd Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Tue, 26 Feb 2019 09:54:42 +0900 Subject: [PATCH 4/4] Move MainMenu initialisation from ctor to load --- osu.Game/Screens/Menu/MainMenu.cs | 57 ++++++++++++++----------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 5aa85b6e71..234fb808c3 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -25,7 +25,7 @@ namespace osu.Game.Screens.Menu { public class MainMenu : OsuScreen { - private readonly ButtonSystem buttons; + private ButtonSystem buttons; public override bool HideOverlaysOnEnter => buttons.State == ButtonSystemState.Initial; @@ -35,26 +35,39 @@ namespace osu.Game.Screens.Menu private Screen songSelect; - private readonly MenuSideFlashes sideFlashes; + private MenuSideFlashes sideFlashes; [Resolved] private GameHost host { get; set; } protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault(); - public MainMenu() + [BackgroundDependencyLoader(true)] + private void load(OsuGame game = null) { - sideFlashes = new MenuSideFlashes(); + if (host.CanExit) + AddInternal(new ExitConfirmOverlay { Action = this.Exit }); - buttons = new ButtonSystem + AddRangeInternal(new Drawable[] { - OnChart = delegate { this.Push(new ChartListing()); }, - OnDirect = delegate { this.Push(new OnlineListing()); }, - OnEdit = delegate { this.Push(new Editor()); }, - OnSolo = onSolo, - OnMulti = delegate { this.Push(new Multiplayer()); }, - OnExit = this.Exit, - }; + new ParallaxContainer + { + ParallaxAmount = 0.01f, + Children = new Drawable[] + { + buttons = new ButtonSystem + { + OnChart = delegate { this.Push(new ChartListing()); }, + OnDirect = delegate { this.Push(new OnlineListing()); }, + OnEdit = delegate { this.Push(new Editor()); }, + OnSolo = onSolo, + OnMulti = delegate { this.Push(new Multiplayer()); }, + OnExit = this.Exit, + } + } + }, + sideFlashes = new MenuSideFlashes(), + }); buttons.StateChanged += state => { @@ -69,26 +82,6 @@ namespace osu.Game.Screens.Menu break; } }; - } - - [BackgroundDependencyLoader(true)] - private void load(OsuGame game = null) - { - if (host.CanExit) - { - AddInternal(new ExitConfirmOverlay - { - Action = this.Exit, - }); - } - - AddInternal(new ParallaxContainer - { - ParallaxAmount = 0.01f, - Child = buttons, - }); - - AddInternal(sideFlashes); if (game != null) {