From 881785900a7ec3b59d446d9a41785beed80479a2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 7 Apr 2025 20:51:22 +0900 Subject: [PATCH] Don't use bindables when binding isn't happening --- osu.Game/Overlays/MarqueeContainer.cs | 49 +++++++++++++++++++------ osu.Game/Overlays/Music/PlaylistItem.cs | 8 ++-- osu.Game/Overlays/NowPlayingOverlay.cs | 30 ++++++--------- 3 files changed, 53 insertions(+), 34 deletions(-) diff --git a/osu.Game/Overlays/MarqueeContainer.cs b/osu.Game/Overlays/MarqueeContainer.cs index 69ac5f7d06..2fed87c4e0 100644 --- a/osu.Game/Overlays/MarqueeContainer.cs +++ b/osu.Game/Overlays/MarqueeContainer.cs @@ -3,7 +3,6 @@ using System; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osuTK; @@ -16,14 +15,35 @@ namespace osu.Game.Overlays /// Whether the marquee should be allowed to scroll the content if it overflows. /// Note that upon changing the value of this, any existing scrolls will be terminated instantly. /// - public Bindable AllowScrolling { get; } = new BindableBool(true); + public bool AllowScrolling + { + get => allowScrolling; + set + { + allowScrolling = value; + ScheduleAfterChildren(updateScrolling); + } + } + + private bool allowScrolling = true; + /// /// The to anchor the content to if it does not overflow. /// public Anchor NonOverflowingContentAnchor { get; init; } = Anchor.TopLeft; - public Bindable> CreateContent = new Bindable>(); + public Func? CreateContent + { + set + { + createContent = value; + if (IsLoaded) + updateContent(); + } + } + + private Func? createContent; private const float initial_move_delay = 1000; private const float pixels_per_second = 50; @@ -57,21 +77,26 @@ namespace osu.Game.Overlays { base.LoadComplete(); - AllowScrolling.BindValueChanged(_ => ScheduleAfterChildren(updateScrolling)); - CreateContent.BindValueChanged(_ => - { - flow.Clear(); - flow.Add(mainContent = CreateContent.Value.Invoke()); - flow.Add(fillerContent = CreateContent.Value.Invoke().With(d => d.Alpha = 0)); - ScheduleAfterChildren(updateScrolling); - }, true); + updateContent(); + } + + private void updateContent() + { + flow.Clear(); + + if (createContent == null) + return; + + flow.Add(mainContent = createContent()); + flow.Add(fillerContent = createContent().With(d => d.Alpha = 0)); + ScheduleAfterChildren(updateScrolling); } private void updateScrolling() { float overflowWidth = mainContent.DrawWidth + padding - DrawWidth; - if (overflowWidth > 0 && AllowScrolling.Value) + if (overflowWidth > 0 && AllowScrolling) { fillerContent.Alpha = 1; flow.Anchor = Anchor.TopLeft; diff --git a/osu.Game/Overlays/Music/PlaylistItem.cs b/osu.Game/Overlays/Music/PlaylistItem.cs index 8503a078e1..5b37e36b16 100644 --- a/osu.Game/Overlays/Music/PlaylistItem.cs +++ b/osu.Game/Overlays/Music/PlaylistItem.cs @@ -47,7 +47,7 @@ namespace osu.Game.Overlays.Music Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, RelativeSizeAxes = Axes.X, - AllowScrolling = { Value = false } + AllowScrolling = false, }; selectedSet.BindTo(playlistOverlay.SelectedSet); @@ -68,7 +68,7 @@ namespace osu.Game.Overlays.Music var title = new RomanisableString(metadata.TitleUnicode, metadata.Title); var artist = new RomanisableString(metadata.ArtistUnicode, metadata.Artist); - text.CreateContent.Value = () => + text.CreateContent = () => { var flow = new OsuTextFlowContainer { @@ -113,13 +113,13 @@ namespace osu.Game.Overlays.Music protected override bool OnHover(HoverEvent e) { - text.AllowScrolling.Value = true; + text.AllowScrolling = true; return true; } protected override void OnHoverLost(HoverLostEvent e) { - text.AllowScrolling.Value = false; + text.AllowScrolling = false; base.OnHoverLost(e); } } diff --git a/osu.Game/Overlays/NowPlayingOverlay.cs b/osu.Game/Overlays/NowPlayingOverlay.cs index 24dffdc066..11819cb485 100644 --- a/osu.Game/Overlays/NowPlayingOverlay.cs +++ b/osu.Game/Overlays/NowPlayingOverlay.cs @@ -113,15 +113,12 @@ namespace osu.Game.Overlays Anchor = Anchor.TopCentre, Position = new Vector2(0, 40), Colour = Color4.White, - CreateContent = + CreateContent = () => new OsuSpriteText { - Value = () => new OsuSpriteText - { - Font = title_font, - Text = @"Nothing to play", - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - } + Font = title_font, + Text = @"Nothing to play", + Anchor = Anchor.Centre, + Origin = Anchor.Centre, }, NonOverflowingContentAnchor = Anchor.Centre, }, @@ -131,15 +128,12 @@ namespace osu.Game.Overlays Anchor = Anchor.TopCentre, Position = new Vector2(0, 45), Colour = Color4.White, - CreateContent = + CreateContent = () => new OsuSpriteText { - Value = () => new OsuSpriteText - { - Font = artist_font, - Text = @"Nothing to play", - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - } + Font = artist_font, + Text = @"Nothing to play", + Anchor = Anchor.Centre, + Origin = Anchor.Centre, }, NonOverflowingContentAnchor = Anchor.Centre, }, @@ -338,14 +332,14 @@ namespace osu.Game.Overlays { BeatmapMetadata metadata = beatmap.Metadata; - title.CreateContent.Value = () => new OsuSpriteText + title.CreateContent = () => new OsuSpriteText { Text = new RomanisableString(metadata.TitleUnicode, metadata.Title), Font = title_font, Anchor = Anchor.Centre, Origin = Anchor.Centre, }; - artist.CreateContent.Value = () => new OsuSpriteText + artist.CreateContent = () => new OsuSpriteText { Text = new RomanisableString(metadata.ArtistUnicode, metadata.Artist), Font = artist_font,