1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-07 01:57:19 +08:00
osu-lazer/osu.Game/Overlays/OverlayRulesetTabItem.cs

103 lines
3.0 KiB
C#
Raw Normal View History

2020-01-01 22:49:04 +03: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.
2022-06-17 16:37:17 +09:00
#nullable disable
2020-01-01 22:49:04 +03:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
using osuTK.Graphics;
using osuTK;
using osu.Framework.Allocation;
2022-04-30 15:35:04 +03:00
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
2022-04-29 12:19:22 +03:00
using osu.Game.Graphics.Containers;
2020-01-01 22:49:04 +03:00
namespace osu.Game.Overlays
{
2022-11-24 14:32:20 +09:00
public partial class OverlayRulesetTabItem : TabItem<RulesetInfo>, IHasTooltip
2020-01-01 22:49:04 +03:00
{
private Color4 accentColour;
2020-01-01 22:49:04 +03:00
protected virtual Color4 AccentColour
2020-01-01 22:49:04 +03:00
{
get => accentColour;
set
{
accentColour = value;
2022-04-29 12:19:22 +03:00
icon.FadeColour(value, 120, Easing.OutQuint);
}
2020-01-01 22:49:04 +03:00
}
2020-02-03 15:13:21 +09:00
protected override Container<Drawable> Content { get; }
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
2020-01-01 22:49:04 +03:00
2022-04-29 12:19:22 +03:00
private readonly Drawable icon;
2020-02-03 15:13:21 +09:00
2022-04-30 15:35:04 +03:00
public LocalisableString TooltipText => Value.Name;
2020-01-01 22:49:04 +03:00
public OverlayRulesetTabItem(RulesetInfo value)
: base(value)
{
AutoSizeAxes = Axes.Both;
AddRangeInternal(new Drawable[]
{
2020-02-03 15:13:21 +09:00
Content = new FillFlowContainer
2020-01-01 22:49:04 +03:00
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
2022-04-30 12:23:08 +03:00
Spacing = new Vector2(4, 0),
2022-04-29 12:19:22 +03:00
Child = icon = new ConstrainedIconContainer
2020-01-01 22:49:04 +03:00
{
Anchor = Anchor.Centre,
2022-04-29 12:19:22 +03:00
Origin = Anchor.Centre,
Size = new Vector2(20f),
Icon = value.CreateInstance().CreateIcon(),
},
2020-01-01 22:49:04 +03:00
},
new HoverClickSounds()
});
Enabled.Value = true;
}
protected override void LoadComplete()
2020-01-01 22:49:04 +03:00
{
base.LoadComplete();
Enabled.BindValueChanged(_ => updateState(), true);
2020-01-01 22:49:04 +03:00
}
2022-04-30 15:36:15 +03:00
public override bool PropagatePositionalInputSubTree => Enabled.Value && base.PropagatePositionalInputSubTree;
2020-02-04 12:53:57 +09:00
2020-01-01 22:49:04 +03:00
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
updateState();
2020-01-01 22:49:04 +03:00
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
updateState();
2020-01-01 22:49:04 +03:00
}
protected override void OnActivated() => updateState();
2020-01-01 22:49:04 +03:00
protected override void OnDeactivated() => updateState();
2020-01-01 22:49:04 +03:00
private void updateState()
2020-01-01 22:49:04 +03:00
{
2020-02-04 00:55:41 +03:00
AccentColour = Enabled.Value ? getActiveColour() : colourProvider.Foreground1;
2020-01-01 22:49:04 +03:00
}
2020-02-04 00:55:41 +03:00
private Color4 getActiveColour() => IsHovered || Active.Value ? Color4.White : colourProvider.Highlight1;
2020-01-01 22:49:04 +03:00
}
}