From 9a061ad80b38eea677eed6bb235951c8f035bb6b Mon Sep 17 00:00:00 2001 From: Lucas A Date: Wed, 5 May 2021 20:27:28 +0200 Subject: [PATCH 1/8] Extract directory selection logic of migration screen to DirectorySelectScreen. --- .../Maintenance/DirectorySelectScreen.cs | 115 ++++++++++++++++++ .../Maintenance/MigrationSelectScreen.cs | 105 +++------------- 2 files changed, 130 insertions(+), 90 deletions(-) create mode 100644 osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs new file mode 100644 index 0000000000..278c1ab20d --- /dev/null +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs @@ -0,0 +1,115 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using System.IO; +using osu.Framework.Allocation; +using osu.Game.Graphics; +using osu.Game.Graphics.UserInterfaceV2; +using osu.Game.Screens; +using osuTK; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using osu.Framework.Screens; + +namespace osu.Game.Overlays.Settings.Sections.Maintenance +{ + public abstract class DirectorySelectScreen : OsuScreen + { + private TriangleButton selectionButton; + + protected DirectorySelector DirectorySelector { get; private set; } + + protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.Disabled; + + protected abstract OsuSpriteText CreateHeader(); + + /// + /// Called upon selection of a directory by the user. + /// + /// The selected directory + protected abstract void OnSelection(DirectoryInfo directory); + + protected virtual bool IsValidDirectory(DirectoryInfo info) => info != null; + + public override bool AllowExternalScreenChange => false; + + public override bool DisallowExternalBeatmapRulesetChanges => true; + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + InternalChild = new Container + { + Masking = true, + CornerRadius = 10, + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(0.5f, 0.8f), + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = colours.GreySeafoamDark + }, + new GridContainer + { + RelativeSizeAxes = Axes.Both, + RowDimensions = new[] + { + new Dimension(), + new Dimension(GridSizeMode.Relative, 0.8f), + new Dimension(), + }, + Content = new[] + { + new Drawable[] + { + CreateHeader().With(header => + { + header.Origin = Anchor.Centre; + header.Anchor = Anchor.Centre; + }) + }, + new Drawable[] + { + DirectorySelector = new DirectorySelector + { + RelativeSizeAxes = Axes.Both, + } + }, + new Drawable[] + { + selectionButton = new TriangleButton + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Width = 300, + Text = "Select directory", + Action = () => OnSelection(DirectorySelector.CurrentPath.Value) + }, + } + } + } + } + }; + } + + protected override void LoadComplete() + { + DirectorySelector.CurrentPath.BindValueChanged(e => selectionButton.Enabled.Value = IsValidDirectory(e.NewValue), true); + base.LoadComplete(); + } + + public override void OnSuspending(IScreen next) + { + base.OnSuspending(next); + + this.FadeOut(250); + } + } +} diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs index ad540e3691..1f14d0991d 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs @@ -4,109 +4,28 @@ using System; using System.IO; using osu.Framework.Allocation; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; using osu.Framework.Logging; using osu.Framework.Platform; using osu.Framework.Screens; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; -using osu.Game.Graphics.UserInterfaceV2; -using osu.Game.Screens; -using osuTK; namespace osu.Game.Overlays.Settings.Sections.Maintenance { - public class MigrationSelectScreen : OsuScreen + public class MigrationSelectScreen : DirectorySelectScreen { - private DirectorySelector directorySelector; + [Resolved] + private Storage storage { get; set; } - public override bool AllowExternalScreenChange => false; - - public override bool DisallowExternalBeatmapRulesetChanges => true; - - public override bool HideOverlaysOnEnter => true; - - [BackgroundDependencyLoader(true)] - private void load(OsuGame game, Storage storage, OsuColour colours) + protected override OsuSpriteText CreateHeader() => new OsuSpriteText { - game?.Toolbar.Hide(); + Text = "Please select a new location", + Font = OsuFont.Default.With(size: 40) + }; - // begin selection in the parent directory of the current storage location - var initialPath = new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent?.FullName; - - InternalChild = new Container - { - Masking = true, - CornerRadius = 10, - RelativeSizeAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(0.5f, 0.8f), - Children = new Drawable[] - { - new Box - { - Colour = colours.GreySeafoamDark, - RelativeSizeAxes = Axes.Both, - }, - new GridContainer - { - RelativeSizeAxes = Axes.Both, - RowDimensions = new[] - { - new Dimension(), - new Dimension(GridSizeMode.Relative, 0.8f), - new Dimension(), - }, - Content = new[] - { - new Drawable[] - { - new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Text = "Please select a new location", - Font = OsuFont.Default.With(size: 40) - }, - }, - new Drawable[] - { - directorySelector = new DirectorySelector(initialPath) - { - RelativeSizeAxes = Axes.Both, - } - }, - new Drawable[] - { - new TriangleButton - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Width = 300, - Text = "Begin folder migration", - Action = start - }, - } - } - } - } - }; - } - - public override void OnSuspending(IScreen next) + protected override void OnSelection(DirectoryInfo directory) { - base.OnSuspending(next); - - this.FadeOut(250); - } - - private void start() - { - var target = directorySelector.CurrentPath.Value; + var target = directory; try { @@ -123,6 +42,12 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance BeginMigration(target); } + protected override void LoadComplete() + { + DirectorySelector.CurrentPath.Value = new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent; + base.LoadComplete(); + } + protected virtual void BeginMigration(DirectoryInfo target) => this.Push(new MigrationRunScreen(target)); } } From 4bb0e6b7d53bca6188470600b5ca3d6d1b007e65 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Wed, 5 May 2021 22:13:25 +0200 Subject: [PATCH 2/8] Create InitialPath property. --- .../Sections/Maintenance/DirectorySelectScreen.cs | 5 +++++ .../Sections/Maintenance/MigrationSelectScreen.cs | 8 ++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs index 278c1ab20d..a6ae3d6132 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs @@ -34,6 +34,8 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance protected virtual bool IsValidDirectory(DirectoryInfo info) => info != null; + protected virtual DirectoryInfo InitialPath => null; + public override bool AllowExternalScreenChange => false; public override bool DisallowExternalBeatmapRulesetChanges => true; @@ -101,6 +103,9 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance protected override void LoadComplete() { + if (InitialPath != null) + DirectorySelector.CurrentPath.Value = InitialPath; + DirectorySelector.CurrentPath.BindValueChanged(e => selectionButton.Enabled.Value = IsValidDirectory(e.NewValue), true); base.LoadComplete(); } diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs index 1f14d0991d..cfbb7d6593 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs @@ -17,6 +17,8 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance [Resolved] private Storage storage { get; set; } + protected override DirectoryInfo InitialPath => new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent; + protected override OsuSpriteText CreateHeader() => new OsuSpriteText { Text = "Please select a new location", @@ -42,12 +44,6 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance BeginMigration(target); } - protected override void LoadComplete() - { - DirectorySelector.CurrentPath.Value = new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent; - base.LoadComplete(); - } - protected virtual void BeginMigration(DirectoryInfo target) => this.Push(new MigrationRunScreen(target)); } } From d3cc418961462f9961ba8551e18671c7046c92ed Mon Sep 17 00:00:00 2001 From: Lucas A Date: Thu, 6 May 2021 11:12:19 +0200 Subject: [PATCH 3/8] Privatize DirectorySelector. --- .../Sections/Maintenance/DirectorySelectScreen.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs index a6ae3d6132..c08323e67c 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs @@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance { private TriangleButton selectionButton; - protected DirectorySelector DirectorySelector { get; private set; } + private DirectorySelector directorySelector; protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.Disabled; @@ -79,7 +79,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance }, new Drawable[] { - DirectorySelector = new DirectorySelector + directorySelector = new DirectorySelector { RelativeSizeAxes = Axes.Both, } @@ -92,7 +92,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance Origin = Anchor.Centre, Width = 300, Text = "Select directory", - Action = () => OnSelection(DirectorySelector.CurrentPath.Value) + Action = () => OnSelection(directorySelector.CurrentPath.Value) }, } } @@ -104,9 +104,9 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance protected override void LoadComplete() { if (InitialPath != null) - DirectorySelector.CurrentPath.Value = InitialPath; + directorySelector.CurrentPath.Value = InitialPath; - DirectorySelector.CurrentPath.BindValueChanged(e => selectionButton.Enabled.Value = IsValidDirectory(e.NewValue), true); + directorySelector.CurrentPath.BindValueChanged(e => selectionButton.Enabled.Value = IsValidDirectory(e.NewValue), true); base.LoadComplete(); } From eee3cd7c5770c1e4e42383980ad9b8d65b6381e6 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Thu, 13 May 2021 11:14:05 +0200 Subject: [PATCH 4/8] Disallow selecting storage root as a valid directory. --- .../Settings/Sections/Maintenance/DirectorySelectScreen.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs index c08323e67c..582d14fbb6 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs @@ -32,7 +32,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance /// The selected directory protected abstract void OnSelection(DirectoryInfo directory); - protected virtual bool IsValidDirectory(DirectoryInfo info) => info != null; + protected virtual bool IsValidDirectory(DirectoryInfo info) => true; protected virtual DirectoryInfo InitialPath => null; @@ -106,7 +106,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance if (InitialPath != null) directorySelector.CurrentPath.Value = InitialPath; - directorySelector.CurrentPath.BindValueChanged(e => selectionButton.Enabled.Value = IsValidDirectory(e.NewValue), true); + directorySelector.CurrentPath.BindValueChanged(e => selectionButton.Enabled.Value = e.NewValue != null ? IsValidDirectory(e.NewValue) : false, true); base.LoadComplete(); } From 09a5b9c872eaee74470f9e3cbe9c3e789715e882 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Thu, 13 May 2021 16:28:03 +0200 Subject: [PATCH 5/8] Add XMLDoc to protected members. --- .../Sections/Maintenance/DirectorySelectScreen.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs index 582d14fbb6..c676e1391d 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs @@ -32,8 +32,16 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance /// The selected directory protected abstract void OnSelection(DirectoryInfo directory); + /// + /// Whether the current directory is considered to be valid and can be selected. + /// + /// The current directory. + /// Whether the selected directory is considered valid. protected virtual bool IsValidDirectory(DirectoryInfo info) => true; + /// + /// The path at which to start selection from. + /// protected virtual DirectoryInfo InitialPath => null; public override bool AllowExternalScreenChange => false; From 0caba57945ba161274132260772580b8f747e9d2 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Thu, 13 May 2021 19:28:23 +0200 Subject: [PATCH 6/8] Make screen properties local to MigrationSelectScreen. --- .../Settings/Sections/Maintenance/DirectorySelectScreen.cs | 6 ------ .../Settings/Sections/Maintenance/MigrationSelectScreen.cs | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs index c676e1391d..6e6df14a92 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs @@ -22,8 +22,6 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance private DirectorySelector directorySelector; - protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.Disabled; - protected abstract OsuSpriteText CreateHeader(); /// @@ -44,10 +42,6 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance /// protected virtual DirectoryInfo InitialPath => null; - public override bool AllowExternalScreenChange => false; - - public override bool DisallowExternalBeatmapRulesetChanges => true; - [BackgroundDependencyLoader] private void load(OsuColour colours) { diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs index cfbb7d6593..6334bffe94 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs @@ -19,6 +19,12 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance protected override DirectoryInfo InitialPath => new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent; + public override bool AllowExternalScreenChange => false; + + public override bool DisallowExternalBeatmapRulesetChanges => true; + + public override bool HideOverlaysOnEnter => true; + protected override OsuSpriteText CreateHeader() => new OsuSpriteText { Text = "Please select a new location", From 6f248db519146eace1face0eb55c96d4c6b3784c Mon Sep 17 00:00:00 2001 From: Lucas A Date: Thu, 13 May 2021 19:31:10 +0200 Subject: [PATCH 7/8] Merge conditional expression. --- .../Settings/Sections/Maintenance/DirectorySelectScreen.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs index 6e6df14a92..c2366ca209 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs @@ -108,7 +108,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance if (InitialPath != null) directorySelector.CurrentPath.Value = InitialPath; - directorySelector.CurrentPath.BindValueChanged(e => selectionButton.Enabled.Value = e.NewValue != null ? IsValidDirectory(e.NewValue) : false, true); + directorySelector.CurrentPath.BindValueChanged(e => selectionButton.Enabled.Value = e.NewValue != null && IsValidDirectory(e.NewValue), true); base.LoadComplete(); } From baa4089364f46eb59c1209dd94d2f2a78a2e718a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 17 May 2021 16:40:42 +0900 Subject: [PATCH 8/8] Expose method to adjust header text, not whole drawable --- .../Maintenance/DirectorySelectScreen.cs | 16 +++++++++++----- .../Maintenance/MigrationSelectScreen.cs | 9 ++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs index c2366ca209..e7c69e89fe 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs @@ -10,6 +10,7 @@ using osu.Game.Screens; using osuTK; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Localisation; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using osu.Framework.Screens; @@ -22,7 +23,10 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance private DirectorySelector directorySelector; - protected abstract OsuSpriteText CreateHeader(); + /// + /// Text to display in the header to inform the user of what they are selecting. + /// + public abstract LocalisableString HeaderText { get; } /// /// Called upon selection of a directory by the user. @@ -73,11 +77,13 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance { new Drawable[] { - CreateHeader().With(header => + new OsuSpriteText { - header.Origin = Anchor.Centre; - header.Anchor = Anchor.Centre; - }) + Text = HeaderText, + Font = OsuFont.Default.With(size: 40), + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + } }, new Drawable[] { diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs index 6334bffe94..1a60ab0638 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs @@ -4,11 +4,10 @@ using System; using System.IO; using osu.Framework.Allocation; +using osu.Framework.Localisation; using osu.Framework.Logging; using osu.Framework.Platform; using osu.Framework.Screens; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; namespace osu.Game.Overlays.Settings.Sections.Maintenance { @@ -25,11 +24,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance public override bool HideOverlaysOnEnter => true; - protected override OsuSpriteText CreateHeader() => new OsuSpriteText - { - Text = "Please select a new location", - Font = OsuFont.Default.With(size: 40) - }; + public override LocalisableString HeaderText => "Please select a new location"; protected override void OnSelection(DirectoryInfo directory) {