2019-01-24 08:43:03 +00: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.
2018-10-03 06:36:14 +00:00
2019-08-15 09:25:31 +00:00
using osu.Framework.Allocation ;
2018-10-03 06:36:14 +00:00
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
using osu.Game.Rulesets.Objects ;
using osu.Game.Rulesets.UI ;
2019-08-29 07:06:40 +00:00
using osu.Game.Screens.Edit ;
2018-10-03 06:36:14 +00:00
namespace osu.Game.Rulesets.Edit
{
2019-08-29 09:20:43 +00:00
/// <summary>
/// A wrapper for a <see cref="DrawableRuleset{TObject}"/>. Handles adding visual representations of <see cref="HitObject"/>s to the underlying <see cref="DrawableRuleset{TObject}"/>.
/// </summary>
internal class DrawableEditRulesetWrapper < TObject > : CompositeDrawable
2018-10-03 06:36:14 +00:00
where TObject : HitObject
{
2019-08-29 09:12:29 +00:00
public Playfield Playfield = > drawableRuleset . Playfield ;
2019-03-30 16:29:37 +00:00
2019-03-20 02:22:34 +00:00
private readonly DrawableRuleset < TObject > drawableRuleset ;
2018-10-17 09:01:38 +00:00
2019-08-29 07:06:40 +00:00
[Resolved]
2019-12-27 10:46:33 +00:00
private EditorBeatmap beatmap { get ; set ; }
2019-08-29 07:06:40 +00:00
2019-08-29 09:20:43 +00:00
public DrawableEditRulesetWrapper ( DrawableRuleset < TObject > drawableRuleset )
2018-10-03 06:36:14 +00:00
{
2019-03-20 02:22:34 +00:00
this . drawableRuleset = drawableRuleset ;
2018-10-17 09:01:38 +00:00
2019-08-29 09:12:29 +00:00
RelativeSizeAxes = Axes . Both ;
2019-03-20 02:22:34 +00:00
InternalChild = drawableRuleset ;
2019-08-15 09:25:31 +00:00
}
2018-10-03 06:36:14 +00:00
2019-08-15 09:25:31 +00:00
[BackgroundDependencyLoader]
private void load ( )
{
drawableRuleset . FrameStablePlayback = false ;
2018-10-17 09:01:38 +00:00
Playfield . DisplayJudgements . Value = false ;
2018-10-03 06:36:14 +00:00
}
2020-10-02 07:21:50 +00:00
[Resolved(canBeNull: true)]
2020-10-02 06:44:37 +00:00
private IEditorChangeHandler changeHandler { get ; set ; }
2019-08-29 07:06:40 +00:00
protected override void LoadComplete ( )
2018-10-03 06:36:14 +00:00
{
2019-08-29 07:06:40 +00:00
base . LoadComplete ( ) ;
2018-10-03 06:36:14 +00:00
2019-08-29 07:06:40 +00:00
beatmap . HitObjectAdded + = addHitObject ;
beatmap . HitObjectRemoved + = removeHitObject ;
2020-10-02 06:44:37 +00:00
2020-10-02 07:21:50 +00:00
if ( changeHandler ! = null )
{
// for now only regenerate replay on a finalised state change, not HitObjectUpdated.
changeHandler . OnStateChange + = updateReplay ;
}
else
{
beatmap . HitObjectUpdated + = _ = > updateReplay ( ) ;
}
2019-08-29 07:06:40 +00:00
}
2018-10-03 06:36:14 +00:00
2020-10-02 06:44:37 +00:00
private void updateReplay ( ) = > drawableRuleset . RegenerateAutoplay ( ) ;
2020-09-28 05:15:54 +00:00
2019-08-29 07:06:40 +00:00
private void addHitObject ( HitObject hitObject )
{
2020-11-13 08:08:20 +00:00
drawableRuleset . AddHitObject ( ( TObject ) hitObject ) ;
2019-03-20 02:22:34 +00:00
drawableRuleset . Playfield . PostProcess ( ) ;
2018-10-03 06:36:14 +00:00
}
2018-10-18 07:36:06 +00:00
2019-08-29 07:06:40 +00:00
private void removeHitObject ( HitObject hitObject )
2018-10-18 07:36:06 +00:00
{
2020-11-13 08:08:20 +00:00
drawableRuleset . RemoveHitObject ( ( TObject ) hitObject ) ;
2019-03-20 02:22:34 +00:00
drawableRuleset . Playfield . PostProcess ( ) ;
2018-10-18 07:36:06 +00:00
}
2019-08-29 07:31:40 +00:00
2019-11-11 04:04:38 +00:00
public override bool PropagatePositionalInputSubTree = > false ;
public override bool PropagateNonPositionalInputSubTree = > false ;
2019-08-29 09:12:29 +00:00
public PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer ( ) = > drawableRuleset . CreatePlayfieldAdjustmentContainer ( ) ;
2019-08-29 07:31:40 +00:00
protected override void Dispose ( bool isDisposing )
{
base . Dispose ( isDisposing ) ;
if ( beatmap ! = null )
{
beatmap . HitObjectAdded - = addHitObject ;
beatmap . HitObjectRemoved - = removeHitObject ;
}
}
2018-10-03 06:36:14 +00:00
}
}