From 5f617e6697aa6e2e4f8be7e411612725a364cc0a Mon Sep 17 00:00:00 2001 From: jkh675 Date: Sat, 21 Dec 2024 20:31:12 +0800 Subject: [PATCH 1/5] Implement rename skin popover and button --- osu.Game/Localisation/SkinSettingsStrings.cs | 5 + .../Overlays/Settings/Sections/SkinSection.cs | 96 +++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/osu.Game/Localisation/SkinSettingsStrings.cs b/osu.Game/Localisation/SkinSettingsStrings.cs index 4b6b0ce1d6..1a812ad04d 100644 --- a/osu.Game/Localisation/SkinSettingsStrings.cs +++ b/osu.Game/Localisation/SkinSettingsStrings.cs @@ -54,6 +54,11 @@ namespace osu.Game.Localisation /// public static LocalisableString BeatmapHitsounds => new TranslatableString(getKey(@"beatmap_hitsounds"), @"Beatmap hitsounds"); + /// + /// "Rename selected skin" + /// + public static LocalisableString RenameSkinButton = new TranslatableString(getKey(@"rename_skin_button"), @"Rename selected skin"); + /// /// "Export selected skin" /// diff --git a/osu.Game/Overlays/Settings/Sections/SkinSection.cs b/osu.Game/Overlays/Settings/Sections/SkinSection.cs index 9b04f208a7..c015affcd2 100644 --- a/osu.Game/Overlays/Settings/Sections/SkinSection.cs +++ b/osu.Game/Overlays/Settings/Sections/SkinSection.cs @@ -9,17 +9,23 @@ using System.Linq; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; +using osu.Framework.Extensions; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; using osu.Framework.Localisation; using osu.Framework.Logging; using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; +using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Localisation; using osu.Game.Overlays.SkinEditor; using osu.Game.Screens.Select; using osu.Game.Skinning; +using osuTK; using Realms; namespace osu.Game.Overlays.Settings.Sections @@ -69,6 +75,7 @@ namespace osu.Game.Overlays.Settings.Sections Text = SkinSettingsStrings.SkinLayoutEditor, Action = () => skinEditor?.ToggleVisibility(), }, + new RenameSkinButton(), new ExportSkinButton(), new DeleteSkinButton(), }; @@ -136,6 +143,95 @@ namespace osu.Game.Overlays.Settings.Sections } } + public partial class RenameSkinButton : SettingsButton, IHasPopover + { + [Resolved] + private SkinManager skins { get; set; } + + private Bindable currentSkin; + + [BackgroundDependencyLoader] + private void load() + { + Text = SkinSettingsStrings.RenameSkinButton; + Action = this.ShowPopover; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + currentSkin = skins.CurrentSkin.GetBoundCopy(); + currentSkin.BindValueChanged(skin => Enabled.Value = skin.NewValue.SkinInfo.PerformRead(s => !s.Protected), true); + } + + public Popover GetPopover() + { + return new RenameSkinPopover(); + } + + public partial class RenameSkinPopover : OsuPopover + { + [Resolved] + private SkinManager skins { get; set; } + + public Action Rename { get; init; } + + private readonly FocusedTextBox textBox; + private readonly RoundedButton renameButton; + + public RenameSkinPopover() + { + AutoSizeAxes = Axes.Both; + Origin = Anchor.TopCentre; + + Child = new FillFlowContainer + { + Direction = FillDirection.Vertical, + AutoSizeAxes = Axes.Y, + Width = 250, + Spacing = new Vector2(10f), + Children = new Drawable[] + { + textBox = new FocusedTextBox + { + PlaceholderText = @"Skin name", + FontSize = OsuFont.DEFAULT_FONT_SIZE, + RelativeSizeAxes = Axes.X, + }, + renameButton = new RoundedButton + { + Height = 40, + RelativeSizeAxes = Axes.X, + MatchingFilter = true, + Text = SkinSettingsStrings.RenameSkinButton, + } + } + }; + + renameButton.Action += rename; + textBox.OnCommit += delegate (TextBox _, bool _) { rename(); }; + } + + protected override void PopIn() + { + textBox.Text = skins.CurrentSkinInfo.Value.Value.Name; + textBox.TakeFocus(); + base.PopIn(); + } + + private void rename() + { + skins.CurrentSkinInfo.Value.PerformWrite(skin => + { + skin.Name = textBox.Text; + PopOut(); + }); + } + } + } + + public partial class ExportSkinButton : SettingsButton { [Resolved] From 9a0d9641ab9d608713f2a3588a2c571c8b7b2aa2 Mon Sep 17 00:00:00 2001 From: jkh675 Date: Sat, 21 Dec 2024 21:26:56 +0800 Subject: [PATCH 2/5] Select all on focus when popover just open --- osu.Game/Overlays/Settings/Sections/SkinSection.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/SkinSection.cs b/osu.Game/Overlays/Settings/Sections/SkinSection.cs index c015affcd2..5ff8c88756 100644 --- a/osu.Game/Overlays/Settings/Sections/SkinSection.cs +++ b/osu.Game/Overlays/Settings/Sections/SkinSection.cs @@ -178,13 +178,14 @@ namespace osu.Game.Overlays.Settings.Sections public Action Rename { get; init; } private readonly FocusedTextBox textBox; - private readonly RoundedButton renameButton; public RenameSkinPopover() { AutoSizeAxes = Axes.Both; Origin = Anchor.TopCentre; + RoundedButton renameButton; + Child = new FillFlowContainer { Direction = FillDirection.Vertical, @@ -198,6 +199,7 @@ namespace osu.Game.Overlays.Settings.Sections PlaceholderText = @"Skin name", FontSize = OsuFont.DEFAULT_FONT_SIZE, RelativeSizeAxes = Axes.X, + SelectAllOnFocus = true, }, renameButton = new RoundedButton { @@ -231,7 +233,6 @@ namespace osu.Game.Overlays.Settings.Sections } } - public partial class ExportSkinButton : SettingsButton { [Resolved] From ae7f1a9ef104d8f18d1f1d24c8fe822e5b95bda0 Mon Sep 17 00:00:00 2001 From: jkh675 Date: Sat, 21 Dec 2024 22:27:21 +0800 Subject: [PATCH 3/5] Fix code quality --- osu.Game/Overlays/Settings/Sections/SkinSection.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Settings/Sections/SkinSection.cs b/osu.Game/Overlays/Settings/Sections/SkinSection.cs index 5ff8c88756..1792c61d48 100644 --- a/osu.Game/Overlays/Settings/Sections/SkinSection.cs +++ b/osu.Game/Overlays/Settings/Sections/SkinSection.cs @@ -212,7 +212,13 @@ namespace osu.Game.Overlays.Settings.Sections }; renameButton.Action += rename; - textBox.OnCommit += delegate (TextBox _, bool _) { rename(); }; + + void onTextboxCommit(TextBox sender, bool newText) + { + rename(); + } + + textBox.OnCommit += onTextboxCommit; } protected override void PopIn() From ae9c7e1b354c43fc606a75031514ea56ec648723 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 24 Dec 2024 13:17:58 +0900 Subject: [PATCH 4/5] Adjust layout and remove localisable strings for temporary buttons --- osu.Game/Localisation/SkinSettingsStrings.cs | 15 -- .../Overlays/Settings/Sections/SkinSection.cs | 150 +++++++++--------- 2 files changed, 76 insertions(+), 89 deletions(-) diff --git a/osu.Game/Localisation/SkinSettingsStrings.cs b/osu.Game/Localisation/SkinSettingsStrings.cs index 1a812ad04d..16dca7fd87 100644 --- a/osu.Game/Localisation/SkinSettingsStrings.cs +++ b/osu.Game/Localisation/SkinSettingsStrings.cs @@ -54,21 +54,6 @@ namespace osu.Game.Localisation /// public static LocalisableString BeatmapHitsounds => new TranslatableString(getKey(@"beatmap_hitsounds"), @"Beatmap hitsounds"); - /// - /// "Rename selected skin" - /// - public static LocalisableString RenameSkinButton = new TranslatableString(getKey(@"rename_skin_button"), @"Rename selected skin"); - - /// - /// "Export selected skin" - /// - public static LocalisableString ExportSkinButton => new TranslatableString(getKey(@"export_skin_button"), @"Export selected skin"); - - /// - /// "Delete selected skin" - /// - public static LocalisableString DeleteSkinButton => new TranslatableString(getKey(@"delete_skin_button"), @"Delete selected skin"); - private static string getKey(string key) => $"{prefix}:{key}"; } } diff --git a/osu.Game/Overlays/Settings/Sections/SkinSection.cs b/osu.Game/Overlays/Settings/Sections/SkinSection.cs index 1792c61d48..7fffd3693c 100644 --- a/osu.Game/Overlays/Settings/Sections/SkinSection.cs +++ b/osu.Game/Overlays/Settings/Sections/SkinSection.cs @@ -75,9 +75,21 @@ namespace osu.Game.Overlays.Settings.Sections Text = SkinSettingsStrings.SkinLayoutEditor, Action = () => skinEditor?.ToggleVisibility(), }, - new RenameSkinButton(), - new ExportSkinButton(), - new DeleteSkinButton(), + new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(5, 0), + Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS, Right = SettingsPanel.CONTENT_MARGINS }, + Children = new Drawable[] + { + // This is all super-temporary until we move skin settings to their own panel / overlay. + new RenameSkinButton { Padding = new MarginPadding(), RelativeSizeAxes = Axes.None, Width = 120 }, + new ExportSkinButton { Padding = new MarginPadding(), RelativeSizeAxes = Axes.None, Width = 120 }, + new DeleteSkinButton { Padding = new MarginPadding(), RelativeSizeAxes = Axes.None, Width = 110 }, + } + }, }; } @@ -153,7 +165,7 @@ namespace osu.Game.Overlays.Settings.Sections [BackgroundDependencyLoader] private void load() { - Text = SkinSettingsStrings.RenameSkinButton; + Text = "Rename"; Action = this.ShowPopover; } @@ -169,74 +181,6 @@ namespace osu.Game.Overlays.Settings.Sections { return new RenameSkinPopover(); } - - public partial class RenameSkinPopover : OsuPopover - { - [Resolved] - private SkinManager skins { get; set; } - - public Action Rename { get; init; } - - private readonly FocusedTextBox textBox; - - public RenameSkinPopover() - { - AutoSizeAxes = Axes.Both; - Origin = Anchor.TopCentre; - - RoundedButton renameButton; - - Child = new FillFlowContainer - { - Direction = FillDirection.Vertical, - AutoSizeAxes = Axes.Y, - Width = 250, - Spacing = new Vector2(10f), - Children = new Drawable[] - { - textBox = new FocusedTextBox - { - PlaceholderText = @"Skin name", - FontSize = OsuFont.DEFAULT_FONT_SIZE, - RelativeSizeAxes = Axes.X, - SelectAllOnFocus = true, - }, - renameButton = new RoundedButton - { - Height = 40, - RelativeSizeAxes = Axes.X, - MatchingFilter = true, - Text = SkinSettingsStrings.RenameSkinButton, - } - } - }; - - renameButton.Action += rename; - - void onTextboxCommit(TextBox sender, bool newText) - { - rename(); - } - - textBox.OnCommit += onTextboxCommit; - } - - protected override void PopIn() - { - textBox.Text = skins.CurrentSkinInfo.Value.Value.Name; - textBox.TakeFocus(); - base.PopIn(); - } - - private void rename() - { - skins.CurrentSkinInfo.Value.PerformWrite(skin => - { - skin.Name = textBox.Text; - PopOut(); - }); - } - } } public partial class ExportSkinButton : SettingsButton @@ -249,7 +193,7 @@ namespace osu.Game.Overlays.Settings.Sections [BackgroundDependencyLoader] private void load() { - Text = SkinSettingsStrings.ExportSkinButton; + Text = "Export"; Action = export; } @@ -287,7 +231,7 @@ namespace osu.Game.Overlays.Settings.Sections [BackgroundDependencyLoader] private void load() { - Text = SkinSettingsStrings.DeleteSkinButton; + Text = "Delete"; Action = delete; } @@ -304,5 +248,63 @@ namespace osu.Game.Overlays.Settings.Sections dialogOverlay?.Push(new SkinDeleteDialog(currentSkin.Value)); } } + + public partial class RenameSkinPopover : OsuPopover + { + [Resolved] + private SkinManager skins { get; set; } + + private readonly FocusedTextBox textBox; + + public RenameSkinPopover() + { + AutoSizeAxes = Axes.Both; + Origin = Anchor.TopCentre; + + RoundedButton renameButton; + + Child = new FillFlowContainer + { + Direction = FillDirection.Vertical, + AutoSizeAxes = Axes.Y, + Width = 250, + Spacing = new Vector2(10f), + Children = new Drawable[] + { + textBox = new FocusedTextBox + { + PlaceholderText = @"Skin name", + FontSize = OsuFont.DEFAULT_FONT_SIZE, + RelativeSizeAxes = Axes.X, + SelectAllOnFocus = true, + }, + renameButton = new RoundedButton + { + Height = 40, + RelativeSizeAxes = Axes.X, + MatchingFilter = true, + Text = "Save", + } + } + }; + + renameButton.Action += rename; + textBox.OnCommit += (_, _) => rename(); + } + + protected override void PopIn() + { + textBox.Text = skins.CurrentSkinInfo.Value.Value.Name; + textBox.TakeFocus(); + + base.PopIn(); + } + + private void rename() => skins.CurrentSkinInfo.Value.PerformWrite(skin => + { + skin.Name = textBox.Text; + PopOut(); + }); + } } } From 378bef34efab9980bbb6de9d62726a3349ae3a6c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 24 Dec 2024 13:42:18 +0900 Subject: [PATCH 5/5] Change order of skin layout editor button for better visual balance --- osu.Game/Overlays/Settings/Sections/SkinSection.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/SkinSection.cs b/osu.Game/Overlays/Settings/Sections/SkinSection.cs index 7fffd3693c..a89d5e2f4a 100644 --- a/osu.Game/Overlays/Settings/Sections/SkinSection.cs +++ b/osu.Game/Overlays/Settings/Sections/SkinSection.cs @@ -70,11 +70,6 @@ namespace osu.Game.Overlays.Settings.Sections Current = skins.CurrentSkinInfo, Keywords = new[] { @"skins" }, }, - new SettingsButton - { - Text = SkinSettingsStrings.SkinLayoutEditor, - Action = () => skinEditor?.ToggleVisibility(), - }, new FillFlowContainer { RelativeSizeAxes = Axes.X, @@ -90,6 +85,11 @@ namespace osu.Game.Overlays.Settings.Sections new DeleteSkinButton { Padding = new MarginPadding(), RelativeSizeAxes = Axes.None, Width = 110 }, } }, + new SettingsButton + { + Text = SkinSettingsStrings.SkinLayoutEditor, + Action = () => skinEditor?.ToggleVisibility(), + }, }; }