Add the ability to override Highlighted action to the ModIcon

This commit is contained in:
Andrei Zavatski 2019-08-12 15:20:21 +03:00
parent 21af390327
commit 62a91e4aaa
2 changed files with 23 additions and 4 deletions

View File

@ -92,11 +92,16 @@ namespace osu.Game.Overlays.BeatmapSet
{
Scale = new Vector2(mod_scale);
Add(new HoverClickSounds());
}
protected override void LoadComplete()
{
base.LoadComplete();
Selected.BindValueChanged(selected =>
{
updateState();
OnSelectionChanged?.Invoke(mod, selected.NewValue);
OnSelectionChanged?.Invoke(Mod, selected.NewValue);
}, true);
}
@ -120,7 +125,12 @@ namespace osu.Game.Overlays.BeatmapSet
private void updateState()
{
this.FadeColour(IsHovered || Selected.Value ? Color4.White : Color4.Gray, duration, Easing.OutQuint);
Highlighted.Value = (IsHovered || Selected.Value) ? true : false;
}
protected override void OnHighlightedChange(ValueChangedEvent<bool> highlighted)
{
this.FadeColour(highlighted.NewValue ? Color4.White : Color4.Gray, duration, Easing.OutQuint);
}
}

View File

@ -34,9 +34,11 @@ namespace osu.Game.Rulesets.UI
public virtual string TooltipText { get; }
protected Mod Mod { get; private set; }
public ModIcon(Mod mod)
{
if (mod == null) throw new ArgumentNullException(nameof(mod));
Mod = mod ?? throw new ArgumentNullException(nameof(mod));
type = mod.Type;
@ -106,12 +108,19 @@ namespace osu.Game.Rulesets.UI
modIcon.Colour = colours.Yellow;
break;
}
background.Colour = backgroundColour;
}
protected override void LoadComplete()
{
base.LoadComplete();
Highlighted.BindValueChanged(highlighted => background.Colour = highlighted.NewValue ? highlightedColour : backgroundColour, true);
Highlighted.BindValueChanged(OnHighlightedChange, true);
}
protected virtual void OnHighlightedChange(ValueChangedEvent<bool> highlighted)
{
background.Colour = highlighted.NewValue ? highlightedColour : backgroundColour;
}
}
}