2022-02-24 06:11: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.
|
|
|
|
|
2023-05-02 19:15:33 +08:00
|
|
|
using System.Collections.Generic;
|
2022-02-24 06:11:12 +08:00
|
|
|
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;
|
2022-02-24 06:11:12 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
2023-06-02 15:51:33 +08:00
|
|
|
public partial class ModPanel : ModSelectPanel, IFilterable
|
2022-02-24 06:11:12 +08:00
|
|
|
{
|
2022-05-12 00:29:14 +08:00
|
|
|
public Mod Mod => modState.Mod;
|
2022-07-22 03:56:23 +08:00
|
|
|
public override BindableBool Active => modState.Active;
|
2022-05-12 00:29:14 +08:00
|
|
|
|
2022-07-22 03:56:23 +08:00
|
|
|
protected override float IdleSwitchWidth => 54;
|
|
|
|
protected override float ExpandedSwitchWidth => 70;
|
2022-02-24 06:11:12 +08:00
|
|
|
|
2022-07-22 03:56:23 +08:00
|
|
|
private readonly ModState modState;
|
2022-02-24 06:11:12 +08:00
|
|
|
|
2022-05-12 00:37:31 +08:00
|
|
|
public ModPanel(ModState modState)
|
2022-02-24 06:11:12 +08:00
|
|
|
{
|
2022-05-12 00:37:31 +08:00
|
|
|
this.modState = modState;
|
2022-02-24 06:11:12 +08:00
|
|
|
|
2022-07-22 03:56:23 +08:00
|
|
|
Title = Mod.Name;
|
|
|
|
Description = Mod.Description;
|
2022-02-24 06:11:12 +08:00
|
|
|
|
2022-07-22 03:56:23 +08:00
|
|
|
SwitchContainer.Child = new ModSwitchSmall(Mod)
|
2022-02-24 06:11:12 +08:00
|
|
|
{
|
2022-07-22 03:56:23 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Active = { BindTarget = Active },
|
2024-05-16 12:27:54 +08:00
|
|
|
Shear = new Vector2(-OsuGame.SHEAR, 0),
|
2022-07-22 03:56:23 +08:00
|
|
|
Scale = new Vector2(HEIGHT / ModSwitchSmall.DEFAULT_SIZE)
|
2022-02-24 06:11:12 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-12 00:37:31 +08:00
|
|
|
public ModPanel(Mod mod)
|
|
|
|
: this(new ModState(mod))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-07-22 03:56:23 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
2022-02-24 06:11:12 +08:00
|
|
|
{
|
2022-07-22 03:56:23 +08:00
|
|
|
AccentColour = colours.ForModType(Mod.Type);
|
2022-02-24 06:11:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2022-05-07 22:35:34 +08:00
|
|
|
|
2023-05-06 03:41:30 +08:00
|
|
|
modState.ValidForSelection.BindValueChanged(_ => updateFilterState());
|
2023-06-18 19:49:29 +08:00
|
|
|
modState.MatchingTextFilter.BindValueChanged(_ => updateFilterState(), true);
|
2022-02-24 06:11:12 +08:00
|
|
|
}
|
2022-02-20 20:40:52 +08:00
|
|
|
|
2022-08-17 04:41:32 +08:00
|
|
|
protected override void Select()
|
2022-08-16 01:40:05 +08:00
|
|
|
{
|
2022-08-17 04:42:30 +08:00
|
|
|
modState.PendingConfiguration = Mod.RequiresConfiguration;
|
2022-08-17 04:41:32 +08:00
|
|
|
Active.Value = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Deselect()
|
|
|
|
{
|
2022-08-17 04:42:30 +08:00
|
|
|
modState.PendingConfiguration = false;
|
2022-08-17 04:41:32 +08:00
|
|
|
Active.Value = false;
|
2022-08-16 01:40:05 +08:00
|
|
|
}
|
|
|
|
|
2022-02-20 20:40:52 +08:00
|
|
|
#region Filtering support
|
|
|
|
|
2023-06-18 19:59:02 +08:00
|
|
|
/// <seealso cref="ModState.Visible"/>
|
|
|
|
public bool Visible => modState.Visible;
|
|
|
|
|
2024-02-22 17:56:50 +08:00
|
|
|
public override IEnumerable<LocalisableString> FilterTerms => new LocalisableString[]
|
2022-02-20 20:40:52 +08:00
|
|
|
{
|
2023-05-02 19:15:33 +08:00
|
|
|
Mod.Name,
|
2024-02-16 18:17:41 +08:00
|
|
|
Mod.Name.Replace(" ", string.Empty),
|
2023-05-02 19:15:33 +08:00
|
|
|
Mod.Acronym,
|
|
|
|
};
|
|
|
|
|
|
|
|
public override bool MatchingFilter
|
|
|
|
{
|
2023-06-18 19:49:29 +08:00
|
|
|
get => modState.MatchingTextFilter.Value;
|
2023-06-18 19:51:13 +08:00
|
|
|
set => modState.MatchingTextFilter.Value = value;
|
2022-02-20 20:40:52 +08:00
|
|
|
}
|
|
|
|
|
2023-05-06 03:41:30 +08:00
|
|
|
private void updateFilterState()
|
|
|
|
{
|
2023-06-02 16:33:38 +08:00
|
|
|
this.FadeTo(Visible ? 1 : 0);
|
2023-05-06 03:41:30 +08:00
|
|
|
}
|
|
|
|
|
2022-02-20 20:40:52 +08:00
|
|
|
#endregion
|
2022-02-24 06:11:12 +08:00
|
|
|
}
|
|
|
|
}
|