2019-09-13 21:44:40 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-06-11 14:39:06 +08:00
|
|
|
|
using System;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-06-11 14:39:06 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-06-29 15:49:01 +08:00
|
|
|
|
using osu.Game.Rulesets.Catch.Judgements;
|
2020-02-19 17:01:59 +08:00
|
|
|
|
using osu.Game.Rulesets.Catch.Objects.Drawables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Catch.Replays;
|
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2020-09-29 13:26:36 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2018-06-11 22:00:26 +08:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.UI
|
|
|
|
|
{
|
2021-06-11 14:39:06 +08:00
|
|
|
|
public class CatcherArea : Container, IKeyBindingHandler<CatchAction>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-02-01 00:57:59 +08:00
|
|
|
|
public const float CATCHER_SIZE = 106.75f;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-07-15 19:58:09 +08:00
|
|
|
|
public readonly Catcher MovableCatcher;
|
2020-09-13 04:39:06 +08:00
|
|
|
|
private readonly CatchComboDisplay comboDisplay;
|
2020-07-15 19:58:09 +08:00
|
|
|
|
|
2021-06-11 14:39:06 +08: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;
|
|
|
|
|
|
2020-12-09 09:35:01 +08:00
|
|
|
|
public CatcherArea(Container<CaughtObject> droppedObjectContainer, BeatmapDifficulty difficulty = null)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-07-01 23:21:45 +08:00
|
|
|
|
Size = new Vector2(CatchPlayfield.WIDTH, CATCHER_SIZE);
|
2020-08-30 04:14:29 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2020-09-13 04:39:06 +08:00
|
|
|
|
comboDisplay = new CatchComboDisplay
|
2020-08-30 04:14:29 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Margin = new MarginPadding { Bottom = 350f },
|
|
|
|
|
X = CatchPlayfield.CENTER_X
|
|
|
|
|
},
|
2020-12-04 09:21:54 +08:00
|
|
|
|
MovableCatcher = new Catcher(this, droppedObjectContainer, difficulty) { X = CatchPlayfield.CENTER_X },
|
2020-08-30 04:14:29 +08:00
|
|
|
|
};
|
2020-03-13 11:59:30 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-11-24 18:57:37 +08:00
|
|
|
|
public void OnNewResult(DrawableCatchHitObject hitObject, JudgementResult result)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-12-08 13:28:30 +08:00
|
|
|
|
MovableCatcher.OnNewResult(hitObject, result);
|
|
|
|
|
|
2020-09-29 13:26:36 +08:00
|
|
|
|
if (!result.Type.IsScorable())
|
2020-02-26 18:31:49 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2020-11-24 18:57:37 +08:00
|
|
|
|
if (hitObject.HitObject.LastInCombo)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-02-26 06:13:32 +08:00
|
|
|
|
if (result.Judgement is CatchJudgement catchJudgement && catchJudgement.ShouldExplodeFor(result))
|
2020-12-02 18:45:34 +08:00
|
|
|
|
MovableCatcher.Explode();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
else
|
|
|
|
|
MovableCatcher.Drop();
|
|
|
|
|
}
|
2020-09-13 04:39:06 +08:00
|
|
|
|
|
2020-11-24 18:57:37 +08:00
|
|
|
|
comboDisplay.OnNewResult(hitObject, result);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-08 13:28:30 +08:00
|
|
|
|
public void OnRevertResult(DrawableCatchHitObject hitObject, JudgementResult result)
|
2018-09-13 23:01:33 +08:00
|
|
|
|
{
|
2020-12-08 13:28:30 +08:00
|
|
|
|
comboDisplay.OnRevertResult(hitObject, result);
|
|
|
|
|
MovableCatcher.OnRevertResult(hitObject, result);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2020-02-21 17:09:50 +08:00
|
|
|
|
|
2021-06-11 14:39:06 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
var replayState = (GetContainingInputManager().CurrentState as RulesetInputManagerInputState<CatchAction>)?.LastReplayState as CatchFramedReplayInputHandler.CatchReplayState;
|
|
|
|
|
|
|
|
|
|
SetCatcherPosition(
|
|
|
|
|
replayState?.CatcherX ??
|
|
|
|
|
(float)(MovableCatcher.X + MovableCatcher.Speed * currentDirection * Clock.ElapsedFrameTime));
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
|
protected override void UpdateAfterChildren()
|
2020-02-21 17:09:50 +08:00
|
|
|
|
{
|
2020-03-13 11:59:30 +08:00
|
|
|
|
base.UpdateAfterChildren();
|
2020-02-21 17:09:50 +08:00
|
|
|
|
|
2021-06-11 14:39:06 +08:00
|
|
|
|
comboDisplay.X = MovableCatcher.X;
|
|
|
|
|
}
|
2020-02-21 17:09:50 +08:00
|
|
|
|
|
2021-06-11 14:39:06 +08:00
|
|
|
|
public void SetCatcherPosition(float X)
|
|
|
|
|
{
|
|
|
|
|
float lastPosition = MovableCatcher.X;
|
|
|
|
|
float newPosition = Math.Clamp(X, 0, CatchPlayfield.WIDTH);
|
2020-08-30 04:14:29 +08:00
|
|
|
|
|
2021-06-11 14:39:06 +08:00
|
|
|
|
MovableCatcher.X = newPosition;
|
|
|
|
|
|
|
|
|
|
if (lastPosition < newPosition)
|
|
|
|
|
MovableCatcher.VisualDirection = Direction.Right;
|
|
|
|
|
else if (lastPosition > newPosition)
|
|
|
|
|
MovableCatcher.VisualDirection = Direction.Left;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnPressed(CatchAction action)
|
|
|
|
|
{
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case CatchAction.MoveLeft:
|
|
|
|
|
currentDirection--;
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case CatchAction.MoveRight:
|
|
|
|
|
currentDirection++;
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case CatchAction.Dash:
|
|
|
|
|
MovableCatcher.Dashing = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnReleased(CatchAction action)
|
|
|
|
|
{
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case CatchAction.MoveLeft:
|
|
|
|
|
currentDirection++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CatchAction.MoveRight:
|
|
|
|
|
currentDirection--;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CatchAction.Dash:
|
|
|
|
|
MovableCatcher.Dashing = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-02-21 17:09:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|