1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:07:44 +08:00

Simplify colour setting for additional elements in OverlayRulesetTabItem

This commit is contained in:
Andrei Zavatski 2020-01-02 13:18:18 +03:00
parent 7cab181c12
commit 904b068a15
2 changed files with 14 additions and 22 deletions

View File

@ -11,6 +11,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
using osuTK.Graphics;
using osuTK;
using System;
namespace osu.Game.Overlays
{
@ -33,10 +34,12 @@ namespace osu.Game.Overlays
accentColour = value;
UpdateState();
updateState();
}
}
protected Action<Color4> OnStateUpdated;
protected override Container<Drawable> Content => content;
public OverlayRulesetTabItem(RulesetInfo value)
@ -67,32 +70,32 @@ namespace osu.Game.Overlays
protected override void LoadComplete()
{
base.LoadComplete();
Enabled.BindValueChanged(_ => UpdateState(), true);
Enabled.BindValueChanged(_ => updateState(), true);
}
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
UpdateState();
updateState();
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
UpdateState();
updateState();
}
protected override void OnActivated() => UpdateState();
protected override void OnActivated() => updateState();
protected override void OnDeactivated() => UpdateState();
protected override void OnDeactivated() => updateState();
protected virtual void UpdateState()
private void updateState()
{
var updatedColour = IsHovered || Active.Value ? Color4.White : Enabled.Value ? AccentColour : Color4.DimGray;
Text.Font = Text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Medium);
Text.FadeColour(GetColour(), 120, Easing.OutQuint);
Text.FadeColour(updatedColour, 120, Easing.OutQuint);
OnStateUpdated?.Invoke(updatedColour);
}
protected Color4 GetColour() => IsHovered || Active.Value ? Color4.White : Enabled.Value ? AccentColour : Color4.DimGray;
}
}

View File

@ -5,7 +5,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays.Profile.Header.Components
{
@ -13,12 +12,6 @@ namespace osu.Game.Overlays.Profile.Header.Components
{
private readonly SpriteIcon icon;
public new Color4 AccentColour
{
get => base.AccentColour;
set => base.AccentColour = icon.Colour = value;
}
private bool isDefault;
public bool IsDefault
@ -47,12 +40,8 @@ namespace osu.Game.Overlays.Profile.Header.Components
Icon = FontAwesome.Solid.Star,
Size = new Vector2(12),
});
}
protected override void UpdateState()
{
base.UpdateState();
icon.FadeColour(GetColour(), 120, Easing.OutQuint);
OnStateUpdated += colour => icon.FadeColour(colour, 120, Easing.OutQuint);
}
}
}