mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:17:23 +08:00
Add relax mod
This commit is contained in:
parent
920d988a9e
commit
7310c38df9
@ -2,14 +2,81 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using static osu.Game.Input.Handlers.ReplayInputHandler;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Mods
|
||||
{
|
||||
public class OsuModRelax : ModRelax
|
||||
public class OsuModRelax : ModRelax, IApplicableFailOverride, IUpdatableByHitObject, IUpdatableByPlayfield
|
||||
{
|
||||
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();
|
||||
|
||||
public bool AllowFail => false;
|
||||
|
||||
private bool hitStill;
|
||||
private bool hitOnce;
|
||||
|
||||
public void Update(DrawableHitObject o)
|
||||
{
|
||||
const float relax_leniency = 3;
|
||||
|
||||
if (!(o is DrawableOsuHitObject d))
|
||||
return;
|
||||
|
||||
double t = d.Clock.CurrentTime;
|
||||
|
||||
if (t >= d.HitObject.StartTime - relax_leniency)
|
||||
{
|
||||
if (d.HitObject is IHasEndTime e && t > e.EndTime || d.IsHit)
|
||||
return;
|
||||
|
||||
hitStill |= d is DrawableSlider s && (s.Ball.IsHovered || d.IsHovered) || d is DrawableSpinner;
|
||||
|
||||
hitOnce |= d is DrawableHitCircle && d.IsHovered;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(Playfield r)
|
||||
{
|
||||
var d = r.HitObjects.Objects.First(h => h is DrawableOsuHitObject) as DrawableOsuHitObject;
|
||||
if (hitOnce)
|
||||
{
|
||||
hit(d, false);
|
||||
hit(d, true);
|
||||
}
|
||||
hit(d, hitStill);
|
||||
|
||||
hitOnce = false;
|
||||
hitStill = false;
|
||||
}
|
||||
|
||||
private bool wasHit;
|
||||
private bool wasLeft;
|
||||
|
||||
private void hit(DrawableOsuHitObject d, bool hitting)
|
||||
{
|
||||
if (wasHit == hitting)
|
||||
return;
|
||||
wasHit = hitting;
|
||||
|
||||
var l = new ReplayState<OsuAction>
|
||||
{
|
||||
PressedActions = new List<OsuAction>()
|
||||
};
|
||||
if (hitting)
|
||||
{
|
||||
l.PressedActions.Add(wasLeft ? OsuAction.LeftButton : OsuAction.RightButton);
|
||||
wasLeft = !wasLeft;
|
||||
}
|
||||
d.OsuActionInputManager.HandleCustomInput(new InputState(), l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
12
osu.Game/Rulesets/Mods/IUpdatableByHitObject.cs
Normal file
12
osu.Game/Rulesets/Mods/IUpdatableByHitObject.cs
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
public interface IUpdatableByHitObject : IApplicableMod
|
||||
{
|
||||
void Update(DrawableHitObject o);
|
||||
}
|
||||
}
|
12
osu.Game/Rulesets/Mods/IUpdatableByPlayfield.cs
Normal file
12
osu.Game/Rulesets/Mods/IUpdatableByPlayfield.cs
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
public interface IUpdatableByPlayfield : IApplicableMod
|
||||
{
|
||||
void Update(Playfield r);
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@ using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Skinning;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
|
||||
namespace osu.Game.Rulesets.Objects.Drawables
|
||||
{
|
||||
@ -41,6 +43,8 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
public IReadOnlyList<Judgement> Judgements => judgements;
|
||||
private readonly List<Judgement> judgements = new List<Judgement>();
|
||||
|
||||
private WorkingBeatmap beatmap;
|
||||
|
||||
/// <summary>
|
||||
/// Whether a visible judgement should be displayed when this representation is hit.
|
||||
/// </summary>
|
||||
@ -80,8 +84,9 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private void load(IBindableBeatmap b)
|
||||
{
|
||||
beatmap = b.Value;
|
||||
var samples = GetSamples().ToArray();
|
||||
|
||||
if (samples.Any())
|
||||
@ -132,6 +137,11 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if(beatmap != null)
|
||||
foreach (var m in beatmap.Mods.Value)
|
||||
if (m is IUpdatableByHitObject u)
|
||||
u.Update(this);
|
||||
|
||||
var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime;
|
||||
|
||||
while (judgements.Count > 0)
|
||||
|
@ -6,6 +6,8 @@ using osu.Framework.Graphics;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
|
||||
namespace osu.Game.Rulesets.UI
|
||||
{
|
||||
@ -42,9 +44,12 @@ namespace osu.Game.Rulesets.UI
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
private WorkingBeatmap beatmap;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private void load(IBindableBeatmap b)
|
||||
{
|
||||
beatmap = b.Value;
|
||||
HitObjects = CreateHitObjectContainer();
|
||||
HitObjects.RelativeSizeAxes = Axes.Both;
|
||||
|
||||
@ -87,5 +92,15 @@ namespace osu.Game.Rulesets.UI
|
||||
/// Creates the container that will be used to contain the <see cref="DrawableHitObject"/>s.
|
||||
/// </summary>
|
||||
protected virtual HitObjectContainer CreateHitObjectContainer() => new HitObjectContainer();
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (beatmap != null)
|
||||
foreach (var m in beatmap.Mods.Value)
|
||||
if (m is IUpdatableByPlayfield u)
|
||||
u.Update(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user