mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 22:33:05 +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.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using System.Diagnostics;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -10,16 +11,18 @@ using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK.Graphics;
|
||||
using osuTK;
|
||||
using System.Collections.Generic;
|
||||
using osuTK.Graphics;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Catch.UI
|
||||
{
|
||||
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!;
|
||||
|
||||
@ -30,17 +33,11 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
private InputArea leftDashBox = null!;
|
||||
private InputArea rightDashBox = null!;
|
||||
|
||||
public override bool PropagatePositionalInputSubTree => true;
|
||||
public override bool PropagateNonPositionalInputSubTree => true;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(CatchInputManager catchInputManager, OsuColour colours)
|
||||
{
|
||||
Debug.Assert(catchInputManager.KeyBindingContainer != null);
|
||||
|
||||
keyBindingContainer = catchInputManager.KeyBindingContainer;
|
||||
|
||||
// Container should handle input everywhere.
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
Children = new Drawable[]
|
||||
@ -48,7 +45,6 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
mainContent = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Alpha = 0,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
@ -56,25 +52,18 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Width = 0.15f,
|
||||
Height = 1,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
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,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
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,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Width = 0.5f,
|
||||
}
|
||||
}
|
||||
@ -83,26 +72,21 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Width = 0.15f,
|
||||
Height = 1,
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
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,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
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,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Width = 0.5f,
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
},
|
||||
}
|
||||
},
|
||||
@ -218,15 +202,9 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
return TouchCatchAction.None;
|
||||
}
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
mainContent.FadeIn(500, Easing.OutQuint);
|
||||
}
|
||||
protected override void PopIn() => mainContent.FadeIn(500, Easing.OutQuint);
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
mainContent.FadeOut(300);
|
||||
}
|
||||
protected override void PopOut() => mainContent.FadeOut(300);
|
||||
|
||||
private class InputArea : CompositeDrawable, IKeyBindingHandler<CatchAction>
|
||||
{
|
||||
@ -234,11 +212,11 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
|
||||
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.trackedActions = trackedActions;
|
||||
@ -273,22 +251,24 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
|
||||
public bool OnPressed(KeyBindingPressEvent<CatchAction> _)
|
||||
{
|
||||
if (trackedActions.ContainsValue(handledAction))
|
||||
{
|
||||
isHiglighted = true;
|
||||
overlay.FadeTo(0.5f, 80, Easing.OutQuint);
|
||||
}
|
||||
|
||||
updateHighlight();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnReleased(KeyBindingReleaseEvent<CatchAction> _)
|
||||
{
|
||||
if (isHiglighted && !trackedActions.ContainsValue(handledAction))
|
||||
{
|
||||
isHiglighted = false;
|
||||
overlay.FadeOut(1000, Easing.Out);
|
||||
}
|
||||
updateHighlight();
|
||||
}
|
||||
|
||||
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