From 6f863ca204cd9488a4e9a141ce8feadbbabef26d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 1 Aug 2021 17:12:04 +0200 Subject: [PATCH 1/3] Adjust game-side text flow containers to part-based model --- .../Graphics/Containers/LinkFlowContainer.cs | 50 ++++++++++++++----- .../Containers/OsuTextFlowContainer.cs | 6 +-- osu.Game/Graphics/ErrorTextFlowContainer.cs | 9 ++-- osu.Game/Online/Chat/DrawableLinkCompiler.cs | 7 +++ .../Overlays/AccountCreation/ScreenEntry.cs | 5 +- .../Changelog/ChangelogSupporterPromo.cs | 7 ++- osu.Game/Overlays/Music/PlaylistItem.cs | 16 +++--- osu.Game/Screens/Menu/Disclaimer.cs | 10 ++-- 8 files changed, 73 insertions(+), 37 deletions(-) diff --git a/osu.Game/Graphics/Containers/LinkFlowContainer.cs b/osu.Game/Graphics/Containers/LinkFlowContainer.cs index 21c1d70d45..7569200c53 100644 --- a/osu.Game/Graphics/Containers/LinkFlowContainer.cs +++ b/osu.Game/Graphics/Containers/LinkFlowContainer.cs @@ -9,6 +9,7 @@ using osu.Framework.Graphics.Sprites; using System.Collections.Generic; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Localisation; using osu.Framework.Platform; using osu.Game.Graphics.Sprites; @@ -71,26 +72,20 @@ namespace osu.Game.Graphics.Containers var spriteText = new OsuSpriteText { Text = text }; AddText(spriteText, creationParameters); - createLink(spriteText.Yield(), new LinkDetails(action, argument), tooltipText); + createLink(new TextPartManual(spriteText.Yield()), new LinkDetails(action, argument), tooltipText); } public void AddLink(IEnumerable text, LinkAction action, string linkArgument, string tooltipText = null) { - foreach (var t in text) - AddArbitraryDrawable(t); - - createLink(text, new LinkDetails(action, linkArgument), tooltipText); + createLink(new TextPartManual(text), new LinkDetails(action, linkArgument), tooltipText); } public void AddUserLink(User user, Action creationParameters = null) => createLink(AddText(user.Username, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.Id.ToString()), "view profile"); - private void createLink(IEnumerable drawables, LinkDetails link, string tooltipText, Action action = null) + private void createLink(ITextPart textPart, LinkDetails link, LocalisableString tooltipText, Action action = null) { - var linkCompiler = CreateLinkCompiler(drawables.OfType()); - linkCompiler.RelativeSizeAxes = Axes.Both; - linkCompiler.TooltipText = tooltipText; - linkCompiler.Action = () => + Action onClickAction = () => { if (action != null) action(); @@ -101,10 +96,41 @@ namespace osu.Game.Graphics.Containers host.OpenUrlExternally(link.Argument); }; - AddInternal(linkCompiler); + AddPart(new TextLink(textPart, tooltipText, onClickAction)); } - protected virtual DrawableLinkCompiler CreateLinkCompiler(IEnumerable parts) => new DrawableLinkCompiler(parts); + private class TextLink : TextPart + { + private readonly ITextPart innerPart; + private readonly LocalisableString tooltipText; + private readonly Action action; + + public TextLink(ITextPart innerPart, LocalisableString tooltipText, Action action) + { + this.innerPart = innerPart; + this.tooltipText = tooltipText; + this.action = action; + } + + protected override IEnumerable CreateDrawablesFor(TextFlowContainer textFlowContainer) + { + var linkFlowContainer = (LinkFlowContainer)textFlowContainer; + + innerPart.RecreateDrawablesFor(linkFlowContainer); + var drawables = innerPart.Drawables.ToList(); + + drawables.Add(linkFlowContainer.CreateLinkCompiler(innerPart).With(c => + { + c.RelativeSizeAxes = Axes.Both; + c.TooltipText = tooltipText; + c.Action = action; + })); + + return drawables; + } + } + + protected virtual DrawableLinkCompiler CreateLinkCompiler(ITextPart textPart) => new DrawableLinkCompiler(textPart); // We want the compilers to always be visible no matter where they are, so RelativeSizeAxes is used. // However due to https://github.com/ppy/osu-framework/issues/2073, it's possible for the compilers to be relative size in the flow's auto-size axes - an unsupported operation. diff --git a/osu.Game/Graphics/Containers/OsuTextFlowContainer.cs b/osu.Game/Graphics/Containers/OsuTextFlowContainer.cs index 6a87a4b8b9..b8237832a3 100644 --- a/osu.Game/Graphics/Containers/OsuTextFlowContainer.cs +++ b/osu.Game/Graphics/Containers/OsuTextFlowContainer.cs @@ -2,7 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -19,8 +19,8 @@ namespace osu.Game.Graphics.Containers protected override SpriteText CreateSpriteText() => new OsuSpriteText(); - public void AddArbitraryDrawable(Drawable drawable) => AddInternal(drawable); + public ITextPart AddArbitraryDrawable(Drawable drawable) => AddPart(new TextPartManual(drawable.Yield())); - public IEnumerable AddIcon(IconUsage icon, Action creationParameters = null) => AddText(icon.Icon.ToString(), creationParameters); + public ITextPart AddIcon(IconUsage icon, Action creationParameters = null) => AddText(icon.Icon.ToString(), creationParameters); } } diff --git a/osu.Game/Graphics/ErrorTextFlowContainer.cs b/osu.Game/Graphics/ErrorTextFlowContainer.cs index 486382bf33..dafc363973 100644 --- a/osu.Game/Graphics/ErrorTextFlowContainer.cs +++ b/osu.Game/Graphics/ErrorTextFlowContainer.cs @@ -2,7 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; -using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Containers; using osuTK.Graphics; @@ -10,7 +10,7 @@ namespace osu.Game.Graphics { public class ErrorTextFlowContainer : OsuTextFlowContainer { - private readonly List errorDrawables = new List(); + private readonly List errorTextParts = new List(); public ErrorTextFlowContainer() : base(cp => cp.Font = cp.Font.With(size: 12)) @@ -19,7 +19,8 @@ namespace osu.Game.Graphics public void ClearErrors() { - errorDrawables.ForEach(d => d.Expire()); + foreach (var textPart in errorTextParts) + RemovePart(textPart); } public void AddErrors(string[] errors) @@ -29,7 +30,7 @@ namespace osu.Game.Graphics if (errors == null) return; foreach (string error in errors) - errorDrawables.AddRange(AddParagraph(error, cp => cp.Colour = Color4.Red)); + errorTextParts.Add(AddParagraph(error, cp => cp.Colour = Color4.Red)); } } } diff --git a/osu.Game/Online/Chat/DrawableLinkCompiler.cs b/osu.Game/Online/Chat/DrawableLinkCompiler.cs index 4df60eba69..8356b36667 100644 --- a/osu.Game/Online/Chat/DrawableLinkCompiler.cs +++ b/osu.Game/Online/Chat/DrawableLinkCompiler.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; @@ -30,6 +32,11 @@ namespace osu.Game.Online.Chat protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new LinkHoverSounds(sampleSet, Parts); + public DrawableLinkCompiler(ITextPart part) + : this(part.Drawables.OfType()) + { + } + public DrawableLinkCompiler(IEnumerable parts) : base(HoverSampleSet.Submit) { diff --git a/osu.Game/Overlays/AccountCreation/ScreenEntry.cs b/osu.Game/Overlays/AccountCreation/ScreenEntry.cs index bcb3d4b635..8ee3b1cb2e 100644 --- a/osu.Game/Overlays/AccountCreation/ScreenEntry.cs +++ b/osu.Game/Overlays/AccountCreation/ScreenEntry.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using osu.Framework.Allocation; @@ -37,7 +36,7 @@ namespace osu.Game.Overlays.AccountCreation private IAPIProvider api { get; set; } private ShakeContainer registerShake; - private IEnumerable characterCheckText; + private ITextPart characterCheckText; private OsuTextBox[] textboxes; private LoadingLayer loadingLayer; @@ -136,7 +135,7 @@ namespace osu.Game.Overlays.AccountCreation characterCheckText = passwordDescription.AddText("8 characters long"); passwordDescription.AddText(". Choose something long but also something you will remember, like a line from your favourite song."); - passwordTextBox.Current.ValueChanged += password => { characterCheckText.ForEach(s => s.Colour = password.NewValue.Length == 0 ? Color4.White : Interpolation.ValueAt(password.NewValue.Length, Color4.OrangeRed, Color4.YellowGreen, 0, 8, Easing.In)); }; + passwordTextBox.Current.ValueChanged += password => { characterCheckText.Drawables.ForEach(s => s.Colour = password.NewValue.Length == 0 ? Color4.White : Interpolation.ValueAt(password.NewValue.Length, Color4.OrangeRed, Color4.YellowGreen, 0, 8, Easing.In)); }; } public override void OnEntering(IScreen last) diff --git a/osu.Game/Overlays/Changelog/ChangelogSupporterPromo.cs b/osu.Game/Overlays/Changelog/ChangelogSupporterPromo.cs index 1b0a62dc4a..5cc598ae70 100644 --- a/osu.Game/Overlays/Changelog/ChangelogSupporterPromo.cs +++ b/osu.Game/Overlays/Changelog/ChangelogSupporterPromo.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; @@ -166,12 +165,12 @@ namespace osu.Game.Overlays.Changelog { } - protected override DrawableLinkCompiler CreateLinkCompiler(IEnumerable parts) => new SupporterPromoLinkCompiler(parts); + protected override DrawableLinkCompiler CreateLinkCompiler(ITextPart textPart) => new SupporterPromoLinkCompiler(textPart); private class SupporterPromoLinkCompiler : DrawableLinkCompiler { - public SupporterPromoLinkCompiler(IEnumerable parts) - : base(parts) + public SupporterPromoLinkCompiler(ITextPart part) + : base(part) { } diff --git a/osu.Game/Overlays/Music/PlaylistItem.cs b/osu.Game/Overlays/Music/PlaylistItem.cs index ef25de77c6..eea2a9dc7e 100644 --- a/osu.Game/Overlays/Music/PlaylistItem.cs +++ b/osu.Game/Overlays/Music/PlaylistItem.cs @@ -3,12 +3,10 @@ using System; using System.Collections.Generic; -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Events; using osu.Framework.Localisation; using osu.Game.Beatmaps; @@ -25,7 +23,7 @@ namespace osu.Game.Overlays.Music public Action RequestSelection; private TextFlowContainer text; - private IEnumerable titleSprites; + private ITextPart titlePart; private ILocalisedBindableString title; private ILocalisedBindableString artist; @@ -63,11 +61,16 @@ namespace osu.Game.Overlays.Music if (set.OldValue?.Equals(Model) != true && set.NewValue?.Equals(Model) != true) return; - foreach (Drawable s in titleSprites) - s.FadeColour(set.NewValue.Equals(Model) ? selectedColour : Color4.White, FADE_DURATION); + updateSelectionState(false); }, true); } + private void updateSelectionState(bool instant) + { + foreach (Drawable s in titlePart.Drawables) + s.FadeColour(SelectedSet.Value?.Equals(Model) == true ? selectedColour : Color4.White, instant ? 0 : FADE_DURATION); + } + protected override Drawable CreateContent() => text = new OsuTextFlowContainer { RelativeSizeAxes = Axes.X, @@ -79,7 +82,8 @@ namespace osu.Game.Overlays.Music text.Clear(); // space after the title to put a space between the title and artist - titleSprites = text.AddText(title.Value + @" ", sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular)).OfType(); + titlePart = text.AddText(title.Value + @" ", sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular)); + updateSelectionState(true); text.AddText(artist.Value, sprite => { diff --git a/osu.Game/Screens/Menu/Disclaimer.cs b/osu.Game/Screens/Menu/Disclaimer.cs index 7f34e1e395..b8abc131fd 100644 --- a/osu.Game/Screens/Menu/Disclaimer.cs +++ b/osu.Game/Screens/Menu/Disclaimer.cs @@ -37,7 +37,7 @@ namespace osu.Game.Screens.Menu private readonly Bindable currentUser = new Bindable(); private FillFlowContainer fill; - private readonly List expendableText = new List(); + private readonly List expendableText = new List(); public Disclaimer(OsuScreen nextScreen = null) { @@ -97,7 +97,7 @@ namespace osu.Game.Screens.Menu textFlow.AddText("this is osu!", t => t.Font = t.Font.With(Typeface.Torus, 30, FontWeight.Regular)); - expendableText.AddRange(textFlow.AddText("lazer", t => + expendableText.Add(textFlow.AddText("lazer", t => { t.Font = t.Font.With(Typeface.Torus, 30, FontWeight.Regular); t.Colour = colours.PinkLight; @@ -114,7 +114,7 @@ namespace osu.Game.Screens.Menu t.Font = t.Font.With(Typeface.Torus, 20, FontWeight.SemiBold); t.Colour = colours.Pink; }); - expendableText.AddRange(textFlow.AddText(" coming to osu!", formatRegular)); + expendableText.Add(textFlow.AddText(" coming to osu!", formatRegular)); textFlow.AddText(".", formatRegular); textFlow.NewParagraph(); @@ -152,7 +152,7 @@ namespace osu.Game.Screens.Menu t.Font = t.Font.With(size: 20); t.Origin = Anchor.Centre; t.Colour = colours.Pink; - }).First(); + }).Drawables.First(); if (IsLoaded) animateHeart(); @@ -193,7 +193,7 @@ namespace osu.Game.Screens.Menu using (BeginDelayedSequence(520 + 160)) { fill.MoveToOffset(new Vector2(0, 15), 160, Easing.OutQuart); - Schedule(() => expendableText.ForEach(t => + Schedule(() => expendableText.SelectMany(t => t.Drawables).ForEach(t => { t.FadeOut(100); t.ScaleTo(new Vector2(0, 1), 100, Easing.OutQuart); From 61f0339c1d43bac24a1b1addf9d66859fba62401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 7 Aug 2021 20:52:12 +0200 Subject: [PATCH 2/3] Avoid double-adding chunks in link flow container --- osu.Game/Graphics/Containers/LinkFlowContainer.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/Containers/LinkFlowContainer.cs b/osu.Game/Graphics/Containers/LinkFlowContainer.cs index 7569200c53..0b43c16ebe 100644 --- a/osu.Game/Graphics/Containers/LinkFlowContainer.cs +++ b/osu.Game/Graphics/Containers/LinkFlowContainer.cs @@ -59,19 +59,20 @@ namespace osu.Game.Graphics.Containers } public void AddLink(string text, string url, Action creationParameters = null) => - createLink(AddText(text, creationParameters), new LinkDetails(LinkAction.External, url), url); + createLink(CreateChunkFor(text, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.External, url), url); public void AddLink(string text, Action action, string tooltipText = null, Action creationParameters = null) - => createLink(AddText(text, creationParameters), new LinkDetails(LinkAction.Custom, string.Empty), tooltipText, action); + => createLink(CreateChunkFor(text, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.Custom, string.Empty), tooltipText, action); public void AddLink(string text, LinkAction action, string argument, string tooltipText = null, Action creationParameters = null) - => createLink(AddText(text, creationParameters), new LinkDetails(action, argument), tooltipText); + => createLink(CreateChunkFor(text, true, CreateSpriteText, creationParameters), new LinkDetails(action, argument), tooltipText); public void AddLink(LocalisableString text, LinkAction action, string argument, string tooltipText = null, Action creationParameters = null) { var spriteText = new OsuSpriteText { Text = text }; AddText(spriteText, creationParameters); + RemoveInternal(spriteText); // TODO: temporary, will go away when TextParts support localisation properly. createLink(new TextPartManual(spriteText.Yield()), new LinkDetails(action, argument), tooltipText); } @@ -81,7 +82,7 @@ namespace osu.Game.Graphics.Containers } public void AddUserLink(User user, Action creationParameters = null) - => createLink(AddText(user.Username, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.Id.ToString()), "view profile"); + => createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.Id.ToString()), "view profile"); private void createLink(ITextPart textPart, LinkDetails link, LocalisableString tooltipText, Action action = null) { From 1fd05ab78aa7b09c63c8040e19fd92420ad02fc6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 29 Oct 2021 18:56:13 +0900 Subject: [PATCH 3/3] Update framework --- osu.Android.props | 2 +- osu.Game/osu.Game.csproj | 2 +- osu.iOS.props | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Android.props b/osu.Android.props index 552675d706..dec994bcb2 100644 --- a/osu.Android.props +++ b/osu.Android.props @@ -52,7 +52,7 @@ - + diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 8ba6e41d53..8052ab5254 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -36,7 +36,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/osu.iOS.props b/osu.iOS.props index e55dbb3bfe..d152cb7066 100644 --- a/osu.iOS.props +++ b/osu.iOS.props @@ -70,7 +70,7 @@ - + @@ -93,7 +93,7 @@ - +