1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00

Make show/hide only invoked once each

This commit is contained in:
smoogipoo 2018-11-13 13:00:00 +09:00
parent 819cba31ce
commit 6d43baf4bf
2 changed files with 47 additions and 7 deletions

View File

@ -1,6 +1,8 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
@ -18,8 +20,18 @@ namespace osu.Game.Rulesets.Edit
/// <summary>
/// A blueprint which governs the creation of a new <see cref="HitObject"/> to actualisation.
/// </summary>
public abstract class PlacementBlueprint : CompositeDrawable, IRequireHighFrequencyMousePosition
public abstract class PlacementBlueprint : CompositeDrawable, IStateful<PlacementState>, IRequireHighFrequencyMousePosition
{
/// <summary>
/// Invoked when <see cref="State"/> has changed.
/// </summary>
public event Action<PlacementState> StateChanged;
/// <summary>
/// Whether the <see cref="HitObject"/> is currently being placed, but has not necessarily finished being placed.
/// </summary>
public bool PlacementBegun { get; private set; }
/// <summary>
/// The <see cref="HitObject"/> that is being placed.
/// </summary>
@ -51,7 +63,25 @@ namespace osu.Game.Rulesets.Edit
ApplyDefaultsToHitObject();
}
public bool PlacementBegun { get; private set; }
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>
/// Signals that the placement of <see cref="HitObject"/> has started.
@ -95,4 +125,10 @@ namespace osu.Game.Rulesets.Edit
}
}
}
public enum PlacementState
{
Hidden,
Shown,
}
}

View File

@ -134,10 +134,15 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
base.Update();
if (composer.RulesetContainer.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position))
currentPlacement?.Show();
else if (currentPlacement?.PlacementBegun == false)
currentPlacement?.Hide();
if (currentPlacement != null)
{
bool cursorInPlayfield = composer.RulesetContainer.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position);
if (cursorInPlayfield)
currentPlacement.State = PlacementState.Shown;
else if (currentPlacement?.PlacementBegun == false)
currentPlacement.State = PlacementState.Hidden;
}
}
/// <summary>
@ -153,7 +158,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
placementBlueprintContainer.Child = currentPlacement = blueprint;
}
/// <summary>
/// Select all masks in a given rectangle selection area.
/// </summary>