1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 02:07:34 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Mods/OsuModGhost.cs

70 lines
2.5 KiB
C#
Raw Normal View History

2021-10-15 06:30:55 +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 System;
2021-10-15 06:30:55 +08:00
using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.Mods;
using osu.Framework.Graphics;
2021-10-15 06:30:55 +08:00
using osu.Framework.Graphics.Sprites;
using osu.Framework.Bindables;
using osu.Framework.Localisation;
using osu.Game.Graphics.UserInterface;
using osu.Game.Configuration;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
namespace osu.Game.Rulesets.Osu.Mods
{
public class OsuModGhost : Mod, IUpdatableByPlayfield, IApplicableToScoreProcessor
{
2021-10-15 08:50:47 +08:00
public const float CURSOR_ALPHA_TRANSITION_DURATION = 100;
2021-10-15 06:30:55 +08:00
public override string Name => "Ghost";
2021-10-15 08:50:47 +08:00
public override string Acronym => "GS";
2021-10-15 06:30:55 +08:00
public override ModType Type => ModType.Fun;
public override IconUsage? Icon => FontAwesome.Solid.Ghost;
public override string Description => "Where's the cursor?";
public override double ScoreMultiplier => 1;
private readonly BindableFloat cursorAlpha = new BindableFloat();
2021-10-15 06:30:55 +08:00
private BindableNumber<int> currentCombo;
[SettingSource(
"Hidden at combo",
"The combo count at which the cursor becomes completely hidden",
SettingControlType = typeof(SettingsSlider<int, HiddenComboSlider>)
)]
public BindableInt HiddenComboCount { get; } = new BindableInt
{
Default = 10,
Value = 10,
MinValue = 0,
MaxValue = 50,
};
public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank;
2021-10-15 06:30:55 +08:00
public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
{
if (HiddenComboCount.Value != 0)
{
2021-10-15 08:50:47 +08:00
currentCombo = scoreProcessor.Combo.GetBoundCopy();
currentCombo.BindValueChanged(combo =>
{
float targetCursorAlpha = (float)Math.Max(1e-3, 1 - (float)combo.NewValue / HiddenComboCount.Value);
scoreProcessor.TransformBindableTo(cursorAlpha, targetCursorAlpha, CURSOR_ALPHA_TRANSITION_DURATION, Easing.OutQuint);
2021-10-15 08:50:47 +08:00
}, true);
}
2021-10-15 06:30:55 +08:00
}
public virtual void Update(Playfield playfield)
{
playfield.Cursor.Alpha = cursorAlpha.Value;
2021-10-15 06:30:55 +08:00
}
}
public class HiddenComboSlider : OsuSliderBar<int>
{
public override LocalisableString TooltipText => Current.Value == 0 ? "always hidden" : base.TooltipText;
}
}