1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 20:22:55 +08:00
osu-lazer/osu.Game/Overlays/Toolbar/ToolbarRulesetTabButton.cs
2024-05-22 16:29:39 +08:00

84 lines
2.5 KiB
C#

// 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.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Rulesets;
namespace osu.Game.Overlays.Toolbar
{
public partial class ToolbarRulesetTabButton : TabItem<RulesetInfo>
{
private readonly RulesetButton ruleset;
private Sample? selectSample;
public ToolbarRulesetTabButton(RulesetInfo value)
: base(value)
{
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
Child = ruleset = new RulesetButton
{
Active = false,
};
var rInstance = value.CreateInstance();
ruleset.TooltipMain = rInstance.Description;
ruleset.TooltipSub = ToolbarStrings.PlaySomeRuleset(rInstance.Description);
ruleset.SetIcon(rInstance.CreateIcon());
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
selectSample = audio.Samples.Get($@"UI/ruleset-select-{Value.ShortName}");
}
protected override void OnActivated() => ruleset.Active = true;
protected override void OnDeactivated() => ruleset.Active = false;
protected override void OnActivatedByUser() => selectSample?.Play();
private partial class RulesetButton : ToolbarButton
{
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverSounds();
[Resolved]
private OsuColour colours { get; set; } = null!;
public RulesetButton()
{
ButtonContent.Padding = new MarginPadding(PADDING)
{
Bottom = 5
};
}
public bool Active
{
set => Scheduler.AddOnce(() =>
{
IconContainer.Colour = value ? Color4Extensions.FromHex("#00FFAA") : colours.GrayF;
});
}
protected override bool OnClick(ClickEvent e)
{
Parent!.TriggerClick();
return base.OnClick(e);
}
}
}
}