osu/osu.Game/Overlays/Mods/ModPanel.cs

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

82 lines
2.2 KiB
C#
Raw Normal View History

// 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.Game.Graphics;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osuTK;
namespace osu.Game.Overlays.Mods
{
2022-07-22 17:14:39 +00:00
public class ModPanel : ModSelectPanel
{
2022-05-11 16:29:14 +00:00
public Mod Mod => modState.Mod;
public override BindableBool Active => modState.Active;
2022-05-11 16:29:14 +00:00
public BindableBool Filtered => modState.Filtered;
protected override float IdleSwitchWidth => 54;
protected override float ExpandedSwitchWidth => 70;
private readonly ModState modState;
2022-05-11 16:37:31 +00:00
public ModPanel(ModState modState)
{
2022-05-11 16:37:31 +00:00
this.modState = modState;
Title = Mod.Name;
Description = Mod.Description;
SwitchContainer.Child = new ModSwitchSmall(Mod)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Active = { BindTarget = Active },
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Scale = new Vector2(HEIGHT / ModSwitchSmall.DEFAULT_SIZE)
};
}
2022-05-11 16:37:31 +00:00
public ModPanel(Mod mod)
: this(new ModState(mod))
{
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AccentColour = colours.ForModType(Mod.Type);
}
protected override void LoadComplete()
{
base.LoadComplete();
Filtered.BindValueChanged(_ => updateFilterState(), true);
}
2022-02-20 12:40:52 +00:00
protected override void Select()
{
modState.PendingConfiguration = Mod.RequiresConfiguration;
Active.Value = true;
}
protected override void Deselect()
{
modState.PendingConfiguration = false;
Active.Value = false;
}
2022-02-20 12:40:52 +00:00
#region Filtering support
private void updateFilterState()
{
this.FadeTo(Filtered.Value ? 0 : 1);
}
#endregion
}
}