2019-01-24 16:43:03 +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.
|
2018-09-06 02:30:03 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
2022-01-24 17:24:40 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-09-06 02:30:03 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-01-24 17:24:40 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2018-09-06 02:30:03 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-09-14 17:18:40 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-09-06 02:30:03 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-09-06 02:30:03 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Mods
|
|
|
|
|
{
|
2020-11-05 15:04:42 +08:00
|
|
|
|
internal class OsuModWiggle : ModWithVisibilityAdjustment
|
2018-09-06 02:30:03 +08:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "Wiggle";
|
2018-11-30 16:16:00 +08:00
|
|
|
|
public override string Acronym => "WG";
|
2020-01-14 21:22:00 +08:00
|
|
|
|
public override IconUsage? Icon => FontAwesome.Solid.Certificate;
|
2018-09-06 02:30:03 +08:00
|
|
|
|
public override ModType Type => ModType.Fun;
|
|
|
|
|
public override string Description => "They just won't stay still...";
|
|
|
|
|
public override double ScoreMultiplier => 1;
|
2018-09-15 20:55:29 +08:00
|
|
|
|
public override Type[] IncompatibleMods => new[] { typeof(OsuModTransform) };
|
2018-09-06 02:30:03 +08:00
|
|
|
|
|
2022-01-24 17:38:11 +08:00
|
|
|
|
[SettingSource("Strength")]
|
2022-01-24 17:24:40 +08:00
|
|
|
|
public BindableDouble WiggleStrength { get; } = new BindableDouble(10)
|
|
|
|
|
{
|
|
|
|
|
MinValue = 1f,
|
|
|
|
|
MaxValue = 15f,
|
|
|
|
|
Precision = .5f
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-24 17:38:11 +08:00
|
|
|
|
[SettingSource("Duration", "Milliseconds per wiggle")]
|
2022-01-24 17:24:40 +08:00
|
|
|
|
public BindableInt WiggleDuration { get; } = new BindableInt(90)
|
|
|
|
|
{
|
|
|
|
|
MinValue = 40,
|
|
|
|
|
MaxValue = 300,
|
|
|
|
|
Precision = 5
|
|
|
|
|
};
|
2018-09-14 16:38:47 +08:00
|
|
|
|
|
2020-11-05 15:04:42 +08:00
|
|
|
|
protected override void ApplyIncreasedVisibilityState(DrawableHitObject hitObject, ArmedState state) => drawableOnApplyCustomUpdateState(hitObject, state);
|
|
|
|
|
|
|
|
|
|
protected override void ApplyNormalVisibilityState(DrawableHitObject hitObject, ArmedState state) => drawableOnApplyCustomUpdateState(hitObject, state);
|
2018-09-06 02:30:03 +08:00
|
|
|
|
|
|
|
|
|
private void drawableOnApplyCustomUpdateState(DrawableHitObject drawable, ArmedState state)
|
|
|
|
|
{
|
2018-09-14 17:18:40 +08:00
|
|
|
|
var osuObject = (OsuHitObject)drawable.HitObject;
|
|
|
|
|
Vector2 origin = drawable.Position;
|
2018-09-14 16:38:47 +08:00
|
|
|
|
|
2021-04-21 09:32:08 +08:00
|
|
|
|
// Wiggle the repeat points and the tail with the slider instead of independently.
|
2018-09-16 06:16:37 +08:00
|
|
|
|
// Also fixes an issue with repeat points being positioned incorrectly.
|
2021-04-21 09:29:18 +08:00
|
|
|
|
if (osuObject is SliderRepeat || osuObject is SliderTailCircle)
|
2018-09-16 06:16:37 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2018-09-14 17:20:19 +08:00
|
|
|
|
Random objRand = new Random((int)osuObject.StartTime);
|
2018-09-06 02:30:03 +08:00
|
|
|
|
|
|
|
|
|
// Wiggle all objects during TimePreempt
|
2022-01-24 17:24:40 +08:00
|
|
|
|
int amountWiggles = (int)osuObject.TimePreempt / WiggleDuration.Value;
|
2018-09-06 02:30:03 +08:00
|
|
|
|
|
2018-09-14 17:18:40 +08:00
|
|
|
|
void wiggle()
|
2018-09-06 02:30:03 +08:00
|
|
|
|
{
|
2018-09-14 17:20:19 +08:00
|
|
|
|
float nextAngle = (float)(objRand.NextDouble() * 2 * Math.PI);
|
2022-01-24 17:24:40 +08:00
|
|
|
|
float nextDist = (float)(objRand.NextDouble() * WiggleStrength.Value);
|
|
|
|
|
drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), WiggleDuration.Value);
|
2018-09-06 02:30:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-14 17:18:40 +08:00
|
|
|
|
for (int i = 0; i < amountWiggles; i++)
|
2019-11-11 19:53:22 +08:00
|
|
|
|
{
|
2022-01-24 17:24:40 +08:00
|
|
|
|
using (drawable.BeginAbsoluteSequence(osuObject.StartTime - osuObject.TimePreempt + i * WiggleDuration.Value))
|
2018-09-14 17:18:40 +08:00
|
|
|
|
wiggle();
|
2019-11-11 19:53:22 +08:00
|
|
|
|
}
|
2018-09-14 17:18:40 +08:00
|
|
|
|
|
2018-09-06 02:30:03 +08:00
|
|
|
|
// Keep wiggling sliders and spinners for their duration
|
2020-05-27 11:38:39 +08:00
|
|
|
|
if (!(osuObject is IHasDuration endTime))
|
2018-09-06 02:30:03 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2022-01-24 17:24:40 +08:00
|
|
|
|
amountWiggles = (int)(endTime.Duration / WiggleDuration.Value);
|
2018-09-06 02:30:03 +08:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < amountWiggles; i++)
|
2019-11-11 19:53:22 +08:00
|
|
|
|
{
|
2022-01-24 17:24:40 +08:00
|
|
|
|
using (drawable.BeginAbsoluteSequence(osuObject.StartTime + i * WiggleDuration.Value))
|
2018-09-14 17:18:40 +08:00
|
|
|
|
wiggle();
|
2019-11-11 19:53:22 +08:00
|
|
|
|
}
|
2018-09-06 02:30:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|