From 905ebc3c1f7cfdfa798c6cffa2bdff3479b4d1d3 Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Tue, 1 Nov 2022 20:46:32 +0100 Subject: [PATCH 01/41] Initial implementation of a Beatmap Information Skinning Element Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> --- osu.Game/OsuGameBase.cs | 2 +- .../Components/BeatmapInfoDrawable.cs | 189 ++++++++++++++++++ 2 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Skinning/Components/BeatmapInfoDrawable.cs diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 39ddffd2d0..622e802b72 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -155,7 +155,7 @@ namespace osu.Game protected Storage Storage { get; set; } - protected Bindable Beatmap { get; private set; } // cached via load() method + public Bindable Beatmap { get; private set; } // cached via load() method [Cached] [Cached(typeof(IBindable))] diff --git a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs new file mode 100644 index 0000000000..770082daf9 --- /dev/null +++ b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs @@ -0,0 +1,189 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using System; +using System.Text; +using JetBrains.Annotations; +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Configuration; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; + +namespace osu.Game.Skinning.Components +{ + /// + /// Intended to be a test bed for skinning. May be removed at some point in the future. + /// + [UsedImplicitly] + public class BeatmapInfoDrawable : Container, ISkinnableDrawable + { + public bool UsesFixedAnchor { get; set; } + + [SettingSource("Tracked Beatmap Info", "Which part of the BeatmapInformation should be tracked")] + public Bindable Type { get; } = new Bindable(BeatmapInfo.StarRating); + + [Resolved] + private OsuGameBase mGameBase { get; set; } + + private readonly OsuSpriteText text; + + public BeatmapInfoDrawable() + { + AutoSizeAxes = Axes.Both; + + InternalChildren = new Drawable[] + { + text = new OsuSpriteText + { + Text = "BeatInfoDrawable", + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.Default.With(size: 40) + } + }; + } + + // [BackgroundDependencyLoader] + // private void load(WorkingBeatmap beatmap) + // { + // this.beatmap = beatmap; + // } + + protected override void LoadComplete() + { + base.LoadComplete(); + Type.BindValueChanged(update, true); + } + + private void update(ValueChangedEvent type) + { + switch (type.NewValue) + { + case BeatmapInfo.CircleSize: + mGameBase.Beatmap.BindValueChanged(bm => + { + text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.CircleSize.ToString("F2"); + }, true); + break; + + case BeatmapInfo.HPDrain: + mGameBase.Beatmap.BindValueChanged(bm => + { + text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.DrainRate.ToString("F2"); + }, true); + break; + + case BeatmapInfo.Accuracy: + mGameBase.Beatmap.BindValueChanged(bm => + { + text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.OverallDifficulty.ToString("F2"); + }, true); + break; + + case BeatmapInfo.ApproachRate: + mGameBase.Beatmap.BindValueChanged(bm => + { + text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.ApproachRate.ToString("F2"); + }, true); + break; + + case BeatmapInfo.StarRating: + mGameBase.Beatmap.BindValueChanged(bm => + { + text.Current.Value = bm.NewValue.BeatmapInfo.StarRating.ToString("F2"); + }, true); + break; + + case BeatmapInfo.Song: + mGameBase.Beatmap.BindValueChanged(bm => + { + text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Title; + }, true); + break; + + case BeatmapInfo.Artist: + mGameBase.Beatmap.BindValueChanged(bm => + { + text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Artist; + }, true); + break; + + case BeatmapInfo.Difficulty: + mGameBase.Beatmap.BindValueChanged(bm => + { + text.Current.Value = bm.NewValue.BeatmapInfo.DifficultyName; + }, true); + break; + + case BeatmapInfo.Mapper: + mGameBase.Beatmap.BindValueChanged(bm => + { + text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Author.Username; + }, true); + break; + + case BeatmapInfo.Length: + mGameBase.Beatmap.BindValueChanged(bm => + { + const long ms_to_s = 1000; + double length = bm.NewValue.BeatmapInfo.Length; + double rawS = length / ms_to_s; + double rawM = rawS / 60; + double rawH = rawM / 60; + double rawD = rawH / 24; + + long s = (long)rawS % 60; + long m = (long)rawM % 60; + long h = (long)rawH % 24; + long d = (long)rawD; + StringBuilder builder = new StringBuilder(); + + if (d != 0) + { + builder.Append(d.ToString("D2")); + builder.Append(":"); + } + + if (h != 0 || d != 0) + { + builder.Append(h.ToString("D2")); + builder.Append(":"); + } + + builder.Append(m.ToString("D2")); + builder.Append(":"); + builder.Append(s.ToString("D2")); + text.Current.Value = builder.ToString(); + }, true); + break; + + case BeatmapInfo.BPM: + mGameBase.Beatmap.BindValueChanged(bm => + { + text.Current.Value = bm.NewValue.BeatmapInfo.BPM.ToString("F2"); + }, true); + break; + } + } + } + + public enum BeatmapInfo + { + CircleSize, + HPDrain, + Accuracy, //OD? + ApproachRate, + StarRating, + Song, + Artist, + Difficulty, + Mapper, + Length, + BPM, + } +} From c231a20cbb9b0607e3e56ec20ef118ff889bbedf Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Tue, 1 Nov 2022 20:54:52 +0100 Subject: [PATCH 02/41] Add a generic text Element Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> --- .../Components/BeatmapInfoDrawable.cs | 12 +----- osu.Game/Skinning/Components/TextElement.cs | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 osu.Game/Skinning/Components/TextElement.cs diff --git a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs index 770082daf9..cb207d7329 100644 --- a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs +++ b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs @@ -3,7 +3,6 @@ #nullable disable -using System; using System.Text; using JetBrains.Annotations; using osu.Framework.Allocation; @@ -16,9 +15,6 @@ using osu.Game.Graphics.Sprites; namespace osu.Game.Skinning.Components { - /// - /// Intended to be a test bed for skinning. May be removed at some point in the future. - /// [UsedImplicitly] public class BeatmapInfoDrawable : Container, ISkinnableDrawable { @@ -48,12 +44,6 @@ namespace osu.Game.Skinning.Components }; } - // [BackgroundDependencyLoader] - // private void load(WorkingBeatmap beatmap) - // { - // this.beatmap = beatmap; - // } - protected override void LoadComplete() { base.LoadComplete(); @@ -176,7 +166,7 @@ namespace osu.Game.Skinning.Components { CircleSize, HPDrain, - Accuracy, //OD? + Accuracy, ApproachRate, StarRating, Song, diff --git a/osu.Game/Skinning/Components/TextElement.cs b/osu.Game/Skinning/Components/TextElement.cs new file mode 100644 index 0000000000..e29ab6de58 --- /dev/null +++ b/osu.Game/Skinning/Components/TextElement.cs @@ -0,0 +1,40 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using JetBrains.Annotations; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Configuration; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; + +namespace osu.Game.Skinning.Components +{ + [UsedImplicitly] + public class TextElement : Container, ISkinnableDrawable + { + public bool UsesFixedAnchor { get; set; } + + [SettingSource("Displayed Text", "What text should be displayed")] + public Bindable Text { get; } = new Bindable("Circles!"); + + public TextElement() + { + AutoSizeAxes = Axes.Both; + OsuSpriteText text; + InternalChildren = new Drawable[] + { + text = new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.Default.With(size: 40) + } + }; + text.Current.BindTo(Text); + } + } +} From 975eed964e5c773de4b882cb7c620e9633130755 Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Tue, 1 Nov 2022 21:19:01 +0100 Subject: [PATCH 03/41] Don't make Beatmap in OsuGameBase public Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> --- osu.Game/OsuGameBase.cs | 2 +- .../Components/BeatmapInfoDrawable.cs | 25 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 622e802b72..39ddffd2d0 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -155,7 +155,7 @@ namespace osu.Game protected Storage Storage { get; set; } - public Bindable Beatmap { get; private set; } // cached via load() method + protected Bindable Beatmap { get; private set; } // cached via load() method [Cached] [Cached(typeof(IBindable))] diff --git a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs index cb207d7329..ae91d14830 100644 --- a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs +++ b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs @@ -9,6 +9,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; @@ -24,7 +25,7 @@ namespace osu.Game.Skinning.Components public Bindable Type { get; } = new Bindable(BeatmapInfo.StarRating); [Resolved] - private OsuGameBase mGameBase { get; set; } + private IBindable beatmap { get; set; } private readonly OsuSpriteText text; @@ -55,70 +56,70 @@ namespace osu.Game.Skinning.Components switch (type.NewValue) { case BeatmapInfo.CircleSize: - mGameBase.Beatmap.BindValueChanged(bm => + beatmap.BindValueChanged(bm => { text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.CircleSize.ToString("F2"); }, true); break; case BeatmapInfo.HPDrain: - mGameBase.Beatmap.BindValueChanged(bm => + beatmap.BindValueChanged(bm => { text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.DrainRate.ToString("F2"); }, true); break; case BeatmapInfo.Accuracy: - mGameBase.Beatmap.BindValueChanged(bm => + beatmap.BindValueChanged(bm => { text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.OverallDifficulty.ToString("F2"); }, true); break; case BeatmapInfo.ApproachRate: - mGameBase.Beatmap.BindValueChanged(bm => + beatmap.BindValueChanged(bm => { text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.ApproachRate.ToString("F2"); }, true); break; case BeatmapInfo.StarRating: - mGameBase.Beatmap.BindValueChanged(bm => + beatmap.BindValueChanged(bm => { text.Current.Value = bm.NewValue.BeatmapInfo.StarRating.ToString("F2"); }, true); break; case BeatmapInfo.Song: - mGameBase.Beatmap.BindValueChanged(bm => + beatmap.BindValueChanged(bm => { text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Title; }, true); break; case BeatmapInfo.Artist: - mGameBase.Beatmap.BindValueChanged(bm => + beatmap.BindValueChanged(bm => { text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Artist; }, true); break; case BeatmapInfo.Difficulty: - mGameBase.Beatmap.BindValueChanged(bm => + beatmap.BindValueChanged(bm => { text.Current.Value = bm.NewValue.BeatmapInfo.DifficultyName; }, true); break; case BeatmapInfo.Mapper: - mGameBase.Beatmap.BindValueChanged(bm => + beatmap.BindValueChanged(bm => { text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Author.Username; }, true); break; case BeatmapInfo.Length: - mGameBase.Beatmap.BindValueChanged(bm => + beatmap.BindValueChanged(bm => { const long ms_to_s = 1000; double length = bm.NewValue.BeatmapInfo.Length; @@ -153,7 +154,7 @@ namespace osu.Game.Skinning.Components break; case BeatmapInfo.BPM: - mGameBase.Beatmap.BindValueChanged(bm => + beatmap.BindValueChanged(bm => { text.Current.Value = bm.NewValue.BeatmapInfo.BPM.ToString("F2"); }, true); From ed7e3a29e2ab96234728f784ea7194d3f74ccdba Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:00:45 +0100 Subject: [PATCH 04/41] Add Localisation Also add Labels for what is displayed, and prefix/suffix for Labels Add a Prefix and Suffix for Values --- .../Components/BeatmapInfoDrawable.cs | 223 ++++++++++++++---- 1 file changed, 180 insertions(+), 43 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs index ae91d14830..4110086b2a 100644 --- a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs +++ b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs @@ -1,45 +1,80 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - -using System.Text; +using System; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Localisation; using osu.Game.Beatmaps; using osu.Game.Configuration; +using osu.Game.Extensions; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Game.Localisation; +using osu.Game.Resources.Localisation.Web; namespace osu.Game.Skinning.Components { [UsedImplicitly] - public class BeatmapInfoDrawable : Container, ISkinnableDrawable + public class BeatmapInfoDrawable : Container, ISkinnableDrawable, IHasTooltip { public bool UsesFixedAnchor { get; set; } [SettingSource("Tracked Beatmap Info", "Which part of the BeatmapInformation should be tracked")] public Bindable Type { get; } = new Bindable(BeatmapInfo.StarRating); + [SettingSource("Show Label", "Should a Label be shown, as to which status is currently Displayed?")] + public BindableBool ShowLabel { get; } = new BindableBool(true); + + [SettingSource("Show Value first?", "Should the Value be shown first?")] + public BindableBool ValueBeforeLabel { get; } = new BindableBool(); + + [SettingSource("Label Prefix", "Add something to be shown before the label")] + public Bindable LabelPrefix { get; set; } = new Bindable(""); + + [SettingSource("Show Label Prefix", "Should the Label Prefix be included?")] + public BindableBool ShowLabelPrefix { get; } = new BindableBool(); + + [SettingSource("Label Suffix", "Add something to be shown after the label")] + public Bindable LabelSuffix { get; set; } = new Bindable(": "); + + [SettingSource("Show Label Suffix", "Should the Label Suffix be included?")] + public BindableBool ShowLabelSuffix { get; } = new BindableBool(true); + + [SettingSource("Value Prefix", "Add something to be shown before the Value")] + public Bindable ValuePrefix { get; set; } = new Bindable(""); + + [SettingSource("Show Value Prefix", "Should the Value Prefix be included?")] + public BindableBool ShowValuePrefix { get; } = new BindableBool(); + + [SettingSource("Value Suffix", "Add something to be shown after the Value")] + public Bindable ValueSuffix { get; set; } = new Bindable(""); + + [SettingSource("Show Value Suffix", "Should the Value Suffix be included?")] + public BindableBool ShowValueSuffix { get; } = new BindableBool(); + [Resolved] - private IBindable beatmap { get; set; } + private IBindable beatmap { get; set; } = null!; private readonly OsuSpriteText text; + public LocalisableString TooltipText { get; set; } + private LocalisableString value; + private LocalisableString labelText; + public BeatmapInfoDrawable() { - AutoSizeAxes = Axes.Both; - InternalChildren = new Drawable[] { text = new OsuSpriteText { Text = "BeatInfoDrawable", - Anchor = Anchor.Centre, - Origin = Anchor.Centre, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, Font = OsuFont.Default.With(size: 40) } }; @@ -49,6 +84,45 @@ namespace osu.Game.Skinning.Components { base.LoadComplete(); Type.BindValueChanged(update, true); + ShowLabel.BindValueChanged(ignored => updateLabel()); + ValueBeforeLabel.BindValueChanged(ignored => updateLabel()); + LabelPrefix.BindValueChanged(ignored => updateLabel()); + ShowLabelPrefix.BindValueChanged(ignored => updateLabel()); + LabelSuffix.BindValueChanged(ignored => updateLabel()); + ShowLabelSuffix.BindValueChanged(ignored => updateLabel()); + ValuePrefix.BindValueChanged(ignored => updateLabel()); + ShowValuePrefix.BindValueChanged(ignored => updateLabel()); + ValueSuffix.BindValueChanged(ignored => updateLabel()); + ShowValueSuffix.BindValueChanged(ignored => updateLabel()); + } + + private LocalisableString getLabelText() + { + if (!ShowLabel.Value) return new LocalisableString(""); + + return LocalisableString.Format("{0}{1}{2}", + ShowLabelPrefix.Value ? LabelPrefix.Value : "", + labelText, + ShowLabelSuffix.Value ? LabelSuffix.Value : ""); + } + + private LocalisableString getValueText() + { + return LocalisableString.Format("{0}{1}{2}", + ShowValuePrefix.Value ? ValuePrefix.Value : "", + value, + ShowValueSuffix.Value ? ValueSuffix.Value : ""); + } + + private void updateLabel() + { + text.Text = LocalisableString.Format( + ValueBeforeLabel.Value ? "{1}{0}" : "{0}{1}", + getLabelText(), + getValueText() + ); + Width = text.Width; + Height = text.Height; } private void update(ValueChangedEvent type) @@ -58,105 +132,167 @@ namespace osu.Game.Skinning.Components case BeatmapInfo.CircleSize: beatmap.BindValueChanged(bm => { - text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.CircleSize.ToString("F2"); + double cs = bm.NewValue.BeatmapInfo.Difficulty.CircleSize; + labelText = TooltipText = BeatmapsetsStrings.ShowStatsCs; + value = cs.ToString("F2"); + updateLabel(); }, true); break; case BeatmapInfo.HPDrain: beatmap.BindValueChanged(bm => { - text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.DrainRate.ToString("F2"); + double hp = bm.NewValue.BeatmapInfo.Difficulty.DrainRate; + labelText = TooltipText = BeatmapsetsStrings.ShowStatsDrain; + value = hp.ToString("F2"); + updateLabel(); }, true); break; case BeatmapInfo.Accuracy: beatmap.BindValueChanged(bm => { - text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.OverallDifficulty.ToString("F2"); + double od = bm.NewValue.BeatmapInfo.Difficulty.OverallDifficulty; + labelText = TooltipText = BeatmapsetsStrings.ShowStatsAccuracy; + value = od.ToString("F2"); + updateLabel(); }, true); break; case BeatmapInfo.ApproachRate: beatmap.BindValueChanged(bm => { - text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.ApproachRate.ToString("F2"); + double ar = bm.NewValue.BeatmapInfo.Difficulty.ApproachRate; + labelText = TooltipText = BeatmapsetsStrings.ShowStatsAr; + value = ar.ToString("F2"); + updateLabel(); }, true); break; case BeatmapInfo.StarRating: beatmap.BindValueChanged(bm => { - text.Current.Value = bm.NewValue.BeatmapInfo.StarRating.ToString("F2"); + double sr = bm.NewValue.BeatmapInfo.StarRating; + labelText = TooltipText = BeatmapsetsStrings.ShowStatsStars; + value = sr.ToString("F2"); + updateLabel(); }, true); break; case BeatmapInfo.Song: beatmap.BindValueChanged(bm => { - text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Title; + string title = bm.NewValue.BeatmapInfo.Metadata.Title; + //todo: no Song Title localisation? + labelText = TooltipText = "Song Title"; + value = title; + updateLabel(); }, true); break; case BeatmapInfo.Artist: beatmap.BindValueChanged(bm => { - text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Artist; + string artist = bm.NewValue.BeatmapInfo.Metadata.Artist; + //todo: Localize Artist + labelText = "Artist"; + TooltipText = BeatmapsetsStrings.ShowDetailsByArtist(artist); + value = artist; + updateLabel(); }, true); break; case BeatmapInfo.Difficulty: beatmap.BindValueChanged(bm => { - text.Current.Value = bm.NewValue.BeatmapInfo.DifficultyName; + string diff = bm.NewValue.BeatmapInfo.DifficultyName; + //todo: no Difficulty name localisation? + labelText = TooltipText = "Difficulty"; + text.Current.Value = diff; + updateLabel(); }, true); break; case BeatmapInfo.Mapper: beatmap.BindValueChanged(bm => { - text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Author.Username; + string mapper = bm.NewValue.BeatmapInfo.Metadata.Author.Username; + //todo: is there a good alternative, to ShowDetailsMappedBy? + labelText = "Mapper"; + TooltipText = BeatmapsetsStrings.ShowDetailsMappedBy(mapper); + value = mapper; + updateLabel(); }, true); break; case BeatmapInfo.Length: beatmap.BindValueChanged(bm => { - const long ms_to_s = 1000; - double length = bm.NewValue.BeatmapInfo.Length; - double rawS = length / ms_to_s; - double rawM = rawS / 60; - double rawH = rawM / 60; - double rawD = rawH / 24; + labelText = TooltipText = BeatmapsetsStrings.ShowStatsTotalLength(TimeSpan.FromMilliseconds(bm.NewValue.BeatmapInfo.Length).ToFormattedDuration()); + value = TimeSpan.FromMilliseconds(bm.NewValue.BeatmapInfo.Length).ToFormattedDuration(); + updateLabel(); + }, true); + break; - long s = (long)rawS % 60; - long m = (long)rawM % 60; - long h = (long)rawH % 24; - long d = (long)rawD; - StringBuilder builder = new StringBuilder(); + case BeatmapInfo.Status: + beatmap.BindValueChanged(bm => + { + BeatmapOnlineStatus status = bm.NewValue.BeatmapInfo.Status; + //todo: no Localizasion for None Beatmap Online Status + //todo: no Localization for Status? + labelText = "Status"; - if (d != 0) + switch (status) { - builder.Append(d.ToString("D2")); - builder.Append(":"); + case BeatmapOnlineStatus.Approved: + value = BeatmapsetsStrings.ShowStatusApproved; + //todo: is this correct? + TooltipText = BeatmapsetsStrings.ShowDetailsDateApproved(bm.NewValue.BeatmapSetInfo.DateRanked.ToString()); + break; + + case BeatmapOnlineStatus.Graveyard: + value = BeatmapsetsStrings.ShowStatusGraveyard; + break; + + case BeatmapOnlineStatus.Loved: + value = BeatmapsetsStrings.ShowStatusLoved; + break; + + case BeatmapOnlineStatus.None: + value = "None"; + break; + + case BeatmapOnlineStatus.Pending: + value = BeatmapsetsStrings.ShowStatusPending; + break; + + case BeatmapOnlineStatus.Qualified: + value = BeatmapsetsStrings.ShowStatusQualified; + break; + + case BeatmapOnlineStatus.Ranked: + value = BeatmapsetsStrings.ShowStatusRanked; + break; + + case BeatmapOnlineStatus.LocallyModified: + value = SongSelectStrings.LocallyModified; + break; + + case BeatmapOnlineStatus.WIP: + value = BeatmapsetsStrings.ShowStatusWip; + break; } - if (h != 0 || d != 0) - { - builder.Append(h.ToString("D2")); - builder.Append(":"); - } - - builder.Append(m.ToString("D2")); - builder.Append(":"); - builder.Append(s.ToString("D2")); - text.Current.Value = builder.ToString(); + updateLabel(); }, true); break; case BeatmapInfo.BPM: beatmap.BindValueChanged(bm => { - text.Current.Value = bm.NewValue.BeatmapInfo.BPM.ToString("F2"); + labelText = TooltipText = BeatmapsetsStrings.ShowStatsBpm; + value = bm.NewValue.BeatmapInfo.BPM.ToString("F2"); + updateLabel(); }, true); break; } @@ -175,6 +311,7 @@ namespace osu.Game.Skinning.Components Difficulty, Mapper, Length, + Status, BPM, } } From 2e5db5e25983d9d074c695c4f27020e6f31dfb83 Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:24:05 +0100 Subject: [PATCH 05/41] Remove nullable disable from TextElement --- osu.Game/Skinning/Components/TextElement.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Skinning/Components/TextElement.cs b/osu.Game/Skinning/Components/TextElement.cs index e29ab6de58..da09aa76b2 100644 --- a/osu.Game/Skinning/Components/TextElement.cs +++ b/osu.Game/Skinning/Components/TextElement.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using JetBrains.Annotations; using osu.Framework.Bindables; using osu.Framework.Graphics; From 95e2521ca46cea560e88d26c1e82f47483e8798b Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:56:55 +0100 Subject: [PATCH 06/41] Use more Localisations --- .../Skinning/Components/BeatmapInfoDrawable.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs index 4110086b2a..44c3914d2c 100644 --- a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs +++ b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs @@ -184,7 +184,7 @@ namespace osu.Game.Skinning.Components { string title = bm.NewValue.BeatmapInfo.Metadata.Title; //todo: no Song Title localisation? - labelText = TooltipText = "Song Title"; + labelText = TooltipText = EditorSetupStrings.Title; value = title; updateLabel(); }, true); @@ -194,8 +194,7 @@ namespace osu.Game.Skinning.Components beatmap.BindValueChanged(bm => { string artist = bm.NewValue.BeatmapInfo.Metadata.Artist; - //todo: Localize Artist - labelText = "Artist"; + labelText = EditorSetupStrings.Artist; TooltipText = BeatmapsetsStrings.ShowDetailsByArtist(artist); value = artist; updateLabel(); @@ -206,8 +205,7 @@ namespace osu.Game.Skinning.Components beatmap.BindValueChanged(bm => { string diff = bm.NewValue.BeatmapInfo.DifficultyName; - //todo: no Difficulty name localisation? - labelText = TooltipText = "Difficulty"; + labelText = TooltipText = EditorSetupStrings.DifficultyHeader; text.Current.Value = diff; updateLabel(); }, true); @@ -218,7 +216,7 @@ namespace osu.Game.Skinning.Components { string mapper = bm.NewValue.BeatmapInfo.Metadata.Author.Username; //todo: is there a good alternative, to ShowDetailsMappedBy? - labelText = "Mapper"; + labelText = AccountsStrings.NotificationsOptionsMapping; TooltipText = BeatmapsetsStrings.ShowDetailsMappedBy(mapper); value = mapper; updateLabel(); @@ -228,7 +226,7 @@ namespace osu.Game.Skinning.Components case BeatmapInfo.Length: beatmap.BindValueChanged(bm => { - labelText = TooltipText = BeatmapsetsStrings.ShowStatsTotalLength(TimeSpan.FromMilliseconds(bm.NewValue.BeatmapInfo.Length).ToFormattedDuration()); + labelText = TooltipText = ArtistStrings.TracklistLength; value = TimeSpan.FromMilliseconds(bm.NewValue.BeatmapInfo.Length).ToFormattedDuration(); updateLabel(); }, true); @@ -239,8 +237,7 @@ namespace osu.Game.Skinning.Components { BeatmapOnlineStatus status = bm.NewValue.BeatmapInfo.Status; //todo: no Localizasion for None Beatmap Online Status - //todo: no Localization for Status? - labelText = "Status"; + labelText = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault; switch (status) { From 75b5025e123f5716b6b0aff6aebe7ef8667553ee Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Wed, 2 Nov 2022 16:37:48 +0100 Subject: [PATCH 07/41] Fix Skin Deserialisation Test --- .../Archives/modified-default-20221102.osk | Bin 0 -> 1534 bytes osu.Game.Tests/Skins/SkinDeserialisationTest.cs | 4 +++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 osu.Game.Tests/Resources/Archives/modified-default-20221102.osk diff --git a/osu.Game.Tests/Resources/Archives/modified-default-20221102.osk b/osu.Game.Tests/Resources/Archives/modified-default-20221102.osk new file mode 100644 index 0000000000000000000000000000000000000000..3ec328db4e8212e2cb709865362b24f83951b93e GIT binary patch literal 1534 zcmWIWW@Zs#U|`^2NN-6B{k=AO?o1$WGgyRyp*TA;PcJhsQ}v7?Uz3A?!^L?i?+t<+ zla2&jio6+_nX1E<*3i4#IPE6y!yGZWliC~`|LOn#{Vzl`#=R|W?&X`O80LDVbQ(Nn znX#yx+1rz4%;f*Sr?uTAxyVI%L+HDUVhxY@BW5nr?WLKLEw~Gv4vZmjIpK z1H`;Q403*EURu6hR&jpb>Ss@b0s=mHpYaXd6clhuUoSMIBhX97>-_odz@Q5TMg~Tg zLN1&*>wnVcw2$w_kV}l(<$7MeIw$p+UUHm0eeSgW`DU+*XQI}d?VI+U#a$tj}*2ki&Obn>bd;h|Bkv}5?LpU=713%Dt z!TEXV!Kpc^$t7S1?wuH$eaJwf^*!r<=WE_87slTzdvNqxt--MwXLd<{RJs<_k*Cm#O61*4n}CKI$QjBky+}4dvo?E9ALgL{iCd#pKZ5a%i#m^JlemmzSzU* zn>F{6i?6z5Vu9M*ZOpwIWqwccDz*t;iaE+#Ikm*syV5-8LP%rPg6fEEm$eUxY&q?i zExc6g`}RX8+cqt23Cb|jk1YMX+$reB>uR>0mVcZD|1z*|e9!){Fs)Yq$l-;;t{+)_ zD=a=GtCuWJe#_;4FMsKl&*IxI>0MR3X!LFROBL6>XIi$rUD$G}r*YRNznnSYH{PDv z&xjiK)eZ7#FMwfR1`K#HVA%U6X6AW>x;W?O7Ubup=9LtKqu}lI*zDT|B5m)v|MII{ zUpK-2QNN?!ttHXNB#gax&A!Ba)Yj7_Ra54qPU4&W;d!#tkD6<1mc2-8c3j_gU-?VH zo5i<38z27}YAcg&a6dQU!$C=n*h&6t7>rH}I%G}a+@^eaHs{O(lcpZ(3Edcw9O}jV z!s>Uy^`DF@c1}|EnwNK7^7aFvM3sdmCt6;oJazi;hx^U5SBy_QraAH4v8r8WV*agk zcT1IP*qvJw#jB1ipVF46{C3S%C>i4mS7sdL-U)uL=KT!B_ z)h7=BUU#+~ArS^MotNz}*>(JyrqrY>aUbn3+u0UquI1j?-rhSYp?rP}qcQ94nrYsq zj^8HhvXm6gSzzb+cj5D`yOyU&{H&{B5%fxWrMmC=@%GT~OMWMQ`ELLD-^VkF+3Q$E z$}TWYvrzM#p?18aC Ghz9_U=60t5 literal 0 HcmV?d00001 diff --git a/osu.Game.Tests/Skins/SkinDeserialisationTest.cs b/osu.Game.Tests/Skins/SkinDeserialisationTest.cs index 989459632e..4ecf307d68 100644 --- a/osu.Game.Tests/Skins/SkinDeserialisationTest.cs +++ b/osu.Game.Tests/Skins/SkinDeserialisationTest.cs @@ -40,7 +40,9 @@ namespace osu.Game.Tests.Skins // Covers clicks/s counter "Archives/modified-default-20220818.osk", // Covers longest combo counter - "Archives/modified-default-20221012.osk" + "Archives/modified-default-20221012.osk", + // Covers TextElement and BeatmapInfoDrawable + "Archives/modified-default-20221102.osk" }; /// From 502bfa950ec94ab296fbae266e82a1e1b3a5b3ee Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Thu, 3 Nov 2022 08:05:26 +0100 Subject: [PATCH 08/41] Fix potential resource leak --- .../Components/BeatmapInfoDrawable.cs | 213 +++++++----------- 1 file changed, 82 insertions(+), 131 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs index 44c3914d2c..ac771af8f9 100644 --- a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs +++ b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs @@ -83,17 +83,18 @@ namespace osu.Game.Skinning.Components protected override void LoadComplete() { base.LoadComplete(); - Type.BindValueChanged(update, true); - ShowLabel.BindValueChanged(ignored => updateLabel()); - ValueBeforeLabel.BindValueChanged(ignored => updateLabel()); - LabelPrefix.BindValueChanged(ignored => updateLabel()); - ShowLabelPrefix.BindValueChanged(ignored => updateLabel()); - LabelSuffix.BindValueChanged(ignored => updateLabel()); - ShowLabelSuffix.BindValueChanged(ignored => updateLabel()); - ValuePrefix.BindValueChanged(ignored => updateLabel()); - ShowValuePrefix.BindValueChanged(ignored => updateLabel()); - ValueSuffix.BindValueChanged(ignored => updateLabel()); - ShowValueSuffix.BindValueChanged(ignored => updateLabel()); + Type.BindValueChanged(_ => updateBeatmapContent()); + beatmap.BindValueChanged(_ => updateBeatmapContent(), true); + ShowLabel.BindValueChanged(_ => updateLabel()); + ValueBeforeLabel.BindValueChanged(_ => updateLabel()); + LabelPrefix.BindValueChanged(_ => updateLabel()); + ShowLabelPrefix.BindValueChanged(_ => updateLabel()); + LabelSuffix.BindValueChanged(_ => updateLabel()); + ShowLabelSuffix.BindValueChanged(_ => updateLabel()); + ValuePrefix.BindValueChanged(_ => updateLabel()); + ShowValuePrefix.BindValueChanged(_ => updateLabel()); + ValueSuffix.BindValueChanged(_ => updateLabel()); + ShowValueSuffix.BindValueChanged(_ => updateLabel()); } private LocalisableString getLabelText() @@ -125,174 +126,124 @@ namespace osu.Game.Skinning.Components Height = text.Height; } - private void update(ValueChangedEvent type) + private void updateBeatmapContent() { - switch (type.NewValue) + switch (Type.Value) { case BeatmapInfo.CircleSize: - beatmap.BindValueChanged(bm => - { - double cs = bm.NewValue.BeatmapInfo.Difficulty.CircleSize; - labelText = TooltipText = BeatmapsetsStrings.ShowStatsCs; - value = cs.ToString("F2"); - updateLabel(); - }, true); + double cs = beatmap.Value.BeatmapInfo.Difficulty.CircleSize; + labelText = TooltipText = BeatmapsetsStrings.ShowStatsCs; + value = cs.ToString("F2"); break; case BeatmapInfo.HPDrain: - beatmap.BindValueChanged(bm => - { - double hp = bm.NewValue.BeatmapInfo.Difficulty.DrainRate; - labelText = TooltipText = BeatmapsetsStrings.ShowStatsDrain; - value = hp.ToString("F2"); - updateLabel(); - }, true); + double hp = beatmap.Value.BeatmapInfo.Difficulty.DrainRate; + labelText = TooltipText = BeatmapsetsStrings.ShowStatsDrain; + value = hp.ToString("F2"); break; case BeatmapInfo.Accuracy: - beatmap.BindValueChanged(bm => - { - double od = bm.NewValue.BeatmapInfo.Difficulty.OverallDifficulty; - labelText = TooltipText = BeatmapsetsStrings.ShowStatsAccuracy; - value = od.ToString("F2"); - updateLabel(); - }, true); + double od = beatmap.Value.BeatmapInfo.Difficulty.OverallDifficulty; + labelText = TooltipText = BeatmapsetsStrings.ShowStatsAccuracy; + value = od.ToString("F2"); break; case BeatmapInfo.ApproachRate: - beatmap.BindValueChanged(bm => - { - double ar = bm.NewValue.BeatmapInfo.Difficulty.ApproachRate; - labelText = TooltipText = BeatmapsetsStrings.ShowStatsAr; - value = ar.ToString("F2"); - updateLabel(); - }, true); + double ar = beatmap.Value.BeatmapInfo.Difficulty.ApproachRate; + labelText = TooltipText = BeatmapsetsStrings.ShowStatsAr; + value = ar.ToString("F2"); break; case BeatmapInfo.StarRating: - beatmap.BindValueChanged(bm => - { - double sr = bm.NewValue.BeatmapInfo.StarRating; - labelText = TooltipText = BeatmapsetsStrings.ShowStatsStars; - value = sr.ToString("F2"); - updateLabel(); - }, true); + double sr = beatmap.Value.BeatmapInfo.StarRating; + labelText = TooltipText = BeatmapsetsStrings.ShowStatsStars; + value = sr.ToString("F2"); break; case BeatmapInfo.Song: - beatmap.BindValueChanged(bm => - { - string title = bm.NewValue.BeatmapInfo.Metadata.Title; - //todo: no Song Title localisation? - labelText = TooltipText = EditorSetupStrings.Title; - value = title; - updateLabel(); - }, true); + string title = beatmap.Value.BeatmapInfo.Metadata.Title; + labelText = TooltipText = EditorSetupStrings.Title; + value = title; break; case BeatmapInfo.Artist: - beatmap.BindValueChanged(bm => - { - string artist = bm.NewValue.BeatmapInfo.Metadata.Artist; - labelText = EditorSetupStrings.Artist; - TooltipText = BeatmapsetsStrings.ShowDetailsByArtist(artist); - value = artist; - updateLabel(); - }, true); + string artist = beatmap.Value.BeatmapInfo.Metadata.Artist; + labelText = EditorSetupStrings.Artist; + TooltipText = BeatmapsetsStrings.ShowDetailsByArtist(artist); + value = artist; break; case BeatmapInfo.Difficulty: - beatmap.BindValueChanged(bm => - { - string diff = bm.NewValue.BeatmapInfo.DifficultyName; - labelText = TooltipText = EditorSetupStrings.DifficultyHeader; - text.Current.Value = diff; - updateLabel(); - }, true); + string diff = beatmap.Value.BeatmapInfo.DifficultyName; + labelText = TooltipText = EditorSetupStrings.DifficultyHeader; + text.Current.Value = diff; break; case BeatmapInfo.Mapper: - beatmap.BindValueChanged(bm => - { - string mapper = bm.NewValue.BeatmapInfo.Metadata.Author.Username; - //todo: is there a good alternative, to ShowDetailsMappedBy? - labelText = AccountsStrings.NotificationsOptionsMapping; - TooltipText = BeatmapsetsStrings.ShowDetailsMappedBy(mapper); - value = mapper; - updateLabel(); - }, true); + string mapper = beatmap.Value.BeatmapInfo.Metadata.Author.Username; + //todo: is there a good alternative, to NotificationsOptionsMapping? + labelText = AccountsStrings.NotificationsOptionsMapping; + TooltipText = BeatmapsetsStrings.ShowDetailsMappedBy(mapper); + value = mapper; break; case BeatmapInfo.Length: - beatmap.BindValueChanged(bm => - { - labelText = TooltipText = ArtistStrings.TracklistLength; - value = TimeSpan.FromMilliseconds(bm.NewValue.BeatmapInfo.Length).ToFormattedDuration(); - updateLabel(); - }, true); + labelText = TooltipText = ArtistStrings.TracklistLength; + value = TimeSpan.FromMilliseconds(beatmap.Value.BeatmapInfo.Length).ToFormattedDuration(); break; case BeatmapInfo.Status: - beatmap.BindValueChanged(bm => + BeatmapOnlineStatus status = beatmap.Value.BeatmapInfo.Status; + TooltipText = labelText = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault; + + switch (status) { - BeatmapOnlineStatus status = bm.NewValue.BeatmapInfo.Status; - //todo: no Localizasion for None Beatmap Online Status - labelText = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault; + case BeatmapOnlineStatus.Approved: + value = BeatmapsetsStrings.ShowStatusApproved; + break; - switch (status) - { - case BeatmapOnlineStatus.Approved: - value = BeatmapsetsStrings.ShowStatusApproved; - //todo: is this correct? - TooltipText = BeatmapsetsStrings.ShowDetailsDateApproved(bm.NewValue.BeatmapSetInfo.DateRanked.ToString()); - break; + case BeatmapOnlineStatus.Graveyard: + value = BeatmapsetsStrings.ShowStatusGraveyard; + break; - case BeatmapOnlineStatus.Graveyard: - value = BeatmapsetsStrings.ShowStatusGraveyard; - break; + case BeatmapOnlineStatus.Loved: + value = BeatmapsetsStrings.ShowStatusLoved; + break; - case BeatmapOnlineStatus.Loved: - value = BeatmapsetsStrings.ShowStatusLoved; - break; + case BeatmapOnlineStatus.None: + value = "None"; + break; - case BeatmapOnlineStatus.None: - value = "None"; - break; + case BeatmapOnlineStatus.Pending: + value = BeatmapsetsStrings.ShowStatusPending; + break; - case BeatmapOnlineStatus.Pending: - value = BeatmapsetsStrings.ShowStatusPending; - break; + case BeatmapOnlineStatus.Qualified: + value = BeatmapsetsStrings.ShowStatusQualified; + break; - case BeatmapOnlineStatus.Qualified: - value = BeatmapsetsStrings.ShowStatusQualified; - break; + case BeatmapOnlineStatus.Ranked: + value = BeatmapsetsStrings.ShowStatusRanked; + break; - case BeatmapOnlineStatus.Ranked: - value = BeatmapsetsStrings.ShowStatusRanked; - break; + case BeatmapOnlineStatus.LocallyModified: + value = SongSelectStrings.LocallyModified; + break; - case BeatmapOnlineStatus.LocallyModified: - value = SongSelectStrings.LocallyModified; - break; + case BeatmapOnlineStatus.WIP: + value = BeatmapsetsStrings.ShowStatusWip; + break; + } - case BeatmapOnlineStatus.WIP: - value = BeatmapsetsStrings.ShowStatusWip; - break; - } - - updateLabel(); - }, true); break; case BeatmapInfo.BPM: - beatmap.BindValueChanged(bm => - { - labelText = TooltipText = BeatmapsetsStrings.ShowStatsBpm; - value = bm.NewValue.BeatmapInfo.BPM.ToString("F2"); - updateLabel(); - }, true); + labelText = TooltipText = BeatmapsetsStrings.ShowStatsBpm; + value = beatmap.Value.BeatmapInfo.BPM.ToString("F2"); break; } + + updateLabel(); } } From a435e365ea966cae81caff8b9923b8f7ed25c77e Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Thu, 3 Nov 2022 18:54:55 +0100 Subject: [PATCH 09/41] Allow for the Value of BeatmapInfoDrawable to be formatted --- .../Components/BeatmapInfoDrawable.cs | 294 ++++++++++-------- 1 file changed, 159 insertions(+), 135 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs index ac771af8f9..479124a43d 100644 --- a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs +++ b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs @@ -2,12 +2,14 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Cursor; using osu.Framework.Localisation; using osu.Game.Beatmaps; using osu.Game.Configuration; @@ -20,12 +22,13 @@ using osu.Game.Resources.Localisation.Web; namespace osu.Game.Skinning.Components { [UsedImplicitly] - public class BeatmapInfoDrawable : Container, ISkinnableDrawable, IHasTooltip + public class BeatmapInfoDrawable : Container, ISkinnableDrawable { + private const BeatmapInfo default_beatmap_info = BeatmapInfo.StarRating; public bool UsesFixedAnchor { get; set; } - [SettingSource("Tracked Beatmap Info", "Which part of the BeatmapInformation should be tracked")] - public Bindable Type { get; } = new Bindable(BeatmapInfo.StarRating); + [SettingSource("Tracked Beatmap Info/Label", "Which part of the BeatmapInformation should be displayed. Gets overridden by complex changes to ValueFormat")] + public Bindable Type { get; } = new Bindable(default_beatmap_info); [SettingSource("Show Label", "Should a Label be shown, as to which status is currently Displayed?")] public BindableBool ShowLabel { get; } = new BindableBool(true); @@ -45,26 +48,37 @@ namespace osu.Game.Skinning.Components [SettingSource("Show Label Suffix", "Should the Label Suffix be included?")] public BindableBool ShowLabelSuffix { get; } = new BindableBool(true); - [SettingSource("Value Prefix", "Add something to be shown before the Value")] - public Bindable ValuePrefix { get; set; } = new Bindable(""); - - [SettingSource("Show Value Prefix", "Should the Value Prefix be included?")] - public BindableBool ShowValuePrefix { get; } = new BindableBool(); - - [SettingSource("Value Suffix", "Add something to be shown after the Value")] - public Bindable ValueSuffix { get; set; } = new Bindable(""); - - [SettingSource("Show Value Suffix", "Should the Value Suffix be included?")] - public BindableBool ShowValueSuffix { get; } = new BindableBool(); + [SettingSource("Value Formatting", "Bypass the restriction of 1 Info per element. Format is '{'+Type+'}' to substitue values. e.g. '{Song}' ")] + public Bindable ValueFormat { get; set; } = new Bindable("{" + default_beatmap_info + "}"); [Resolved] private IBindable beatmap { get; set; } = null!; + private readonly Dictionary valueDictionary = new Dictionary(); + private static readonly ImmutableDictionary label_dictionary; + private readonly OsuSpriteText text; - public LocalisableString TooltipText { get; set; } - private LocalisableString value; - private LocalisableString labelText; + static BeatmapInfoDrawable() + { + label_dictionary = new Dictionary + { + [BeatmapInfo.CircleSize] = BeatmapsetsStrings.ShowStatsCs, + [BeatmapInfo.Accuracy] = BeatmapsetsStrings.ShowStatsAccuracy, + [BeatmapInfo.HPDrain] = BeatmapsetsStrings.ShowStatsDrain, + [BeatmapInfo.ApproachRate] = BeatmapsetsStrings.ShowStatsAr, + [BeatmapInfo.StarRating] = BeatmapsetsStrings.ShowStatsStars, + [BeatmapInfo.Song] = EditorSetupStrings.Title, + [BeatmapInfo.Artist] = EditorSetupStrings.Artist, + [BeatmapInfo.Difficulty] = EditorSetupStrings.DifficultyHeader, + //todo: is there a good alternative, to NotificationsOptionsMapping? + [BeatmapInfo.Mapper] = AccountsStrings.NotificationsOptionsMapping, + [BeatmapInfo.Length] = ArtistStrings.TracklistLength, + [BeatmapInfo.Status] = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault, + [BeatmapInfo.BPM] = BeatmapsetsStrings.ShowStatsBpm, + [BeatmapInfo.Custom] = BeatmapInfo.Custom.ToString() + }.ToImmutableDictionary(); + } public BeatmapInfoDrawable() { @@ -78,23 +92,78 @@ namespace osu.Game.Skinning.Components Font = OsuFont.Default.With(size: 40) } }; + + foreach (var type in Enum.GetValues(typeof(BeatmapInfo)).Cast()) + { + valueDictionary[type] = type.ToString(); + } + } + + /// + /// This will return the if the format-String contains of a singular replacement of type info, or not. + /// If there is only one one replacement of type info, it will also return the prefix/suffix (or null if no prefix/suffix exists). + /// + /// The format-String to work on + /// The replacement Type to look for + /// (true, prefix, suffix), if there is only one replacement of type info. Else (false, null, null) + private static (bool, string?, string?) isOnlyPrefixedOrSuffixed(string format, BeatmapInfo info) + { + string[] s = format.Split("{" + info + "}"); + + foreach (string si in s) + { + foreach (var type in Enum.GetValues(typeof(BeatmapInfo)).Cast()) + { + if (si.Contains("{" + type + "}")) return (false, null, null); + } + } + + //Debug.WriteLine($"format:'{format}', type:{info} is only prefixed/suffixed"); + + return (true, + s.Length >= 1 ? s[0] : null, //prefix + s.Length >= 2 ? s[1] : null //suffix + ); } protected override void LoadComplete() { base.LoadComplete(); - Type.BindValueChanged(_ => updateBeatmapContent()); - beatmap.BindValueChanged(_ => updateBeatmapContent(), true); + Type.BindValueChanged(v => + { + string newDefault = "{" + v.NewValue + "}"; + bool custom = v.NewValue == BeatmapInfo.Custom; + + //If the ValueFormat is Default and the user did not change anything we should be able to just swap the strings. + //If it was Default before, it should be default after the Type is changed. + if (ValueFormat.IsDefault && !custom) + ValueFormat.Value = newDefault; + else + { + //In this if statement we decide if the ValueFormat has been trivially changed (so only been prefixed or suffixed) + (bool preOrSuffixed, string? prefix, string? suffix) = isOnlyPrefixedOrSuffixed(ValueFormat.Value, v.OldValue); + if (preOrSuffixed) + //If it has, we can keep the prefix and suffix and just change the thing that would be substituted. + ValueFormat.Value = (prefix ?? "") + newDefault + (suffix ?? ""); + //else we just keep the ValueFormat. I determine here, that the user probably knows what they are doing, and how the ValueFormat works. + } + + //Only if we could preserve the ValueFormat (so nothing was changed except a static prefix/suffix) I want to set the new Default. + ValueFormat.Default = newDefault; + updateLabel(); + }); + ValueFormat.BindValueChanged(f => updateLabel(), true); + beatmap.BindValueChanged(b => + { + UpdateBeatmapContent(b.NewValue); + updateLabel(); + }, true); ShowLabel.BindValueChanged(_ => updateLabel()); ValueBeforeLabel.BindValueChanged(_ => updateLabel()); LabelPrefix.BindValueChanged(_ => updateLabel()); ShowLabelPrefix.BindValueChanged(_ => updateLabel()); LabelSuffix.BindValueChanged(_ => updateLabel()); ShowLabelSuffix.BindValueChanged(_ => updateLabel()); - ValuePrefix.BindValueChanged(_ => updateLabel()); - ShowValuePrefix.BindValueChanged(_ => updateLabel()); - ValueSuffix.BindValueChanged(_ => updateLabel()); - ShowValueSuffix.BindValueChanged(_ => updateLabel()); } private LocalisableString getLabelText() @@ -103,16 +172,20 @@ namespace osu.Game.Skinning.Components return LocalisableString.Format("{0}{1}{2}", ShowLabelPrefix.Value ? LabelPrefix.Value : "", - labelText, + label_dictionary[Type.Value], ShowLabelSuffix.Value ? LabelSuffix.Value : ""); } private LocalisableString getValueText() { - return LocalisableString.Format("{0}{1}{2}", - ShowValuePrefix.Value ? ValuePrefix.Value : "", - value, - ShowValueSuffix.Value ? ValueSuffix.Value : ""); + string value = ValueFormat.Value; + + foreach (var type in Enum.GetValues(typeof(BeatmapInfo)).Cast()) + { + value = value.Replace("{" + type + "}", valueDictionary[type].ToString()); + } + + return value; } private void updateLabel() @@ -126,124 +199,74 @@ namespace osu.Game.Skinning.Components Height = text.Height; } - private void updateBeatmapContent() + public void UpdateBeatmapContent(WorkingBeatmap workingBeatmap) { - switch (Type.Value) + //update cs + double cs = workingBeatmap.BeatmapInfo.Difficulty.CircleSize; + valueDictionary[BeatmapInfo.CircleSize] = cs.ToString("F2"); + //update HP + double hp = workingBeatmap.BeatmapInfo.Difficulty.DrainRate; + valueDictionary[BeatmapInfo.HPDrain] = hp.ToString("F2"); + //update od + double od = workingBeatmap.BeatmapInfo.Difficulty.OverallDifficulty; + valueDictionary[BeatmapInfo.Accuracy] = od.ToString("F2"); + //update ar + double ar = workingBeatmap.BeatmapInfo.Difficulty.ApproachRate; + valueDictionary[BeatmapInfo.ApproachRate] = ar.ToString("F2"); + //update sr + double sr = workingBeatmap.BeatmapInfo.StarRating; + valueDictionary[BeatmapInfo.StarRating] = sr.ToString("F2"); + //update song title + valueDictionary[BeatmapInfo.Song] = workingBeatmap.BeatmapInfo.Metadata.Title; + //update artist + valueDictionary[BeatmapInfo.Artist] = workingBeatmap.BeatmapInfo.Metadata.Artist; + //update difficulty name + valueDictionary[BeatmapInfo.Difficulty] = workingBeatmap.BeatmapInfo.DifficultyName; + //update mapper + valueDictionary[BeatmapInfo.Mapper] = workingBeatmap.BeatmapInfo.Metadata.Author.Username; + //update Length + valueDictionary[BeatmapInfo.Length] = TimeSpan.FromMilliseconds(workingBeatmap.BeatmapInfo.Length).ToFormattedDuration(); + //update Status + valueDictionary[BeatmapInfo.Status] = GetBetmapStatus(workingBeatmap.BeatmapInfo.Status); + //update BPM + valueDictionary[BeatmapInfo.BPM] = workingBeatmap.BeatmapInfo.BPM.ToString("F2"); + valueDictionary[BeatmapInfo.Custom] = BeatmapInfo.Custom.ToString(); + } + + public static LocalisableString GetBetmapStatus(BeatmapOnlineStatus status) + { + switch (status) { - case BeatmapInfo.CircleSize: - double cs = beatmap.Value.BeatmapInfo.Difficulty.CircleSize; - labelText = TooltipText = BeatmapsetsStrings.ShowStatsCs; - value = cs.ToString("F2"); - break; + case BeatmapOnlineStatus.Approved: + return BeatmapsetsStrings.ShowStatusApproved; - case BeatmapInfo.HPDrain: - double hp = beatmap.Value.BeatmapInfo.Difficulty.DrainRate; - labelText = TooltipText = BeatmapsetsStrings.ShowStatsDrain; - value = hp.ToString("F2"); - break; + case BeatmapOnlineStatus.Graveyard: + return BeatmapsetsStrings.ShowStatusGraveyard; - case BeatmapInfo.Accuracy: - double od = beatmap.Value.BeatmapInfo.Difficulty.OverallDifficulty; - labelText = TooltipText = BeatmapsetsStrings.ShowStatsAccuracy; - value = od.ToString("F2"); - break; + case BeatmapOnlineStatus.Loved: + return BeatmapsetsStrings.ShowStatusLoved; - case BeatmapInfo.ApproachRate: - double ar = beatmap.Value.BeatmapInfo.Difficulty.ApproachRate; - labelText = TooltipText = BeatmapsetsStrings.ShowStatsAr; - value = ar.ToString("F2"); - break; + case BeatmapOnlineStatus.None: + return "None"; - case BeatmapInfo.StarRating: - double sr = beatmap.Value.BeatmapInfo.StarRating; - labelText = TooltipText = BeatmapsetsStrings.ShowStatsStars; - value = sr.ToString("F2"); - break; + case BeatmapOnlineStatus.Pending: + return BeatmapsetsStrings.ShowStatusPending; - case BeatmapInfo.Song: - string title = beatmap.Value.BeatmapInfo.Metadata.Title; - labelText = TooltipText = EditorSetupStrings.Title; - value = title; - break; + case BeatmapOnlineStatus.Qualified: + return BeatmapsetsStrings.ShowStatusQualified; - case BeatmapInfo.Artist: - string artist = beatmap.Value.BeatmapInfo.Metadata.Artist; - labelText = EditorSetupStrings.Artist; - TooltipText = BeatmapsetsStrings.ShowDetailsByArtist(artist); - value = artist; - break; + case BeatmapOnlineStatus.Ranked: + return BeatmapsetsStrings.ShowStatusRanked; - case BeatmapInfo.Difficulty: - string diff = beatmap.Value.BeatmapInfo.DifficultyName; - labelText = TooltipText = EditorSetupStrings.DifficultyHeader; - text.Current.Value = diff; - break; + case BeatmapOnlineStatus.LocallyModified: + return SongSelectStrings.LocallyModified; - case BeatmapInfo.Mapper: - string mapper = beatmap.Value.BeatmapInfo.Metadata.Author.Username; - //todo: is there a good alternative, to NotificationsOptionsMapping? - labelText = AccountsStrings.NotificationsOptionsMapping; - TooltipText = BeatmapsetsStrings.ShowDetailsMappedBy(mapper); - value = mapper; - break; + case BeatmapOnlineStatus.WIP: + return BeatmapsetsStrings.ShowStatusWip; - case BeatmapInfo.Length: - labelText = TooltipText = ArtistStrings.TracklistLength; - value = TimeSpan.FromMilliseconds(beatmap.Value.BeatmapInfo.Length).ToFormattedDuration(); - break; - - case BeatmapInfo.Status: - BeatmapOnlineStatus status = beatmap.Value.BeatmapInfo.Status; - TooltipText = labelText = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault; - - switch (status) - { - case BeatmapOnlineStatus.Approved: - value = BeatmapsetsStrings.ShowStatusApproved; - break; - - case BeatmapOnlineStatus.Graveyard: - value = BeatmapsetsStrings.ShowStatusGraveyard; - break; - - case BeatmapOnlineStatus.Loved: - value = BeatmapsetsStrings.ShowStatusLoved; - break; - - case BeatmapOnlineStatus.None: - value = "None"; - break; - - case BeatmapOnlineStatus.Pending: - value = BeatmapsetsStrings.ShowStatusPending; - break; - - case BeatmapOnlineStatus.Qualified: - value = BeatmapsetsStrings.ShowStatusQualified; - break; - - case BeatmapOnlineStatus.Ranked: - value = BeatmapsetsStrings.ShowStatusRanked; - break; - - case BeatmapOnlineStatus.LocallyModified: - value = SongSelectStrings.LocallyModified; - break; - - case BeatmapOnlineStatus.WIP: - value = BeatmapsetsStrings.ShowStatusWip; - break; - } - - break; - - case BeatmapInfo.BPM: - labelText = TooltipText = BeatmapsetsStrings.ShowStatsBpm; - value = beatmap.Value.BeatmapInfo.BPM.ToString("F2"); - break; + default: + return @"null"; } - - updateLabel(); } } @@ -261,5 +284,6 @@ namespace osu.Game.Skinning.Components Length, Status, BPM, + Custom, } } From 28ab092b6f1d278f406e4e25cc812ac8184f3a74 Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Mon, 7 Nov 2022 07:55:42 +0100 Subject: [PATCH 10/41] Simplify the whole Templating process --- .../Components/BeatmapInfoDrawable.cs | 125 +++--------------- 1 file changed, 17 insertions(+), 108 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs index 479124a43d..eda956e6d8 100644 --- a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs +++ b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs @@ -27,29 +27,11 @@ namespace osu.Game.Skinning.Components private const BeatmapInfo default_beatmap_info = BeatmapInfo.StarRating; public bool UsesFixedAnchor { get; set; } - [SettingSource("Tracked Beatmap Info/Label", "Which part of the BeatmapInformation should be displayed. Gets overridden by complex changes to ValueFormat")] + [SettingSource("Tracked Beatmap Info/Label", "Which part of the BeatmapInformation should be displayed.")] public Bindable Type { get; } = new Bindable(default_beatmap_info); - [SettingSource("Show Label", "Should a Label be shown, as to which status is currently Displayed?")] - public BindableBool ShowLabel { get; } = new BindableBool(true); - - [SettingSource("Show Value first?", "Should the Value be shown first?")] - public BindableBool ValueBeforeLabel { get; } = new BindableBool(); - - [SettingSource("Label Prefix", "Add something to be shown before the label")] - public Bindable LabelPrefix { get; set; } = new Bindable(""); - - [SettingSource("Show Label Prefix", "Should the Label Prefix be included?")] - public BindableBool ShowLabelPrefix { get; } = new BindableBool(); - - [SettingSource("Label Suffix", "Add something to be shown after the label")] - public Bindable LabelSuffix { get; set; } = new Bindable(": "); - - [SettingSource("Show Label Suffix", "Should the Label Suffix be included?")] - public BindableBool ShowLabelSuffix { get; } = new BindableBool(true); - - [SettingSource("Value Formatting", "Bypass the restriction of 1 Info per element. Format is '{'+Type+'}' to substitue values. e.g. '{Song}' ")] - public Bindable ValueFormat { get; set; } = new Bindable("{" + default_beatmap_info + "}"); + [SettingSource("Template", "Bypass the restriction of 1 Info per element. Format is '{'+Type+'}' to substitue values. e.g. '{Song}' ")] + public Bindable Template { get; set; } = new Bindable("{Label}: {Value}"); [Resolved] private IBindable beatmap { get; set; } = null!; @@ -76,7 +58,7 @@ namespace osu.Game.Skinning.Components [BeatmapInfo.Length] = ArtistStrings.TracklistLength, [BeatmapInfo.Status] = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault, [BeatmapInfo.BPM] = BeatmapsetsStrings.ShowStatsBpm, - [BeatmapInfo.Custom] = BeatmapInfo.Custom.ToString() + [BeatmapInfo.None] = BeatmapInfo.None.ToString() }.ToImmutableDictionary(); } @@ -99,102 +81,29 @@ namespace osu.Game.Skinning.Components } } - /// - /// This will return the if the format-String contains of a singular replacement of type info, or not. - /// If there is only one one replacement of type info, it will also return the prefix/suffix (or null if no prefix/suffix exists). - /// - /// The format-String to work on - /// The replacement Type to look for - /// (true, prefix, suffix), if there is only one replacement of type info. Else (false, null, null) - private static (bool, string?, string?) isOnlyPrefixedOrSuffixed(string format, BeatmapInfo info) - { - string[] s = format.Split("{" + info + "}"); - - foreach (string si in s) - { - foreach (var type in Enum.GetValues(typeof(BeatmapInfo)).Cast()) - { - if (si.Contains("{" + type + "}")) return (false, null, null); - } - } - - //Debug.WriteLine($"format:'{format}', type:{info} is only prefixed/suffixed"); - - return (true, - s.Length >= 1 ? s[0] : null, //prefix - s.Length >= 2 ? s[1] : null //suffix - ); - } - protected override void LoadComplete() { base.LoadComplete(); - Type.BindValueChanged(v => - { - string newDefault = "{" + v.NewValue + "}"; - bool custom = v.NewValue == BeatmapInfo.Custom; - - //If the ValueFormat is Default and the user did not change anything we should be able to just swap the strings. - //If it was Default before, it should be default after the Type is changed. - if (ValueFormat.IsDefault && !custom) - ValueFormat.Value = newDefault; - else - { - //In this if statement we decide if the ValueFormat has been trivially changed (so only been prefixed or suffixed) - (bool preOrSuffixed, string? prefix, string? suffix) = isOnlyPrefixedOrSuffixed(ValueFormat.Value, v.OldValue); - if (preOrSuffixed) - //If it has, we can keep the prefix and suffix and just change the thing that would be substituted. - ValueFormat.Value = (prefix ?? "") + newDefault + (suffix ?? ""); - //else we just keep the ValueFormat. I determine here, that the user probably knows what they are doing, and how the ValueFormat works. - } - - //Only if we could preserve the ValueFormat (so nothing was changed except a static prefix/suffix) I want to set the new Default. - ValueFormat.Default = newDefault; - updateLabel(); - }); - ValueFormat.BindValueChanged(f => updateLabel(), true); + Type.BindValueChanged(_ => updateLabel()); + Template.BindValueChanged(f => updateLabel(), true); beatmap.BindValueChanged(b => { UpdateBeatmapContent(b.NewValue); updateLabel(); }, true); - ShowLabel.BindValueChanged(_ => updateLabel()); - ValueBeforeLabel.BindValueChanged(_ => updateLabel()); - LabelPrefix.BindValueChanged(_ => updateLabel()); - ShowLabelPrefix.BindValueChanged(_ => updateLabel()); - LabelSuffix.BindValueChanged(_ => updateLabel()); - ShowLabelSuffix.BindValueChanged(_ => updateLabel()); - } - - private LocalisableString getLabelText() - { - if (!ShowLabel.Value) return new LocalisableString(""); - - return LocalisableString.Format("{0}{1}{2}", - ShowLabelPrefix.Value ? LabelPrefix.Value : "", - label_dictionary[Type.Value], - ShowLabelSuffix.Value ? LabelSuffix.Value : ""); - } - - private LocalisableString getValueText() - { - string value = ValueFormat.Value; - - foreach (var type in Enum.GetValues(typeof(BeatmapInfo)).Cast()) - { - value = value.Replace("{" + type + "}", valueDictionary[type].ToString()); - } - - return value; } private void updateLabel() { - text.Text = LocalisableString.Format( - ValueBeforeLabel.Value ? "{1}{0}" : "{0}{1}", - getLabelText(), - getValueText() - ); + string newText = Template.Value.Replace("{Label}", label_dictionary[Type.Value].ToString()) + .Replace("{Value}", valueDictionary[Type.Value].ToString()); + + foreach (var type in Enum.GetValues(typeof(BeatmapInfo)).Cast()) + { + newText = newText.Replace("{" + type + "}", valueDictionary[type].ToString()); + } + + text.Text = newText; Width = text.Width; Height = text.Height; } @@ -230,7 +139,7 @@ namespace osu.Game.Skinning.Components valueDictionary[BeatmapInfo.Status] = GetBetmapStatus(workingBeatmap.BeatmapInfo.Status); //update BPM valueDictionary[BeatmapInfo.BPM] = workingBeatmap.BeatmapInfo.BPM.ToString("F2"); - valueDictionary[BeatmapInfo.Custom] = BeatmapInfo.Custom.ToString(); + valueDictionary[BeatmapInfo.None] = string.Empty; } public static LocalisableString GetBetmapStatus(BeatmapOnlineStatus status) @@ -284,6 +193,6 @@ namespace osu.Game.Skinning.Components Length, Status, BPM, - Custom, + None, } } From ab650d8a1bf790616c6bbf5f2d082f2b9277497c Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Mon, 7 Nov 2022 15:22:20 +0100 Subject: [PATCH 11/41] Use AutoSizeAxes --- osu.Game/Skinning/Components/BeatmapInfoDrawable.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs index eda956e6d8..379bdec333 100644 --- a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs +++ b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs @@ -64,6 +64,7 @@ namespace osu.Game.Skinning.Components public BeatmapInfoDrawable() { + AutoSizeAxes = Axes.Both; InternalChildren = new Drawable[] { text = new OsuSpriteText @@ -104,8 +105,6 @@ namespace osu.Game.Skinning.Components } text.Text = newText; - Width = text.Width; - Height = text.Height; } public void UpdateBeatmapContent(WorkingBeatmap workingBeatmap) From 3f8c4a5dfff5c094c2bb4ce6100da4f636a2a037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=BB=93=20Nguy=C3=AAn=20Minh?= Date: Sun, 13 Nov 2022 17:09:43 +0700 Subject: [PATCH 12/41] Stack Catch dash/normal touch input vertically --- .../UI/CatchTouchInputMapper.cs | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/CatchTouchInputMapper.cs b/osu.Game.Rulesets.Catch/UI/CatchTouchInputMapper.cs index e6736d6c93..12d695393f 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchTouchInputMapper.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchTouchInputMapper.cs @@ -35,6 +35,8 @@ namespace osu.Game.Rulesets.Catch.UI private void load(CatchInputManager catchInputManager, OsuColour colours) { const float width = 0.15f; + // Ratio between normal move area height and total input height + const float normal_area_height_ratio = 0.45f; keyBindingContainer = catchInputManager.KeyBindingContainer; @@ -54,18 +56,18 @@ namespace osu.Game.Rulesets.Catch.UI Width = width, Children = new Drawable[] { - leftDashBox = new InputArea(TouchCatchAction.DashLeft, trackedActionSources) - { - RelativeSizeAxes = Axes.Both, - Width = 0.5f, - }, leftBox = new InputArea(TouchCatchAction.MoveLeft, trackedActionSources) { RelativeSizeAxes = Axes.Both, - Width = 0.5f, + Height = normal_area_height_ratio, Colour = colours.Gray9, - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, + Anchor = Anchor.BottomRight, + Origin = Anchor.BottomRight, + }, + leftDashBox = new InputArea(TouchCatchAction.DashLeft, trackedActionSources) + { + RelativeSizeAxes = Axes.Both, + Height = 1 - normal_area_height_ratio, }, } }, @@ -80,15 +82,15 @@ namespace osu.Game.Rulesets.Catch.UI rightBox = new InputArea(TouchCatchAction.MoveRight, trackedActionSources) { RelativeSizeAxes = Axes.Both, - Width = 0.5f, + Height = normal_area_height_ratio, Colour = colours.Gray9, + Anchor = Anchor.BottomRight, + Origin = Anchor.BottomRight, }, rightDashBox = new InputArea(TouchCatchAction.DashRight, trackedActionSources) { RelativeSizeAxes = Axes.Both, - Width = 0.5f, - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, + Height = 1 - normal_area_height_ratio, }, } }, From 81c9ea98e2119997b22181161974642d826c5f63 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sun, 13 Nov 2022 14:59:17 +0300 Subject: [PATCH 13/41] Implement TrianglesV2 component --- .../TestSceneTriangleBorderShader.cs | 59 ++++ .../TestSceneTrianglesBackground.cs | 43 +++ osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 313 ++++++++++++++++++ 3 files changed, 415 insertions(+) create mode 100644 osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs create mode 100644 osu.Game.Tests/Visual/Background/TestSceneTrianglesBackground.cs create mode 100644 osu.Game/Graphics/Backgrounds/TrianglesV2.cs diff --git a/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs b/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs new file mode 100644 index 0000000000..470962088e --- /dev/null +++ b/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs @@ -0,0 +1,59 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using osu.Framework.Allocation; +using osu.Framework.Graphics.Shaders; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics; +using osuTK; +using osuTK.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Rendering; + +namespace osu.Game.Tests.Visual.Background +{ + public class TestSceneTriangleBorderShader : OsuTestScene + { + public TestSceneTriangleBorderShader() + { + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.DarkGreen + }, + new TriangleBorder + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(100) + } + }; + } + + private class TriangleBorder : Sprite + { + [BackgroundDependencyLoader] + private void load(ShaderManager shaders, IRenderer renderer) + { + TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "TriangleBorder"); + Texture = renderer.WhitePixel; + } + + protected override DrawNode CreateDrawNode() => new TriangleBorderDrawNode(this); + + private class TriangleBorderDrawNode : SpriteDrawNode + { + public TriangleBorderDrawNode(TriangleBorder source) + : base(source) + { + } + + protected override bool CanDrawOpaqueInterior => false; + } + } + } +} diff --git a/osu.Game.Tests/Visual/Background/TestSceneTrianglesBackground.cs b/osu.Game.Tests/Visual/Background/TestSceneTrianglesBackground.cs new file mode 100644 index 0000000000..a40d363dbe --- /dev/null +++ b/osu.Game.Tests/Visual/Background/TestSceneTrianglesBackground.cs @@ -0,0 +1,43 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osuTK; +using osuTK.Graphics; +using osu.Game.Graphics.Backgrounds; + +namespace osu.Game.Tests.Visual.Background +{ + public class TestSceneTrianglesBackground : OsuTestScene + { + public TestSceneTrianglesBackground() + { + AddRange(new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Gray + }, + new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(200), + Masking = true, + CornerRadius = 40, + Child = new TrianglesV2 + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + ColourTop = Color4.Red, + ColourBottom = Color4.Orange + } + } + }); + } + } +} diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs new file mode 100644 index 0000000000..89ec7d2ad5 --- /dev/null +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -0,0 +1,313 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using osu.Framework.Utils; +using osuTK; +using System; +using osu.Framework.Graphics.Shaders; +using osu.Framework.Graphics.Textures; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Allocation; +using System.Collections.Generic; +using osu.Framework.Graphics.Rendering; +using osu.Framework.Graphics.Rendering.Vertices; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp; +using osuTK.Graphics; +using osu.Framework.Bindables; +using osu.Framework.Graphics; + +namespace osu.Game.Graphics.Backgrounds +{ + public class TrianglesV2 : Drawable + { + private const float triangle_size = 100; + private const float base_velocity = 50; + private const int texture_height = 128; + + private readonly Bindable colourTop = new Bindable(Color4.White); + private readonly Bindable colourBottom = new Bindable(Color4.Black); + + public Color4 ColourTop + { + get => colourTop.Value; + set => colourTop.Value = value; + } + + public Color4 ColourBottom + { + get => colourBottom.Value; + set => colourBottom.Value = value; + } + + /// + /// Whether we should create new triangles as others expire. + /// + protected virtual bool CreateNewTriangles => true; + + /// + /// The amount of triangles we want compared to the default distribution. + /// + protected virtual float SpawnRatio => 1; + + private float triangleScale = 1; + + /// + /// The relative velocity of the triangles. Default is 1. + /// + public float Velocity = 1; + + private readonly List parts = new List(); + + [Resolved] + private IRenderer renderer { get; set; } + + private Random stableRandom; + private IShader shader; + private Texture texture; + + /// + /// Construct a new triangle visualisation. + /// + /// An optional seed to stabilise random positions / attributes. Note that this does not guarantee stable playback when seeking in time. + public TrianglesV2(int? seed = null) + { + if (seed != null) + stableRandom = new Random(seed.Value); + } + + [BackgroundDependencyLoader] + private void load(ShaderManager shaders) + { + shader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "TriangleBorder"); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + colourTop.BindValueChanged(_ => updateTexture()); + colourBottom.BindValueChanged(_ => updateTexture(), true); + + addTriangles(true); + } + + private void updateTexture() + { + var image = new Image(texture_height, 1); + + texture = renderer.CreateTexture(1, texture_height, true); + + for (int i = 0; i < texture_height; i++) + { + float ratio = (float)i / texture_height; + + image[i, 0] = new Rgba32( + colourBottom.Value.R * ratio + colourTop.Value.R * (1f - ratio), + colourBottom.Value.G * ratio + colourTop.Value.G * (1f - ratio), + colourBottom.Value.B * ratio + colourTop.Value.B * (1f - ratio), + 1f + ); + } + + texture.SetData(new TextureUpload(image)); + Invalidate(Invalidation.DrawNode); + } + + public float TriangleScale + { + get => triangleScale; + set + { + float change = value / triangleScale; + triangleScale = value; + + for (int i = 0; i < parts.Count; i++) + { + TriangleParticle newParticle = parts[i]; + newParticle.Scale *= change; + parts[i] = newParticle; + } + } + } + + protected override void Update() + { + base.Update(); + + Invalidate(Invalidation.DrawNode); + + if (CreateNewTriangles) + addTriangles(false); + + float elapsedSeconds = (float)Time.Elapsed / 1000; + // Since position is relative, the velocity needs to scale inversely with DrawHeight. + // Since we will later multiply by the scale of individual triangles we normalize by + // dividing by triangleScale. + float movedDistance = -elapsedSeconds * Velocity * base_velocity / (DrawHeight * triangleScale); + + for (int i = 0; i < parts.Count; i++) + { + TriangleParticle newParticle = parts[i]; + + // Scale moved distance by the size of the triangle. Smaller triangles should move more slowly. + newParticle.Position.Y += Math.Max(0.5f, parts[i].Scale) * movedDistance; + + parts[i] = newParticle; + + float bottomPos = parts[i].Position.Y + triangle_size * parts[i].Scale * 0.866f / DrawHeight; + if (bottomPos < 0) + parts.RemoveAt(i); + } + } + + /// + /// Clears and re-initialises triangles according to a given seed. + /// + /// An optional seed to stabilise random positions / attributes. Note that this does not guarantee stable playback when seeking in time. + public void Reset(int? seed = null) + { + if (seed != null) + stableRandom = new Random(seed.Value); + + parts.Clear(); + addTriangles(true); + } + + protected int AimCount { get; private set; } + + private void addTriangles(bool randomY) + { + // Limited by the maximum size of QuadVertexBuffer for safety. + const int max_triangles = ushort.MaxValue / (IRenderer.VERTICES_PER_QUAD + 2); + + AimCount = (int)Math.Min(max_triangles, DrawWidth * DrawHeight * 0.002f / (triangleScale * triangleScale) * SpawnRatio); + + for (int i = 0; i < AimCount - parts.Count; i++) + parts.Add(createTriangle(randomY)); + } + + private TriangleParticle createTriangle(bool randomY) + { + TriangleParticle particle = CreateTriangle(); + + particle.Position = new Vector2(nextRandom(), randomY ? nextRandom() : 1); + + return particle; + } + + /// + /// Creates a triangle particle with a random scale. + /// + /// The triangle particle. + protected virtual TriangleParticle CreateTriangle() + { + const float std_dev = 0.16f; + const float mean = 0.5f; + + float u1 = 1 - nextRandom(); //uniform(0,1] random floats + float u2 = 1 - nextRandom(); + float randStdNormal = (float)(Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2)); // random normal(0,1) + float scale = Math.Max(triangleScale * (mean + std_dev * randStdNormal), 0.1f); // random normal(mean,stdDev^2) + + return new TriangleParticle { Scale = scale }; + } + + private float nextRandom() => (float)(stableRandom?.NextDouble() ?? RNG.NextSingle()); + + protected override DrawNode CreateDrawNode() => new TrianglesDrawNode(this); + + private class TrianglesDrawNode : DrawNode + { + protected new TrianglesV2 Source => (TrianglesV2)base.Source; + + private IShader shader; + private Texture texture; + + private readonly List parts = new List(); + private Vector2 size; + + private IVertexBatch vertexBatch; + + public TrianglesDrawNode(TrianglesV2 source) + : base(source) + { + } + + public override void ApplyState() + { + base.ApplyState(); + + shader = Source.shader; + texture = Source.texture; + size = Source.DrawSize; + + parts.Clear(); + parts.AddRange(Source.parts); + } + + public override void Draw(IRenderer renderer) + { + base.Draw(renderer); + + if (Source.AimCount > 0 && (vertexBatch == null || vertexBatch.Size != Source.AimCount)) + { + vertexBatch?.Dispose(); + vertexBatch = renderer.CreateQuadBatch(Source.AimCount, 1); + } + + shader.Bind(); + + foreach (TriangleParticle particle in parts) + { + var offset = triangle_size * new Vector2(particle.Scale * 0.5f, particle.Scale * 0.866f); + + Vector2 topLeft = particle.Position * size + new Vector2(-offset.X, 0f); + Vector2 topRight = particle.Position * size + new Vector2(offset.X, 0); + Vector2 bottomLeft = particle.Position * size + new Vector2(-offset.X, offset.Y); + Vector2 bottomRight = particle.Position * size + new Vector2(offset.X, offset.Y); + + var drawQuad = new Quad( + Vector2Extensions.Transform(topLeft, DrawInfo.Matrix), + Vector2Extensions.Transform(topRight, DrawInfo.Matrix), + Vector2Extensions.Transform(bottomLeft, DrawInfo.Matrix), + Vector2Extensions.Transform(bottomRight, DrawInfo.Matrix) + ); + + var tRect = new Quad( + topLeft.X / size.X, + topLeft.Y / size.Y * texture_height, + (topRight.X - topLeft.X) / size.X, + (bottomRight.Y - topRight.Y) / size.Y * texture_height + ).AABBFloat; + + renderer.DrawQuad(texture, drawQuad, DrawColourInfo.Colour, tRect, vertexBatch.AddAction, textureCoords: tRect); + } + + shader.Unbind(); + } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + vertexBatch?.Dispose(); + } + } + + protected struct TriangleParticle + { + /// + /// The position of the top vertex of the triangle. + /// + public Vector2 Position; + + /// + /// The scale of the triangle. + /// + public float Scale; + } + } +} From bda32d71bf3f2f9467875a5d0a06574bc713153d Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 16 Nov 2022 14:53:55 +0300 Subject: [PATCH 14/41] Change test scene name --- .../TestSceneTrianglesV2Background.cs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs diff --git a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs new file mode 100644 index 0000000000..59922377b0 --- /dev/null +++ b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs @@ -0,0 +1,43 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osuTK; +using osuTK.Graphics; +using osu.Game.Graphics.Backgrounds; + +namespace osu.Game.Tests.Visual.Background +{ + public class TestSceneTrianglesV2Background : OsuTestScene + { + public TestSceneTrianglesV2Background() + { + AddRange(new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Gray + }, + new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(200), + Masking = true, + CornerRadius = 40, + Child = new TrianglesV2 + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + ColourTop = Color4.Red, + ColourBottom = Color4.Orange + } + } + }); + } + } +} From 109aa37dd873f5dc56872c13208accc0a490eb93 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 16 Nov 2022 15:02:09 +0300 Subject: [PATCH 15/41] Apply fixes from original Triangles --- osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 57 +++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index 89ec7d2ad5..01e4a39431 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -27,6 +27,11 @@ namespace osu.Game.Graphics.Backgrounds private const float base_velocity = 50; private const int texture_height = 128; + /// + /// sqrt(3) / 2 + /// + private const float equilateral_triangle_ratio = 0.866f; + private readonly Bindable colourTop = new Bindable(Color4.White); private readonly Bindable colourBottom = new Bindable(Color4.Black); @@ -52,7 +57,13 @@ namespace osu.Game.Graphics.Backgrounds /// protected virtual float SpawnRatio => 1; - private float triangleScale = 1; + private readonly BindableFloat triangleScale = new BindableFloat(1f); + + public float TriangleScale + { + get => triangleScale.Value; + set => triangleScale.Value = value; + } /// /// The relative velocity of the triangles. Default is 1. @@ -91,7 +102,7 @@ namespace osu.Game.Graphics.Backgrounds colourTop.BindValueChanged(_ => updateTexture()); colourBottom.BindValueChanged(_ => updateTexture(), true); - addTriangles(true); + triangleScale.BindValueChanged(_ => Reset(), true); } private void updateTexture() @@ -116,23 +127,6 @@ namespace osu.Game.Graphics.Backgrounds Invalidate(Invalidation.DrawNode); } - public float TriangleScale - { - get => triangleScale; - set - { - float change = value / triangleScale; - triangleScale = value; - - for (int i = 0; i < parts.Count; i++) - { - TriangleParticle newParticle = parts[i]; - newParticle.Scale *= change; - parts[i] = newParticle; - } - } - } - protected override void Update() { base.Update(); @@ -146,7 +140,7 @@ namespace osu.Game.Graphics.Backgrounds // Since position is relative, the velocity needs to scale inversely with DrawHeight. // Since we will later multiply by the scale of individual triangles we normalize by // dividing by triangleScale. - float movedDistance = -elapsedSeconds * Velocity * base_velocity / (DrawHeight * triangleScale); + float movedDistance = -elapsedSeconds * Velocity * base_velocity / (DrawHeight * TriangleScale); for (int i = 0; i < parts.Count; i++) { @@ -157,7 +151,7 @@ namespace osu.Game.Graphics.Backgrounds parts[i] = newParticle; - float bottomPos = parts[i].Position.Y + triangle_size * parts[i].Scale * 0.866f / DrawHeight; + float bottomPos = parts[i].Position.Y + triangle_size * parts[i].Scale * equilateral_triangle_ratio / DrawHeight; if (bottomPos < 0) parts.RemoveAt(i); } @@ -183,9 +177,11 @@ namespace osu.Game.Graphics.Backgrounds // Limited by the maximum size of QuadVertexBuffer for safety. const int max_triangles = ushort.MaxValue / (IRenderer.VERTICES_PER_QUAD + 2); - AimCount = (int)Math.Min(max_triangles, DrawWidth * DrawHeight * 0.002f / (triangleScale * triangleScale) * SpawnRatio); + AimCount = (int)Math.Min(max_triangles, DrawWidth * DrawHeight * 0.002f / (TriangleScale * TriangleScale) * SpawnRatio); - for (int i = 0; i < AimCount - parts.Count; i++) + int currentCount = parts.Count; + + for (int i = 0; i < AimCount - currentCount; i++) parts.Add(createTriangle(randomY)); } @@ -193,7 +189,16 @@ namespace osu.Game.Graphics.Backgrounds { TriangleParticle particle = CreateTriangle(); - particle.Position = new Vector2(nextRandom(), randomY ? nextRandom() : 1); + float y = 1; + + if (randomY) + { + // since triangles are drawn from the top - allow them to be positioned a bit above the screen + float maxOffset = triangle_size * particle.Scale * equilateral_triangle_ratio / DrawHeight; + y = Interpolation.ValueAt(nextRandom(), -maxOffset, 1f, 0f, 1f); + } + + particle.Position = new Vector2(nextRandom(), y); return particle; } @@ -210,7 +215,7 @@ namespace osu.Game.Graphics.Backgrounds float u1 = 1 - nextRandom(); //uniform(0,1] random floats float u2 = 1 - nextRandom(); float randStdNormal = (float)(Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2)); // random normal(0,1) - float scale = Math.Max(triangleScale * (mean + std_dev * randStdNormal), 0.1f); // random normal(mean,stdDev^2) + float scale = Math.Max(TriangleScale * (mean + std_dev * randStdNormal), 0.1f); // random normal(mean,stdDev^2) return new TriangleParticle { Scale = scale }; } @@ -262,7 +267,7 @@ namespace osu.Game.Graphics.Backgrounds foreach (TriangleParticle particle in parts) { - var offset = triangle_size * new Vector2(particle.Scale * 0.5f, particle.Scale * 0.866f); + var offset = triangle_size * new Vector2(particle.Scale * 0.5f, particle.Scale * equilateral_triangle_ratio); Vector2 topLeft = particle.Position * size + new Vector2(-offset.X, 0f); Vector2 topRight = particle.Position * size + new Vector2(offset.X, 0); From cc4f05f3d3ce98a33f3c51a2779d42930f4cc480 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 16 Nov 2022 15:12:57 +0300 Subject: [PATCH 16/41] Replace Scale with SpeedMultiplier --- osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 35 +++++++------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index 01e4a39431..da31c6112b 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -57,14 +57,6 @@ namespace osu.Game.Graphics.Backgrounds /// protected virtual float SpawnRatio => 1; - private readonly BindableFloat triangleScale = new BindableFloat(1f); - - public float TriangleScale - { - get => triangleScale.Value; - set => triangleScale.Value = value; - } - /// /// The relative velocity of the triangles. Default is 1. /// @@ -102,7 +94,7 @@ namespace osu.Game.Graphics.Backgrounds colourTop.BindValueChanged(_ => updateTexture()); colourBottom.BindValueChanged(_ => updateTexture(), true); - triangleScale.BindValueChanged(_ => Reset(), true); + addTriangles(true); } private void updateTexture() @@ -138,20 +130,17 @@ namespace osu.Game.Graphics.Backgrounds float elapsedSeconds = (float)Time.Elapsed / 1000; // Since position is relative, the velocity needs to scale inversely with DrawHeight. - // Since we will later multiply by the scale of individual triangles we normalize by - // dividing by triangleScale. - float movedDistance = -elapsedSeconds * Velocity * base_velocity / (DrawHeight * TriangleScale); + float movedDistance = -elapsedSeconds * Velocity * base_velocity / DrawHeight; for (int i = 0; i < parts.Count; i++) { TriangleParticle newParticle = parts[i]; - // Scale moved distance by the size of the triangle. Smaller triangles should move more slowly. - newParticle.Position.Y += Math.Max(0.5f, parts[i].Scale) * movedDistance; + newParticle.Position.Y += Math.Max(0.5f, parts[i].SpeedMultiplier) * movedDistance; parts[i] = newParticle; - float bottomPos = parts[i].Position.Y + triangle_size * parts[i].Scale * equilateral_triangle_ratio / DrawHeight; + float bottomPos = parts[i].Position.Y + triangle_size * equilateral_triangle_ratio / DrawHeight; if (bottomPos < 0) parts.RemoveAt(i); } @@ -177,7 +166,7 @@ namespace osu.Game.Graphics.Backgrounds // Limited by the maximum size of QuadVertexBuffer for safety. const int max_triangles = ushort.MaxValue / (IRenderer.VERTICES_PER_QUAD + 2); - AimCount = (int)Math.Min(max_triangles, DrawWidth * DrawHeight * 0.002f / (TriangleScale * TriangleScale) * SpawnRatio); + AimCount = (int)Math.Min(max_triangles, DrawWidth * DrawHeight * 0.001f * SpawnRatio); int currentCount = parts.Count; @@ -194,7 +183,7 @@ namespace osu.Game.Graphics.Backgrounds if (randomY) { // since triangles are drawn from the top - allow them to be positioned a bit above the screen - float maxOffset = triangle_size * particle.Scale * equilateral_triangle_ratio / DrawHeight; + float maxOffset = triangle_size * equilateral_triangle_ratio / DrawHeight; y = Interpolation.ValueAt(nextRandom(), -maxOffset, 1f, 0f, 1f); } @@ -204,7 +193,7 @@ namespace osu.Game.Graphics.Backgrounds } /// - /// Creates a triangle particle with a random scale. + /// Creates a triangle particle with a random speed multiplier. /// /// The triangle particle. protected virtual TriangleParticle CreateTriangle() @@ -215,9 +204,9 @@ namespace osu.Game.Graphics.Backgrounds float u1 = 1 - nextRandom(); //uniform(0,1] random floats float u2 = 1 - nextRandom(); float randStdNormal = (float)(Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2)); // random normal(0,1) - float scale = Math.Max(TriangleScale * (mean + std_dev * randStdNormal), 0.1f); // random normal(mean,stdDev^2) + float speedMultiplier = Math.Max(mean + std_dev * randStdNormal, 0.1f); // random normal(mean,stdDev^2) - return new TriangleParticle { Scale = scale }; + return new TriangleParticle { SpeedMultiplier = speedMultiplier }; } private float nextRandom() => (float)(stableRandom?.NextDouble() ?? RNG.NextSingle()); @@ -267,7 +256,7 @@ namespace osu.Game.Graphics.Backgrounds foreach (TriangleParticle particle in parts) { - var offset = triangle_size * new Vector2(particle.Scale * 0.5f, particle.Scale * equilateral_triangle_ratio); + var offset = triangle_size * new Vector2(0.5f, equilateral_triangle_ratio); Vector2 topLeft = particle.Position * size + new Vector2(-offset.X, 0f); Vector2 topRight = particle.Position * size + new Vector2(offset.X, 0); @@ -310,9 +299,9 @@ namespace osu.Game.Graphics.Backgrounds public Vector2 Position; /// - /// The scale of the triangle. + /// The speed multiplier of the triangle. /// - public float Scale; + public float SpeedMultiplier; } } } From 13cf3fc40c7940b7cbbb2a759eff206bed97349f Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 16 Nov 2022 15:17:50 +0300 Subject: [PATCH 17/41] Make SpawnRatio public --- .../Background/TestSceneTrianglesV2Background.cs | 13 +++++++++++-- osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 12 +++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs index 59922377b0..f6207c46a5 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs @@ -12,6 +12,8 @@ namespace osu.Game.Tests.Visual.Background { public class TestSceneTrianglesV2Background : OsuTestScene { + private readonly TrianglesV2 triangles; + public TestSceneTrianglesV2Background() { AddRange(new Drawable[] @@ -25,10 +27,10 @@ namespace osu.Game.Tests.Visual.Background { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Size = new Vector2(200), + Size = new Vector2(500), Masking = true, CornerRadius = 40, - Child = new TrianglesV2 + Child = triangles = new TrianglesV2 { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -39,5 +41,12 @@ namespace osu.Game.Tests.Visual.Background } }); } + + protected override void LoadComplete() + { + base.LoadComplete(); + + AddSliderStep("Spawn ratio", 0f, 2f, 1f, s => triangles.SpawnRatio = s); + } } } diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index da31c6112b..0c4bf59732 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -52,10 +52,16 @@ namespace osu.Game.Graphics.Backgrounds /// protected virtual bool CreateNewTriangles => true; + private readonly BindableFloat spawnRatio = new BindableFloat(1f); + /// /// The amount of triangles we want compared to the default distribution. /// - protected virtual float SpawnRatio => 1; + public float SpawnRatio + { + get => spawnRatio.Value; + set => spawnRatio.Value = value; + } /// /// The relative velocity of the triangles. Default is 1. @@ -94,7 +100,7 @@ namespace osu.Game.Graphics.Backgrounds colourTop.BindValueChanged(_ => updateTexture()); colourBottom.BindValueChanged(_ => updateTexture(), true); - addTriangles(true); + spawnRatio.BindValueChanged(_ => Reset(), true); } private void updateTexture() @@ -166,7 +172,7 @@ namespace osu.Game.Graphics.Backgrounds // Limited by the maximum size of QuadVertexBuffer for safety. const int max_triangles = ushort.MaxValue / (IRenderer.VERTICES_PER_QUAD + 2); - AimCount = (int)Math.Min(max_triangles, DrawWidth * DrawHeight * 0.001f * SpawnRatio); + AimCount = (int)Math.Min(max_triangles, DrawWidth * DrawHeight * 0.0005f * SpawnRatio); int currentCount = parts.Count; From fa7b45dfb133dca53206c105c83fbaafeb6810bc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 21 Nov 2022 13:51:49 +0900 Subject: [PATCH 18/41] Fix chat day separator not being added on pending message resolution Closes #21316. --- osu.Game/Overlays/Chat/DrawableChannel.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index 544daf7d2c..7f9be1a782 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -134,8 +134,7 @@ namespace osu.Game.Overlays.Chat foreach (var message in displayMessages) { - if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Date != message.Timestamp.ToLocalTime().Date) - ChatLineFlow.Add(CreateDaySeparator(message.Timestamp)); + addDaySeparatorIfRequired(lastMessage, message); ChatLineFlow.Add(CreateChatLine(message)); lastMessage = message; @@ -183,10 +182,18 @@ namespace osu.Game.Overlays.Chat ChatLineFlow.Remove(found, false); found.Message = updated; + + addDaySeparatorIfRequired(chatLines.LastOrDefault()?.Message, updated); ChatLineFlow.Add(found); } }); + private void addDaySeparatorIfRequired(Message lastMessage, Message message) + { + if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Date != message.Timestamp.ToLocalTime().Date) + ChatLineFlow.Add(CreateDaySeparator(message.Timestamp)); + } + private void messageRemoved(Message removed) => Schedule(() => { chatLines.FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire(); From e53b4321ffa1eb91524558e15f786a8476b92905 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 21 Nov 2022 14:01:10 +0900 Subject: [PATCH 19/41] Ensure two day separators are not added in a row --- osu.Game/Overlays/Chat/DrawableChannel.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index 7f9be1a782..3d2eafd973 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -191,7 +191,15 @@ namespace osu.Game.Overlays.Chat private void addDaySeparatorIfRequired(Message lastMessage, Message message) { if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Date != message.Timestamp.ToLocalTime().Date) + { + // A day separator is displayed even if no messages are in the channel. + // If there are no messages after it, the simplest way to ensure it is fresh is to remove it + // and add a new one instead. + if (ChatLineFlow.LastOrDefault() is DaySeparator ds) + ChatLineFlow.Remove(ds, true); + ChatLineFlow.Add(CreateDaySeparator(message.Timestamp)); + } } private void messageRemoved(Message removed) => Schedule(() => From 40f2da364c1f6753bef8bbf3ae6d976dbbed406f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 21 Nov 2022 14:34:35 +0900 Subject: [PATCH 20/41] Limit how far before the first hitobject that barlines can be generated --- osu.Game/Rulesets/Objects/BarLineGenerator.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Objects/BarLineGenerator.cs b/osu.Game/Rulesets/Objects/BarLineGenerator.cs index c2709db747..185088878c 100644 --- a/osu.Game/Rulesets/Objects/BarLineGenerator.cs +++ b/osu.Game/Rulesets/Objects/BarLineGenerator.cs @@ -27,7 +27,10 @@ namespace osu.Game.Rulesets.Objects if (beatmap.HitObjects.Count == 0) return; + HitObject firstObject = beatmap.HitObjects.First(); HitObject lastObject = beatmap.HitObjects.Last(); + + double firstHitTime = firstObject.StartTime; double lastHitTime = 1 + lastObject.GetEndTime(); var timingPoints = beatmap.ControlPointInfo.TimingPoints; @@ -41,10 +44,14 @@ namespace osu.Game.Rulesets.Objects EffectControlPoint currentEffectPoint = beatmap.ControlPointInfo.EffectPointAt(currentTimingPoint.Time); int currentBeat = 0; + // Don't generate barlines before the hit object or t=0 (whichever is earliest). Some beatmaps use very unrealistic values here (although none are ranked). + // I'm not sure we ever want barlines to appear before the first hitobject, but let's keep some degree of compatibility for now. + // Of note, this will still differ from stable if the first timing control point is t<0 and is not near the first hitobject. + double startTime = Math.Max(Math.Min(0, firstHitTime), currentTimingPoint.Time); + // Stop on the next timing point, or if there is no next timing point stop slightly past the last object double endTime = i < timingPoints.Count - 1 ? timingPoints[i + 1].Time : lastHitTime + currentTimingPoint.BeatLength * currentTimingPoint.TimeSignature.Numerator; - double startTime = currentTimingPoint.Time; double barLength = currentTimingPoint.BeatLength * currentTimingPoint.TimeSignature.Numerator; if (currentEffectPoint.OmitFirstBarLine) From 9a330c3cdbcf8d275d957216efe43e9bd4e727e8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 21 Nov 2022 14:56:58 +0900 Subject: [PATCH 21/41] Apply nullability and clean up conditionals --- .../TestSceneTriangleBorderShader.cs | 2 -- osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 25 ++++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs b/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs index 470962088e..41a1d9b42e 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Graphics.Shaders; using osu.Framework.Graphics.Shapes; diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index 0c4bf59732..4da227d5d6 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Utils; using osuTK; using System; @@ -71,11 +69,12 @@ namespace osu.Game.Graphics.Backgrounds private readonly List parts = new List(); [Resolved] - private IRenderer renderer { get; set; } + private IRenderer renderer { get; set; } = null!; - private Random stableRandom; - private IShader shader; - private Texture texture; + private Random? stableRandom; + + private IShader shader = null!; + private Texture texture = null!; /// /// Construct a new triangle visualisation. @@ -116,8 +115,7 @@ namespace osu.Game.Graphics.Backgrounds image[i, 0] = new Rgba32( colourBottom.Value.R * ratio + colourTop.Value.R * (1f - ratio), colourBottom.Value.G * ratio + colourTop.Value.G * (1f - ratio), - colourBottom.Value.B * ratio + colourTop.Value.B * (1f - ratio), - 1f + colourBottom.Value.B * ratio + colourTop.Value.B * (1f - ratio) ); } @@ -223,13 +221,13 @@ namespace osu.Game.Graphics.Backgrounds { protected new TrianglesV2 Source => (TrianglesV2)base.Source; - private IShader shader; - private Texture texture; + private IShader shader = null!; + private Texture texture = null!; private readonly List parts = new List(); private Vector2 size; - private IVertexBatch vertexBatch; + private IVertexBatch? vertexBatch; public TrianglesDrawNode(TrianglesV2 source) : base(source) @@ -252,7 +250,10 @@ namespace osu.Game.Graphics.Backgrounds { base.Draw(renderer); - if (Source.AimCount > 0 && (vertexBatch == null || vertexBatch.Size != Source.AimCount)) + if (Source.AimCount == 0) + return; + + if (vertexBatch == null || vertexBatch.Size != Source.AimCount) { vertexBatch?.Dispose(); vertexBatch = renderer.CreateQuadBatch(Source.AimCount, 1); From 14a4de36f4cbd269f40b982930c9aedd8dbbba59 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 21 Nov 2022 10:20:35 +0300 Subject: [PATCH 22/41] Expose thickness property --- .../TestSceneTriangleBorderShader.cs | 41 ++++++++++++++++++- .../TestSceneTrianglesV2Background.cs | 1 + osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 18 ++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs b/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs index 41a1d9b42e..64512bc651 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneTriangleBorderShader.cs @@ -14,6 +14,8 @@ namespace osu.Game.Tests.Visual.Background { public class TestSceneTriangleBorderShader : OsuTestScene { + private readonly TriangleBorder border; + public TestSceneTriangleBorderShader() { Children = new Drawable[] @@ -23,7 +25,7 @@ namespace osu.Game.Tests.Visual.Background RelativeSizeAxes = Axes.Both, Colour = Color4.DarkGreen }, - new TriangleBorder + border = new TriangleBorder { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -32,8 +34,27 @@ namespace osu.Game.Tests.Visual.Background }; } + protected override void LoadComplete() + { + base.LoadComplete(); + + AddSliderStep("Thickness", 0f, 1f, 0.02f, t => border.Thickness = t); + } + private class TriangleBorder : Sprite { + private float thickness = 0.02f; + + public float Thickness + { + get => thickness; + set + { + thickness = value; + Invalidate(Invalidation.DrawNode); + } + } + [BackgroundDependencyLoader] private void load(ShaderManager shaders, IRenderer renderer) { @@ -45,11 +66,29 @@ namespace osu.Game.Tests.Visual.Background private class TriangleBorderDrawNode : SpriteDrawNode { + public new TriangleBorder Source => (TriangleBorder)base.Source; + public TriangleBorderDrawNode(TriangleBorder source) : base(source) { } + private float thickness; + + public override void ApplyState() + { + base.ApplyState(); + + thickness = Source.thickness; + } + + public override void Draw(IRenderer renderer) + { + TextureShader.GetUniform("thickness").UpdateValue(ref thickness); + + base.Draw(renderer); + } + protected override bool CanDrawOpaqueInterior => false; } } diff --git a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs index f6207c46a5..e8abc573cd 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs @@ -47,6 +47,7 @@ namespace osu.Game.Tests.Visual.Background base.LoadComplete(); AddSliderStep("Spawn ratio", 0f, 2f, 1f, s => triangles.SpawnRatio = s); + AddSliderStep("Thickness", 0f, 1f, 0.02f, t => triangles.Thickness = t); } } } diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index 4da227d5d6..ca920bdd66 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -45,6 +45,21 @@ namespace osu.Game.Graphics.Backgrounds set => colourBottom.Value = value; } + private float thickness = 0.02f; + + public float Thickness + { + get => thickness; + set + { + if (thickness == value) + return; + + thickness = value; + // No need for invalidation since it's happening in Update() + } + } + /// /// Whether we should create new triangles as others expire. /// @@ -226,6 +241,7 @@ namespace osu.Game.Graphics.Backgrounds private readonly List parts = new List(); private Vector2 size; + private float thickness; private IVertexBatch? vertexBatch; @@ -241,6 +257,7 @@ namespace osu.Game.Graphics.Backgrounds shader = Source.shader; texture = Source.texture; size = Source.DrawSize; + thickness = Source.thickness; parts.Clear(); parts.AddRange(Source.parts); @@ -260,6 +277,7 @@ namespace osu.Game.Graphics.Backgrounds } shader.Bind(); + shader.GetUniform("thickness").UpdateValue(ref thickness); foreach (TriangleParticle particle in parts) { From ec8532951c7547fc3d30943debf081962f52b170 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 21 Nov 2022 10:32:19 +0300 Subject: [PATCH 23/41] Make Thickness property auto --- osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index ca920bdd66..5fc32ff704 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -45,20 +45,7 @@ namespace osu.Game.Graphics.Backgrounds set => colourBottom.Value = value; } - private float thickness = 0.02f; - - public float Thickness - { - get => thickness; - set - { - if (thickness == value) - return; - - thickness = value; - // No need for invalidation since it's happening in Update() - } - } + public float Thickness { get; set; } = 0.02f; // No need for invalidation since it's happening in Update() /// /// Whether we should create new triangles as others expire. @@ -257,7 +244,7 @@ namespace osu.Game.Graphics.Backgrounds shader = Source.shader; texture = Source.texture; size = Source.DrawSize; - thickness = Source.thickness; + thickness = Source.Thickness; parts.Clear(); parts.AddRange(Source.parts); From 76bb529cfa750daf08d15f61f32e034b49ecbd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 21 Nov 2022 20:30:42 +0100 Subject: [PATCH 24/41] Add test for local echo adding day separator --- .../Visual/Online/TestSceneDrawableChannel.cs | 87 +++++++++++++++++++ osu.Game/Online/Chat/StandAloneChatDisplay.cs | 4 +- osu.Game/Overlays/Chat/DaySeparator.cs | 8 +- 3 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 osu.Game.Tests/Visual/Online/TestSceneDrawableChannel.cs diff --git a/osu.Game.Tests/Visual/Online/TestSceneDrawableChannel.cs b/osu.Game.Tests/Visual/Online/TestSceneDrawableChannel.cs new file mode 100644 index 0000000000..dc1e00ee8f --- /dev/null +++ b/osu.Game.Tests/Visual/Online/TestSceneDrawableChannel.cs @@ -0,0 +1,87 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Linq; +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Framework.Testing; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Online.Chat; +using osu.Game.Overlays.Chat; + +namespace osu.Game.Tests.Visual.Online +{ + [TestFixture] + public class TestSceneDrawableChannel : OsuTestScene + { + private Channel channel = null!; + private DrawableChannel drawableChannel = null!; + + [SetUpSteps] + public void SetUpSteps() + { + AddStep("create channel", () => channel = new Channel + { + Id = 1, + Name = "Test channel" + }); + AddStep("create drawable channel", () => Child = drawableChannel = new DrawableChannel(channel) + { + RelativeSizeAxes = Axes.Both + }); + } + + [Test] + public void TestDaySeparators() + { + var localUser = new APIUser + { + Id = 3, + Username = "LocalUser" + }; + string uuid = Guid.NewGuid().ToString(); + AddStep("add local echo message", () => channel.AddLocalEcho(new LocalEchoMessage + { + Sender = localUser, + Content = "Hi there all!", + Timestamp = new DateTimeOffset(2022, 11, 21, 20, 11, 13, TimeSpan.Zero), + Uuid = uuid + })); + AddUntilStep("one day separator present", () => drawableChannel.ChildrenOfType().Count() == 1); + + AddStep("add two prior messages to channel", () => channel.AddNewMessages( + new Message(1) + { + Sender = new APIUser + { + Id = 1, + Username = "TestUser" + }, + Content = "This is a message", + Timestamp = new DateTimeOffset(2021, 10, 10, 13, 33, 23, TimeSpan.Zero), + }, + new Message(2) + { + Sender = new APIUser + { + Id = 2, + Username = "TestUser2" + }, + Content = "This is another message", + Timestamp = new DateTimeOffset(2021, 10, 11, 13, 33, 23, TimeSpan.Zero) + })); + AddUntilStep("three day separators present", () => drawableChannel.ChildrenOfType().Count() == 3); + + AddStep("resolve pending message", () => channel.ReplaceMessage(channel.Messages.OfType().Single(), new Message(3) + { + Sender = localUser, + Content = "Hi there all!", + Timestamp = new DateTimeOffset(2022, 11, 22, 20, 11, 16, TimeSpan.Zero), + Uuid = uuid + })); + AddUntilStep("three day separators present", () => drawableChannel.ChildrenOfType().Count() == 3); + AddAssert("last day separator is from correct day", () => drawableChannel.ChildrenOfType().Last().Date.Date == new DateTime(2022, 11, 22)); + } + } +} diff --git a/osu.Game/Online/Chat/StandAloneChatDisplay.cs b/osu.Game/Online/Chat/StandAloneChatDisplay.cs index 81db3f0d53..e45a14136d 100644 --- a/osu.Game/Online/Chat/StandAloneChatDisplay.cs +++ b/osu.Game/Online/Chat/StandAloneChatDisplay.cs @@ -174,8 +174,8 @@ namespace osu.Game.Online.Chat protected override float Spacing => 5; protected override float DateAlign => 125; - public StandAloneDaySeparator(DateTimeOffset time) - : base(time) + public StandAloneDaySeparator(DateTimeOffset date) + : base(date) { } diff --git a/osu.Game/Overlays/Chat/DaySeparator.cs b/osu.Game/Overlays/Chat/DaySeparator.cs index be0b53785c..d68f325738 100644 --- a/osu.Game/Overlays/Chat/DaySeparator.cs +++ b/osu.Game/Overlays/Chat/DaySeparator.cs @@ -22,14 +22,14 @@ namespace osu.Game.Overlays.Chat protected virtual float Spacing => 15; - private readonly DateTimeOffset time; + public readonly DateTimeOffset Date; [Resolved(CanBeNull = true)] private OverlayColourProvider? colourProvider { get; set; } - public DaySeparator(DateTimeOffset time) + public DaySeparator(DateTimeOffset date) { - this.time = time; + Date = date; Height = 40; } @@ -80,7 +80,7 @@ namespace osu.Game.Overlays.Chat { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, - Text = time.ToLocalTime().ToLocalisableString(@"dd MMMM yyyy").ToUpper(), + Text = Date.ToLocalTime().ToLocalisableString(@"dd MMMM yyyy").ToUpper(), Font = OsuFont.Torus.With(size: TextSize, weight: FontWeight.SemiBold), Colour = colourProvider?.Content1 ?? Colour4.White, }, From d146f86511ac3b34e995c586ad6889cc2c2ef194 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 15:39:56 +0900 Subject: [PATCH 25/41] Fix crash when hitting 'T' to tap timing while no timing point is selected --- osu.Game/Screens/Edit/Timing/TapButton.cs | 3 +++ osu.Game/Screens/Edit/Timing/TapTimingControl.cs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/osu.Game/Screens/Edit/Timing/TapButton.cs b/osu.Game/Screens/Edit/Timing/TapButton.cs index 151c3cea2e..2944eea4fe 100644 --- a/osu.Game/Screens/Edit/Timing/TapButton.cs +++ b/osu.Game/Screens/Edit/Timing/TapButton.cs @@ -295,6 +295,9 @@ namespace osu.Game.Screens.Edit.Timing private void handleTap() { + if (selectedGroup?.Value == null) + return; + tapTimings.Add(Clock.CurrentTime); if (tapTimings.Count > initial_taps_to_ignore + max_taps_to_consider) diff --git a/osu.Game/Screens/Edit/Timing/TapTimingControl.cs b/osu.Game/Screens/Edit/Timing/TapTimingControl.cs index abc73851e4..daa3168746 100644 --- a/osu.Game/Screens/Edit/Timing/TapTimingControl.cs +++ b/osu.Game/Screens/Edit/Timing/TapTimingControl.cs @@ -183,12 +183,18 @@ namespace osu.Game.Screens.Edit.Timing private void start() { + if (selectedGroup.Value == null) + return; + editorClock.Seek(selectedGroup.Value.Time); editorClock.Start(); } private void reset() { + if (selectedGroup.Value == null) + return; + editorClock.Stop(); editorClock.Seek(selectedGroup.Value.Time); } From b89689a34a4dd719c18b73b29180463170f5a7e3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 16:31:50 +0900 Subject: [PATCH 26/41] Rename class and reword settings text/tooltips to avoid clashing with other naming --- ...nfoDrawable.cs => BeatmapAttributeText.cs} | 83 +++++++++---------- osu.Game/Skinning/Components/TextElement.cs | 2 +- 2 files changed, 42 insertions(+), 43 deletions(-) rename osu.Game/Skinning/Components/{BeatmapInfoDrawable.cs => BeatmapAttributeText.cs} (57%) diff --git a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs b/osu.Game/Skinning/Components/BeatmapAttributeText.cs similarity index 57% rename from osu.Game/Skinning/Components/BeatmapInfoDrawable.cs rename to osu.Game/Skinning/Components/BeatmapAttributeText.cs index 379bdec333..6520130e75 100644 --- a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs +++ b/osu.Game/Skinning/Components/BeatmapAttributeText.cs @@ -22,47 +22,46 @@ using osu.Game.Resources.Localisation.Web; namespace osu.Game.Skinning.Components { [UsedImplicitly] - public class BeatmapInfoDrawable : Container, ISkinnableDrawable + public class BeatmapAttributeText : Container, ISkinnableDrawable { - private const BeatmapInfo default_beatmap_info = BeatmapInfo.StarRating; public bool UsesFixedAnchor { get; set; } - [SettingSource("Tracked Beatmap Info/Label", "Which part of the BeatmapInformation should be displayed.")] - public Bindable Type { get; } = new Bindable(default_beatmap_info); + [SettingSource("Attribute", "The attribute to be displayed.")] + public Bindable Attribute { get; } = new Bindable(BeatmapAttribute.StarRating); - [SettingSource("Template", "Bypass the restriction of 1 Info per element. Format is '{'+Type+'}' to substitue values. e.g. '{Song}' ")] + [SettingSource("Template", "Supports {Label} and {Value}, but also including arbitrary attributes like {StarRating} (see attribute list for supported values).")] public Bindable Template { get; set; } = new Bindable("{Label}: {Value}"); [Resolved] private IBindable beatmap { get; set; } = null!; - private readonly Dictionary valueDictionary = new Dictionary(); - private static readonly ImmutableDictionary label_dictionary; + private readonly Dictionary valueDictionary = new Dictionary(); + private static readonly ImmutableDictionary label_dictionary; private readonly OsuSpriteText text; - static BeatmapInfoDrawable() + static BeatmapAttributeText() { - label_dictionary = new Dictionary + label_dictionary = new Dictionary { - [BeatmapInfo.CircleSize] = BeatmapsetsStrings.ShowStatsCs, - [BeatmapInfo.Accuracy] = BeatmapsetsStrings.ShowStatsAccuracy, - [BeatmapInfo.HPDrain] = BeatmapsetsStrings.ShowStatsDrain, - [BeatmapInfo.ApproachRate] = BeatmapsetsStrings.ShowStatsAr, - [BeatmapInfo.StarRating] = BeatmapsetsStrings.ShowStatsStars, - [BeatmapInfo.Song] = EditorSetupStrings.Title, - [BeatmapInfo.Artist] = EditorSetupStrings.Artist, - [BeatmapInfo.Difficulty] = EditorSetupStrings.DifficultyHeader, + [BeatmapAttribute.CircleSize] = BeatmapsetsStrings.ShowStatsCs, + [BeatmapAttribute.Accuracy] = BeatmapsetsStrings.ShowStatsAccuracy, + [BeatmapAttribute.HPDrain] = BeatmapsetsStrings.ShowStatsDrain, + [BeatmapAttribute.ApproachRate] = BeatmapsetsStrings.ShowStatsAr, + [BeatmapAttribute.StarRating] = BeatmapsetsStrings.ShowStatsStars, + [BeatmapAttribute.Song] = EditorSetupStrings.Title, + [BeatmapAttribute.Artist] = EditorSetupStrings.Artist, + [BeatmapAttribute.Difficulty] = EditorSetupStrings.DifficultyHeader, //todo: is there a good alternative, to NotificationsOptionsMapping? - [BeatmapInfo.Mapper] = AccountsStrings.NotificationsOptionsMapping, - [BeatmapInfo.Length] = ArtistStrings.TracklistLength, - [BeatmapInfo.Status] = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault, - [BeatmapInfo.BPM] = BeatmapsetsStrings.ShowStatsBpm, - [BeatmapInfo.None] = BeatmapInfo.None.ToString() + [BeatmapAttribute.Mapper] = AccountsStrings.NotificationsOptionsMapping, + [BeatmapAttribute.Length] = ArtistStrings.TracklistLength, + [BeatmapAttribute.Status] = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault, + [BeatmapAttribute.BPM] = BeatmapsetsStrings.ShowStatsBpm, + [BeatmapAttribute.None] = BeatmapAttribute.None.ToString() }.ToImmutableDictionary(); } - public BeatmapInfoDrawable() + public BeatmapAttributeText() { AutoSizeAxes = Axes.Both; InternalChildren = new Drawable[] @@ -76,7 +75,7 @@ namespace osu.Game.Skinning.Components } }; - foreach (var type in Enum.GetValues(typeof(BeatmapInfo)).Cast()) + foreach (var type in Enum.GetValues(typeof(BeatmapAttribute)).Cast()) { valueDictionary[type] = type.ToString(); } @@ -85,7 +84,7 @@ namespace osu.Game.Skinning.Components protected override void LoadComplete() { base.LoadComplete(); - Type.BindValueChanged(_ => updateLabel()); + Attribute.BindValueChanged(_ => updateLabel()); Template.BindValueChanged(f => updateLabel(), true); beatmap.BindValueChanged(b => { @@ -96,10 +95,10 @@ namespace osu.Game.Skinning.Components private void updateLabel() { - string newText = Template.Value.Replace("{Label}", label_dictionary[Type.Value].ToString()) - .Replace("{Value}", valueDictionary[Type.Value].ToString()); + string newText = Template.Value.Replace("{Label}", label_dictionary[Attribute.Value].ToString()) + .Replace("{Value}", valueDictionary[Attribute.Value].ToString()); - foreach (var type in Enum.GetValues(typeof(BeatmapInfo)).Cast()) + foreach (var type in Enum.GetValues(typeof(BeatmapAttribute)).Cast()) { newText = newText.Replace("{" + type + "}", valueDictionary[type].ToString()); } @@ -111,34 +110,34 @@ namespace osu.Game.Skinning.Components { //update cs double cs = workingBeatmap.BeatmapInfo.Difficulty.CircleSize; - valueDictionary[BeatmapInfo.CircleSize] = cs.ToString("F2"); + valueDictionary[BeatmapAttribute.CircleSize] = cs.ToString("F2"); //update HP double hp = workingBeatmap.BeatmapInfo.Difficulty.DrainRate; - valueDictionary[BeatmapInfo.HPDrain] = hp.ToString("F2"); + valueDictionary[BeatmapAttribute.HPDrain] = hp.ToString("F2"); //update od double od = workingBeatmap.BeatmapInfo.Difficulty.OverallDifficulty; - valueDictionary[BeatmapInfo.Accuracy] = od.ToString("F2"); + valueDictionary[BeatmapAttribute.Accuracy] = od.ToString("F2"); //update ar double ar = workingBeatmap.BeatmapInfo.Difficulty.ApproachRate; - valueDictionary[BeatmapInfo.ApproachRate] = ar.ToString("F2"); + valueDictionary[BeatmapAttribute.ApproachRate] = ar.ToString("F2"); //update sr double sr = workingBeatmap.BeatmapInfo.StarRating; - valueDictionary[BeatmapInfo.StarRating] = sr.ToString("F2"); + valueDictionary[BeatmapAttribute.StarRating] = sr.ToString("F2"); //update song title - valueDictionary[BeatmapInfo.Song] = workingBeatmap.BeatmapInfo.Metadata.Title; + valueDictionary[BeatmapAttribute.Song] = workingBeatmap.BeatmapInfo.Metadata.Title; //update artist - valueDictionary[BeatmapInfo.Artist] = workingBeatmap.BeatmapInfo.Metadata.Artist; + valueDictionary[BeatmapAttribute.Artist] = workingBeatmap.BeatmapInfo.Metadata.Artist; //update difficulty name - valueDictionary[BeatmapInfo.Difficulty] = workingBeatmap.BeatmapInfo.DifficultyName; + valueDictionary[BeatmapAttribute.Difficulty] = workingBeatmap.BeatmapInfo.DifficultyName; //update mapper - valueDictionary[BeatmapInfo.Mapper] = workingBeatmap.BeatmapInfo.Metadata.Author.Username; + valueDictionary[BeatmapAttribute.Mapper] = workingBeatmap.BeatmapInfo.Metadata.Author.Username; //update Length - valueDictionary[BeatmapInfo.Length] = TimeSpan.FromMilliseconds(workingBeatmap.BeatmapInfo.Length).ToFormattedDuration(); + valueDictionary[BeatmapAttribute.Length] = TimeSpan.FromMilliseconds(workingBeatmap.BeatmapInfo.Length).ToFormattedDuration(); //update Status - valueDictionary[BeatmapInfo.Status] = GetBetmapStatus(workingBeatmap.BeatmapInfo.Status); + valueDictionary[BeatmapAttribute.Status] = GetBetmapStatus(workingBeatmap.BeatmapInfo.Status); //update BPM - valueDictionary[BeatmapInfo.BPM] = workingBeatmap.BeatmapInfo.BPM.ToString("F2"); - valueDictionary[BeatmapInfo.None] = string.Empty; + valueDictionary[BeatmapAttribute.BPM] = workingBeatmap.BeatmapInfo.BPM.ToString("F2"); + valueDictionary[BeatmapAttribute.None] = string.Empty; } public static LocalisableString GetBetmapStatus(BeatmapOnlineStatus status) @@ -178,7 +177,7 @@ namespace osu.Game.Skinning.Components } } - public enum BeatmapInfo + public enum BeatmapAttribute { CircleSize, HPDrain, diff --git a/osu.Game/Skinning/Components/TextElement.cs b/osu.Game/Skinning/Components/TextElement.cs index da09aa76b2..1e618a7f82 100644 --- a/osu.Game/Skinning/Components/TextElement.cs +++ b/osu.Game/Skinning/Components/TextElement.cs @@ -16,7 +16,7 @@ namespace osu.Game.Skinning.Components { public bool UsesFixedAnchor { get; set; } - [SettingSource("Displayed Text", "What text should be displayed")] + [SettingSource("Text", "The text to be displayed.")] public Bindable Text { get; } = new Bindable("Circles!"); public TextElement() From 27473262af2757a9142922c46221700c585fc6b5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 16:39:13 +0900 Subject: [PATCH 27/41] Rename attributes in enum to match better with user expectations --- .../Components/BeatmapAttributeText.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapAttributeText.cs b/osu.Game/Skinning/Components/BeatmapAttributeText.cs index 6520130e75..a3b0ed7168 100644 --- a/osu.Game/Skinning/Components/BeatmapAttributeText.cs +++ b/osu.Game/Skinning/Components/BeatmapAttributeText.cs @@ -8,6 +8,8 @@ using System.Linq; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; +using osu.Framework.Extensions; +using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Localisation; @@ -18,6 +20,7 @@ using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Localisation; using osu.Game.Resources.Localisation.Web; +using osu.Game.Screens.Select.Filter; namespace osu.Game.Skinning.Components { @@ -36,6 +39,7 @@ namespace osu.Game.Skinning.Components private IBindable beatmap { get; set; } = null!; private readonly Dictionary valueDictionary = new Dictionary(); + private static readonly ImmutableDictionary label_dictionary; private readonly OsuSpriteText text; @@ -49,15 +53,13 @@ namespace osu.Game.Skinning.Components [BeatmapAttribute.HPDrain] = BeatmapsetsStrings.ShowStatsDrain, [BeatmapAttribute.ApproachRate] = BeatmapsetsStrings.ShowStatsAr, [BeatmapAttribute.StarRating] = BeatmapsetsStrings.ShowStatsStars, - [BeatmapAttribute.Song] = EditorSetupStrings.Title, + [BeatmapAttribute.Title] = EditorSetupStrings.Title, [BeatmapAttribute.Artist] = EditorSetupStrings.Artist, - [BeatmapAttribute.Difficulty] = EditorSetupStrings.DifficultyHeader, - //todo: is there a good alternative, to NotificationsOptionsMapping? - [BeatmapAttribute.Mapper] = AccountsStrings.NotificationsOptionsMapping, - [BeatmapAttribute.Length] = ArtistStrings.TracklistLength, - [BeatmapAttribute.Status] = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault, + [BeatmapAttribute.DifficultyName] = EditorSetupStrings.DifficultyHeader, + [BeatmapAttribute.Creator] = EditorSetupStrings.Creator, + [BeatmapAttribute.Length] = ArtistStrings.TracklistLength.ToTitle(), + [BeatmapAttribute.RankedStatus] = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault, [BeatmapAttribute.BPM] = BeatmapsetsStrings.ShowStatsBpm, - [BeatmapAttribute.None] = BeatmapAttribute.None.ToString() }.ToImmutableDictionary(); } @@ -124,20 +126,19 @@ namespace osu.Game.Skinning.Components double sr = workingBeatmap.BeatmapInfo.StarRating; valueDictionary[BeatmapAttribute.StarRating] = sr.ToString("F2"); //update song title - valueDictionary[BeatmapAttribute.Song] = workingBeatmap.BeatmapInfo.Metadata.Title; + valueDictionary[BeatmapAttribute.Title] = workingBeatmap.BeatmapInfo.Metadata.Title; //update artist valueDictionary[BeatmapAttribute.Artist] = workingBeatmap.BeatmapInfo.Metadata.Artist; //update difficulty name - valueDictionary[BeatmapAttribute.Difficulty] = workingBeatmap.BeatmapInfo.DifficultyName; + valueDictionary[BeatmapAttribute.DifficultyName] = workingBeatmap.BeatmapInfo.DifficultyName; //update mapper - valueDictionary[BeatmapAttribute.Mapper] = workingBeatmap.BeatmapInfo.Metadata.Author.Username; + valueDictionary[BeatmapAttribute.Creator] = workingBeatmap.BeatmapInfo.Metadata.Author.Username; //update Length valueDictionary[BeatmapAttribute.Length] = TimeSpan.FromMilliseconds(workingBeatmap.BeatmapInfo.Length).ToFormattedDuration(); //update Status - valueDictionary[BeatmapAttribute.Status] = GetBetmapStatus(workingBeatmap.BeatmapInfo.Status); + valueDictionary[BeatmapAttribute.RankedStatus] = GetBetmapStatus(workingBeatmap.BeatmapInfo.Status); //update BPM valueDictionary[BeatmapAttribute.BPM] = workingBeatmap.BeatmapInfo.BPM.ToString("F2"); - valueDictionary[BeatmapAttribute.None] = string.Empty; } public static LocalisableString GetBetmapStatus(BeatmapOnlineStatus status) @@ -184,13 +185,12 @@ namespace osu.Game.Skinning.Components Accuracy, ApproachRate, StarRating, - Song, + Title, Artist, - Difficulty, - Mapper, + DifficultyName, + Creator, Length, - Status, + RankedStatus, BPM, - None, } } From a8af83e62a0709d32f30215f044443f2fe07fc67 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 16:49:39 +0900 Subject: [PATCH 28/41] Move label initialisation out of ctor --- .../Components/BeatmapAttributeText.cs | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapAttributeText.cs b/osu.Game/Skinning/Components/BeatmapAttributeText.cs index a3b0ed7168..1d6661d26e 100644 --- a/osu.Game/Skinning/Components/BeatmapAttributeText.cs +++ b/osu.Game/Skinning/Components/BeatmapAttributeText.cs @@ -20,7 +20,6 @@ using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Localisation; using osu.Game.Resources.Localisation.Web; -using osu.Game.Screens.Select.Filter; namespace osu.Game.Skinning.Components { @@ -40,29 +39,24 @@ namespace osu.Game.Skinning.Components private readonly Dictionary valueDictionary = new Dictionary(); - private static readonly ImmutableDictionary label_dictionary; + private static readonly ImmutableDictionary label_dictionary = new Dictionary + { + [BeatmapAttribute.CircleSize] = BeatmapsetsStrings.ShowStatsCs, + [BeatmapAttribute.Accuracy] = BeatmapsetsStrings.ShowStatsAccuracy, + [BeatmapAttribute.HPDrain] = BeatmapsetsStrings.ShowStatsDrain, + [BeatmapAttribute.ApproachRate] = BeatmapsetsStrings.ShowStatsAr, + [BeatmapAttribute.StarRating] = BeatmapsetsStrings.ShowStatsStars, + [BeatmapAttribute.Title] = EditorSetupStrings.Title, + [BeatmapAttribute.Artist] = EditorSetupStrings.Artist, + [BeatmapAttribute.DifficultyName] = EditorSetupStrings.DifficultyHeader, + [BeatmapAttribute.Creator] = EditorSetupStrings.Creator, + [BeatmapAttribute.Length] = ArtistStrings.TracklistLength.ToTitle(), + [BeatmapAttribute.RankedStatus] = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault, + [BeatmapAttribute.BPM] = BeatmapsetsStrings.ShowStatsBpm, + }.ToImmutableDictionary(); private readonly OsuSpriteText text; - static BeatmapAttributeText() - { - label_dictionary = new Dictionary - { - [BeatmapAttribute.CircleSize] = BeatmapsetsStrings.ShowStatsCs, - [BeatmapAttribute.Accuracy] = BeatmapsetsStrings.ShowStatsAccuracy, - [BeatmapAttribute.HPDrain] = BeatmapsetsStrings.ShowStatsDrain, - [BeatmapAttribute.ApproachRate] = BeatmapsetsStrings.ShowStatsAr, - [BeatmapAttribute.StarRating] = BeatmapsetsStrings.ShowStatsStars, - [BeatmapAttribute.Title] = EditorSetupStrings.Title, - [BeatmapAttribute.Artist] = EditorSetupStrings.Artist, - [BeatmapAttribute.DifficultyName] = EditorSetupStrings.DifficultyHeader, - [BeatmapAttribute.Creator] = EditorSetupStrings.Creator, - [BeatmapAttribute.Length] = ArtistStrings.TracklistLength.ToTitle(), - [BeatmapAttribute.RankedStatus] = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault, - [BeatmapAttribute.BPM] = BeatmapsetsStrings.ShowStatsBpm, - }.ToImmutableDictionary(); - } - public BeatmapAttributeText() { AutoSizeAxes = Axes.Both; From 0f034606fd68b4106bd0deeaae75b962fb617489 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 16:49:51 +0900 Subject: [PATCH 29/41] Use `LocalisableDescription` from `BeatmapOnlineStatus` enum instead of locally defined --- .../Components/BeatmapAttributeText.cs | 38 +------------------ 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapAttributeText.cs b/osu.Game/Skinning/Components/BeatmapAttributeText.cs index 1d6661d26e..5cb78864f7 100644 --- a/osu.Game/Skinning/Components/BeatmapAttributeText.cs +++ b/osu.Game/Skinning/Components/BeatmapAttributeText.cs @@ -130,46 +130,10 @@ namespace osu.Game.Skinning.Components //update Length valueDictionary[BeatmapAttribute.Length] = TimeSpan.FromMilliseconds(workingBeatmap.BeatmapInfo.Length).ToFormattedDuration(); //update Status - valueDictionary[BeatmapAttribute.RankedStatus] = GetBetmapStatus(workingBeatmap.BeatmapInfo.Status); + valueDictionary[BeatmapAttribute.RankedStatus] = workingBeatmap.BeatmapInfo.Status.GetLocalisableDescription(); //update BPM valueDictionary[BeatmapAttribute.BPM] = workingBeatmap.BeatmapInfo.BPM.ToString("F2"); } - - public static LocalisableString GetBetmapStatus(BeatmapOnlineStatus status) - { - switch (status) - { - case BeatmapOnlineStatus.Approved: - return BeatmapsetsStrings.ShowStatusApproved; - - case BeatmapOnlineStatus.Graveyard: - return BeatmapsetsStrings.ShowStatusGraveyard; - - case BeatmapOnlineStatus.Loved: - return BeatmapsetsStrings.ShowStatusLoved; - - case BeatmapOnlineStatus.None: - return "None"; - - case BeatmapOnlineStatus.Pending: - return BeatmapsetsStrings.ShowStatusPending; - - case BeatmapOnlineStatus.Qualified: - return BeatmapsetsStrings.ShowStatusQualified; - - case BeatmapOnlineStatus.Ranked: - return BeatmapsetsStrings.ShowStatusRanked; - - case BeatmapOnlineStatus.LocallyModified: - return SongSelectStrings.LocallyModified; - - case BeatmapOnlineStatus.WIP: - return BeatmapsetsStrings.ShowStatusWip; - - default: - return @"null"; - } - } } public enum BeatmapAttribute From 0749a7bb0777691b35f438311ce1e7c3acf3a973 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 16:53:36 +0900 Subject: [PATCH 30/41] Simplify attribute assignment --- .../Components/BeatmapAttributeText.cs | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapAttributeText.cs b/osu.Game/Skinning/Components/BeatmapAttributeText.cs index 5cb78864f7..498ea1d268 100644 --- a/osu.Game/Skinning/Components/BeatmapAttributeText.cs +++ b/osu.Game/Skinning/Components/BeatmapAttributeText.cs @@ -104,35 +104,18 @@ namespace osu.Game.Skinning.Components public void UpdateBeatmapContent(WorkingBeatmap workingBeatmap) { - //update cs - double cs = workingBeatmap.BeatmapInfo.Difficulty.CircleSize; - valueDictionary[BeatmapAttribute.CircleSize] = cs.ToString("F2"); - //update HP - double hp = workingBeatmap.BeatmapInfo.Difficulty.DrainRate; - valueDictionary[BeatmapAttribute.HPDrain] = hp.ToString("F2"); - //update od - double od = workingBeatmap.BeatmapInfo.Difficulty.OverallDifficulty; - valueDictionary[BeatmapAttribute.Accuracy] = od.ToString("F2"); - //update ar - double ar = workingBeatmap.BeatmapInfo.Difficulty.ApproachRate; - valueDictionary[BeatmapAttribute.ApproachRate] = ar.ToString("F2"); - //update sr - double sr = workingBeatmap.BeatmapInfo.StarRating; - valueDictionary[BeatmapAttribute.StarRating] = sr.ToString("F2"); - //update song title valueDictionary[BeatmapAttribute.Title] = workingBeatmap.BeatmapInfo.Metadata.Title; - //update artist valueDictionary[BeatmapAttribute.Artist] = workingBeatmap.BeatmapInfo.Metadata.Artist; - //update difficulty name valueDictionary[BeatmapAttribute.DifficultyName] = workingBeatmap.BeatmapInfo.DifficultyName; - //update mapper valueDictionary[BeatmapAttribute.Creator] = workingBeatmap.BeatmapInfo.Metadata.Author.Username; - //update Length valueDictionary[BeatmapAttribute.Length] = TimeSpan.FromMilliseconds(workingBeatmap.BeatmapInfo.Length).ToFormattedDuration(); - //update Status valueDictionary[BeatmapAttribute.RankedStatus] = workingBeatmap.BeatmapInfo.Status.GetLocalisableDescription(); - //update BPM - valueDictionary[BeatmapAttribute.BPM] = workingBeatmap.BeatmapInfo.BPM.ToString("F2"); + valueDictionary[BeatmapAttribute.BPM] = workingBeatmap.BeatmapInfo.BPM.ToString(@"F2"); + valueDictionary[BeatmapAttribute.CircleSize] = ((double)workingBeatmap.BeatmapInfo.Difficulty.CircleSize).ToString(@"F2"); + valueDictionary[BeatmapAttribute.HPDrain] = ((double)workingBeatmap.BeatmapInfo.Difficulty.DrainRate).ToString(@"F2"); + valueDictionary[BeatmapAttribute.Accuracy] = ((double)workingBeatmap.BeatmapInfo.Difficulty.OverallDifficulty).ToString(@"F2"); + valueDictionary[BeatmapAttribute.ApproachRate] = ((double)workingBeatmap.BeatmapInfo.Difficulty.ApproachRate).ToString(@"F2"); + valueDictionary[BeatmapAttribute.StarRating] = workingBeatmap.BeatmapInfo.StarRating.ToString(@"F2"); } } From 774f70e380ab129f4472a73494e1397e556b0238 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 16:56:40 +0900 Subject: [PATCH 31/41] Simplify class structure --- .../Components/BeatmapAttributeText.cs | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapAttributeText.cs b/osu.Game/Skinning/Components/BeatmapAttributeText.cs index 498ea1d268..572b4ba818 100644 --- a/osu.Game/Skinning/Components/BeatmapAttributeText.cs +++ b/osu.Game/Skinning/Components/BeatmapAttributeText.cs @@ -60,49 +60,32 @@ namespace osu.Game.Skinning.Components public BeatmapAttributeText() { AutoSizeAxes = Axes.Both; + InternalChildren = new Drawable[] { text = new OsuSpriteText { - Text = "BeatInfoDrawable", Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Font = OsuFont.Default.With(size: 40) } }; - - foreach (var type in Enum.GetValues(typeof(BeatmapAttribute)).Cast()) - { - valueDictionary[type] = type.ToString(); - } } protected override void LoadComplete() { base.LoadComplete(); + Attribute.BindValueChanged(_ => updateLabel()); - Template.BindValueChanged(f => updateLabel(), true); + Template.BindValueChanged(_ => updateLabel()); beatmap.BindValueChanged(b => { - UpdateBeatmapContent(b.NewValue); + updateBeatmapContent(b.NewValue); updateLabel(); }, true); } - private void updateLabel() - { - string newText = Template.Value.Replace("{Label}", label_dictionary[Attribute.Value].ToString()) - .Replace("{Value}", valueDictionary[Attribute.Value].ToString()); - - foreach (var type in Enum.GetValues(typeof(BeatmapAttribute)).Cast()) - { - newText = newText.Replace("{" + type + "}", valueDictionary[type].ToString()); - } - - text.Text = newText; - } - - public void UpdateBeatmapContent(WorkingBeatmap workingBeatmap) + private void updateBeatmapContent(WorkingBeatmap workingBeatmap) { valueDictionary[BeatmapAttribute.Title] = workingBeatmap.BeatmapInfo.Metadata.Title; valueDictionary[BeatmapAttribute.Artist] = workingBeatmap.BeatmapInfo.Metadata.Artist; @@ -117,6 +100,19 @@ namespace osu.Game.Skinning.Components valueDictionary[BeatmapAttribute.ApproachRate] = ((double)workingBeatmap.BeatmapInfo.Difficulty.ApproachRate).ToString(@"F2"); valueDictionary[BeatmapAttribute.StarRating] = workingBeatmap.BeatmapInfo.StarRating.ToString(@"F2"); } + + private void updateLabel() + { + string newText = Template.Value.Replace("{Label}", label_dictionary[Attribute.Value].ToString()) + .Replace("{Value}", valueDictionary[Attribute.Value].ToString()); + + foreach (var type in Enum.GetValues(typeof(BeatmapAttribute)).Cast()) + { + newText = newText.Replace("{" + type + "}", valueDictionary[type].ToString()); + } + + text.Text = newText; + } } public enum BeatmapAttribute From a6bba1967ebfa392a27e2c77f4f0e4e68aac353f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 17:06:22 +0900 Subject: [PATCH 32/41] Update serialisation test to match new comopnent naming --- .../Archives/modified-default-20221102.osk | Bin 1534 -> 1599 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/osu.Game.Tests/Resources/Archives/modified-default-20221102.osk b/osu.Game.Tests/Resources/Archives/modified-default-20221102.osk index 3ec328db4e8212e2cb709865362b24f83951b93e..c1333acd13185826f4516eccf92f6d6d2e24cb8a 100644 GIT binary patch literal 1599 zcmWIWW@Zs#U|`^2$nGc)?YJIvbt{k;!UPgwU?|Sc%+t%v%e>pam(S5rp!Iic*Tsns z{)H?Gei;(7NFq&7dbjbWax?RJz7HqvVN%k%*!@oB{`ASkdDF844}3asA%o*q<;}x> zMuqE-a7=Q9Ftyj^XG=3j=%kV4kr1`we2WdC?W-Z$=X>o@7xxcT1BKAM-*l|!M zCuDkQtlz4W&+OxB5tz+^=dFGg6cF&q z`;2esrl5dR`g)-u7c?|a`JC}S@2Pt&1Z=74Gy|2P}=+8&6z!W&g?1KD=?$mLCK2CfYmEzD+8*dXMK!&cbbub;Q=25gBZ}! zzKNN69-%JI`MCx8d8v6N#bDRJo$ly=+d$;_`@bTA=MNTjOkU$*>u@S8bGBIEgC+}! z?_0MP`xqr3 z(fq@?w z{lWQp>A|TvsmUeact08(n|;VYr1pDwO6@zRTVGB$@@w6eJ2vA?p8g}}wdH0r)RuZW z3jY5clxwclY-ld2$p2l%@_CWpyEW|>&gHbMsfcbUZPr<-RWtud!}4r37GZ6hX_bns z9BV&t2+dVL8t{6Ot`@Ih&X(R=>Sk4~L57-aEb`NOkBMFn3vsjsGqZ`LW`W`=;U=f$H{l&EfbuG28E+4RM_}%t6^3{@u zE57zWF!8mRvq?zii}S0X?T2qIh-)v=xa2eK*_QhZ{;JU%qYiUQKXGl`l`I`mcc<2S zN7FXO3%4v*zLJZ&RCw&irj}W$X75dt>`yNG_HUYVURSrfgW=a2p&eV2uWfyv_)2L0 z1!LoaTaVi=T#1){KgqseU+AS{J8s>L2+M3MVbe%WJ>?i1Df=~E{fqu(p;`JeErI0` zix{k*t*=gh=Ca{Ed!9tay^|Yc9)4(g{7Et@?t_cG&;4Gt{^~6npYlJwI(r`&PmD|= z47dwUU}Ql+BZz_(qv*QO%Ot2C28PDlP+jm63SBFD$$-#00hnO0mlNn_peHYc8U4%{ Vi7mjJl?|kT1qeR@X>(Q(4*+f4o~Hl+ literal 1534 zcmWIWW@Zs#U|`^2NN-6B{k=AO?o1$WGgyRyp*TA;PcJhsQ}v7?Uz3A?!^L?i?+t<+ zla2&jio6+_nX1E<*3i4#IPE6y!yGZWliC~`|LOn#{Vzl`#=R|W?&X`O80LDVbQ(Nn znX#yx+1rz4%;f*Sr?uTAxyVI%L+HDUVhxY@BW5nr?WLKLEw~Gv4vZmjIpK z1H`;Q403*EURu6hR&jpb>Ss@b0s=mHpYaXd6clhuUoSMIBhX97>-_odz@Q5TMg~Tg zLN1&*>wnVcw2$w_kV}l(<$7MeIw$p+UUHm0eeSgW`DU+*XQI}d?VI+U#a$tj}*2ki&Obn>bd;h|Bkv}5?LpU=713%Dt z!TEXV!Kpc^$t7S1?wuH$eaJwf^*!r<=WE_87slTzdvNqxt--MwXLd<{RJs<_k*Cm#O61*4n}CKI$QjBky+}4dvo?E9ALgL{iCd#pKZ5a%i#m^JlemmzSzU* zn>F{6i?6z5Vu9M*ZOpwIWqwccDz*t;iaE+#Ikm*syV5-8LP%rPg6fEEm$eUxY&q?i zExc6g`}RX8+cqt23Cb|jk1YMX+$reB>uR>0mVcZD|1z*|e9!){Fs)Yq$l-;;t{+)_ zD=a=GtCuWJe#_;4FMsKl&*IxI>0MR3X!LFROBL6>XIi$rUD$G}r*YRNznnSYH{PDv z&xjiK)eZ7#FMwfR1`K#HVA%U6X6AW>x;W?O7Ubup=9LtKqu}lI*zDT|B5m)v|MII{ zUpK-2QNN?!ttHXNB#gax&A!Ba)Yj7_Ra54qPU4&W;d!#tkD6<1mc2-8c3j_gU-?VH zo5i<38z27}YAcg&a6dQU!$C=n*h&6t7>rH}I%G}a+@^eaHs{O(lcpZ(3Edcw9O}jV z!s>Uy^`DF@c1}|EnwNK7^7aFvM3sdmCt6;oJazi;hx^U5SBy_QraAH4v8r8WV*agk zcT1IP*qvJw#jB1ipVF46{C3S%C>i4mS7sdL-U)uL=KT!B_ z)h7=BUU#+~ArS^MotNz}*>(JyrqrY>aUbn3+u0UquI1j?-rhSYp?rP}qcQ94nrYsq zj^8HhvXm6gSzzb+cj5D`yOyU&{H&{B5%fxWrMmC=@%GT~OMWMQ`ELLD-^VkF+3Q$E z$}TWYvrzM#p?18aC Ghz9_U=60t5 From e69ed67335ab9824b238e4f0953be2d9c0b46ea9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 18:09:47 +0900 Subject: [PATCH 33/41] Add test of barline generation with negative start time control point --- .../TestSceneBarLineGeneration.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/osu.Game.Rulesets.Taiko.Tests/TestSceneBarLineGeneration.cs b/osu.Game.Rulesets.Taiko.Tests/TestSceneBarLineGeneration.cs index 095fddc33f..bd52af7615 100644 --- a/osu.Game.Rulesets.Taiko.Tests/TestSceneBarLineGeneration.cs +++ b/osu.Game.Rulesets.Taiko.Tests/TestSceneBarLineGeneration.cs @@ -83,5 +83,41 @@ namespace osu.Game.Rulesets.Taiko.Tests AddAssert("first barline ommited", () => barlines.All(b => b.StartTime != start_time)); AddAssert("second barline generated", () => barlines.Any(b => b.StartTime == start_time + (beat_length * time_signature_numerator))); } + + [Test] + public void TestNegativeStartTimeTimingPoint() + { + const double beat_length = 250; + + const int time_signature_numerator = 4; + + var beatmap = new Beatmap + { + HitObjects = + { + new Hit + { + Type = HitType.Centre, + StartTime = 1000 + } + }, + BeatmapInfo = + { + Difficulty = new BeatmapDifficulty { SliderTickRate = 4 }, + Ruleset = new TaikoRuleset().RulesetInfo + }, + }; + + beatmap.ControlPointInfo.Add(-100, new TimingControlPoint + { + BeatLength = beat_length, + TimeSignature = new TimeSignature(time_signature_numerator) + }); + + var barlines = new BarLineGenerator(beatmap).BarLines; + + AddAssert("bar line generated at t=900", () => barlines.Any(line => line.StartTime == 900)); + AddAssert("bar line generated at t=1900", () => barlines.Any(line => line.StartTime == 1900)); + } } } From f9d952220fcee1e1aadc588cbec85ce179461e55 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 18:12:03 +0900 Subject: [PATCH 34/41] Fix barlines being misaligned if generation start time is clamped --- osu.Game/Rulesets/Objects/BarLineGenerator.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Objects/BarLineGenerator.cs b/osu.Game/Rulesets/Objects/BarLineGenerator.cs index 185088878c..5c76c43f20 100644 --- a/osu.Game/Rulesets/Objects/BarLineGenerator.cs +++ b/osu.Game/Rulesets/Objects/BarLineGenerator.cs @@ -47,13 +47,28 @@ namespace osu.Game.Rulesets.Objects // Don't generate barlines before the hit object or t=0 (whichever is earliest). Some beatmaps use very unrealistic values here (although none are ranked). // I'm not sure we ever want barlines to appear before the first hitobject, but let's keep some degree of compatibility for now. // Of note, this will still differ from stable if the first timing control point is t<0 and is not near the first hitobject. - double startTime = Math.Max(Math.Min(0, firstHitTime), currentTimingPoint.Time); + double generationStartTime = Math.Min(0, firstHitTime); // Stop on the next timing point, or if there is no next timing point stop slightly past the last object double endTime = i < timingPoints.Count - 1 ? timingPoints[i + 1].Time : lastHitTime + currentTimingPoint.BeatLength * currentTimingPoint.TimeSignature.Numerator; double barLength = currentTimingPoint.BeatLength * currentTimingPoint.TimeSignature.Numerator; + double startTime; + + if (currentTimingPoint.Time > generationStartTime) + { + startTime = currentTimingPoint.Time; + } + else + { + // If the timing point starts before the minimum allowable time for bar lines, + // we still need to compute a start time for generation that is actually properly aligned with the timing point. + int barCount = (int)Math.Ceiling((generationStartTime - currentTimingPoint.Time) / barLength); + + startTime = currentTimingPoint.Time + barCount * barLength; + } + if (currentEffectPoint.OmitFirstBarLine) { startTime += barLength; From 5467097387b97f0dbf2ae9defb7234368977e5c2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 18:49:51 +0900 Subject: [PATCH 35/41] Fix adjacent day separators potentially being left behind after pending message resolution --- osu.Game/Overlays/Chat/DrawableChannel.cs | 36 ++++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index 3d2eafd973..65876fd7c5 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -141,27 +141,15 @@ namespace osu.Game.Overlays.Chat } var staleMessages = chatLines.Where(c => c.LifetimeEnd == double.MaxValue).ToArray(); + int count = staleMessages.Length - Channel.MAX_HISTORY; if (count > 0) { - void expireAndAdjustScroll(Drawable d) - { - scroll.OffsetScrollPosition(-d.DrawHeight); - d.Expire(); - } - for (int i = 0; i < count; i++) expireAndAdjustScroll(staleMessages[i]); - // remove all adjacent day separators after stale message removal - for (int i = 0; i < ChatLineFlow.Count - 1; i++) - { - if (!(ChatLineFlow[i] is DaySeparator)) break; - if (!(ChatLineFlow[i + 1] is DaySeparator)) break; - - expireAndAdjustScroll(ChatLineFlow[i]); - } + removeAdjacentDaySeparators(); } // due to the scroll adjusts from old messages removal above, a scroll-to-end must be enforced, @@ -199,9 +187,29 @@ namespace osu.Game.Overlays.Chat ChatLineFlow.Remove(ds, true); ChatLineFlow.Add(CreateDaySeparator(message.Timestamp)); + + removeAdjacentDaySeparators(); } } + private void removeAdjacentDaySeparators() + { + // remove all adjacent day separators after stale message removal + for (int i = 0; i < ChatLineFlow.Count - 1; i++) + { + if (!(ChatLineFlow[i] is DaySeparator)) break; + if (!(ChatLineFlow[i + 1] is DaySeparator)) break; + + expireAndAdjustScroll(ChatLineFlow[i]); + } + } + + private void expireAndAdjustScroll(Drawable d) + { + scroll.OffsetScrollPosition(-d.DrawHeight); + d.Expire(); + } + private void messageRemoved(Message removed) => Schedule(() => { chatLines.FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire(); From 2204af04e485cbd2af81f51d8846684a36a17477 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 23 Nov 2022 16:12:13 +0300 Subject: [PATCH 36/41] Improve test scene to better show colour gradient --- .../TestSceneTrianglesV2Background.cs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs index e8abc573cd..0c3a21d510 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs @@ -27,16 +27,24 @@ namespace osu.Game.Tests.Visual.Background { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Size = new Vector2(500), + Size = new Vector2(500, 100), Masking = true, CornerRadius = 40, - Child = triangles = new TrianglesV2 + Children = new Drawable[] { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - ColourTop = Color4.Red, - ColourBottom = Color4.Orange + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Red + }, + triangles = new TrianglesV2 + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + ColourTop = Color4.White, + ColourBottom = Color4.Red + } } } }); From 06449b62f1517ab9f77e3a0c8050af8c0065ee5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 23 Nov 2022 16:03:54 +0100 Subject: [PATCH 37/41] Add test coverage for crash scenario --- .../Visual/Editing/TestSceneTapTimingControl.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTapTimingControl.cs b/osu.Game.Tests/Visual/Editing/TestSceneTapTimingControl.cs index 10e1206b53..f2bfffda06 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneTapTimingControl.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneTapTimingControl.cs @@ -18,6 +18,7 @@ using osu.Game.Overlays; using osu.Game.Screens.Edit; using osu.Game.Screens.Edit.Timing; using osuTK; +using osuTK.Input; namespace osu.Game.Tests.Visual.Editing { @@ -125,6 +126,13 @@ namespace osu.Game.Tests.Visual.Editing AddUntilStep("wait for track stopped", () => !EditorClock.IsRunning); } + [Test] + public void TestNoCrashOnTapWhenNoGroupSelected() + { + AddStep("unset selected group", () => selectedGroup.Value = null); + AddStep("press T to tap", () => InputManager.Key(Key.T)); + } + protected override void Dispose(bool isDisposing) { Beatmap.Disabled = false; From cf5f5a4de310147523f2a41ff5621149758b07e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 23 Nov 2022 17:19:58 +0100 Subject: [PATCH 38/41] Extend tap timing control test coverage in no point selected case --- .../Editing/TestSceneTapTimingControl.cs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTapTimingControl.cs b/osu.Game.Tests/Visual/Editing/TestSceneTapTimingControl.cs index f2bfffda06..6ed63515e9 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneTapTimingControl.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneTapTimingControl.cs @@ -127,10 +127,38 @@ namespace osu.Game.Tests.Visual.Editing } [Test] - public void TestNoCrashOnTapWhenNoGroupSelected() + public void TestNoCrashesWhenNoGroupSelected() { AddStep("unset selected group", () => selectedGroup.Value = null); AddStep("press T to tap", () => InputManager.Key(Key.T)); + + AddStep("click tap button", () => + { + control.ChildrenOfType() + .Last() + .TriggerClick(); + }); + + AddStep("click reset button", () => + { + control.ChildrenOfType() + .First() + .TriggerClick(); + }); + + AddStep("adjust offset", () => + { + var adjustOffsetButton = control.ChildrenOfType().First(); + InputManager.MoveMouseTo(adjustOffsetButton); + InputManager.Click(MouseButton.Left); + }); + + AddStep("adjust BPM", () => + { + var adjustBPMButton = control.ChildrenOfType().Last(); + InputManager.MoveMouseTo(adjustBPMButton); + InputManager.Click(MouseButton.Left); + }); } protected override void Dispose(bool isDisposing) From 30f9cc46a7618031088f98fc2d2444279f9e6dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 23 Nov 2022 17:22:40 +0100 Subject: [PATCH 39/41] Protect offset and bpm adjustments from null selection too --- osu.Game/Screens/Edit/Timing/TapTimingControl.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Timing/TapTimingControl.cs b/osu.Game/Screens/Edit/Timing/TapTimingControl.cs index daa3168746..3b26e335d9 100644 --- a/osu.Game/Screens/Edit/Timing/TapTimingControl.cs +++ b/osu.Game/Screens/Edit/Timing/TapTimingControl.cs @@ -201,6 +201,9 @@ namespace osu.Game.Screens.Edit.Timing private void adjustOffset(double adjust) { + if (selectedGroup.Value == null) + return; + bool wasAtStart = editorClock.CurrentTimeAccurate == selectedGroup.Value.Time; // VERY TEMPORARY @@ -222,7 +225,7 @@ namespace osu.Game.Screens.Edit.Timing private void adjustBpm(double adjust) { - var timing = selectedGroup.Value.ControlPoints.OfType().FirstOrDefault(); + var timing = selectedGroup.Value?.ControlPoints.OfType().FirstOrDefault(); if (timing == null) return; From 4b44f31b5edd98f43e57ed81bb94f5c16c87b9a1 Mon Sep 17 00:00:00 2001 From: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Date: Wed, 23 Nov 2022 21:02:43 +0100 Subject: [PATCH 40/41] Use LocaliseableStings in `BeatmapAttributeText` --- .../Components/BeatmapAttributeText.cs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapAttributeText.cs b/osu.Game/Skinning/Components/BeatmapAttributeText.cs index 572b4ba818..ec84831fb4 100644 --- a/osu.Game/Skinning/Components/BeatmapAttributeText.cs +++ b/osu.Game/Skinning/Components/BeatmapAttributeText.cs @@ -93,25 +93,34 @@ namespace osu.Game.Skinning.Components valueDictionary[BeatmapAttribute.Creator] = workingBeatmap.BeatmapInfo.Metadata.Author.Username; valueDictionary[BeatmapAttribute.Length] = TimeSpan.FromMilliseconds(workingBeatmap.BeatmapInfo.Length).ToFormattedDuration(); valueDictionary[BeatmapAttribute.RankedStatus] = workingBeatmap.BeatmapInfo.Status.GetLocalisableDescription(); - valueDictionary[BeatmapAttribute.BPM] = workingBeatmap.BeatmapInfo.BPM.ToString(@"F2"); - valueDictionary[BeatmapAttribute.CircleSize] = ((double)workingBeatmap.BeatmapInfo.Difficulty.CircleSize).ToString(@"F2"); - valueDictionary[BeatmapAttribute.HPDrain] = ((double)workingBeatmap.BeatmapInfo.Difficulty.DrainRate).ToString(@"F2"); - valueDictionary[BeatmapAttribute.Accuracy] = ((double)workingBeatmap.BeatmapInfo.Difficulty.OverallDifficulty).ToString(@"F2"); - valueDictionary[BeatmapAttribute.ApproachRate] = ((double)workingBeatmap.BeatmapInfo.Difficulty.ApproachRate).ToString(@"F2"); - valueDictionary[BeatmapAttribute.StarRating] = workingBeatmap.BeatmapInfo.StarRating.ToString(@"F2"); + valueDictionary[BeatmapAttribute.BPM] = workingBeatmap.BeatmapInfo.BPM.ToLocalisableString(@"F2"); + valueDictionary[BeatmapAttribute.CircleSize] = ((double)workingBeatmap.BeatmapInfo.Difficulty.CircleSize).ToLocalisableString(@"F2"); + valueDictionary[BeatmapAttribute.HPDrain] = ((double)workingBeatmap.BeatmapInfo.Difficulty.DrainRate).ToLocalisableString(@"F2"); + valueDictionary[BeatmapAttribute.Accuracy] = ((double)workingBeatmap.BeatmapInfo.Difficulty.OverallDifficulty).ToLocalisableString(@"F2"); + valueDictionary[BeatmapAttribute.ApproachRate] = ((double)workingBeatmap.BeatmapInfo.Difficulty.ApproachRate).ToLocalisableString(@"F2"); + valueDictionary[BeatmapAttribute.StarRating] = workingBeatmap.BeatmapInfo.StarRating.ToLocalisableString(@"F2"); } private void updateLabel() { - string newText = Template.Value.Replace("{Label}", label_dictionary[Attribute.Value].ToString()) - .Replace("{Value}", valueDictionary[Attribute.Value].ToString()); + string numberedTemplate = Template.Value + .Replace("{", "{{") + .Replace("}", "}}") + .Replace(@"{{Label}}", "{0}") + .Replace(@"{{Value}}", $"{{{1 + (int)Attribute.Value}}}"); + + object?[] args = valueDictionary.OrderBy(pair => pair.Key) + .Select(pair => pair.Value) + .Prepend(label_dictionary[Attribute.Value]) + .Cast() + .ToArray(); foreach (var type in Enum.GetValues(typeof(BeatmapAttribute)).Cast()) { - newText = newText.Replace("{" + type + "}", valueDictionary[type].ToString()); + numberedTemplate = numberedTemplate.Replace($"{{{{{type}}}}}", $"{{{1 + (int)type}}}"); } - text.Text = newText; + text.Text = LocalisableString.Format(numberedTemplate, args); } } From 2e277ef40a3b51b8e935863f3ceea5bc4694597c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 24 Nov 2022 15:18:49 +0900 Subject: [PATCH 41/41] Update resources --- osu.Android.props | 2 +- osu.Game/osu.Game.csproj | 2 +- osu.iOS.props | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Android.props b/osu.Android.props index 5f3fb858ee..647c7b179c 100644 --- a/osu.Android.props +++ b/osu.Android.props @@ -51,7 +51,7 @@ - + diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 858cac1dac..5c4b5642b5 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -36,7 +36,7 @@ - + diff --git a/osu.iOS.props b/osu.iOS.props index 25217b872b..19f4248055 100644 --- a/osu.iOS.props +++ b/osu.iOS.props @@ -61,7 +61,7 @@ - +