1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 23:03:21 +08:00
osu-lazer/osu.Game/Overlays/Mods/ModPanel.cs

128 lines
3.5 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.
2023-05-02 19:15:33 +08:00
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
2023-05-02 19:15:33 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osuTK;
namespace osu.Game.Overlays.Mods
{
2023-05-02 19:15:33 +08:00
public partial class ModPanel : ModSelectPanel, IConditionalFilterable
{
2022-05-12 00:29:14 +08:00
public Mod Mod => modState.Mod;
public override BindableBool Active => modState.Active;
2022-05-12 00:29:14 +08:00
protected override float IdleSwitchWidth => 54;
protected override float ExpandedSwitchWidth => 70;
private readonly ModState modState;
2022-05-12 00:37:31 +08:00
public ModPanel(ModState modState)
{
2022-05-12 00:37:31 +08: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-12 00:37:31 +08: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();
2023-05-06 03:41:30 +08:00
modState.ValidForSelection.BindValueChanged(_ => updateFilterState());
modState.MatchingFilter.BindValueChanged(_ => updateFilterState(), true);
}
2022-02-20 20:40:52 +08:00
protected override void Select()
{
modState.PendingConfiguration = Mod.RequiresConfiguration;
Active.Value = true;
}
protected override void Deselect()
{
modState.PendingConfiguration = false;
Active.Value = false;
}
2023-05-06 03:41:30 +08:00
/// <summary>
/// Determine if <see cref="ModPanel"/> is valid and can be shown
/// </summary>
public bool IsValid => modState.IsValid;
public bool ValidForSelection
{
get => modState.ValidForSelection.Value;
set
{
if (modState.ValidForSelection.Value == value)
return;
modState.ValidForSelection.Value = value;
}
}
2022-02-20 20:40:52 +08:00
#region Filtering support
2023-05-02 19:15:33 +08:00
public override IEnumerable<LocalisableString> FilterTerms => new[]
2022-02-20 20:40:52 +08:00
{
2023-05-02 19:15:33 +08:00
Mod.Name,
Mod.Acronym,
Mod.Description
};
public override bool MatchingFilter
{
get => modState.MatchingFilter.Value;
set
{
if (modState.MatchingFilter.Value == value)
return;
modState.MatchingFilter.Value = value;
}
2022-02-20 20:40:52 +08:00
}
2023-05-06 03:41:30 +08:00
/// <summary>
/// This property is always <see langword="true"/> because it affects search result
/// </summary>
2023-05-02 19:15:33 +08:00
private readonly BindableBool canBeShown = new BindableBool(true);
2023-05-06 03:41:30 +08:00
2023-05-02 19:15:33 +08:00
IBindable<bool> IConditionalFilterable.CanBeShown => canBeShown;
2023-05-06 03:41:30 +08:00
private void updateFilterState()
{
this.FadeTo(IsValid ? 1 : 0);
}
2022-02-20 20:40:52 +08:00
#endregion
}
}