1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 19:47:51 +08:00
osu-lazer/osu.Game/Rulesets/UI/ModSwitchSmall.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
3.7 KiB
C#
Raw Normal View History

2022-02-22 07:03:12 +08: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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
2022-02-22 07:03:12 +08:00
using osu.Framework.Utils;
using osu.Game.Graphics;
using osu.Game.Overlays;
using osu.Game.Rulesets.Mods;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.UI
{
public partial class ModSwitchSmall : CompositeDrawable
{
public BindableBool Active { get; } = new BindableBool();
public const float DEFAULT_SIZE = 60;
2022-02-22 07:03:12 +08:00
private readonly IMod mod;
2022-02-22 07:03:12 +08:00
private Drawable background = null!;
private SpriteIcon? modIcon;
2022-02-22 07:03:12 +08:00
private Color4 activeForegroundColour;
private Color4 inactiveForegroundColour;
private Color4 activeBackgroundColour;
private Color4 inactiveBackgroundColour;
public ModSwitchSmall(IMod mod)
{
this.mod = mod;
Size = new Vector2(DEFAULT_SIZE);
}
2022-02-22 07:03:12 +08:00
[BackgroundDependencyLoader]
private void load(TextureStore textures, OsuColour colours, OverlayColourProvider? colourProvider)
{
2022-02-22 07:03:12 +08:00
FillFlowContainer contentFlow;
ModSwitchTiny tinySwitch;
InternalChildren = new[]
2022-02-22 07:03:12 +08:00
{
background = new Sprite
2022-02-22 07:03:12 +08:00
{
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit,
Texture = textures.Get("Icons/BeatmapDetails/mod-icon"),
2022-02-22 07:03:12 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
contentFlow = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Spacing = new Vector2(0, 4),
Direction = FillDirection.Vertical,
Child = tinySwitch = new ModSwitchTiny(mod)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Scale = new Vector2(0.6f),
Active = { BindTarget = Active }
}
}
};
if (mod.Icon != null)
{
contentFlow.Insert(-1, modIcon = new SpriteIcon
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Size = new Vector2(21),
Icon = mod.Icon.Value
});
tinySwitch.Scale = new Vector2(0.3f);
}
2023-11-06 18:24:56 +08:00
var modTypeColour = colours.ForModType(mod.Type);
2022-02-22 07:03:12 +08:00
inactiveForegroundColour = colourProvider?.Background5 ?? colours.Gray3;
2023-11-06 23:40:57 +08:00
activeForegroundColour = modTypeColour;
2022-02-22 07:03:12 +08:00
inactiveBackgroundColour = colourProvider?.Background2 ?? colours.Gray5;
2023-11-06 23:40:57 +08:00
activeBackgroundColour = Interpolation.ValueAt<Colour4>(0.1f, Colour4.Black, modTypeColour, 0, 1);
2022-02-22 07:03:12 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
Active.BindValueChanged(_ => updateState(), true);
FinishTransforms(true);
}
private void updateState()
{
modIcon?.FadeColour(Active.Value ? activeForegroundColour : inactiveForegroundColour, 200, Easing.OutQuint);
background.FadeColour(Active.Value ? activeBackgroundColour : inactiveBackgroundColour, 200, Easing.OutQuint);
}
}
}