2019-09-13 22:44:40 +09:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 17:43:03 +09:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2021-06-11 15:39:06 +09:00
|
|
|
|
using System;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-06-11 15:39:06 +09:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-09-16 18:26:12 +09:00
|
|
|
|
using osu.Framework.Input.Events;
|
2020-02-19 18:01:59 +09:00
|
|
|
|
using osu.Game.Rulesets.Catch.Objects.Drawables;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Game.Rulesets.Catch.Replays;
|
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2018-06-11 23:00:26 +09:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2023-07-08 13:31:21 +02:00
|
|
|
|
using osu.Game.Screens.Play;
|
2018-11-20 16:51:59 +09:00
|
|
|
|
using osuTK;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.UI
|
|
|
|
|
{
|
2021-07-21 16:40:35 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The horizontal band at the bottom of the playfield the catcher is moving on.
|
|
|
|
|
/// It holds a <see cref="Catcher"/> as a child and translates input to the catcher movement.
|
|
|
|
|
/// It also holds a combo display that is above the catcher, and judgment results are translated to the catcher and the combo display.
|
|
|
|
|
/// </summary>
|
2022-11-24 14:32:20 +09:00
|
|
|
|
public partial class CatcherArea : Container, IKeyBindingHandler<CatchAction>
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2021-07-21 16:28:31 +09:00
|
|
|
|
public Catcher Catcher
|
2021-07-19 19:44:40 +09:00
|
|
|
|
{
|
|
|
|
|
get => catcher;
|
2021-07-27 18:59:55 +09:00
|
|
|
|
set => catcherContainer.Child = catcher = value;
|
2021-07-19 19:44:40 +09:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-27 18:59:55 +09:00
|
|
|
|
private readonly Container<Catcher> catcherContainer;
|
|
|
|
|
|
2020-09-12 22:39:06 +02:00
|
|
|
|
private readonly CatchComboDisplay comboDisplay;
|
2020-07-15 20:58:09 +09:00
|
|
|
|
|
2021-07-28 18:13:43 +09:00
|
|
|
|
private readonly CatcherTrailDisplay catcherTrails;
|
|
|
|
|
|
2023-01-15 16:26:11 +09:00
|
|
|
|
private Catcher catcher = null!;
|
2021-07-19 19:44:40 +09:00
|
|
|
|
|
2021-06-11 15:39:06 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <c>-1</c> when only left button is pressed.
|
|
|
|
|
/// <c>1</c> when only right button is pressed.
|
|
|
|
|
/// <c>0</c> when none or both left and right buttons are pressed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int currentDirection;
|
|
|
|
|
|
2021-07-27 18:59:55 +09:00
|
|
|
|
// TODO: support replay rewind
|
|
|
|
|
private bool lastHyperDashState;
|
|
|
|
|
|
2021-07-21 16:40:35 +09:00
|
|
|
|
/// <remarks>
|
|
|
|
|
/// <see cref="Catcher"/> must be set before loading.
|
|
|
|
|
/// </remarks>
|
2021-07-19 19:44:40 +09:00
|
|
|
|
public CatcherArea()
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2021-07-21 16:43:24 +09:00
|
|
|
|
Size = new Vector2(CatchPlayfield.WIDTH, Catcher.BASE_SIZE);
|
2021-07-27 18:59:55 +09:00
|
|
|
|
Children = new Drawable[]
|
2020-08-29 23:14:29 +03:00
|
|
|
|
{
|
2021-07-27 18:59:55 +09:00
|
|
|
|
catcherContainer = new Container<Catcher> { RelativeSizeAxes = Axes.Both },
|
2021-07-28 18:13:43 +09:00
|
|
|
|
catcherTrails = new CatcherTrailDisplay(),
|
2021-07-27 18:59:55 +09:00
|
|
|
|
comboDisplay = new CatchComboDisplay
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Margin = new MarginPadding { Bottom = 350f },
|
|
|
|
|
X = CatchPlayfield.CENTER_X
|
|
|
|
|
}
|
2020-08-29 23:14:29 +03:00
|
|
|
|
};
|
2020-03-13 12:59:30 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-11-24 19:57:37 +09:00
|
|
|
|
public void OnNewResult(DrawableCatchHitObject hitObject, JudgementResult result)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2021-07-21 16:28:31 +09:00
|
|
|
|
Catcher.OnNewResult(hitObject, result);
|
2020-11-24 19:57:37 +09:00
|
|
|
|
comboDisplay.OnNewResult(hitObject, result);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 19:43:23 +09:00
|
|
|
|
public void OnRevertResult(JudgementResult result)
|
2018-09-13 17:01:33 +02:00
|
|
|
|
{
|
2023-01-19 19:43:23 +09:00
|
|
|
|
comboDisplay.OnRevertResult(result);
|
|
|
|
|
Catcher.OnRevertResult(result);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
2020-02-21 18:09:50 +09:00
|
|
|
|
|
2021-06-11 15:39:06 +09:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2024-05-27 11:23:32 +02:00
|
|
|
|
var replayState = (GetContainingInputManager()!.CurrentState as RulesetInputManagerInputState<CatchAction>)?.LastReplayState as CatchFramedReplayInputHandler.CatchReplayState;
|
2021-06-11 15:39:06 +09:00
|
|
|
|
|
|
|
|
|
SetCatcherPosition(
|
|
|
|
|
replayState?.CatcherX ??
|
2021-07-21 16:28:31 +09:00
|
|
|
|
(float)(Catcher.X + Catcher.Speed * currentDirection * Clock.ElapsedFrameTime));
|
2021-06-11 15:39:06 +09:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-13 12:59:30 +09:00
|
|
|
|
protected override void UpdateAfterChildren()
|
2020-02-21 18:09:50 +09:00
|
|
|
|
{
|
2020-03-13 12:59:30 +09:00
|
|
|
|
base.UpdateAfterChildren();
|
2020-02-21 18:09:50 +09:00
|
|
|
|
|
2021-07-21 16:28:31 +09:00
|
|
|
|
comboDisplay.X = Catcher.X;
|
2021-07-27 18:59:55 +09:00
|
|
|
|
|
2023-07-08 13:31:21 +02:00
|
|
|
|
if ((Clock as IGameplayClock)?.IsRewinding == true)
|
2021-07-29 17:32:20 +09:00
|
|
|
|
{
|
|
|
|
|
// This is probably a wrong value, but currently the true value is not recorded.
|
2021-07-30 15:44:09 +09:00
|
|
|
|
// Setting `true` will prevent generation of false-positive after-images (with more false-negatives).
|
2021-07-29 17:32:20 +09:00
|
|
|
|
lastHyperDashState = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lastHyperDashState && Catcher.HyperDashing)
|
2021-08-02 15:08:42 +09:00
|
|
|
|
displayCatcherTrail(CatcherTrailAnimation.HyperDashAfterImage);
|
2021-07-27 18:59:55 +09:00
|
|
|
|
|
|
|
|
|
if (Catcher.Dashing || Catcher.HyperDashing)
|
|
|
|
|
{
|
2024-08-19 15:01:11 +09:00
|
|
|
|
const double trail_generation_interval = 16;
|
2021-07-27 18:59:55 +09:00
|
|
|
|
|
2024-08-19 15:01:11 +09:00
|
|
|
|
if (Time.Current - catcherTrails.LastDashTrailTime >= trail_generation_interval)
|
2021-07-29 17:12:01 +09:00
|
|
|
|
displayCatcherTrail(Catcher.HyperDashing ? CatcherTrailAnimation.HyperDashing : CatcherTrailAnimation.Dashing);
|
2021-07-27 18:59:55 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lastHyperDashState = Catcher.HyperDashing;
|
2021-06-11 15:39:06 +09:00
|
|
|
|
}
|
2020-02-21 18:09:50 +09:00
|
|
|
|
|
2022-07-06 14:28:47 +09:00
|
|
|
|
public void SetCatcherPosition(float x)
|
2021-06-11 15:39:06 +09:00
|
|
|
|
{
|
2021-07-21 16:28:31 +09:00
|
|
|
|
float lastPosition = Catcher.X;
|
2022-07-06 14:28:47 +09:00
|
|
|
|
float newPosition = Math.Clamp(x, 0, CatchPlayfield.WIDTH);
|
2020-08-29 23:14:29 +03:00
|
|
|
|
|
2021-07-21 16:28:31 +09:00
|
|
|
|
Catcher.X = newPosition;
|
2021-06-11 15:39:06 +09:00
|
|
|
|
|
|
|
|
|
if (lastPosition < newPosition)
|
2021-07-21 16:28:31 +09:00
|
|
|
|
Catcher.VisualDirection = Direction.Right;
|
2021-06-11 15:39:06 +09:00
|
|
|
|
else if (lastPosition > newPosition)
|
2021-07-21 16:28:31 +09:00
|
|
|
|
Catcher.VisualDirection = Direction.Left;
|
2021-06-11 15:39:06 +09:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 18:26:12 +09:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<CatchAction> e)
|
2021-06-11 15:39:06 +09:00
|
|
|
|
{
|
2021-09-16 18:26:12 +09:00
|
|
|
|
switch (e.Action)
|
2021-06-11 15:39:06 +09:00
|
|
|
|
{
|
|
|
|
|
case CatchAction.MoveLeft:
|
|
|
|
|
currentDirection--;
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case CatchAction.MoveRight:
|
|
|
|
|
currentDirection++;
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case CatchAction.Dash:
|
2021-07-21 16:28:31 +09:00
|
|
|
|
Catcher.Dashing = true;
|
2021-06-11 15:39:06 +09:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 18:26:12 +09:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<CatchAction> e)
|
2021-06-11 15:39:06 +09:00
|
|
|
|
{
|
2021-09-16 18:26:12 +09:00
|
|
|
|
switch (e.Action)
|
2021-06-11 15:39:06 +09:00
|
|
|
|
{
|
|
|
|
|
case CatchAction.MoveLeft:
|
|
|
|
|
currentDirection++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CatchAction.MoveRight:
|
|
|
|
|
currentDirection--;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CatchAction.Dash:
|
2021-07-21 16:28:31 +09:00
|
|
|
|
Catcher.Dashing = false;
|
2021-06-11 15:39:06 +09:00
|
|
|
|
break;
|
|
|
|
|
}
|
2020-02-21 18:09:50 +09:00
|
|
|
|
}
|
2021-07-29 17:12:01 +09:00
|
|
|
|
|
|
|
|
|
private void displayCatcherTrail(CatcherTrailAnimation animation) => catcherTrails.Add(new CatcherTrailEntry(Time.Current, Catcher.CurrentState, Catcher.X, Catcher.BodyScale, animation));
|
2020-02-21 18:09:50 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|