1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02:55 +08:00

Don't inherit VisbilityContainer

This commit is contained in:
Dean Herbert 2018-04-04 20:44:07 +09:00
parent 94c3f38541
commit b7325d73e8
3 changed files with 67 additions and 35 deletions

View File

@ -3,7 +3,6 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
@ -40,7 +39,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Layers.Selection.Overlays
AddInternal(new RingPiece()); AddInternal(new RingPiece());
State = Visibility.Visible; Select();
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System; using System;
using osu.Framework;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Input; using osu.Framework.Input;
@ -13,7 +14,7 @@ namespace osu.Game.Rulesets.Edit
/// <summary> /// <summary>
/// A mask placed above a <see cref="DrawableHitObject"/> adding editing functionality. /// A mask placed above a <see cref="DrawableHitObject"/> adding editing functionality.
/// </summary> /// </summary>
public class HitObjectMask : VisibilityContainer public class HitObjectMask : CompositeDrawable, IStateful<SelectionState>
{ {
/// <summary> /// <summary>
/// Invoked when this <see cref="HitObjectMask"/> has been selected. /// Invoked when this <see cref="HitObjectMask"/> has been selected.
@ -36,7 +37,7 @@ namespace osu.Game.Rulesets.Edit
/// </summary> /// </summary>
public readonly DrawableHitObject HitObject; public readonly DrawableHitObject HitObject;
protected override bool ShouldBeAlive => HitObject.IsAlive && HitObject.IsPresent || State == Visibility.Visible; protected override bool ShouldBeAlive => HitObject.IsAlive && HitObject.IsPresent || State == SelectionState.Selected;
public override bool HandleMouseInput => ShouldBeAlive; public override bool HandleMouseInput => ShouldBeAlive;
public override bool RemoveWhenNotAlive => false; public override bool RemoveWhenNotAlive => false;
@ -45,45 +46,72 @@ namespace osu.Game.Rulesets.Edit
HitObject = hitObject; HitObject = hitObject;
AlwaysPresent = true; AlwaysPresent = true;
State = Visibility.Hidden; Alpha = 0;
}
private SelectionState state;
public event Action<SelectionState> StateChanged;
public SelectionState State
{
get => state;
set
{
if (state == value) return;
state = value;
switch (state)
{
case SelectionState.Selected:
Show();
Selected?.Invoke(this);
break;
case SelectionState.NotSelected:
Hide();
Deselected?.Invoke(this);
break;
}
}
} }
/// <summary> /// <summary>
/// Selects this <see cref="HitObjectMask"/>, causing it to become visible. /// Selects this <see cref="HitObjectMask"/>, causing it to become visible.
/// </summary> /// </summary>
/// <returns>True if the <see cref="HitObjectMask"/> was selected. False if the <see cref="HitObjectMask"/> was already selected.</returns> public void Select() => State = SelectionState.Selected;
public bool Select()
{
if (State == Visibility.Visible)
return false;
Show();
Selected?.Invoke(this);
return true;
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
SelectionRequested?.Invoke(this, state);
return base.OnMouseDown(state, args);
}
/// <summary> /// <summary>
/// Deselects this <see cref="HitObjectMask"/>, causing it to become invisible. /// Deselects this <see cref="HitObjectMask"/>, causing it to become invisible.
/// </summary> /// </summary>
/// <returns>True if the <see cref="HitObjectMask"/> was deselected. False if the <see cref="HitObjectMask"/> was already deselected.</returns> public void Deselect() => State = SelectionState.NotSelected;
public bool Deselect()
{
if (State == Visibility.Hidden)
return false;
Hide(); public bool IsSelected => State == SelectionState.Selected;
Deselected?.Invoke(this);
return true; private bool selectionRequested;
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
selectionRequested = false;
if (State == SelectionState.NotSelected && !selectionRequested)
{
SelectionRequested?.Invoke(this, state);
selectionRequested = true;
}
return base.OnMouseDown(state, args);
} }
protected override void PopIn() => Alpha = 1; protected override bool OnClick(InputState state)
protected override void PopOut() => Alpha = 0; {
if (State == SelectionState.Selected && !selectionRequested)
{
selectionRequested = true;
SelectionRequested?.Invoke(this, state);
}
return base.OnClick(state);
}
/// <summary> /// <summary>
/// The screen-space point that causes this <see cref="HitObjectMask"/> to be selected. /// The screen-space point that causes this <see cref="HitObjectMask"/> to be selected.
@ -95,4 +123,10 @@ namespace osu.Game.Rulesets.Edit
/// </summary> /// </summary>
public virtual Quad SelectionQuad => ScreenSpaceDrawQuad; public virtual Quad SelectionQuad => ScreenSpaceDrawQuad;
} }
public enum SelectionState
{
NotSelected,
Selected
}
} }

View File

@ -123,15 +123,14 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
{ {
if (state.Keyboard.ControlPressed) if (state.Keyboard.ControlPressed)
{ {
if (mask.State == Visibility.Visible) if (mask.IsSelected)
// we don't want this deselection to affect input for this frame. mask.Deselect();
Schedule(() => mask.Deselect());
else else
mask.Select(); mask.Select();
} }
else else
{ {
if (mask.State == Visibility.Visible) if (mask.IsSelected)
return; return;