osu/osu.Game/Overlays/OverlayRulesetTabItem.cs

101 lines
3.1 KiB
C#
Raw Normal View History

2020-01-01 19:49:04 +00:00
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
using osuTK.Graphics;
using osuTK;
2020-01-03 18:02:56 +00:00
using osu.Framework.Bindables;
2020-01-01 19:49:04 +00:00
namespace osu.Game.Overlays
{
public class OverlayRulesetTabItem : TabItem<RulesetInfo>, IHasAccentColour
{
protected readonly OsuSpriteText Text;
private readonly FillFlowContainer content;
public override bool PropagatePositionalInputSubTree => Enabled.Value && !Active.Value && base.PropagatePositionalInputSubTree;
2020-01-03 18:02:56 +00:00
private readonly Bindable<Color4> accentColour = new Bindable<Color4>();
private readonly Bindable<Color4> currentColour = new Bindable<Color4>();
2020-01-01 19:49:04 +00:00
public Color4 AccentColour
{
2020-01-03 18:02:56 +00:00
get => accentColour.Value;
set => accentColour.Value = value;
2020-01-01 19:49:04 +00:00
}
protected override Container<Drawable> Content => content;
public OverlayRulesetTabItem(RulesetInfo value)
: base(value)
{
AutoSizeAxes = Axes.Both;
AddRangeInternal(new Drawable[]
{
content = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(3, 0),
Child = Text = new OsuSpriteText
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Text = value.Name,
}
},
new HoverClickSounds()
});
Enabled.Value = true;
}
protected override void LoadComplete()
{
base.LoadComplete();
2020-01-03 18:02:56 +00:00
currentColour.BindValueChanged(OnCurrentColourChanged);
accentColour.BindValueChanged(_ => updateState());
Enabled.BindValueChanged(_ => updateState(), true);
2020-01-01 19:49:04 +00:00
}
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
updateState();
2020-01-01 19:49:04 +00:00
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
updateState();
2020-01-01 19:49:04 +00:00
}
protected override void OnActivated() => updateState();
2020-01-01 19:49:04 +00:00
protected override void OnDeactivated() => updateState();
2020-01-01 19:49:04 +00:00
private void updateState()
2020-01-01 19:49:04 +00:00
{
Text.Font = Text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Medium);
2020-01-03 18:02:56 +00:00
currentColour.Value = IsHovered || Active.Value
? Color4.White
2020-01-03 18:20:31 +00:00
: Enabled.Value
? AccentColour
: Color4.DimGray;
2020-01-01 19:49:04 +00:00
}
2020-01-03 18:02:56 +00:00
protected virtual void OnCurrentColourChanged(ValueChangedEvent<Color4> colour) => Text.FadeColour(colour.NewValue, 120, Easing.OutQuint);
2020-01-01 19:49:04 +00:00
}
}