mirror of
https://github.com/ppy/osu.git
synced 2026-05-23 23:32:15 +08:00
Merge pull request #33103 from frenzibyte/mod-tooltip-fix
Fix mod tooltip not handling settings changes to same mod instance
This commit is contained in:
@@ -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<ModIcon>().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<ModTooltip>().SingleOrDefault();
|
||||
|
||||
// we could also just expose those directly from ModTooltip, but this works.
|
||||
string getTooltipText() => getTooltip().ChildrenOfType<SpriteText>().First().Text.ToString();
|
||||
IEnumerable<string> getTooltipSettingsLabels() => getTooltip().ChildrenOfType<TextFlowContainer>().First().ChildrenOfType<SpriteText>().Select(t => t.Text.ToString());
|
||||
IEnumerable<string> getTooltipSettingsValues() => getTooltip().ChildrenOfType<TextFlowContainer>().Last().ChildrenOfType<SpriteText>().Select(t => t.Text.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user