From 62a8c8dfc95e4fb4c501f9590d4c3f3ceffb7ddf Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Mon, 12 May 2025 14:51:00 +0300 Subject: [PATCH 1/2] Add failing test case --- .../Visual/UserInterface/TestSceneModIcon.cs | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneModIcon.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneModIcon.cs index c8283d0956..c18f00677d 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneModIcon.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneModIcon.cs @@ -6,6 +6,7 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; using osu.Framework.Testing; using osu.Framework.Utils; using osu.Game.Rulesets.Mods; @@ -16,7 +17,7 @@ using osu.Game.Screens.Play.HUD; namespace osu.Game.Tests.Visual.UserInterface { - public partial class TestSceneModIcon : OsuTestScene + public partial class TestSceneModIcon : OsuManualInputManagerTestScene { private FillFlowContainer spreadOutFlow = null!; private ModDisplay modDisplay = null!; @@ -181,5 +182,40 @@ namespace osu.Game.Tests.Visual.UserInterface ]); }); } + + [Test] + public void TestTooltip() + { + OsuModDoubleTime mod = null!; + + AddStep("create icon", () => addRange([mod = new OsuModDoubleTime()])); + AddStep("hover", () => InputManager.MoveMouseTo(this.ChildrenOfType().First())); + AddUntilStep("tooltip displayed", () => getTooltip()?.IsPresent, () => Is.True); + AddAssert("tooltip text = \"Double Time\"", getTooltipText, () => Is.EqualTo("Double Time")); + AddAssert("tooltip settings empty", () => getTooltipSettingsLabels().Concat(getTooltipSettingsValues()), () => Is.Empty); + + AddStep("change settings", () => mod.SpeedChange.Value = 1.75f); + AddAssert("tooltip text = \"Double Time\"", getTooltipText, () => Is.EqualTo("Double Time")); + AddAssert("tooltip settings updated", + () => getTooltipSettingsLabels().Concat(getTooltipSettingsValues()), + () => Is.EquivalentTo(new[] { "Speed ", "change", "1.75x" })); + + AddStep("change settings", () => mod.SpeedChange.Value = 1.25f); + AddAssert("tooltip text = \"Double Time\"", getTooltipText, () => Is.EqualTo("Double Time")); + AddAssert("tooltip settings updated", + () => getTooltipSettingsLabels().Concat(getTooltipSettingsValues()), + () => Is.EquivalentTo(new[] { "Speed ", "change", "1.25x" })); + + AddStep("rest settings", () => mod.SpeedChange.SetDefault()); + AddAssert("tooltip text = \"Double Time\"", getTooltipText, () => Is.EqualTo("Double Time")); + AddAssert("tooltip settings empty", () => getTooltipSettingsLabels().Concat(getTooltipSettingsValues()), () => Is.Empty); + + ModTooltip? getTooltip() => this.ChildrenOfType().SingleOrDefault(); + + // we could also just expose those directly from ModTooltip, but this works. + string getTooltipText() => getTooltip().ChildrenOfType().First().Text.ToString(); + IEnumerable getTooltipSettingsLabels() => getTooltip().ChildrenOfType().First().ChildrenOfType().Select(t => t.Text.ToString()); + IEnumerable getTooltipSettingsValues() => getTooltip().ChildrenOfType().Last().ChildrenOfType().Select(t => t.Text.ToString()); + } } } From d5be4bf8d40d6bcf16fb039a174555b446e8a441 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Mon, 12 May 2025 14:51:14 +0300 Subject: [PATCH 2/2] Fix mod tooltip not handling settings changes to same mod instance --- osu.Game/Rulesets/UI/ModTooltip.cs | 43 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/osu.Game/Rulesets/UI/ModTooltip.cs b/osu.Game/Rulesets/UI/ModTooltip.cs index 07bb30e15a..6f60390798 100644 --- a/osu.Game/Rulesets/UI/ModTooltip.cs +++ b/osu.Game/Rulesets/UI/ModTooltip.cs @@ -9,6 +9,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; +using osu.Framework.Localisation; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Overlays; @@ -101,36 +102,38 @@ namespace osu.Game.Rulesets.UI }; } - private Mod? displayedContent; + private (LocalisableString setting, LocalisableString value)[]? displayedSettings; public void SetContent(Mod content) { - if (content == displayedContent) - return; - - displayedContent = content; nameText.Text = content.Name; - settingsLabelsFlow.Clear(); - settingsValuesFlow.Clear(); - if (content.SettingDescription.Any()) + if (displayedSettings == null || !displayedSettings.SequenceEqual(content.SettingDescription)) { - settingsLabelsFlow.Show(); - settingsValuesFlow.Show(); + displayedSettings = content.SettingDescription.ToArray(); - foreach (var part in content.SettingDescription) + settingsLabelsFlow.Clear(); + settingsValuesFlow.Clear(); + + if (displayedSettings.Any()) { - settingsLabelsFlow.AddText(part.setting); - settingsLabelsFlow.NewLine(); + settingsLabelsFlow.Show(); + settingsValuesFlow.Show(); - settingsValuesFlow.AddText(part.value); - settingsValuesFlow.NewLine(); + foreach (var part in displayedSettings) + { + settingsLabelsFlow.AddText(part.setting); + settingsLabelsFlow.NewLine(); + + settingsValuesFlow.AddText(part.value); + settingsValuesFlow.NewLine(); + } + } + else + { + settingsLabelsFlow.Hide(); + settingsValuesFlow.Hide(); } - } - else - { - settingsLabelsFlow.Hide(); - settingsValuesFlow.Hide(); } }