2019-09-13 13:44:40 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 08:43:03 +00:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Beatmaps;
|
2018-06-29 07:49:01 +00:00
|
|
|
|
using osu.Game.Rulesets.Catch.Judgements;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
2020-02-19 09:01:59 +00:00
|
|
|
|
using osu.Game.Rulesets.Catch.Objects.Drawables;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Catch.Replays;
|
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-06-11 14:00:26 +00:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.UI
|
|
|
|
|
{
|
|
|
|
|
public class CatcherArea : Container
|
|
|
|
|
{
|
2019-01-31 16:57:59 +00:00
|
|
|
|
public const float CATCHER_SIZE = 106.75f;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-24 14:40:43 +00:00
|
|
|
|
public Func<CatchHitObject, DrawableHitObject<CatchHitObject>> CreateDrawableRepresentation;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-07-15 11:58:09 +00:00
|
|
|
|
public readonly Catcher MovableCatcher;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public Container ExplodingFruitTarget
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
set => MovableCatcher.ExplodingFruitTarget = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-13 03:59:30 +00:00
|
|
|
|
private DrawableCatchHitObject lastPlateableFruit;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public CatcherArea(BeatmapDifficulty difficulty = null)
|
|
|
|
|
{
|
2020-07-01 15:21:45 +00:00
|
|
|
|
Size = new Vector2(CatchPlayfield.WIDTH, CATCHER_SIZE);
|
|
|
|
|
Child = MovableCatcher = new Catcher(this, difficulty) { X = CatchPlayfield.CENTER_X };
|
2020-03-13 03:59:30 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-08-06 03:23:08 +00:00
|
|
|
|
public void OnResult(DrawableCatchHitObject fruit, JudgementResult result)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-02-26 10:31:49 +00:00
|
|
|
|
if (result.Judgement is IgnoreJudgement)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-06-15 06:44:47 +00:00
|
|
|
|
void runAfterLoaded(Action action)
|
|
|
|
|
{
|
2018-07-26 12:00:18 +00:00
|
|
|
|
if (lastPlateableFruit == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-08-26 12:16:01 +00:00
|
|
|
|
// this is required to make this run after the last caught fruit runs updateState() at least once.
|
2018-06-15 06:44:47 +00:00
|
|
|
|
// TODO: find a better alternative
|
2018-09-06 04:09:57 +00:00
|
|
|
|
if (lastPlateableFruit.IsLoaded)
|
2018-06-15 06:44:47 +00:00
|
|
|
|
action();
|
|
|
|
|
else
|
2019-03-17 04:43:23 +00:00
|
|
|
|
lastPlateableFruit.OnLoadComplete += _ => action();
|
2018-06-15 06:44:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 11:37:07 +00:00
|
|
|
|
if (result.IsHit && fruit.CanBePlated)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-02-18 03:11:30 +00:00
|
|
|
|
// create a new (cloned) fruit to stay on the plate. the original is faded out immediately.
|
2019-03-24 14:40:43 +00:00
|
|
|
|
var caughtFruit = (DrawableCatchHitObject)CreateDrawableRepresentation?.Invoke(fruit.HitObject);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
if (caughtFruit == null) return;
|
|
|
|
|
|
|
|
|
|
caughtFruit.RelativePositionAxes = Axes.None;
|
|
|
|
|
caughtFruit.Position = new Vector2(MovableCatcher.ToLocalSpace(fruit.ScreenSpaceDrawQuad.Centre).X - MovableCatcher.DrawSize.X / 2, 0);
|
2019-09-07 15:10:31 +00:00
|
|
|
|
caughtFruit.IsOnPlate = true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
caughtFruit.Anchor = Anchor.TopCentre;
|
|
|
|
|
caughtFruit.Origin = Anchor.Centre;
|
2020-02-19 08:28:40 +00:00
|
|
|
|
caughtFruit.Scale *= 0.5f;
|
2019-09-13 11:25:08 +00:00
|
|
|
|
caughtFruit.LifetimeStart = caughtFruit.HitObject.StartTime;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
caughtFruit.LifetimeEnd = double.MaxValue;
|
|
|
|
|
|
2020-02-19 08:28:40 +00:00
|
|
|
|
MovableCatcher.PlaceOnPlate(caughtFruit);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
lastPlateableFruit = caughtFruit;
|
2018-06-15 06:44:47 +00:00
|
|
|
|
|
|
|
|
|
if (!fruit.StaysOnPlate)
|
|
|
|
|
runAfterLoaded(() => MovableCatcher.Explode(caughtFruit));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fruit.HitObject.LastInCombo)
|
|
|
|
|
{
|
2020-02-25 22:13:32 +00:00
|
|
|
|
if (result.Judgement is CatchJudgement catchJudgement && catchJudgement.ShouldExplodeFor(result))
|
2018-06-15 06:44:47 +00:00
|
|
|
|
runAfterLoaded(() => MovableCatcher.Explode());
|
2018-04-13 09:19:50 +00:00
|
|
|
|
else
|
|
|
|
|
MovableCatcher.Drop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 04:22:34 +00:00
|
|
|
|
public void OnReleased(CatchAction action)
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-03-13 03:59:30 +00:00
|
|
|
|
public bool AttemptCatch(CatchHitObject obj)
|
2018-09-13 15:01:33 +00:00
|
|
|
|
{
|
2020-03-13 03:59:30 +00:00
|
|
|
|
return MovableCatcher.AttemptCatch(obj);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2020-02-21 09:09:50 +00:00
|
|
|
|
|
2020-03-13 03:59:30 +00:00
|
|
|
|
protected override void UpdateAfterChildren()
|
2020-02-21 09:09:50 +00:00
|
|
|
|
{
|
2020-03-13 03:59:30 +00:00
|
|
|
|
base.UpdateAfterChildren();
|
2020-02-21 09:09:50 +00:00
|
|
|
|
|
2020-03-13 03:59:30 +00:00
|
|
|
|
var state = (GetContainingInputManager().CurrentState as RulesetInputManagerInputState<CatchAction>)?.LastReplayState as CatchFramedReplayInputHandler.CatchReplayState;
|
2020-02-21 09:09:50 +00:00
|
|
|
|
|
2020-03-13 03:59:30 +00:00
|
|
|
|
if (state?.CatcherX != null)
|
|
|
|
|
MovableCatcher.X = state.CatcherX.Value;
|
2020-02-21 09:09:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|