Merge pull request #11667 from smoogipoo/fix-mod-icon

Fix ModIcon not updating background colour correctly
This commit is contained in:
Dean Herbert 2021-02-03 22:06:29 +09:00 committed by GitHub
commit b27557f278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 20 deletions

View File

@ -0,0 +1,21 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.UI;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneModIcon : OsuTestScene
{
[Test]
public void TestChangeModType()
{
ModIcon icon = null;
AddStep("create mod icon", () => Child = icon = new ModIcon(new OsuModDoubleTime()));
AddStep("change mod", () => icon.Mod = new OsuModEasy());
}
}
}

View File

@ -29,8 +29,6 @@ namespace osu.Game.Rulesets.UI
private const float size = 80;
private readonly ModType type;
public virtual string TooltipText => showTooltip ? mod.IconTooltip : null;
private Mod mod;
@ -42,10 +40,18 @@ namespace osu.Game.Rulesets.UI
set
{
mod = value;
updateMod(value);
if (IsLoaded)
updateMod(value);
}
}
[Resolved]
private OsuColour colours { get; set; }
private Color4 backgroundColour;
private Color4 highlightedColour;
/// <summary>
/// Construct a new instance.
/// </summary>
@ -56,8 +62,6 @@ namespace osu.Game.Rulesets.UI
this.mod = mod ?? throw new ArgumentNullException(nameof(mod));
this.showTooltip = showTooltip;
type = mod.Type;
Size = new Vector2(size);
Children = new Drawable[]
@ -89,6 +93,13 @@ namespace osu.Game.Rulesets.UI
Icon = FontAwesome.Solid.Question
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Selected.BindValueChanged(_ => updateColour());
updateMod(mod);
}
@ -102,20 +113,14 @@ namespace osu.Game.Rulesets.UI
{
modIcon.FadeOut();
modAcronym.FadeIn();
return;
}
else
{
modIcon.FadeIn();
modAcronym.FadeOut();
}
modIcon.FadeIn();
modAcronym.FadeOut();
}
private Color4 backgroundColour;
private Color4 highlightedColour;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
switch (type)
switch (value.Type)
{
default:
case ModType.DifficultyIncrease:
@ -149,12 +154,13 @@ namespace osu.Game.Rulesets.UI
modIcon.Colour = colours.Yellow;
break;
}
updateColour();
}
protected override void LoadComplete()
private void updateColour()
{
base.LoadComplete();
Selected.BindValueChanged(selected => background.Colour = selected.NewValue ? highlightedColour : backgroundColour, true);
background.Colour = Selected.Value ? highlightedColour : backgroundColour;
}
}
}