2020-04-22 10:12:29 +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.
|
|
|
|
|
2021-07-27 18:11:08 +08:00
|
|
|
using System;
|
2024-11-01 20:07:32 +08:00
|
|
|
using System.Linq;
|
2021-07-29 16:12:01 +08:00
|
|
|
using osu.Framework.Allocation;
|
2023-01-15 15:26:11 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2020-04-22 10:12:29 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-12-07 17:12:55 +08:00
|
|
|
using osu.Framework.Graphics.Pooling;
|
2021-07-27 17:48:31 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Skinning;
|
2021-07-29 16:12:01 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Pooling;
|
2021-07-27 17:48:31 +08:00
|
|
|
using osu.Game.Skinning;
|
2024-10-25 05:17:47 +08:00
|
|
|
using osuTK;
|
2020-04-22 10:12:29 +08:00
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.UI
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Represents a component responsible for displaying
|
|
|
|
/// the appropriate catcher trails when requested to.
|
|
|
|
/// </summary>
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class CatcherTrailDisplay : PooledDrawableWithLifetimeContainer<CatcherTrailEntry, CatcherTrail>
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
2021-07-26 16:50:10 +08:00
|
|
|
/// <summary>
|
2021-07-27 18:11:08 +08:00
|
|
|
/// The most recent time a dash trail was added to this container.
|
2021-07-26 16:50:10 +08:00
|
|
|
/// Only alive (not faded out) trails are considered.
|
2021-07-27 18:11:08 +08:00
|
|
|
/// Returns <see cref="double.NegativeInfinity"/> if no dash trail is alive.
|
2021-07-26 16:50:10 +08:00
|
|
|
/// </summary>
|
2021-07-27 18:11:08 +08:00
|
|
|
public double LastDashTrailTime => getLastDashTrailTime();
|
2020-04-22 10:12:29 +08:00
|
|
|
|
2021-07-27 17:48:31 +08:00
|
|
|
public Color4 HyperDashTrailsColour => hyperDashTrails.Colour;
|
|
|
|
|
2021-07-28 18:02:24 +08:00
|
|
|
public Color4 HyperDashAfterImageColour => hyperDashAfterImages.Colour;
|
2021-07-27 17:48:31 +08:00
|
|
|
|
2021-07-29 16:12:01 +08:00
|
|
|
protected override bool RemoveRewoundEntry => true;
|
|
|
|
|
2021-06-14 18:47:18 +08:00
|
|
|
private readonly DrawablePool<CatcherTrail> trailPool;
|
2020-12-07 17:12:55 +08:00
|
|
|
|
2021-06-14 18:47:18 +08:00
|
|
|
private readonly Container<CatcherTrail> dashTrails;
|
|
|
|
private readonly Container<CatcherTrail> hyperDashTrails;
|
2021-07-28 18:02:24 +08:00
|
|
|
private readonly Container<CatcherTrail> hyperDashAfterImages;
|
2020-04-22 10:12:29 +08:00
|
|
|
|
2021-07-29 16:12:01 +08:00
|
|
|
[Resolved]
|
2023-01-15 15:26:11 +08:00
|
|
|
private ISkinSource skin { get; set; } = null!;
|
2021-07-29 16:12:01 +08:00
|
|
|
|
2021-07-26 16:46:56 +08:00
|
|
|
public CatcherTrailDisplay()
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
2020-12-07 17:12:55 +08:00
|
|
|
InternalChildren = new Drawable[]
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
2021-06-14 18:47:18 +08:00
|
|
|
trailPool = new DrawablePool<CatcherTrail>(30),
|
|
|
|
dashTrails = new Container<CatcherTrail> { RelativeSizeAxes = Axes.Both },
|
|
|
|
hyperDashTrails = new Container<CatcherTrail> { RelativeSizeAxes = Axes.Both, Colour = Catcher.DEFAULT_HYPER_DASH_COLOUR },
|
2021-07-28 18:02:24 +08:00
|
|
|
hyperDashAfterImages = new Container<CatcherTrail> { RelativeSizeAxes = Axes.Both, Colour = Catcher.DEFAULT_HYPER_DASH_COLOUR },
|
2020-04-22 10:12:29 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-10-25 05:17:47 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Update the scale of all trails.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="scale">The new body scale of the Catcher</param>
|
|
|
|
public void UpdateCatcherTrailsScale(Vector2 scale)
|
|
|
|
{
|
2024-11-01 20:07:32 +08:00
|
|
|
var oldEntries = Entries.ToList();
|
2024-10-25 05:40:23 +08:00
|
|
|
|
2024-11-01 20:07:32 +08:00
|
|
|
Clear();
|
2024-10-25 05:17:47 +08:00
|
|
|
|
2024-11-01 20:07:32 +08:00
|
|
|
foreach (var oldEntry in oldEntries)
|
2024-10-25 05:17:47 +08:00
|
|
|
{
|
2024-11-01 20:07:32 +08:00
|
|
|
// 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));
|
2024-10-25 05:17:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-29 16:12:01 +08:00
|
|
|
protected override void LoadComplete()
|
2021-07-27 17:48:31 +08:00
|
|
|
{
|
2021-07-29 16:12:01 +08:00
|
|
|
base.LoadComplete();
|
2021-07-27 17:48:31 +08:00
|
|
|
|
2021-07-29 16:12:01 +08:00
|
|
|
skin.SourceChanged += skinSourceChanged;
|
|
|
|
skinSourceChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void skinSourceChanged()
|
|
|
|
{
|
2021-07-27 17:48:31 +08:00
|
|
|
hyperDashTrails.Colour = skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDash)?.Value ?? Catcher.DEFAULT_HYPER_DASH_COLOUR;
|
2021-07-28 18:02:24 +08:00
|
|
|
hyperDashAfterImages.Colour = skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDashAfterImage)?.Value ?? hyperDashTrails.Colour;
|
2021-07-27 17:48:31 +08:00
|
|
|
}
|
|
|
|
|
2021-07-29 16:12:01 +08:00
|
|
|
protected override void AddDrawable(CatcherTrailEntry entry, CatcherTrail drawable)
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
2021-07-29 16:12:01 +08:00
|
|
|
switch (entry.Animation)
|
|
|
|
{
|
|
|
|
case CatcherTrailAnimation.Dashing:
|
|
|
|
dashTrails.Add(drawable);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CatcherTrailAnimation.HyperDashing:
|
|
|
|
hyperDashTrails.Add(drawable);
|
|
|
|
break;
|
|
|
|
|
2021-08-02 14:08:42 +08:00
|
|
|
case CatcherTrailAnimation.HyperDashAfterImage:
|
2021-07-29 16:12:01 +08:00
|
|
|
hyperDashAfterImages.Add(drawable);
|
|
|
|
break;
|
|
|
|
}
|
2020-04-22 10:12:29 +08:00
|
|
|
}
|
|
|
|
|
2021-07-29 16:12:01 +08:00
|
|
|
protected override void RemoveDrawable(CatcherTrailEntry entry, CatcherTrail drawable)
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
2021-07-29 16:12:01 +08:00
|
|
|
switch (entry.Animation)
|
|
|
|
{
|
|
|
|
case CatcherTrailAnimation.Dashing:
|
2022-08-26 14:19:05 +08:00
|
|
|
dashTrails.Remove(drawable, false);
|
2021-07-29 16:12:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CatcherTrailAnimation.HyperDashing:
|
2022-08-26 14:19:05 +08:00
|
|
|
hyperDashTrails.Remove(drawable, false);
|
2021-07-29 16:12:01 +08:00
|
|
|
break;
|
|
|
|
|
2021-08-02 14:08:42 +08:00
|
|
|
case CatcherTrailAnimation.HyperDashAfterImage:
|
2022-08-26 14:19:05 +08:00
|
|
|
hyperDashAfterImages.Remove(drawable, false);
|
2021-07-29 16:12:01 +08:00
|
|
|
break;
|
|
|
|
}
|
2020-04-22 10:12:29 +08:00
|
|
|
}
|
|
|
|
|
2021-07-29 16:12:01 +08:00
|
|
|
protected override CatcherTrail GetDrawable(CatcherTrailEntry entry)
|
2020-04-22 10:12:29 +08:00
|
|
|
{
|
2021-07-28 18:05:48 +08:00
|
|
|
CatcherTrail trail = trailPool.Get();
|
2021-07-29 16:12:01 +08:00
|
|
|
trail.Apply(entry);
|
2021-07-28 18:05:48 +08:00
|
|
|
return trail;
|
2020-04-22 10:12:29 +08:00
|
|
|
}
|
2021-07-27 18:11:08 +08:00
|
|
|
|
|
|
|
private double getLastDashTrailTime()
|
|
|
|
{
|
|
|
|
double maxTime = double.NegativeInfinity;
|
|
|
|
|
|
|
|
foreach (var trail in dashTrails)
|
|
|
|
maxTime = Math.Max(maxTime, trail.LifetimeStart);
|
|
|
|
|
|
|
|
foreach (var trail in hyperDashTrails)
|
|
|
|
maxTime = Math.Max(maxTime, trail.LifetimeStart);
|
|
|
|
|
|
|
|
return maxTime;
|
|
|
|
}
|
2021-07-29 16:12:01 +08:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
2023-01-15 15:26:11 +08:00
|
|
|
if (skin.IsNotNull())
|
2021-07-29 16:12:01 +08:00
|
|
|
skin.SourceChanged -= skinSourceChanged;
|
|
|
|
}
|
2020-04-22 10:12:29 +08:00
|
|
|
}
|
|
|
|
}
|