Skip to content

Commit

Permalink
Merge pull request #484 from LumpBloom7/better-scroll-adjustment
Browse files Browse the repository at this point in the history
Refactor AnimationSpeed related stuff
  • Loading branch information
LumpBloom7 authored Sep 4, 2023
2 parents daa2f80 + ccffacd commit c8ba623
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 111 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using osu.Game.Configuration;
using osu.Framework.Configuration.Tracking;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Rulesets.Configuration;

namespace osu.Game.Rulesets.Sentakki.Configuration
Expand All @@ -25,6 +27,30 @@ protected override void InitialiseDefaults()
SetDefault(SentakkiRulesetSettings.DetailedJudgements, false);
SetDefault(SentakkiRulesetSettings.BreakSampleVolume, 1d, 0d, 1d, 0.01f);
}

public override TrackedSettings CreateTrackedSettings() => new TrackedSettings
{
new TrackedSetting<double>(SentakkiRulesetSettings.AnimationDuration, t => new SettingDescription(
rawValue: t,
name: "Note animation speed",
value: generateNoteSpeedDescription(t)
))
};

private string generateNoteSpeedDescription(double time)
{
string speedRating()
{
double speed = (2200 - time) / 200;

if (speed == 10.5)
return "Sonic";

return speed.ToString();
}

return $"{time:N0}ms ({speedRating()})";
}
}

public enum SentakkiRulesetSettings
Expand Down
17 changes: 17 additions & 0 deletions osu.Game.Rulesets.Sentakki/Extensions/BindableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using osu.Framework.Bindables;

namespace osu.Game.Rulesets.Sentakki.Extensions;

public static class BindableExtensions
{
/// <summary>
/// Attempts to bind <paramref name="bindable"/> to <paramref name="other"/>, but does nothing if <paramref name="other"/> is null.
/// </summary>
public static void TryBindTo<T>(this Bindable<T> bindable, Bindable<T>? other)
{
if (other is null)
return;

bindable.BindTo(other);
}
}
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableHold.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override void OnFree()
protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();
double animTime = AdjustedAnimationDuration / 2;
double animTime = AnimationDuration.Value / 2;
NoteBody.FadeInFromZero(animTime).ScaleTo(1, animTime);

NoteBody.FadeColour(AccentColour.Value);
Expand Down Expand Up @@ -129,7 +129,7 @@ protected override void CheckForResult(bool userTriggered, double timeOffset)
protected override void UpdateHitStateTransforms(ArmedState state)
{
base.UpdateHitStateTransforms(state);
const double time_fade_miss = 400;
double time_fade_miss = 400 * (DrawableSentakkiRuleset?.GameplaySpeed ?? 1);

switch (state)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Sentakki.Objects.Drawables
{
public partial class DrawableSentakkiHitObject : DrawableHitObject<SentakkiHitObject>
{
protected override double InitialLifetimeOffset => AdjustedAnimationDuration;
protected override double InitialLifetimeOffset => AnimationDuration.Value;

public readonly BindableBool AutoBindable = new BindableBool();

Expand All @@ -36,11 +36,7 @@ public DrawableSentakkiHitObject(SentakkiHitObject? hitObject = null)
}

[Resolved]
private DrawableSentakkiRuleset? drawableSentakkiRuleset { get; set; }

public double GameplaySpeed => drawableSentakkiRuleset?.GameplaySpeed ?? 1;

protected double AdjustedAnimationDuration => AnimationDuration.Value * GameplaySpeed;
protected DrawableSentakkiRuleset? DrawableSentakkiRuleset { get; private set; }

protected override void LoadAsyncComplete()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Sentakki.Configuration;
using osu.Game.Rulesets.Sentakki.UI;
using osuTK;
using osuTK.Graphics;

Expand All @@ -28,8 +29,11 @@ public partial class DrawableSentakkiJudgement : PoolableDrawable

private readonly BindableBool detailedJudgements = new BindableBool();

[Resolved]
private DrawableSentakkiRuleset drawableRuleset { get; set; } = null!;

[BackgroundDependencyLoader]
private void load(SentakkiRulesetConfigManager? sentakkiConfigs)
private void load(SentakkiRulesetConfigManager sentakkiConfigs)
{
sentakkiConfigs?.BindWith(SentakkiRulesetSettings.DetailedJudgements, detailedJudgements);

Expand Down Expand Up @@ -116,13 +120,14 @@ protected override void PrepareForUse()

private void applyHitAnimations()
{
judgementBody.ScaleTo(1, 50, Easing.OutElastic);
double speedFactor = drawableRuleset.GameplaySpeed;
judgementBody.ScaleTo(1, 50 * speedFactor, Easing.OutElastic);

judgementBody.Delay(50)
.ScaleTo(0.8f, 300)
.FadeOut(300);
judgementBody.Delay(50 * speedFactor)
.ScaleTo(0.8f, 300 * speedFactor)
.FadeOut(300 * speedFactor);

this.Delay(350).Expire();
this.Delay(350 * speedFactor).Expire();
}

private partial class SentakkiJudgementPiece : DefaultJudgementPiece
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ private void load(SentakkiRulesetConfigManager? sentakkiConfig)
breakSample = new PausableSkinnableSound(),
});

sentakkiConfig?.BindWith(SentakkiRulesetSettings.AnimationDuration, AnimationDuration);
if (DrawableSentakkiRuleset is not null)
AnimationDuration.BindTo(DrawableSentakkiRuleset?.AdjustedAnimDuration);

sentakkiConfig?.BindWith(SentakkiRulesetSettings.BreakSampleVolume, breakSample.Volume);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void onRevertResult(DrawableHitObject hitObject, JudgementResult result)
protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();
Slidepath.PerformEntryAnimation(AdjustedAnimationDuration);
Slidepath.PerformEntryAnimation(AnimationDuration.Value);

using (BeginAbsoluteSequence(HitObject.StartTime - 50))
{
Expand Down Expand Up @@ -212,19 +212,20 @@ protected override void CheckForResult(bool userTriggered, double timeOffset)
protected override void UpdateHitStateTransforms(ArmedState state)
{
base.UpdateHitStateTransforms(state);
const double time_fade_miss = 400 /* time_fade_miss = 400 */;
double time_fade_miss = 400 * (DrawableSentakkiRuleset?.GameplaySpeed ?? 1);
double time_fade_hit = 200 * (DrawableSentakkiRuleset?.GameplaySpeed ?? 1);

switch (state)
{
case ArmedState.Hit:
using (BeginAbsoluteSequence(Math.Max(Result.TimeAbsolute, HitObject.GetEndTime() - HitObject.HitWindows.WindowFor(HitResult.Good))))
{
Slidepath.PerformExitAnimation(200);
Slidepath.PerformExitAnimation(time_fade_hit);

foreach (var star in SlideStars)
star.FadeOut(200);
star.FadeOut(time_fade_hit);

this.FadeOut(200).Expire();
this.FadeOut(time_fade_hit).Expire();
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();

const double baseline_spin_duration = 250;

var note = (SlideTapPiece)TapVisual;

double spinDuration = 0;
double spinDuration = baseline_spin_duration * (DrawableSentakkiRuleset?.GameplaySpeed ?? 1);

if (ParentHitObject is DrawableSlide slide)
{
spinDuration = ((Slide)slide.HitObject).SlideInfoList.FirstOrDefault()?.Duration ?? 1000;
spinDuration += ((Slide)slide.HitObject).SlideInfoList.FirstOrDefault()?.Duration ?? 1000;
note.SecondStar.Alpha = slide.SlideBodies.Count > 1 ? 1 : 0;
}

Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void load()
protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();
double animTime = AdjustedAnimationDuration / 2;
double animTime = AnimationDuration.Value / 2;
TapVisual.FadeInFromZero(animTime).ScaleTo(1, animTime);

using (BeginDelayedSequence(animTime))
Expand Down Expand Up @@ -100,7 +100,7 @@ protected override void CheckForResult(bool userTriggered, double timeOffset)
protected override void UpdateHitStateTransforms(ArmedState state)
{
base.UpdateHitStateTransforms(state);
const double time_fade_miss = 400;
double time_fade_miss = 400 * (DrawableSentakkiRuleset?.GameplaySpeed ?? 1);

switch (state)
{
Expand Down
13 changes: 6 additions & 7 deletions osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public DrawableTouch(Touch? hitObject)
}

[BackgroundDependencyLoader]
private void load(SentakkiRulesetConfigManager? sentakkiConfigs)
private void load()
{
sentakkiConfigs?.BindWith(SentakkiRulesetSettings.TouchAnimationDuration, AnimationDuration);
if (DrawableSentakkiRuleset is not null)
AnimationDuration.BindTo(DrawableSentakkiRuleset?.AdjustedTouchAnimDuration);

Size = new Vector2(100);
Origin = Anchor.Centre;
Expand Down Expand Up @@ -79,7 +80,7 @@ protected override void OnFree()
protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();
double fadeIn = AdjustedAnimationDuration / 2;
double fadeIn = AnimationDuration.Value / 2;
double moveTo = HitObject.HitWindows.WindowFor(HitResult.Great);

TouchBody.FadeIn(fadeIn);
Expand Down Expand Up @@ -125,14 +126,12 @@ protected override void CheckForResult(bool userTriggered, double timeOffset)
protected override void UpdateHitStateTransforms(ArmedState state)
{
base.UpdateHitStateTransforms(state);
const double time_fade_hit = 100, time_fade_miss = 400;
double time_fade_miss = 400 * (DrawableSentakkiRuleset?.GameplaySpeed ?? 1);

switch (state)
{
case ArmedState.Hit:
TouchBody.FadeOut();
this.Delay(time_fade_hit).Expire();

Expire();
break;

case ArmedState.Miss:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected override void OnFree()
protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();
double fadeIn = AdjustedAnimationDuration;
double fadeIn = AnimationDuration.Value;
this.FadeInFromZero(fadeIn).ScaleTo(1, fadeIn);

using (BeginDelayedSequence(fadeIn))
Expand Down Expand Up @@ -163,12 +163,12 @@ protected override void CheckForResult(bool userTriggered, double timeOffset)
protected override void UpdateHitStateTransforms(ArmedState state)
{
base.UpdateHitStateTransforms(state);
const double time_fade_hit = 100, time_fade_miss = 400;
double time_fade_miss = 400 * (DrawableSentakkiRuleset?.GameplaySpeed ?? 1);

switch (state)
{
case ArmedState.Hit:
this.Delay(time_fade_hit).Expire();
Expire();
break;

case ArmedState.Miss:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,5 @@ public TouchHoldBody()
centrePiece = new TouchHoldCentrePiece(),
};
}

private readonly IBindable<Color4> accentColour = new Bindable<Color4>();

[BackgroundDependencyLoader]
private void load(DrawableHitObject drawableObject)
{
drawableObject.ApplyCustomUpdateState += updateState;
}

private void updateState(DrawableHitObject drawableObject, ArmedState state)
{
using (BeginAbsoluteSequence(drawableObject.HitStateUpdateTime))
{
switch (state)
{
case ArmedState.Hit:
ProgressPiece.FadeOut();
centrePiece.FadeOut();
break;
}
}
}
}
}
14 changes: 10 additions & 4 deletions osu.Game.Rulesets.Sentakki/UI/Components/HitExplosion.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand All @@ -18,7 +19,10 @@ public partial class HitExplosion : PoolableDrawable
private readonly CircularContainer circle;

private const float default_explosion_size = 75;
private const float touch_hold_explosion_size = 110;
private const float touch_hold_explosion_size = 100;

[Resolved]
private DrawableSentakkiRuleset? drawableRuleset { get; set; }

public HitExplosion()
{
Expand Down Expand Up @@ -97,13 +101,15 @@ public TransformSequence<HitExplosion> Explode()
{
const double explode_duration = 100;

double adjustedExplodeDuration = explode_duration * (drawableRuleset?.GameplaySpeed ?? 1);

var sequence = this.FadeIn()
.TransformBindableTo(borderRatio, 1)
.ScaleTo(1)
.Then()
.TransformBindableTo(borderRatio, 0f, explode_duration)
.ScaleTo(2f, explode_duration)
.FadeOut(explode_duration);
.TransformBindableTo(borderRatio, 0f, adjustedExplodeDuration)
.ScaleTo(2f, adjustedExplodeDuration)
.FadeOut(adjustedExplodeDuration);

return sequence;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Rulesets.Sentakki.Configuration;
using osu.Game.Rulesets.Sentakki.Extensions;
using osuTK;

namespace osu.Game.Rulesets.Sentakki.UI.Components.HitObjectLine
Expand All @@ -27,9 +27,9 @@ public DrawableLine()
private readonly BindableDouble animationDuration = new BindableDouble(1000);

[BackgroundDependencyLoader]
private void load(SentakkiRulesetConfigManager? sentakkiConfigs)
private void load(DrawableSentakkiRuleset? drawableRuleset)
{
sentakkiConfigs?.BindWith(SentakkiRulesetSettings.AnimationDuration, animationDuration);
animationDuration.TryBindTo(drawableRuleset?.AdjustedAnimDuration);
animationDuration.BindValueChanged(_ => resetAnimation());

AddInternal(line = new CircularProgress
Expand Down Expand Up @@ -60,8 +60,8 @@ private void resetAnimation()

ApplyTransformsAt(double.MinValue);
ClearTransforms();
using (BeginAbsoluteSequence(Entry.StartTime - Entry.AdjustedAnimationDuration))
this.FadeIn(Entry.AdjustedAnimationDuration / 2).Then().ScaleTo(1, Entry.AdjustedAnimationDuration / 2).Then().FadeOut();
using (BeginAbsoluteSequence(Entry.StartTime - animationDuration.Value))
this.FadeIn(animationDuration.Value / 2).Then().ScaleTo(1, animationDuration.Value / 2).Then().FadeOut();
}
}
}
Loading

0 comments on commit c8ba623

Please sign in to comment.