1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Osu.Objects;
@ -40,7 +39,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Layers.Selection.Overlays
AddInternal(new RingPiece());
State = Visibility.Visible;
Select();
}
[BackgroundDependencyLoader]

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Input;
@ -13,7 +14,7 @@ namespace osu.Game.Rulesets.Edit
/// <summary>
/// A mask placed above a <see cref="DrawableHitObject"/> adding editing functionality.
/// </summary>
public class HitObjectMask : VisibilityContainer
public class HitObjectMask : CompositeDrawable, IStateful<SelectionState>
{
/// <summary>
/// Invoked when this <see cref="HitObjectMask"/> has been selected.
@ -36,7 +37,7 @@ namespace osu.Game.Rulesets.Edit
/// </summary>
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 RemoveWhenNotAlive => false;
@ -45,45 +46,72 @@ namespace osu.Game.Rulesets.Edit
HitObject = hitObject;
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>
/// Selects this <see cref="HitObjectMask"/>, causing it to become visible.
/// </summary>
/// <returns>True if the <see cref="HitObjectMask"/> was selected. False if the <see cref="HitObjectMask"/> was already selected.</returns>
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);
}
public void Select() => State = SelectionState.Selected;
/// <summary>
/// Deselects this <see cref="HitObjectMask"/>, causing it to become invisible.
/// </summary>
/// <returns>True if the <see cref="HitObjectMask"/> was deselected. False if the <see cref="HitObjectMask"/> was already deselected.</returns>
public bool Deselect()
{
if (State == Visibility.Hidden)
return false;
public void Deselect() => State = SelectionState.NotSelected;
Hide();
Deselected?.Invoke(this);
return true;
public bool IsSelected => State == SelectionState.Selected;
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 void PopOut() => Alpha = 0;
protected override bool OnClick(InputState state)
{
if (State == SelectionState.Selected && !selectionRequested)
{
selectionRequested = true;
SelectionRequested?.Invoke(this, state);
}
return base.OnClick(state);
}
/// <summary>
/// The screen-space point that causes this <see cref="HitObjectMask"/> to be selected.
@ -95,4 +123,10 @@ namespace osu.Game.Rulesets.Edit
/// </summary>
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 (mask.State == Visibility.Visible)
// we don't want this deselection to affect input for this frame.
Schedule(() => mask.Deselect());
if (mask.IsSelected)
mask.Deselect();
else
mask.Select();
}
else
{
if (mask.State == Visibility.Visible)
if (mask.IsSelected)
return;