2023-06-23 00:37:25 +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-10-03 14:36:14 +08:00
2021-06-02 10:06:30 +08:00
using System.Linq ;
2019-08-15 17:25:31 +08:00
using osu.Framework.Allocation ;
2023-06-23 23:59:36 +08:00
using osu.Framework.Extensions.ObjectExtensions ;
2018-10-03 14:36:14 +08:00
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
2021-06-02 10:06:30 +08:00
using osu.Game.Rulesets.Mods ;
2018-10-03 14:36:14 +08:00
using osu.Game.Rulesets.Objects ;
using osu.Game.Rulesets.UI ;
2019-08-29 15:06:40 +08:00
using osu.Game.Screens.Edit ;
2018-10-03 14:36:14 +08:00
namespace osu.Game.Rulesets.Edit
{
2019-08-29 17:20:43 +08: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>
2022-11-24 13:32:20 +08:00
internal partial class DrawableEditorRulesetWrapper < TObject > : CompositeDrawable
2018-10-03 14:36:14 +08:00
where TObject : HitObject
{
2019-08-29 17:12:29 +08:00
public Playfield Playfield = > drawableRuleset . Playfield ;
2019-03-31 00:29:37 +08:00
2019-03-20 10:22:34 +08:00
private readonly DrawableRuleset < TObject > drawableRuleset ;
2018-10-17 17:01:38 +08:00
2019-08-29 15:06:40 +08:00
[Resolved]
2023-06-23 00:37:25 +08:00
private EditorBeatmap beatmap { get ; set ; } = null ! ;
2019-08-29 15:06:40 +08:00
2021-04-26 14:37:42 +08:00
public DrawableEditorRulesetWrapper ( DrawableRuleset < TObject > drawableRuleset )
2018-10-03 14:36:14 +08:00
{
2019-03-20 10:22:34 +08:00
this . drawableRuleset = drawableRuleset ;
2018-10-17 17:01:38 +08:00
2019-08-29 17:12:29 +08:00
RelativeSizeAxes = Axes . Both ;
2019-03-20 10:22:34 +08:00
InternalChild = drawableRuleset ;
2019-08-15 17:25:31 +08:00
}
2018-10-03 14:36:14 +08:00
2019-08-15 17:25:31 +08:00
[BackgroundDependencyLoader]
private void load ( )
{
drawableRuleset . FrameStablePlayback = false ;
2018-10-17 17:01:38 +08:00
Playfield . DisplayJudgements . Value = false ;
2018-10-03 14:36:14 +08:00
}
2023-06-23 00:37:25 +08:00
[Resolved]
private IEditorChangeHandler ? changeHandler { get ; set ; }
2020-10-02 14:44:37 +08:00
2019-08-29 15:06:40 +08:00
protected override void LoadComplete ( )
2018-10-03 14:36:14 +08:00
{
2019-08-29 15:06:40 +08:00
base . LoadComplete ( ) ;
2018-10-03 14:36:14 +08:00
2019-08-29 15:06:40 +08:00
beatmap . HitObjectAdded + = addHitObject ;
beatmap . HitObjectRemoved + = removeHitObject ;
2020-10-02 14:44:37 +08:00
2020-10-02 15:21:50 +08:00
if ( changeHandler ! = null )
{
// for now only regenerate replay on a finalised state change, not HitObjectUpdated.
2021-06-02 10:06:30 +08:00
changeHandler . OnStateChange + = ( ) = > Scheduler . AddOnce ( regenerateAutoplay ) ;
2020-10-02 15:21:50 +08:00
}
else
{
2021-06-02 10:06:30 +08:00
beatmap . HitObjectUpdated + = _ = > Scheduler . AddOnce ( regenerateAutoplay ) ;
2020-10-02 15:21:50 +08:00
}
2021-06-02 10:06:30 +08:00
Scheduler . AddOnce ( regenerateAutoplay ) ;
2019-08-29 15:06:40 +08:00
}
2018-10-03 14:36:14 +08:00
2021-06-02 10:06:30 +08:00
private void regenerateAutoplay ( )
{
var autoplayMod = drawableRuleset . Mods . OfType < ModAutoplay > ( ) . Single ( ) ;
2022-03-29 15:45:21 +08:00
drawableRuleset . SetReplayScore ( autoplayMod . CreateScoreFromReplayData ( drawableRuleset . Beatmap , drawableRuleset . Mods ) ) ;
2021-06-02 10:06:30 +08:00
}
2020-09-28 13:15:54 +08:00
2019-08-29 15:06:40 +08:00
private void addHitObject ( HitObject hitObject )
{
2020-11-13 16:08:20 +08:00
drawableRuleset . AddHitObject ( ( TObject ) hitObject ) ;
2019-03-20 10:22:34 +08:00
drawableRuleset . Playfield . PostProcess ( ) ;
2018-10-03 14:36:14 +08:00
}
2018-10-18 15:36:06 +08:00
2019-08-29 15:06:40 +08:00
private void removeHitObject ( HitObject hitObject )
2018-10-18 15:36:06 +08:00
{
2020-11-13 16:08:20 +08:00
drawableRuleset . RemoveHitObject ( ( TObject ) hitObject ) ;
2019-03-20 10:22:34 +08:00
drawableRuleset . Playfield . PostProcess ( ) ;
2018-10-18 15:36:06 +08:00
}
2019-08-29 15:31:40 +08:00
2019-11-11 12:04:38 +08:00
public override bool PropagatePositionalInputSubTree = > false ;
public override bool PropagateNonPositionalInputSubTree = > false ;
2019-08-29 17:12:29 +08:00
public PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer ( ) = > drawableRuleset . CreatePlayfieldAdjustmentContainer ( ) ;
2019-08-29 15:31:40 +08:00
protected override void Dispose ( bool isDisposing )
{
base . Dispose ( isDisposing ) ;
2023-06-23 23:59:36 +08:00
if ( beatmap . IsNotNull ( ) )
2019-08-29 15:31:40 +08:00
{
beatmap . HitObjectAdded - = addHitObject ;
beatmap . HitObjectRemoved - = removeHitObject ;
}
}
2018-10-03 14:36:14 +08:00
}
}