Skip to content

Commit

Permalink
Merge pull request ppy#30300 from Darius-Wattimena/resizable-catcher
Browse files Browse the repository at this point in the history
Fix catcher size and hyperdashes indication on adjusting CircleSize
  • Loading branch information
bdach authored Nov 1, 2024
2 parents 9df9a97 + 37c2ab9 commit 0811de7
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 10 deletions.
1 change: 0 additions & 1 deletion osu.Game.Rulesets.Catch/Edit/CatchEditorPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace osu.Game.Rulesets.Catch.Edit
{
public partial class CatchEditorPlayfield : CatchPlayfield
{
// TODO fixme: the size of the catcher is not changed when circle size is changed in setup screen.
public CatchEditorPlayfield(IBeatmapDifficultyInfo difficulty)
: base(difficulty)
{
Expand Down
30 changes: 30 additions & 0 deletions osu.Game.Rulesets.Catch/Edit/DrawableCatchEditorRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Edit;

namespace osu.Game.Rulesets.Catch.Edit
{
public partial class DrawableCatchEditorRuleset : DrawableCatchRuleset
{
[Resolved]
private EditorBeatmap editorBeatmap { get; set; } = null!;

public readonly BindableDouble TimeRangeMultiplier = new BindableDouble(1);

public DrawableCatchEditorRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod>? mods = null)
Expand All @@ -28,6 +34,30 @@ protected override void Update()
TimeRange.Value = gamePlayTimeRange * TimeRangeMultiplier.Value * playfieldStretch;
}

protected override void LoadComplete()
{
base.LoadComplete();

editorBeatmap.BeatmapReprocessed += onBeatmapReprocessed;
}

protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);

if (editorBeatmap.IsNotNull())
editorBeatmap.BeatmapReprocessed -= onBeatmapReprocessed;
}

private void onBeatmapReprocessed()
{
if (Playfield is CatchEditorPlayfield catchPlayfield)
{
catchPlayfield.Catcher.ApplyDifficulty(editorBeatmap.Difficulty);
catchPlayfield.CatcherArea.CatcherTrails.UpdateCatcherTrailsScale(catchPlayfield.Catcher.BodyScale);
}
}

protected override Playfield CreatePlayfield() => new CatchEditorPlayfield(Beatmap.Difficulty);

public override PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => new CatchEditorPlayfieldAdjustmentContainer();
Expand Down
18 changes: 13 additions & 5 deletions osu.Game.Rulesets.Catch/UI/Catcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public CatcherAnimationState CurrentState
/// <summary>
/// Width of the area that can be used to attempt catches during gameplay.
/// </summary>
public readonly float CatchWidth;
public float CatchWidth { get; private set; }

private readonly SkinnableCatcher body;

Expand All @@ -142,10 +142,7 @@ public Catcher(DroppedObjectContainer droppedObjectTarget, IBeatmapDifficultyInf

Size = new Vector2(BASE_SIZE);

if (difficulty != null)
Scale = calculateScale(difficulty);

CatchWidth = CalculateCatchWidth(Scale);
ApplyDifficulty(difficulty);

InternalChildren = new Drawable[]
{
Expand Down Expand Up @@ -312,6 +309,17 @@ public void SetHyperDashState(double modifier = 1, float targetPosition = -1)
}
}

/// <summary>
/// Set the scale and catch width.
/// </summary>
public void ApplyDifficulty(IBeatmapDifficultyInfo? difficulty)
{
if (difficulty != null)
Scale = calculateScale(difficulty);

CatchWidth = CalculateCatchWidth(Scale);
}

/// <summary>
/// Drop any fruit off the plate.
/// </summary>
Expand Down
8 changes: 4 additions & 4 deletions osu.Game.Rulesets.Catch/UI/CatcherArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Catcher Catcher

private readonly CatchComboDisplay comboDisplay;

private readonly CatcherTrailDisplay catcherTrails;
public readonly CatcherTrailDisplay CatcherTrails;

private Catcher catcher = null!;

Expand All @@ -55,7 +55,7 @@ public CatcherArea()
Children = new Drawable[]
{
catcherContainer = new Container<Catcher> { RelativeSizeAxes = Axes.Both },
catcherTrails = new CatcherTrailDisplay(),
CatcherTrails = new CatcherTrailDisplay(),
comboDisplay = new CatchComboDisplay
{
RelativeSizeAxes = Axes.None,
Expand Down Expand Up @@ -112,7 +112,7 @@ protected override void UpdateAfterChildren()
{
const double trail_generation_interval = 16;

if (Time.Current - catcherTrails.LastDashTrailTime >= trail_generation_interval)
if (Time.Current - CatcherTrails.LastDashTrailTime >= trail_generation_interval)
displayCatcherTrail(Catcher.HyperDashing ? CatcherTrailAnimation.HyperDashing : CatcherTrailAnimation.Dashing);
}

Expand Down Expand Up @@ -170,6 +170,6 @@ public void OnReleased(KeyBindingReleaseEvent<CatchAction> e)
}
}

private void displayCatcherTrail(CatcherTrailAnimation animation) => catcherTrails.Add(new CatcherTrailEntry(Time.Current, Catcher.CurrentState, Catcher.X, Catcher.BodyScale, animation));
private void displayCatcherTrail(CatcherTrailAnimation animation) => CatcherTrails.Add(new CatcherTrailEntry(Time.Current, Catcher.CurrentState, Catcher.X, Catcher.BodyScale, animation));
}
}
21 changes: 21 additions & 0 deletions osu.Game.Rulesets.Catch/UI/CatcherTrailDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
Expand All @@ -10,6 +11,7 @@
using osu.Game.Rulesets.Catch.Skinning;
using osu.Game.Rulesets.Objects.Pooling;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Rulesets.Catch.UI
Expand Down Expand Up @@ -55,6 +57,25 @@ public CatcherTrailDisplay()
};
}

/// <summary>
/// Update the scale of all trails.
/// </summary>
/// <param name="scale">The new body scale of the Catcher</param>
public void UpdateCatcherTrailsScale(Vector2 scale)
{
var oldEntries = Entries.ToList();

Clear();

foreach (var oldEntry in oldEntries)
{
// use magnitude of the new scale while preserving the sign of the old one in the X direction.
// the end effect is preserving the direction in which the trail sprites face, which is important.
var targetScale = new Vector2(Math.Abs(scale.X) * Math.Sign(oldEntry.Scale.X), Math.Abs(scale.Y));
Add(new CatcherTrailEntry(oldEntry.LifetimeStart, oldEntry.CatcherState, oldEntry.Position, targetScale, oldEntry.Animation));
}
}

protected override void LoadComplete()
{
base.LoadComplete();
Expand Down

0 comments on commit 0811de7

Please sign in to comment.