mirror of
https://github.com/ppy/osu.git
synced 2025-03-23 02:57:25 +08:00
move ModAlternate
to OsuModAlternate
and check if intro has ended
This commit is contained in:
parent
2326c36836
commit
98d8b26a9c
@ -1,31 +1,63 @@
|
||||
// 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;
|
||||
using System.Linq;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.Play;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Mods
|
||||
{
|
||||
public class OsuModAlternate : ModAlternate<OsuHitObject, OsuAction>
|
||||
public class OsuModAlternate : Mod, IApplicableToDrawableRuleset<OsuHitObject>, IApplicableToPlayer, IUpdatableByPlayfield
|
||||
{
|
||||
public override string Name => @"Alternate";
|
||||
public override string Acronym => @"AL";
|
||||
public override string Description => @"Don't use the same key twice in a row!";
|
||||
public override double ScoreMultiplier => 1.0;
|
||||
public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay) };
|
||||
public override ModType Type => ModType.DifficultyIncrease;
|
||||
public override IconUsage? Icon => FontAwesome.Solid.Keyboard;
|
||||
|
||||
/// <summary>
|
||||
/// Whether incoming input must be checked by <see cref="InputInterceptor"/>.
|
||||
/// </summary>
|
||||
public bool CanIntercept => !isBreakTime.Value && introEnded;
|
||||
|
||||
private bool introEnded;
|
||||
private double earliestStartTime;
|
||||
private IBindable<bool> isBreakTime;
|
||||
private const double flash_duration = 1000;
|
||||
private OsuAction? lastActionPressed;
|
||||
private DrawableRuleset<OsuHitObject> ruleset;
|
||||
|
||||
public override void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
|
||||
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
|
||||
{
|
||||
ruleset = drawableRuleset;
|
||||
base.ApplyToDrawableRuleset(drawableRuleset);
|
||||
drawableRuleset.KeyBindingInputManager.Add(new InputInterceptor(this));
|
||||
|
||||
var firstHitObject = ruleset.Objects.FirstOrDefault();
|
||||
earliestStartTime = (firstHitObject?.StartTime ?? 0) - (firstHitObject?.HitWindows.WindowFor(HitResult.Meh) ?? 0);
|
||||
}
|
||||
|
||||
protected override void Reset()
|
||||
public void ApplyToPlayer(Player player)
|
||||
{
|
||||
lastActionPressed = null;
|
||||
isBreakTime = player.IsBreakTime.GetBoundCopy();
|
||||
isBreakTime.ValueChanged += e =>
|
||||
{
|
||||
if (e.NewValue)
|
||||
lastActionPressed = null;
|
||||
};
|
||||
}
|
||||
|
||||
protected override bool OnPressed(OsuAction key)
|
||||
private bool onPressed(OsuAction key)
|
||||
{
|
||||
if (lastActionPressed == key)
|
||||
{
|
||||
@ -37,5 +69,28 @@ namespace osu.Game.Rulesets.Osu.Mods
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Update(Playfield playfield)
|
||||
{
|
||||
if (!introEnded)
|
||||
introEnded = playfield.Clock.CurrentTime > earliestStartTime;
|
||||
}
|
||||
|
||||
private class InputInterceptor : Component, IKeyBindingHandler<OsuAction>
|
||||
{
|
||||
private readonly OsuModAlternate mod;
|
||||
|
||||
public InputInterceptor(OsuModAlternate mod)
|
||||
{
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
|
||||
=> mod.CanIntercept && mod.onPressed(e.Action);
|
||||
|
||||
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,76 +0,0 @@
|
||||
// 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;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.Play;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
public abstract class ModAlternate : Mod
|
||||
{
|
||||
public override string Name => @"Alternate";
|
||||
public override string Acronym => @"AL";
|
||||
public override string Description => @"Don't use the same key twice in a row!";
|
||||
public override double ScoreMultiplier => 1.0;
|
||||
public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay) };
|
||||
public override ModType Type => ModType.DifficultyIncrease;
|
||||
public override IconUsage? Icon => FontAwesome.Solid.Keyboard;
|
||||
}
|
||||
|
||||
public abstract class ModAlternate<THitObject, TAction> : ModAlternate, IApplicableToDrawableRuleset<THitObject>, IApplicableToPlayer
|
||||
where THitObject : HitObject
|
||||
where TAction : struct
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether incoming input must be checked by <see cref="InputInterceptor"/>.
|
||||
/// </summary>
|
||||
public bool CanIntercept => !isBreakTime.Value;
|
||||
|
||||
private IBindable<bool> isBreakTime;
|
||||
|
||||
public virtual void ApplyToDrawableRuleset(DrawableRuleset<THitObject> drawableRuleset)
|
||||
{
|
||||
drawableRuleset.KeyBindingInputManager.Add(new InputInterceptor(this));
|
||||
}
|
||||
|
||||
public void ApplyToPlayer(Player player)
|
||||
{
|
||||
isBreakTime = player.IsBreakTime.GetBoundCopy();
|
||||
isBreakTime.ValueChanged += e =>
|
||||
{
|
||||
if (e.NewValue)
|
||||
Reset();
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract void Reset();
|
||||
|
||||
protected abstract bool OnPressed(TAction key);
|
||||
|
||||
private class InputInterceptor : Component, IKeyBindingHandler<TAction>
|
||||
{
|
||||
private readonly ModAlternate<THitObject, TAction> mod;
|
||||
|
||||
public InputInterceptor(ModAlternate<THitObject, TAction> mod)
|
||||
{
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
public bool OnPressed(KeyBindingPressEvent<TAction> e)
|
||||
{
|
||||
return mod.CanIntercept && mod.OnPressed(e.Action);
|
||||
}
|
||||
|
||||
public void OnReleased(KeyBindingReleaseEvent<TAction> e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user