From 48c608e0169a1f9280f75fb3bdc0eadaa3466976 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Mon, 18 Mar 2024 12:22:23 -0700 Subject: [PATCH 1/7] Make player width a const --- osu.Game/Overlays/NowPlayingOverlay.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/NowPlayingOverlay.cs b/osu.Game/Overlays/NowPlayingOverlay.cs index ab99370603..1145ebaa2f 100644 --- a/osu.Game/Overlays/NowPlayingOverlay.cs +++ b/osu.Game/Overlays/NowPlayingOverlay.cs @@ -33,6 +33,7 @@ namespace osu.Game.Overlays public LocalisableString Title => NowPlayingStrings.HeaderTitle; public LocalisableString Description => NowPlayingStrings.HeaderDescription; + private const float player_width = 400; private const float player_height = 130; private const float transition_length = 800; private const float progress_height = 10; @@ -70,7 +71,7 @@ namespace osu.Game.Overlays public NowPlayingOverlay() { - Width = 400; + Width = player_width; Margin = new MarginPadding(margin); } @@ -319,15 +320,15 @@ namespace osu.Game.Overlays switch (direction) { case TrackChangeDirection.Next: - newBackground.Position = new Vector2(400, 0); + newBackground.Position = new Vector2(player_width, 0); newBackground.MoveToX(0, 500, Easing.OutCubic); - background.MoveToX(-400, 500, Easing.OutCubic); + background.MoveToX(-player_width, 500, Easing.OutCubic); break; case TrackChangeDirection.Prev: - newBackground.Position = new Vector2(-400, 0); + newBackground.Position = new Vector2(-player_width, 0); newBackground.MoveToX(0, 500, Easing.OutCubic); - background.MoveToX(400, 500, Easing.OutCubic); + background.MoveToX(player_width, 500, Easing.OutCubic); break; } From d4951a093fd9746c1ac885a8af13874dfc5390a8 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Mon, 18 Mar 2024 12:24:02 -0700 Subject: [PATCH 2/7] Scroll now playing overlay text when overflowing --- .../TestSceneNowPlayingOverlay.cs | 20 +++- osu.Game/Overlays/NowPlayingOverlay.cs | 100 +++++++++++++++++- 2 files changed, 115 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs index d07b90025f..40e0d9250d 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Game.Beatmaps; using osu.Game.Overlays; using osu.Game.Rulesets.Osu; @@ -22,8 +23,6 @@ namespace osu.Game.Tests.Visual.UserInterface [BackgroundDependencyLoader] private void load() { - Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); - nowPlayingOverlay = new NowPlayingOverlay { Origin = Anchor.Centre, @@ -37,9 +36,26 @@ namespace osu.Game.Tests.Visual.UserInterface [Test] public void TestShowHideDisable() { + AddStep(@"set beatmap", () => Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo)); AddStep(@"show", () => nowPlayingOverlay.Show()); AddToggleStep(@"toggle beatmap lock", state => Beatmap.Disabled = state); AddStep(@"hide", () => nowPlayingOverlay.Hide()); } + + [Test] + public void TestLongMetadata() + { + AddStep(@"set beatmap", () => Beatmap.Value = CreateWorkingBeatmap(new Beatmap + { + Metadata = + { + Artist = "very very very very very very very very very very very long artist", + ArtistUnicode = "very very very very very very very very very very very long artist", + Title = "very very very very very very very very very very very long title", + TitleUnicode = "very very very very very very very very very very very long title", + } + })); + AddStep(@"show", () => nowPlayingOverlay.Show()); + } } } diff --git a/osu.Game/Overlays/NowPlayingOverlay.cs b/osu.Game/Overlays/NowPlayingOverlay.cs index 1145ebaa2f..be405257ca 100644 --- a/osu.Game/Overlays/NowPlayingOverlay.cs +++ b/osu.Game/Overlays/NowPlayingOverlay.cs @@ -6,6 +6,7 @@ using System.Threading; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -48,7 +49,7 @@ namespace osu.Game.Overlays private IconButton nextButton = null!; private IconButton playlistButton = null!; - private SpriteText title = null!, artist = null!; + private ScrollingTextContainer title = null!, artist = null!; private PlaylistOverlay? playlist; @@ -102,7 +103,7 @@ namespace osu.Game.Overlays Children = new[] { background = Empty(), - title = new OsuSpriteText + title = new ScrollingTextContainer { Origin = Anchor.BottomCentre, Anchor = Anchor.TopCentre, @@ -111,7 +112,7 @@ namespace osu.Game.Overlays Colour = Color4.White, Text = @"Nothing to play", }, - artist = new OsuSpriteText + artist = new ScrollingTextContainer { Origin = Anchor.TopCentre, Anchor = Anchor.TopCentre, @@ -470,5 +471,98 @@ namespace osu.Game.Overlays base.OnHoverLost(e); } } + + private partial class ScrollingTextContainer : CompositeDrawable + { + private const float initial_move_delay = 1000; + private const float pixels_per_second = 50; + + private LocalisableString text; + private OsuSpriteText mainSpriteText = null!; + private OsuSpriteText fillerSpriteText = null!; + + public LocalisableString Text + { + get => text; + set + { + text = value; + Schedule(updateText); + } + } + + public FontUsage Font + { + set => + Schedule(() => + { + mainSpriteText.Font = value; + fillerSpriteText.Font = value; + + updateText(); + }); + } + + public ScrollingTextContainer() + { + AutoSizeAxes = Axes.Both; + } + + [BackgroundDependencyLoader] + private void load() + { + InternalChild = new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Children = new[] + { + mainSpriteText = new OsuSpriteText { Padding = new MarginPadding { Horizontal = margin } }, + fillerSpriteText = new OsuSpriteText { Padding = new MarginPadding { Horizontal = margin }, Alpha = 0 }, + } + }; + } + + private void updateText() + { + mainSpriteText.Text = text; + fillerSpriteText.Alpha = 0; + + ClearTransforms(); + X = 0; + + float textOverflowWidth = mainSpriteText.Width - player_width; + + if (textOverflowWidth > 0) + { + fillerSpriteText.Alpha = 1; + fillerSpriteText.Text = text; + + float initialX; + float targetX; + + if (Anchor.HasFlagFast(Anchor.x0)) + { + initialX = 0; + targetX = -mainSpriteText.Width; + } + else if (Anchor.HasFlagFast(Anchor.x1)) + { + initialX = (textOverflowWidth + mainSpriteText.Width) / 2; + targetX = (textOverflowWidth - mainSpriteText.Width) / 2; + } + else // Anchor.x2 + { + initialX = textOverflowWidth + mainSpriteText.Width; + targetX = textOverflowWidth; + } + + this.MoveToX(initialX) + .Delay(initial_move_delay) + .MoveToX(targetX, mainSpriteText.Width * 1000 / pixels_per_second) + .Loop(); + } + } + } } } From 2f075e32479542e8b3dc0abd0ae3c93c4f0dae9f Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Thu, 2 May 2024 17:01:40 -0700 Subject: [PATCH 3/7] Apply half margin of tolerance on both sides before text scrolls --- .../TestSceneNowPlayingOverlay.cs | 22 ++++++++++++++----- osu.Game/Overlays/NowPlayingOverlay.cs | 4 +++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs index 40e0d9250d..1670741cbd 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneNowPlayingOverlay.cs @@ -45,16 +45,28 @@ namespace osu.Game.Tests.Visual.UserInterface [Test] public void TestLongMetadata() { - AddStep(@"set beatmap", () => Beatmap.Value = CreateWorkingBeatmap(new Beatmap + AddStep(@"set metadata within tolerance", () => Beatmap.Value = CreateWorkingBeatmap(new Beatmap { Metadata = { - Artist = "very very very very very very very very very very very long artist", - ArtistUnicode = "very very very very very very very very very very very long artist", - Title = "very very very very very very very very very very very long title", - TitleUnicode = "very very very very very very very very very very very long title", + Artist = "very very very very very very very very very very verry long artist", + ArtistUnicode = "very very very very very very very very very very verry long artist", + Title = "very very very very very verry long title", + TitleUnicode = "very very very very very verry long title", } })); + + AddStep(@"set metadata outside bounds", () => Beatmap.Value = CreateWorkingBeatmap(new Beatmap + { + Metadata = + { + Artist = "very very very very very very very very very very verrry long artist", + ArtistUnicode = "very very very very very very very very very very verrry long artist", + Title = "very very very very very verrry long title", + TitleUnicode = "very very very very very verrry long title", + } + })); + AddStep(@"show", () => nowPlayingOverlay.Show()); } } diff --git a/osu.Game/Overlays/NowPlayingOverlay.cs b/osu.Game/Overlays/NowPlayingOverlay.cs index be405257ca..b1f72fd792 100644 --- a/osu.Game/Overlays/NowPlayingOverlay.cs +++ b/osu.Game/Overlays/NowPlayingOverlay.cs @@ -9,6 +9,7 @@ using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; +using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; @@ -533,7 +534,8 @@ namespace osu.Game.Overlays float textOverflowWidth = mainSpriteText.Width - player_width; - if (textOverflowWidth > 0) + // apply half margin of tolerance on both sides before the text scrolls + if (textOverflowWidth > margin) { fillerSpriteText.Alpha = 1; fillerSpriteText.Text = text; From 269077f85496142f470b3fce4306ac33ac8216ea Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Thu, 2 May 2024 17:04:22 -0700 Subject: [PATCH 4/7] Only support centre anchors --- osu.Game/Overlays/NowPlayingOverlay.cs | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/osu.Game/Overlays/NowPlayingOverlay.cs b/osu.Game/Overlays/NowPlayingOverlay.cs index b1f72fd792..7329a3b404 100644 --- a/osu.Game/Overlays/NowPlayingOverlay.cs +++ b/osu.Game/Overlays/NowPlayingOverlay.cs @@ -540,24 +540,8 @@ namespace osu.Game.Overlays fillerSpriteText.Alpha = 1; fillerSpriteText.Text = text; - float initialX; - float targetX; - - if (Anchor.HasFlagFast(Anchor.x0)) - { - initialX = 0; - targetX = -mainSpriteText.Width; - } - else if (Anchor.HasFlagFast(Anchor.x1)) - { - initialX = (textOverflowWidth + mainSpriteText.Width) / 2; - targetX = (textOverflowWidth - mainSpriteText.Width) / 2; - } - else // Anchor.x2 - { - initialX = textOverflowWidth + mainSpriteText.Width; - targetX = textOverflowWidth; - } + float initialX = (textOverflowWidth + mainSpriteText.Width) / 2; + float targetX = (textOverflowWidth - mainSpriteText.Width) / 2; this.MoveToX(initialX) .Delay(initial_move_delay) From 381ddb067618abb7b7cfceed944669e346b1bdf3 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Thu, 2 May 2024 17:05:12 -0700 Subject: [PATCH 5/7] Fix weird formatting --- osu.Game/Overlays/NowPlayingOverlay.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/NowPlayingOverlay.cs b/osu.Game/Overlays/NowPlayingOverlay.cs index 7329a3b404..1488f59246 100644 --- a/osu.Game/Overlays/NowPlayingOverlay.cs +++ b/osu.Game/Overlays/NowPlayingOverlay.cs @@ -494,14 +494,13 @@ namespace osu.Game.Overlays public FontUsage Font { - set => - Schedule(() => - { - mainSpriteText.Font = value; - fillerSpriteText.Font = value; + set => Schedule(() => + { + mainSpriteText.Font = value; + fillerSpriteText.Font = value; - updateText(); - }); + updateText(); + }); } public ScrollingTextContainer() From c15a68507152b0710b90a4fa947cb5b994258bf9 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Thu, 2 May 2024 17:07:49 -0700 Subject: [PATCH 6/7] Remove unused usings --- osu.Game/Overlays/NowPlayingOverlay.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Overlays/NowPlayingOverlay.cs b/osu.Game/Overlays/NowPlayingOverlay.cs index 1488f59246..8f97ce50cc 100644 --- a/osu.Game/Overlays/NowPlayingOverlay.cs +++ b/osu.Game/Overlays/NowPlayingOverlay.cs @@ -6,10 +6,8 @@ using System.Threading; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; -using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; From c21b7c7df994fa6a00a3edf7bc79653035bbaa8c Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Thu, 2 May 2024 22:46:42 -0700 Subject: [PATCH 7/7] Use `IsLoaded` instead of `Schedule` --- osu.Game/Overlays/NowPlayingOverlay.cs | 35 ++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/NowPlayingOverlay.cs b/osu.Game/Overlays/NowPlayingOverlay.cs index 8f97ce50cc..744d32ff7e 100644 --- a/osu.Game/Overlays/NowPlayingOverlay.cs +++ b/osu.Game/Overlays/NowPlayingOverlay.cs @@ -476,29 +476,35 @@ namespace osu.Game.Overlays private const float initial_move_delay = 1000; private const float pixels_per_second = 50; - private LocalisableString text; private OsuSpriteText mainSpriteText = null!; private OsuSpriteText fillerSpriteText = null!; + private LocalisableString text; + public LocalisableString Text { get => text; set { text = value; - Schedule(updateText); + + if (IsLoaded) + updateText(); } } + private FontUsage font = OsuFont.Default; + public FontUsage Font { - set => Schedule(() => + get => font; + set { - mainSpriteText.Font = value; - fillerSpriteText.Font = value; + font = value; - updateText(); - }); + if (IsLoaded) + updateFontAndText(); + } } public ScrollingTextContainer() @@ -521,6 +527,21 @@ namespace osu.Game.Overlays }; } + protected override void LoadComplete() + { + base.LoadComplete(); + + updateFontAndText(); + } + + private void updateFontAndText() + { + mainSpriteText.Font = font; + fillerSpriteText.Font = font; + + updateText(); + } + private void updateText() { mainSpriteText.Text = text;