From f3f0960335303bcdc8a53a491fe02fd12580dff2 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 15 Jun 2022 09:02:48 +0300 Subject: [PATCH 1/9] Use unified filename for background and track during editor import --- .../Editing/TestSceneEditorBeatmapCreation.cs | 3 ++ .../Screens/Edit/Setup/ResourcesSection.cs | 29 +++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs index b109234fec..841f50e7bd 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs @@ -101,6 +101,9 @@ namespace osu.Game.Tests.Visual.Editing File.Delete(temp); Directory.Delete(extractedFolder, true); + // ensure audio file is copied to beatmap as "audio.mp3" rather than original filename. + Assert.That(Beatmap.Value.Metadata.AudioFile == "audio.mp3"); + return success; }); diff --git a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs index 1e97218074..9d4e72d1f3 100644 --- a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs +++ b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs @@ -64,26 +64,28 @@ namespace osu.Game.Screens.Edit.Setup public bool ChangeBackgroundImage(string path) { - var info = new FileInfo(path); + var source = new FileInfo(path); - if (!info.Exists) + if (!source.Exists) return false; var set = working.Value.BeatmapSetInfo; + var destination = new FileInfo($@"bg{source.Extension}"); + // remove the previous background for now. // in the future we probably want to check if this is being used elsewhere (other difficulties?) - var oldFile = set.Files.FirstOrDefault(f => f.Filename == working.Value.Metadata.BackgroundFile); + var oldFile = set.Files.FirstOrDefault(f => Path.GetFileNameWithoutExtension(f.Filename) == destination.Name); - using (var stream = info.OpenRead()) + using (var stream = source.OpenRead()) { if (oldFile != null) beatmaps.DeleteFile(set, oldFile); - beatmaps.AddFile(set, stream, info.Name); + beatmaps.AddFile(set, stream, destination.Name); } - working.Value.Metadata.BackgroundFile = info.Name; + working.Value.Metadata.BackgroundFile = destination.Name; header.Background.UpdateBackground(); return true; @@ -91,25 +93,28 @@ namespace osu.Game.Screens.Edit.Setup public bool ChangeAudioTrack(string path) { - var info = new FileInfo(path); + var source = new FileInfo(path); - if (!info.Exists) + if (!source.Exists) return false; var set = working.Value.BeatmapSetInfo; + var destination = new FileInfo($@"audio{source.Extension}"); + // remove the previous audio track for now. // in the future we probably want to check if this is being used elsewhere (other difficulties?) - var oldFile = set.Files.FirstOrDefault(f => f.Filename == working.Value.Metadata.AudioFile); + var oldFile = set.Files.FirstOrDefault(f => Path.GetFileNameWithoutExtension(f.Filename) == destination.Name); - using (var stream = info.OpenRead()) + using (var stream = source.OpenRead()) { if (oldFile != null) beatmaps.DeleteFile(set, oldFile); - beatmaps.AddFile(set, stream, info.Name); + + beatmaps.AddFile(set, stream, destination.Name); } - working.Value.Metadata.AudioFile = info.Name; + working.Value.Metadata.AudioFile = destination.Name; music.ReloadCurrentTrack(); From 6a8cf514e0f18291d6d136db3f565dadf31740d1 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 15 Jun 2022 09:52:12 +0300 Subject: [PATCH 2/9] Update background/track file chooser to not display filename --- .../UserInterfaceV2/LabelledComponent.cs | 2 +- ...elledTextBox.cs => LabelledFileChooser.cs} | 15 +++++--- .../Screens/Edit/Setup/ResourcesSection.cs | 37 ++++++++++++------- 3 files changed, 35 insertions(+), 19 deletions(-) rename osu.Game/Screens/Edit/Setup/{FileChooserLabelledTextBox.cs => LabelledFileChooser.cs} (86%) diff --git a/osu.Game/Graphics/UserInterfaceV2/LabelledComponent.cs b/osu.Game/Graphics/UserInterfaceV2/LabelledComponent.cs index dd6a902989..77267e453c 100644 --- a/osu.Game/Graphics/UserInterfaceV2/LabelledComponent.cs +++ b/osu.Game/Graphics/UserInterfaceV2/LabelledComponent.cs @@ -15,7 +15,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 { } - public Bindable Current + public virtual Bindable Current { get => Component.Current; set => Component.Current = value; diff --git a/osu.Game/Screens/Edit/Setup/FileChooserLabelledTextBox.cs b/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs similarity index 86% rename from osu.Game/Screens/Edit/Setup/FileChooserLabelledTextBox.cs rename to osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs index fd916894ea..745c989b3b 100644 --- a/osu.Game/Screens/Edit/Setup/FileChooserLabelledTextBox.cs +++ b/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs @@ -21,10 +21,7 @@ using osuTK; namespace osu.Game.Screens.Edit.Setup { - /// - /// A labelled textbox which reveals an inline file chooser when clicked. - /// - internal class FileChooserLabelledTextBox : LabelledTextBoxWithPopover, ICanAcceptFiles + internal class LabelledFileChooser : LabelledTextBoxWithPopover, ICanAcceptFiles { private readonly string[] handledExtensions; @@ -35,7 +32,15 @@ namespace osu.Game.Screens.Edit.Setup [Resolved] private OsuGameBase game { get; set; } = null!; - public FileChooserLabelledTextBox(params string[] handledExtensions) + private readonly BindableWithCurrent current = new BindableWithCurrent(); + + public override Bindable Current + { + get => current.Current; + set => current.Current = value; + } + + public LabelledFileChooser(params string[] handledExtensions) { this.handledExtensions = handledExtensions; } diff --git a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs index 9d4e72d1f3..36edb5dd83 100644 --- a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs +++ b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs @@ -8,15 +8,14 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Localisation; using osu.Game.Beatmaps; -using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Overlays; namespace osu.Game.Screens.Edit.Setup { internal class ResourcesSection : SetupSection { - private LabelledTextBox audioTrackTextBox; - private LabelledTextBox backgroundTextBox; + private LabelledFileChooser audioTrackChooser; + private LabelledFileChooser backgroundChooser; public override LocalisableString Title => "Resources"; @@ -40,26 +39,24 @@ namespace osu.Game.Screens.Edit.Setup { Children = new Drawable[] { - backgroundTextBox = new FileChooserLabelledTextBox(".jpg", ".jpeg", ".png") + backgroundChooser = new LabelledFileChooser(".jpg", ".jpeg", ".png") { Label = "Background", FixedLabelWidth = LABEL_WIDTH, - PlaceholderText = "Click to select a background image", Current = { Value = working.Value.Metadata.BackgroundFile }, TabbableContentContainer = this }, - audioTrackTextBox = new FileChooserLabelledTextBox(".mp3", ".ogg") + audioTrackChooser = new LabelledFileChooser(".mp3", ".ogg") { Label = "Audio Track", FixedLabelWidth = LABEL_WIDTH, - PlaceholderText = "Click to select a track", Current = { Value = working.Value.Metadata.AudioFile }, TabbableContentContainer = this }, }; - backgroundTextBox.Current.BindValueChanged(backgroundChanged); - audioTrackTextBox.Current.BindValueChanged(audioTrackChanged); + backgroundChooser.Current.BindValueChanged(backgroundChanged, true); + audioTrackChooser.Current.BindValueChanged(audioTrackChanged, true); } public bool ChangeBackgroundImage(string path) @@ -124,14 +121,28 @@ namespace osu.Game.Screens.Edit.Setup private void backgroundChanged(ValueChangedEvent filePath) { - if (!ChangeBackgroundImage(filePath.NewValue)) - backgroundTextBox.Current.Value = filePath.OldValue; + backgroundChooser.PlaceholderText = string.IsNullOrEmpty(filePath.NewValue) + ? "Click to select a background image" + : "Click to replace the background image"; + + if (filePath.NewValue != filePath.OldValue) + { + if (!ChangeBackgroundImage(filePath.NewValue)) + backgroundChooser.Current.Value = filePath.OldValue; + } } private void audioTrackChanged(ValueChangedEvent filePath) { - if (!ChangeAudioTrack(filePath.NewValue)) - audioTrackTextBox.Current.Value = filePath.OldValue; + audioTrackChooser.PlaceholderText = string.IsNullOrEmpty(filePath.NewValue) + ? "Click to select a track" + : "Click to replace the track"; + + if (filePath.NewValue != filePath.OldValue) + { + if (!ChangeAudioTrack(filePath.NewValue)) + audioTrackChooser.Current.Value = filePath.OldValue; + } } } } From 1ff070f5ff3722ee464c1196f987f678b725aa21 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 15 Jun 2022 17:45:31 +0300 Subject: [PATCH 3/9] Decouple `LabelledFileChooser` from `LabelledTextBoxWithPopover` --- .../Screens/Edit/Setup/LabelledFileChooser.cs | 33 +++++++++++++++++-- .../Screens/Edit/Setup/ResourcesSection.cs | 4 +-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs b/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs index 745c989b3b..2cb3af61c8 100644 --- a/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs +++ b/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs @@ -14,14 +14,20 @@ using osu.Framework.Extensions; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.UserInterface; +using osu.Framework.Localisation; using osu.Game.Database; using osu.Game.Graphics.UserInterfaceV2; using osuTK; namespace osu.Game.Screens.Edit.Setup { - internal class LabelledFileChooser : LabelledTextBoxWithPopover, ICanAcceptFiles + /// + /// A labelled drawable displaying file chooser on click, with placeholder text support. + /// todo: this should probably not use PopoverTextBox just to display placeholder text, but is the best way for now. + /// + internal class LabelledFileChooser : LabelledDrawable, IHasCurrentValue, ICanAcceptFiles, IHasPopover { private readonly string[] handledExtensions; @@ -34,13 +40,25 @@ namespace osu.Game.Screens.Edit.Setup private readonly BindableWithCurrent current = new BindableWithCurrent(); - public override Bindable Current + public Bindable Current { get => current.Current; set => current.Current = value; } + public LocalisableString Text + { + get => Component.PlaceholderText; + set => Component.PlaceholderText = value; + } + + public CompositeDrawable TabbableContentContainer + { + set => Component.TabbableContentContainer = value; + } + public LabelledFileChooser(params string[] handledExtensions) + : base(false) { this.handledExtensions = handledExtensions; } @@ -78,7 +96,16 @@ namespace osu.Game.Screens.Edit.Setup game.UnregisterImportHandler(this); } - public override Popover GetPopover() => new FileChooserPopover(handledExtensions, currentFile); + protected override LabelledTextBoxWithPopover.PopoverTextBox CreateComponent() => new LabelledTextBoxWithPopover.PopoverTextBox + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + CornerRadius = CORNER_RADIUS, + OnFocused = this.ShowPopover, + }; + + public Popover GetPopover() => new FileChooserPopover(handledExtensions, currentFile); private class FileChooserPopover : OsuPopover { diff --git a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs index 36edb5dd83..b4e350b94b 100644 --- a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs +++ b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs @@ -121,7 +121,7 @@ namespace osu.Game.Screens.Edit.Setup private void backgroundChanged(ValueChangedEvent filePath) { - backgroundChooser.PlaceholderText = string.IsNullOrEmpty(filePath.NewValue) + backgroundChooser.Text = string.IsNullOrEmpty(filePath.NewValue) ? "Click to select a background image" : "Click to replace the background image"; @@ -134,7 +134,7 @@ namespace osu.Game.Screens.Edit.Setup private void audioTrackChanged(ValueChangedEvent filePath) { - audioTrackChooser.PlaceholderText = string.IsNullOrEmpty(filePath.NewValue) + audioTrackChooser.Text = string.IsNullOrEmpty(filePath.NewValue) ? "Click to select a track" : "Click to replace the track"; From 5d74d92fcf030d6c98fb8941ea3159914b09a6dd Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 15 Jun 2022 19:28:43 +0300 Subject: [PATCH 4/9] Revert `virtual` current bindable --- osu.Game/Graphics/UserInterfaceV2/LabelledComponent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterfaceV2/LabelledComponent.cs b/osu.Game/Graphics/UserInterfaceV2/LabelledComponent.cs index 77267e453c..dd6a902989 100644 --- a/osu.Game/Graphics/UserInterfaceV2/LabelledComponent.cs +++ b/osu.Game/Graphics/UserInterfaceV2/LabelledComponent.cs @@ -15,7 +15,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 { } - public virtual Bindable Current + public Bindable Current { get => Component.Current; set => Component.Current = value; From 2c35b1404b877767e2c39ac6218a05c3e6b1572c Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 15 Jun 2022 19:29:09 +0300 Subject: [PATCH 5/9] Use `FileInfo` as current bindable type --- .../Editing/TestSceneEditorBeatmapCreation.cs | 2 +- .../Screens/Edit/Setup/LabelledFileChooser.cs | 21 +++++------ .../Screens/Edit/Setup/ResourcesSection.cs | 36 +++++++++---------- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs index 841f50e7bd..6bcd947f2f 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorBeatmapCreation.cs @@ -96,7 +96,7 @@ namespace osu.Game.Tests.Visual.Editing using (var zip = ZipArchive.Open(temp)) zip.WriteToDirectory(extractedFolder); - bool success = setup.ChildrenOfType().First().ChangeAudioTrack(Path.Combine(extractedFolder, "03. Renatus - Soleily 192kbps.mp3")); + bool success = setup.ChildrenOfType().First().ChangeAudioTrack(new FileInfo(Path.Combine(extractedFolder, "03. Renatus - Soleily 192kbps.mp3"))); File.Delete(temp); Directory.Delete(extractedFolder, true); diff --git a/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs b/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs index 2cb3af61c8..6c56320666 100644 --- a/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs +++ b/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs @@ -27,20 +27,18 @@ namespace osu.Game.Screens.Edit.Setup /// A labelled drawable displaying file chooser on click, with placeholder text support. /// todo: this should probably not use PopoverTextBox just to display placeholder text, but is the best way for now. /// - internal class LabelledFileChooser : LabelledDrawable, IHasCurrentValue, ICanAcceptFiles, IHasPopover + internal class LabelledFileChooser : LabelledDrawable, IHasCurrentValue, ICanAcceptFiles, IHasPopover { private readonly string[] handledExtensions; public IEnumerable HandledExtensions => handledExtensions; - private readonly Bindable currentFile = new Bindable(); - [Resolved] private OsuGameBase game { get; set; } = null!; - private readonly BindableWithCurrent current = new BindableWithCurrent(); + private readonly BindableWithCurrent current = new BindableWithCurrent(); - public Bindable Current + public Bindable Current { get => current.Current; set => current.Current = value; @@ -68,21 +66,18 @@ namespace osu.Game.Screens.Edit.Setup base.LoadComplete(); game.RegisterImportHandler(this); - currentFile.BindValueChanged(onFileSelected); + Current.BindValueChanged(onFileSelected); } private void onFileSelected(ValueChangedEvent file) { - if (file.NewValue == null) - return; - - this.HidePopover(); - Current.Value = file.NewValue.FullName; + if (file.NewValue != null) + this.HidePopover(); } Task ICanAcceptFiles.Import(params string[] paths) { - Schedule(() => currentFile.Value = new FileInfo(paths.First())); + Schedule(() => Current.Value = new FileInfo(paths.First())); return Task.CompletedTask; } @@ -105,7 +100,7 @@ namespace osu.Game.Screens.Edit.Setup OnFocused = this.ShowPopover, }; - public Popover GetPopover() => new FileChooserPopover(handledExtensions, currentFile); + public Popover GetPopover() => new FileChooserPopover(handledExtensions, Current); private class FileChooserPopover : OsuPopover { diff --git a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs index b4e350b94b..2471886d9b 100644 --- a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs +++ b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs @@ -43,26 +43,28 @@ namespace osu.Game.Screens.Edit.Setup { Label = "Background", FixedLabelWidth = LABEL_WIDTH, - Current = { Value = working.Value.Metadata.BackgroundFile }, TabbableContentContainer = this }, audioTrackChooser = new LabelledFileChooser(".mp3", ".ogg") { Label = "Audio Track", FixedLabelWidth = LABEL_WIDTH, - Current = { Value = working.Value.Metadata.AudioFile }, TabbableContentContainer = this }, }; + if (!string.IsNullOrEmpty(working.Value.Metadata.BackgroundFile)) + backgroundChooser.Current.Value = new FileInfo(working.Value.Metadata.BackgroundFile); + + if (!string.IsNullOrEmpty(working.Value.Metadata.AudioFile)) + audioTrackChooser.Current.Value = new FileInfo(working.Value.Metadata.AudioFile); + backgroundChooser.Current.BindValueChanged(backgroundChanged, true); audioTrackChooser.Current.BindValueChanged(audioTrackChanged, true); } - public bool ChangeBackgroundImage(string path) + public bool ChangeBackgroundImage(FileInfo source) { - var source = new FileInfo(path); - if (!source.Exists) return false; @@ -88,10 +90,8 @@ namespace osu.Game.Screens.Edit.Setup return true; } - public bool ChangeAudioTrack(string path) + public bool ChangeAudioTrack(FileInfo source) { - var source = new FileInfo(path); - if (!source.Exists) return false; @@ -119,29 +119,29 @@ namespace osu.Game.Screens.Edit.Setup return true; } - private void backgroundChanged(ValueChangedEvent filePath) + private void backgroundChanged(ValueChangedEvent file) { - backgroundChooser.Text = string.IsNullOrEmpty(filePath.NewValue) + backgroundChooser.Text = file.NewValue == null ? "Click to select a background image" : "Click to replace the background image"; - if (filePath.NewValue != filePath.OldValue) + if (file.NewValue != file.OldValue) { - if (!ChangeBackgroundImage(filePath.NewValue)) - backgroundChooser.Current.Value = filePath.OldValue; + if (!ChangeBackgroundImage(file.NewValue)) + backgroundChooser.Current.Value = file.OldValue; } } - private void audioTrackChanged(ValueChangedEvent filePath) + private void audioTrackChanged(ValueChangedEvent file) { - audioTrackChooser.Text = string.IsNullOrEmpty(filePath.NewValue) + audioTrackChooser.Text = file.NewValue == null ? "Click to select a track" : "Click to replace the track"; - if (filePath.NewValue != filePath.OldValue) + if (file.NewValue != file.OldValue) { - if (!ChangeAudioTrack(filePath.NewValue)) - audioTrackChooser.Current.Value = filePath.OldValue; + if (!ChangeAudioTrack(file.NewValue)) + audioTrackChooser.Current.Value = file.OldValue; } } } From f1081db953887ba597675c772772d5a8ca94acff Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 16 Jun 2022 18:48:32 +0300 Subject: [PATCH 6/9] Fix background/track implicitly renamed on initial load --- .../Screens/Edit/Setup/ResourcesSection.cs | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs index 2471886d9b..5054f7a393 100644 --- a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs +++ b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs @@ -59,8 +59,10 @@ namespace osu.Game.Screens.Edit.Setup if (!string.IsNullOrEmpty(working.Value.Metadata.AudioFile)) audioTrackChooser.Current.Value = new FileInfo(working.Value.Metadata.AudioFile); - backgroundChooser.Current.BindValueChanged(backgroundChanged, true); - audioTrackChooser.Current.BindValueChanged(audioTrackChanged, true); + backgroundChooser.Current.BindValueChanged(backgroundChanged); + audioTrackChooser.Current.BindValueChanged(audioTrackChanged); + + updatePlaceholderText(); } public bool ChangeBackgroundImage(FileInfo source) @@ -121,28 +123,29 @@ namespace osu.Game.Screens.Edit.Setup private void backgroundChanged(ValueChangedEvent file) { - backgroundChooser.Text = file.NewValue == null - ? "Click to select a background image" - : "Click to replace the background image"; + if (!ChangeBackgroundImage(file.NewValue)) + backgroundChooser.Current.Value = file.OldValue; - if (file.NewValue != file.OldValue) - { - if (!ChangeBackgroundImage(file.NewValue)) - backgroundChooser.Current.Value = file.OldValue; - } + updatePlaceholderText(); } private void audioTrackChanged(ValueChangedEvent file) { - audioTrackChooser.Text = file.NewValue == null + if (!ChangeAudioTrack(file.NewValue)) + audioTrackChooser.Current.Value = file.OldValue; + + updatePlaceholderText(); + } + + private void updatePlaceholderText() + { + audioTrackChooser.Text = audioTrackChooser.Current.Value == null ? "Click to select a track" : "Click to replace the track"; - if (file.NewValue != file.OldValue) - { - if (!ChangeAudioTrack(file.NewValue)) - audioTrackChooser.Current.Value = file.OldValue; - } + backgroundChooser.Text = backgroundChooser.Current.Value == null + ? "Click to select a background image" + : "Click to replace the background image"; } } } From 6aee6895863be43435e648161c0c3e831cae5507 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 16 Jun 2022 18:50:28 +0300 Subject: [PATCH 7/9] Fix previous file lookup not using metadata properties --- osu.Game/Screens/Edit/Setup/ResourcesSection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs index 5054f7a393..1a37f539e8 100644 --- a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs +++ b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs @@ -76,7 +76,7 @@ namespace osu.Game.Screens.Edit.Setup // remove the previous background for now. // in the future we probably want to check if this is being used elsewhere (other difficulties?) - var oldFile = set.Files.FirstOrDefault(f => Path.GetFileNameWithoutExtension(f.Filename) == destination.Name); + var oldFile = set.Files.FirstOrDefault(f => f.Filename == working.Value.Metadata.BackgroundFile); using (var stream = source.OpenRead()) { @@ -103,7 +103,7 @@ namespace osu.Game.Screens.Edit.Setup // remove the previous audio track for now. // in the future we probably want to check if this is being used elsewhere (other difficulties?) - var oldFile = set.Files.FirstOrDefault(f => Path.GetFileNameWithoutExtension(f.Filename) == destination.Name); + var oldFile = set.Files.FirstOrDefault(f => f.Filename == working.Value.Metadata.AudioFile); using (var stream = source.OpenRead()) { From db02cb81c5aac24b82f08986d8c43a28ad24d208 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 16 Jun 2022 20:48:17 +0300 Subject: [PATCH 8/9] Fix file chooser path not opening home directory initially --- osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs b/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs index 6c56320666..ab83c2a2e4 100644 --- a/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs +++ b/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs @@ -36,6 +36,8 @@ namespace osu.Game.Screens.Edit.Setup [Resolved] private OsuGameBase game { get; set; } = null!; + private string? chooserPath; + private readonly BindableWithCurrent current = new BindableWithCurrent(); public Bindable Current @@ -73,6 +75,8 @@ namespace osu.Game.Screens.Edit.Setup { if (file.NewValue != null) this.HidePopover(); + + chooserPath = file.NewValue?.DirectoryName; } Task ICanAcceptFiles.Import(params string[] paths) @@ -100,16 +104,16 @@ namespace osu.Game.Screens.Edit.Setup OnFocused = this.ShowPopover, }; - public Popover GetPopover() => new FileChooserPopover(handledExtensions, Current); + public Popover GetPopover() => new FileChooserPopover(handledExtensions, Current, chooserPath); private class FileChooserPopover : OsuPopover { - public FileChooserPopover(string[] handledExtensions, Bindable currentFile) + public FileChooserPopover(string[] handledExtensions, Bindable currentFile, string? chooserPath) { Child = new Container { Size = new Vector2(600, 400), - Child = new OsuFileSelector(currentFile.Value?.DirectoryName, handledExtensions) + Child = new OsuFileSelector(chooserPath, handledExtensions) { RelativeSizeAxes = Axes.Both, CurrentFile = { BindTarget = currentFile } From 6ff6a3f5b3395e32288bc04bab964410eb260dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 16 Jun 2022 21:51:31 +0200 Subject: [PATCH 9/9] Rename and document `chooserPath` --- osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs b/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs index ab83c2a2e4..5a2ac7424c 100644 --- a/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs +++ b/osu.Game/Screens/Edit/Setup/LabelledFileChooser.cs @@ -17,6 +17,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.UserInterface; using osu.Framework.Localisation; +using osu.Framework.Platform; using osu.Game.Database; using osu.Game.Graphics.UserInterfaceV2; using osuTK; @@ -36,7 +37,14 @@ namespace osu.Game.Screens.Edit.Setup [Resolved] private OsuGameBase game { get; set; } = null!; - private string? chooserPath; + /// + /// The initial path to use when displaying the . + /// + /// + /// Uses a value before the first selection is made + /// to ensure that the first selection starts at . + /// + private string? initialChooserPath; private readonly BindableWithCurrent current = new BindableWithCurrent(); @@ -76,7 +84,7 @@ namespace osu.Game.Screens.Edit.Setup if (file.NewValue != null) this.HidePopover(); - chooserPath = file.NewValue?.DirectoryName; + initialChooserPath = file.NewValue?.DirectoryName; } Task ICanAcceptFiles.Import(params string[] paths) @@ -104,7 +112,7 @@ namespace osu.Game.Screens.Edit.Setup OnFocused = this.ShowPopover, }; - public Popover GetPopover() => new FileChooserPopover(handledExtensions, Current, chooserPath); + public Popover GetPopover() => new FileChooserPopover(handledExtensions, Current, initialChooserPath); private class FileChooserPopover : OsuPopover {