Simplify blueprints by removing visible state

This commit is contained in:
Dean Herbert 2020-02-13 10:00:09 +09:00
parent 0fe41fd50a
commit b65e839bd2
2 changed files with 14 additions and 46 deletions

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -20,13 +18,8 @@ namespace osu.Game.Rulesets.Edit
/// <summary> /// <summary>
/// A blueprint which governs the creation of a new <see cref="HitObject"/> to actualisation. /// A blueprint which governs the creation of a new <see cref="HitObject"/> to actualisation.
/// </summary> /// </summary>
public abstract class PlacementBlueprint : CompositeDrawable, IStateful<PlacementState> public abstract class PlacementBlueprint : CompositeDrawable
{ {
/// <summary>
/// Invoked when <see cref="State"/> has changed.
/// </summary>
public event Action<PlacementState> StateChanged;
/// <summary> /// <summary>
/// Whether the <see cref="HitObject"/> is currently mid-placement, but has not necessarily finished being placed. /// Whether the <see cref="HitObject"/> is currently mid-placement, but has not necessarily finished being placed.
/// </summary> /// </summary>
@ -53,8 +46,6 @@ namespace osu.Game.Rulesets.Edit
// This is required to allow the blueprint's position to be updated via OnMouseMove/Handle // This is required to allow the blueprint's position to be updated via OnMouseMove/Handle
// on the same frame it is made visible via a PlacementState change. // on the same frame it is made visible via a PlacementState change.
AlwaysPresent = true; AlwaysPresent = true;
Alpha = 0;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -67,27 +58,6 @@ namespace osu.Game.Rulesets.Edit
ApplyDefaultsToHitObject(); ApplyDefaultsToHitObject();
} }
private PlacementState state;
public PlacementState State
{
get => state;
set
{
if (state == value)
return;
state = value;
if (state == PlacementState.Shown)
Show();
else
Hide();
StateChanged?.Invoke(value);
}
}
/// <summary> /// <summary>
/// Signals that the placement of <see cref="HitObject"/> has started. /// Signals that the placement of <see cref="HitObject"/> has started.
/// </summary> /// </summary>
@ -144,10 +114,4 @@ namespace osu.Game.Rulesets.Edit
} }
} }
} }
public enum PlacementState
{
Hidden,
Shown,
}
} }

View File

@ -64,8 +64,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
{ {
placementBlueprintContainer.Clear(); placementBlueprintContainer.Clear();
currentPlacement?.EndPlacement(false); removePlacement();
currentPlacement = null;
var blueprint = CurrentTool?.CreatePlacementBlueprint(); var blueprint = CurrentTool?.CreatePlacementBlueprint();
@ -103,18 +102,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
{ {
base.Update(); base.Update();
if (currentPlacement != null) if (currentPlacement?.PlacementActive == false && !composer.CursorInPlacementArea)
{ removePlacement();
if (composer.CursorInPlacementArea)
currentPlacement.State = PlacementState.Shown;
else if (currentPlacement?.PlacementActive == false)
currentPlacement.State = PlacementState.Hidden;
}
} }
protected sealed override SelectionBlueprint CreateBlueprintFor(HitObject hitObject) protected sealed override SelectionBlueprint CreateBlueprintFor(HitObject hitObject)
{ {
var drawable = drawableHitObjects.FirstOrDefault(d => d.HitObject == hitObject); var drawable = drawableHitObjects.FirstOrDefault(d => d.HitObject == hitObject);
if (drawable == null) if (drawable == null)
return null; return null;
@ -129,6 +124,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
base.AddBlueprintFor(hitObject); base.AddBlueprintFor(hitObject);
} }
private void removePlacement()
{
if (currentPlacement == null) return;
currentPlacement.EndPlacement(false);
currentPlacement = null;
}
private HitObjectCompositionTool currentTool; private HitObjectCompositionTool currentTool;
/// <summary> /// <summary>
@ -137,6 +140,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
public HitObjectCompositionTool CurrentTool public HitObjectCompositionTool CurrentTool
{ {
get => currentTool; get => currentTool;
set set
{ {
if (currentTool == value) if (currentTool == value)