osu/osu.Game.Rulesets.Osu/Mods/OsuModRelax.cs

94 lines
3.1 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.
2018-04-13 09:19:50 +00:00
using System;
2018-08-03 12:03:11 +00:00
using System.Collections.Generic;
using System.Diagnostics;
2018-04-13 09:19:50 +00:00
using System.Linq;
using osu.Game.Rulesets.Mods;
2018-08-03 12:03:11 +00:00
using osu.Game.Rulesets.Objects.Types;
2018-08-16 09:18:15 +00:00
using osu.Game.Rulesets.Osu.Objects;
2018-08-03 12:03:11 +00:00
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.UI;
using static osu.Game.Input.Handlers.ReplayInputHandler;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Rulesets.Osu.Mods
{
public class OsuModRelax : ModRelax, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
2018-04-13 09:19:50 +00:00
{
public override string Description => @"You don't need to click. Give your clicking/tapping fingers a break from the heat of things.";
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModAutopilot)).ToArray();
2018-08-03 12:03:11 +00:00
public void Update(Playfield playfield)
2018-08-03 12:03:11 +00:00
{
2018-08-16 09:18:15 +00:00
bool requiresHold = false;
bool requiresHit = false;
2018-08-03 12:03:11 +00:00
const float relax_leniency = 3;
foreach (var drawable in playfield.HitObjectContainer.AliveObjects)
{
if (!(drawable is DrawableOsuHitObject osuHit))
continue;
2018-08-03 12:03:11 +00:00
double time = osuHit.Clock.CurrentTime;
2018-08-05 07:58:15 +00:00
double relativetime = time - osuHit.HitObject.StartTime;
2018-08-03 12:03:11 +00:00
2018-08-16 09:18:15 +00:00
if (time < osuHit.HitObject.StartTime - relax_leniency) continue;
2018-08-03 12:03:11 +00:00
if ((osuHit.HitObject is IHasEndTime hasEnd && time > hasEnd.EndTime) || osuHit.IsHit)
2018-08-16 09:18:15 +00:00
continue;
2018-08-03 12:03:11 +00:00
if (osuHit is DrawableHitCircle && osuHit.IsHovered)
{
Debug.Assert(osuHit.HitObject.HitWindows != null);
requiresHit |= osuHit.HitObject.HitWindows.CanBeHit(relativetime);
}
requiresHold |= (osuHit is DrawableSlider slider && (slider.Ball.IsHovered || osuHit.IsHovered)) || osuHit is DrawableSpinner;
2018-08-03 12:03:11 +00:00
}
2018-08-16 09:18:15 +00:00
if (requiresHit)
2018-08-03 12:03:11 +00:00
{
2018-08-16 09:18:15 +00:00
addAction(false);
addAction(true);
2018-08-03 12:03:11 +00:00
}
2018-08-16 09:18:15 +00:00
addAction(requiresHold);
2018-08-03 12:03:11 +00:00
}
private bool wasHit;
private bool wasLeft;
2018-08-16 09:18:15 +00:00
private OsuInputManager osuInputManager;
private void addAction(bool hitting)
2018-08-03 12:03:11 +00:00
{
if (wasHit == hitting)
return;
2018-08-16 09:18:15 +00:00
2018-08-03 12:03:11 +00:00
wasHit = hitting;
2018-08-03 22:18:09 +00:00
var state = new ReplayState<OsuAction>
2018-08-03 12:03:11 +00:00
{
PressedActions = new List<OsuAction>()
};
2018-08-16 09:18:15 +00:00
2018-08-03 12:03:11 +00:00
if (hitting)
{
2018-08-03 22:18:09 +00:00
state.PressedActions.Add(wasLeft ? OsuAction.LeftButton : OsuAction.RightButton);
2018-08-03 12:03:11 +00:00
wasLeft = !wasLeft;
}
2018-08-16 09:18:15 +00:00
state.Apply(osuInputManager.CurrentState, osuInputManager);
2018-08-16 09:18:15 +00:00
}
2019-03-20 02:22:34 +00:00
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
2018-08-16 09:18:15 +00:00
{
// grab the input manager for future use.
2019-03-20 02:22:34 +00:00
osuInputManager = (OsuInputManager)drawableRuleset.KeyBindingInputManager;
2018-08-17 10:33:14 +00:00
osuInputManager.AllowUserPresses = false;
2018-08-03 12:03:11 +00:00
}
2018-04-13 09:19:50 +00:00
}
}