From 5d171cd58b61394e1d8b90500678d0fd68a8686b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 17 Aug 2024 21:41:25 +0800 Subject: [PATCH 1/4] Should re-draw the interactable lyric if change the skin's font size. --- .../Lyrics/Content/Compose/LyricEditor.cs | 73 ++++++++++--------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/LyricEditor.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/LyricEditor.cs index cfbbdf64d..63581996a 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/LyricEditor.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/LyricEditor.cs @@ -38,50 +38,55 @@ public LyricEditor() bindableFocusedLyric.BindValueChanged(e => { - skinProvidingContainer.Clear(); + refreshPreviewLyric(e.NewValue); + }); - var lyric = e.NewValue; - if (lyric == null) - return; + bindableFontSize.BindValueChanged(e => + { + skin.FontSize = e.NewValue; + refreshPreviewLyric(bindableFocusedLyric.Value); + }); + } - const int border = 36; + private void refreshPreviewLyric(Lyric? lyric) + { + skinProvidingContainer.Clear(); + + if (lyric == null) + return; + + const int border = 36; - skinProvidingContainer.Add(new InteractableLyric(lyric) + skinProvidingContainer.Add(new InteractableLyric(lyric) + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + TextSizeChanged = (self, size) => { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - TextSizeChanged = (self, size) => - { - self.Width = size.X + border * 2; - self.Height = size.Y + border * 2; - }, - Loaders = new LayerLoader[] + self.Width = size.X + border * 2; + self.Height = size.Y + border * 2; + }, + Loaders = new LayerLoader[] + { + new LayerLoader { - new LayerLoader + OnLoad = layer => { - OnLoad = layer => - { - layer.Spacing = 10; - }, + layer.Spacing = 10; }, - new LayerLoader + }, + new LayerLoader + { + OnLoad = layer => { - OnLoad = layer => - { - layer.LyricPosition = new Vector2(border); - }, + layer.LyricPosition = new Vector2(border); }, - new LayerLoader(), - new LayerLoader(), - new LayerLoader(), - new LayerLoader(), }, - }); - }); - - bindableFontSize.BindValueChanged(e => - { - skin.FontSize = e.NewValue; + new LayerLoader(), + new LayerLoader(), + new LayerLoader(), + new LayerLoader(), + }, }); } From f8b2f657145a8626a5e62bc616dccb36581e572f Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 17 Aug 2024 21:54:02 +0800 Subject: [PATCH 2/4] Add key for increase/decrease the preview font size. --- osu.Game.Rulesets.Karaoke/KaraokeEditInputManager.cs | 7 +++++++ osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/osu.Game.Rulesets.Karaoke/KaraokeEditInputManager.cs b/osu.Game.Rulesets.Karaoke/KaraokeEditInputManager.cs index 17089828d..73e5ebd67 100644 --- a/osu.Game.Rulesets.Karaoke/KaraokeEditInputManager.cs +++ b/osu.Game.Rulesets.Karaoke/KaraokeEditInputManager.cs @@ -99,4 +99,11 @@ public enum KaraokeEditAction [Description("Clear time")] ClearTime, + + // Action for compose mode. + [Description("Increase font size.")] + IncreasePreviewFontSize, + + [Description("Decrease font size.")] + DecreasePreviewFontSize, } diff --git a/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs b/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs index 424c6843c..e2805d34c 100644 --- a/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs +++ b/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs @@ -121,6 +121,10 @@ public override IEnumerable GetDefaultKeyBindings(int variant = 0) = new KeyBinding(InputKey.S, KaraokeEditAction.RemoveEndTimeTag), new KeyBinding(InputKey.Enter, KaraokeEditAction.SetTime), new KeyBinding(InputKey.BackSpace, KaraokeEditAction.ClearTime), + + // Action for compose mode. + new KeyBinding(new[] { InputKey.Control, InputKey.Plus }, KaraokeEditAction.IncreasePreviewFontSize), + new KeyBinding(new[] { InputKey.Control, InputKey.Minus }, KaraokeEditAction.DecreasePreviewFontSize), }, _ => Array.Empty(), }; From d8758ebaef93884190e6d135d971a3f7d12ddfb3 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 18 Aug 2024 22:24:50 +0800 Subject: [PATCH 3/4] Click the button and handle the keyboard event should did the same things(trigger the action). --- .../Content/Compose/Toolbar/ToolbarEditActionButton.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/Toolbar/ToolbarEditActionButton.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/Toolbar/ToolbarEditActionButton.cs index aec6037f2..74fad1c68 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/Toolbar/ToolbarEditActionButton.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/Toolbar/ToolbarEditActionButton.cs @@ -17,10 +17,11 @@ public abstract partial class ToolbarEditActionButton : ToolbarButton, IKeyBindi public bool OnPressed(KeyBindingPressEvent e) { - if (e.Action == EditAction) - ToggleClickEffect(); + if (e.Action != EditAction) + return false; - return false; + // press button should did the same things as click. + return TriggerClick(); } public void OnReleased(KeyBindingReleaseEvent e) From 78282f9cb5fa3a160eb04f53a9b249e2d623b46e Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 18 Aug 2024 22:07:32 +0800 Subject: [PATCH 4/4] Change size button should inherit the ToolbarEditActionButton. --- .../Toolbar/View/AdjustFontSizeButton.cs | 82 +++++++++++++------ 1 file changed, 56 insertions(+), 26 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/Toolbar/View/AdjustFontSizeButton.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/Toolbar/View/AdjustFontSizeButton.cs index 126d2a08d..f702e4d98 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/Toolbar/View/AdjustFontSizeButton.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Content/Compose/Toolbar/View/AdjustFontSizeButton.cs @@ -8,7 +8,6 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; using osu.Game.Rulesets.Karaoke.Configuration; using osu.Game.Rulesets.Karaoke.Utils; using osuTK; @@ -21,10 +20,7 @@ public partial class AdjustFontSizeButton : CompositeDrawable public AdjustFontSizeButton() { - IconButton previousSizeButton; OsuSpriteText fontSizeSpriteText; - IconButton nextSizeButton; - float[] sizes = FontUtils.ComposerFontSize(); Height = SpecialActionToolbar.HEIGHT; AutoSizeAxes = Axes.X; @@ -36,18 +32,9 @@ public AdjustFontSizeButton() Direction = FillDirection.Horizontal, Children = new Drawable[] { - previousSizeButton = new IconButton + new DecreasePreviewFontSizeActionButton { Size = new Vector2(SpecialActionToolbar.ICON_SIZE), - Icon = FontAwesome.Solid.Minus, - Action = () => - { - float previousSize = sizes.GetPrevious(bindableFontSize.Value); - if (previousSize == default) - return; - - bindableFontSize.Value = previousSize; - }, }, new Container { @@ -59,18 +46,9 @@ public AdjustFontSizeButton() Origin = Anchor.Centre, }, }, - nextSizeButton = new IconButton + new IncreasePreviewFontSizeActionButton { Size = new Vector2(SpecialActionToolbar.ICON_SIZE), - Icon = FontAwesome.Solid.Plus, - Action = () => - { - float nextSize = sizes.GetNext(bindableFontSize.Value); - if (nextSize == default) - return; - - bindableFontSize.Value = nextSize; - }, }, }, }; @@ -78,8 +56,6 @@ public AdjustFontSizeButton() bindableFontSize.BindValueChanged(e => { fontSizeSpriteText.Text = FontUtils.GetText(e.NewValue); - previousSizeButton.Enabled.Value = sizes.GetPrevious(e.NewValue) != default; - nextSizeButton.Enabled.Value = sizes.GetNext(e.NewValue) != default; }); } @@ -88,4 +64,58 @@ private void load(KaraokeRulesetLyricEditorConfigManager lyricEditorConfigManage { lyricEditorConfigManager.BindWith(KaraokeRulesetLyricEditorSetting.FontSizeInComposer, bindableFontSize); } + + private partial class DecreasePreviewFontSizeActionButton : PreviewFontSizeActionButton + { + protected override KaraokeEditAction EditAction => KaraokeEditAction.DecreasePreviewFontSize; + + protected override float GetTriggeredFontSize(float[] sizes, float currentFontSize) => sizes.GetPrevious(currentFontSize); + + public DecreasePreviewFontSizeActionButton() + { + SetIcon(FontAwesome.Solid.Minus); + } + } + + private partial class IncreasePreviewFontSizeActionButton : PreviewFontSizeActionButton + { + protected override KaraokeEditAction EditAction => KaraokeEditAction.IncreasePreviewFontSize; + + protected override float GetTriggeredFontSize(float[] sizes, float currentFontSize) => sizes.GetNext(currentFontSize); + + public IncreasePreviewFontSizeActionButton() + { + SetIcon(FontAwesome.Solid.Plus); + } + } + + private abstract partial class PreviewFontSizeActionButton : ToolbarEditActionButton + { + private static readonly float[] sizes = FontUtils.ComposerFontSize(); + + private readonly Bindable bindableFontSize = new(); + + protected PreviewFontSizeActionButton() + { + Action = () => + { + float triggeredFontSize = GetTriggeredFontSize(sizes, bindableFontSize.Value); + bindableFontSize.Value = triggeredFontSize != default ? triggeredFontSize : bindableFontSize.Value; + }; + + bindableFontSize.BindValueChanged(e => + { + float triggeredFontSize = GetTriggeredFontSize(sizes, e.NewValue); + SetState(triggeredFontSize != default); + }); + } + + protected abstract float GetTriggeredFontSize(float[] sizes, float currentFontSize); + + [BackgroundDependencyLoader] + private void load(KaraokeRulesetLyricEditorConfigManager lyricEditorConfigManager) + { + lyricEditorConfigManager.BindWith(KaraokeRulesetLyricEditorSetting.FontSizeInComposer, bindableFontSize); + } + } }