mirror of
https://github.com/ppy/osu.git
synced 2025-02-05 05:33:21 +08:00
Tidy up highlighting code and ensure read-only access to dictionary by highlight areas
This commit is contained in:
parent
715e9018da
commit
a42c1af09e
@ -1,8 +1,9 @@
|
|||||||
// 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.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using System.Diagnostics;
|
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -10,16 +11,18 @@ using osu.Framework.Graphics.Shapes;
|
|||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osuTK.Graphics;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using System.Collections.Generic;
|
using osuTK.Graphics;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Catch.UI
|
namespace osu.Game.Rulesets.Catch.UI
|
||||||
{
|
{
|
||||||
public class CatchTouchInputMapper : VisibilityContainer
|
public class CatchTouchInputMapper : VisibilityContainer
|
||||||
{
|
{
|
||||||
private Dictionary<object, TouchCatchAction> trackedActionSources = new Dictionary<object, TouchCatchAction>();
|
public override bool PropagatePositionalInputSubTree => true;
|
||||||
|
public override bool PropagateNonPositionalInputSubTree => true;
|
||||||
|
|
||||||
|
private readonly Dictionary<object, TouchCatchAction> trackedActionSources = new Dictionary<object, TouchCatchAction>();
|
||||||
|
|
||||||
private KeyBindingContainer<CatchAction> keyBindingContainer = null!;
|
private KeyBindingContainer<CatchAction> keyBindingContainer = null!;
|
||||||
|
|
||||||
@ -30,17 +33,11 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
private InputArea leftDashBox = null!;
|
private InputArea leftDashBox = null!;
|
||||||
private InputArea rightDashBox = null!;
|
private InputArea rightDashBox = null!;
|
||||||
|
|
||||||
public override bool PropagatePositionalInputSubTree => true;
|
|
||||||
public override bool PropagateNonPositionalInputSubTree => true;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(CatchInputManager catchInputManager, OsuColour colours)
|
private void load(CatchInputManager catchInputManager, OsuColour colours)
|
||||||
{
|
{
|
||||||
Debug.Assert(catchInputManager.KeyBindingContainer != null);
|
|
||||||
|
|
||||||
keyBindingContainer = catchInputManager.KeyBindingContainer;
|
keyBindingContainer = catchInputManager.KeyBindingContainer;
|
||||||
|
|
||||||
// Container should handle input everywhere.
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
@ -48,7 +45,6 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
mainContent = new Container
|
mainContent = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
RelativePositionAxes = Axes.Both,
|
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -56,25 +52,18 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Width = 0.15f,
|
Width = 0.15f,
|
||||||
Height = 1,
|
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
leftBox = new InputArea(TouchCatchAction.MoveLeft, ref trackedActionSources, colours.Gray3)
|
leftBox = new InputArea(TouchCatchAction.MoveLeft, trackedActionSources, colours.Gray3)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreRight,
|
|
||||||
Origin = Anchor.CentreRight,
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
RelativePositionAxes = Axes.Both,
|
|
||||||
Width = 0.5f,
|
Width = 0.5f,
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
},
|
},
|
||||||
leftDashBox = new InputArea(TouchCatchAction.DashLeft, ref trackedActionSources, colours.Gray2)
|
leftDashBox = new InputArea(TouchCatchAction.DashLeft, trackedActionSources, colours.Gray2)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
RelativePositionAxes = Axes.Both,
|
|
||||||
Width = 0.5f,
|
Width = 0.5f,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,26 +72,21 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Width = 0.15f,
|
Width = 0.15f,
|
||||||
Height = 1,
|
Anchor = Anchor.TopRight,
|
||||||
Anchor = Anchor.CentreRight,
|
Origin = Anchor.TopRight,
|
||||||
Origin = Anchor.CentreRight,
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
rightBox = new InputArea(TouchCatchAction.MoveRight, ref trackedActionSources, colours.Gray3)
|
rightBox = new InputArea(TouchCatchAction.MoveRight, trackedActionSources, colours.Gray3)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
RelativePositionAxes = Axes.Both,
|
|
||||||
Width = 0.5f,
|
Width = 0.5f,
|
||||||
},
|
},
|
||||||
rightDashBox = new InputArea(TouchCatchAction.DashRight, ref trackedActionSources, colours.Gray2)
|
rightDashBox = new InputArea(TouchCatchAction.DashRight, trackedActionSources, colours.Gray2)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreRight,
|
|
||||||
Origin = Anchor.CentreRight,
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
RelativePositionAxes = Axes.Both,
|
|
||||||
Width = 0.5f,
|
Width = 0.5f,
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -218,15 +202,9 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
return TouchCatchAction.None;
|
return TouchCatchAction.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void PopIn()
|
protected override void PopIn() => mainContent.FadeIn(500, Easing.OutQuint);
|
||||||
{
|
|
||||||
mainContent.FadeIn(500, Easing.OutQuint);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void PopOut()
|
protected override void PopOut() => mainContent.FadeOut(300);
|
||||||
{
|
|
||||||
mainContent.FadeOut(300);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InputArea : CompositeDrawable, IKeyBindingHandler<CatchAction>
|
private class InputArea : CompositeDrawable, IKeyBindingHandler<CatchAction>
|
||||||
{
|
{
|
||||||
@ -234,11 +212,11 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
|
|
||||||
private readonly Box overlay;
|
private readonly Box overlay;
|
||||||
|
|
||||||
private readonly Dictionary<object, TouchCatchAction> trackedActions;
|
private readonly IEnumerable<KeyValuePair<object, TouchCatchAction>> trackedActions;
|
||||||
|
|
||||||
private bool isHiglighted;
|
private bool isHighlighted;
|
||||||
|
|
||||||
public InputArea(TouchCatchAction handledAction, ref Dictionary<object, TouchCatchAction> trackedActions, Color4 colour)
|
public InputArea(TouchCatchAction handledAction, IEnumerable<KeyValuePair<object, TouchCatchAction>> trackedActions, Color4 colour)
|
||||||
{
|
{
|
||||||
this.handledAction = handledAction;
|
this.handledAction = handledAction;
|
||||||
this.trackedActions = trackedActions;
|
this.trackedActions = trackedActions;
|
||||||
@ -273,22 +251,24 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
|
|
||||||
public bool OnPressed(KeyBindingPressEvent<CatchAction> _)
|
public bool OnPressed(KeyBindingPressEvent<CatchAction> _)
|
||||||
{
|
{
|
||||||
if (trackedActions.ContainsValue(handledAction))
|
updateHighlight();
|
||||||
{
|
|
||||||
isHiglighted = true;
|
|
||||||
overlay.FadeTo(0.5f, 80, Easing.OutQuint);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnReleased(KeyBindingReleaseEvent<CatchAction> _)
|
public void OnReleased(KeyBindingReleaseEvent<CatchAction> _)
|
||||||
{
|
{
|
||||||
if (isHiglighted && !trackedActions.ContainsValue(handledAction))
|
updateHighlight();
|
||||||
{
|
}
|
||||||
isHiglighted = false;
|
|
||||||
overlay.FadeOut(1000, Easing.Out);
|
private void updateHighlight()
|
||||||
}
|
{
|
||||||
|
bool isHandling = trackedActions.Any(a => a.Value == handledAction);
|
||||||
|
|
||||||
|
if (isHandling == isHighlighted)
|
||||||
|
return;
|
||||||
|
|
||||||
|
isHighlighted = isHandling;
|
||||||
|
overlay.FadeTo(isHighlighted ? 0.5f : 0, isHighlighted ? 80 : 400, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user