1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 14:32:54 +08:00
osu-lazer/osu.Game.Rulesets.Catch/UI/CatcherArea.cs

132 lines
4.7 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
2018-06-29 15:49:01 +08:00
using osu.Game.Rulesets.Catch.Judgements;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Catch.Objects;
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;
using osu.Game.Rulesets.Objects.Drawables;
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
{
public class CatcherArea : Container
{
2019-02-01 00:57:59 +08:00
public const float CATCHER_SIZE = 106.75f;
2018-04-13 17:19:50 +08:00
public Func<CatchHitObject, DrawableHitObject<CatchHitObject>> CreateDrawableRepresentation;
2018-04-13 17:19:50 +08:00
public readonly Catcher MovableCatcher;
2020-09-13 04:39:06 +08:00
private readonly CatchComboDisplay comboDisplay;
2018-04-13 17:19:50 +08:00
public Container ExplodingFruitTarget
{
set => MovableCatcher.ExplodingFruitTarget = value;
2018-04-13 17:19:50 +08:00
}
private DrawableCatchHitObject lastPlateableFruit;
2018-04-13 17:19:50 +08:00
public CatcherArea(BeatmapDifficulty difficulty = null)
{
Size = new Vector2(CatchPlayfield.WIDTH, CATCHER_SIZE);
Children = new Drawable[]
{
2020-09-13 04:39:06 +08: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
},
MovableCatcher = new Catcher(this, difficulty) { X = CatchPlayfield.CENTER_X },
};
}
2018-04-13 17:19:50 +08:00
2020-09-13 04:39:06 +08:00
public void OnNewResult(DrawableCatchHitObject fruit, JudgementResult result)
2018-04-13 17:19:50 +08:00
{
2020-09-29 13:26:36 +08:00
if (!result.Type.IsScorable())
return;
void runAfterLoaded(Action action)
{
if (lastPlateableFruit == null)
return;
2019-08-26 20:16:01 +08:00
// this is required to make this run after the last caught fruit runs updateState() at least once.
// TODO: find a better alternative
2018-09-06 12:09:57 +08:00
if (lastPlateableFruit.IsLoaded)
action();
else
2019-03-17 12:43:23 +08:00
lastPlateableFruit.OnLoadComplete += _ => action();
}
if (result.IsHit && fruit.HitObject.CanBePlated)
2018-04-13 17:19:50 +08:00
{
// create a new (cloned) fruit to stay on the plate. the original is faded out immediately.
var caughtFruit = (DrawableCatchHitObject)CreateDrawableRepresentation?.Invoke(fruit.HitObject);
2018-04-13 17:19:50 +08:00
if (caughtFruit == null) return;
caughtFruit.RelativePositionAxes = Axes.None;
caughtFruit.Position = new Vector2(MovableCatcher.ToLocalSpace(fruit.ScreenSpaceDrawQuad.Centre).X - MovableCatcher.DrawSize.X / 2, 0);
caughtFruit.IsOnPlate = true;
2018-04-13 17:19:50 +08:00
caughtFruit.Anchor = Anchor.TopCentre;
caughtFruit.Origin = Anchor.Centre;
caughtFruit.Scale *= 0.5f;
caughtFruit.LifetimeStart = caughtFruit.HitObject.StartTime;
2018-04-13 17:19:50 +08:00
caughtFruit.LifetimeEnd = double.MaxValue;
MovableCatcher.PlaceOnPlate(caughtFruit);
2018-04-13 17:19:50 +08:00
lastPlateableFruit = caughtFruit;
if (!fruit.StaysOnPlate)
runAfterLoaded(() => MovableCatcher.Explode(caughtFruit));
2018-04-13 17:19:50 +08:00
}
if (fruit.HitObject.LastInCombo)
{
if (result.Judgement is CatchJudgement catchJudgement && catchJudgement.ShouldExplodeFor(result))
runAfterLoaded(() => MovableCatcher.Explode());
2018-04-13 17:19:50 +08:00
else
MovableCatcher.Drop();
}
2020-09-13 04:39:06 +08:00
comboDisplay.OnNewResult(fruit, result);
2018-04-13 17:19:50 +08:00
}
2020-09-13 04:39:06 +08:00
public void OnRevertResult(DrawableCatchHitObject fruit, JudgementResult result)
=> comboDisplay.OnRevertResult(fruit, result);
public void OnReleased(CatchAction action)
{
}
2018-04-13 17:19:50 +08:00
public bool AttemptCatch(CatchHitObject obj)
{
return MovableCatcher.AttemptCatch(obj);
2018-04-13 17:19:50 +08:00
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
var state = (GetContainingInputManager().CurrentState as RulesetInputManagerInputState<CatchAction>)?.LastReplayState as CatchFramedReplayInputHandler.CatchReplayState;
if (state?.CatcherX != null)
MovableCatcher.X = state.CatcherX.Value;
2020-09-13 04:39:06 +08:00
comboDisplay.X = MovableCatcher.X;
}
}
2018-04-13 17:19:50 +08:00
}