1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Refactor UI and add drag support

This commit is contained in:
Josh 2022-09-03 02:31:58 +08:00
parent 7168cb27c5
commit 40ff2d50dd
No known key found for this signature in database
GPG Key ID: B8D8E955D50CAA2C
2 changed files with 42 additions and 18 deletions

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Testing; using osu.Framework.Testing;

View File

@ -13,6 +13,7 @@ using osu.Game.Graphics;
using osuTK.Graphics; using osuTK.Graphics;
using osuTK; using osuTK;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Logging;
namespace osu.Game.Rulesets.Catch.UI namespace osu.Game.Rulesets.Catch.UI
{ {
@ -39,10 +40,13 @@ namespace osu.Game.Rulesets.Catch.UI
private ArrowHitbox leftDashBox = null!; private ArrowHitbox leftDashBox = null!;
private ArrowHitbox rightDashBox = null!; private ArrowHitbox rightDashBox = null!;
// Force input to be prossed even when hidden.
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)
{ {
Show();
Debug.Assert(catchInputManager.KeyBindingContainer != null); Debug.Assert(catchInputManager.KeyBindingContainer != null);
keyBindingContainer = catchInputManager.KeyBindingContainer; keyBindingContainer = catchInputManager.KeyBindingContainer;
@ -121,7 +125,7 @@ namespace osu.Game.Rulesets.Catch.UI
protected override bool OnKeyDown(KeyDownEvent e) protected override bool OnKeyDown(KeyDownEvent e)
{ {
// Hide whenever the keyboard is used. // Hide whenever the keyboard is used.
PopOut(); Hide();
return false; return false;
} }
@ -143,19 +147,39 @@ namespace osu.Game.Rulesets.Catch.UI
base.OnMouseUp(e); base.OnMouseUp(e);
} }
/* I plan to come back to this code to add touch support protected override bool OnDragStart(DragStartEvent e)
* protected override void OnTouchMove(TouchMoveEvent e) {
return true;
}
protected override void OnDragEnd(DragEndEvent e)
{
base.OnDragEnd(e);
}
protected override void OnDrag(DragEvent e)
{
// I'm not sure if this is posible but let's be safe
if (!trackedActions.ContainsKey(e.Button))
trackedActions.Add(e.Button, TouchCatchAction.None);
trackedActions[e.Button] = getTouchCatchActionFromInput(e.ScreenSpaceMousePosition);
calculateActiveKeys();
base.OnDrag(e);
}
protected override void OnTouchMove(TouchMoveEvent e)
{ {
// I'm not sure if this is posible but let's be safe // I'm not sure if this is posible but let's be safe
if (!trackedActions.ContainsKey(e.Touch.Source)) if (!trackedActions.ContainsKey(e.Touch.Source))
trackedActions.Add(e.Touch.Source, TouchCatchAction.None); trackedActions.Add(e.Touch.Source, TouchCatchAction.None);
trackedActions[e.Touch.Source] = getTouchCatchActionFromInput(e.MousePosition); trackedActions[e.Touch.Source] = getTouchCatchActionFromInput(e.ScreenSpaceTouchDownPosition);
calculateActiveKeys(); calculateActiveKeys();
base.OnTouchMove(e); base.OnTouchMove(e);
}*/ }
protected override bool OnTouchDown(TouchDownEvent e) protected override bool OnTouchDown(TouchDownEvent e)
{ {
@ -189,7 +213,7 @@ namespace osu.Game.Rulesets.Catch.UI
private void handleDown(object source, Vector2 position) private void handleDown(object source, Vector2 position)
{ {
PopIn(); Show();
TouchCatchAction catchAction = getTouchCatchActionFromInput(position); TouchCatchAction catchAction = getTouchCatchActionFromInput(position);
@ -217,8 +241,10 @@ namespace osu.Game.Rulesets.Catch.UI
if (leftBox.Contains(inputPosition)) if (leftBox.Contains(inputPosition))
return TouchCatchAction.MoveLeft; return TouchCatchAction.MoveLeft;
if (rightBox.Contains(inputPosition)) if (rightBox.Contains(inputPosition))
{
Logger.Log(inputPosition.ToString());
return TouchCatchAction.MoveRight; return TouchCatchAction.MoveRight;
}
return TouchCatchAction.None; return TouchCatchAction.None;
} }
@ -255,20 +281,20 @@ namespace osu.Game.Rulesets.Catch.UI
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
{ {
overlay = new Box
{
Alpha = 0,
Colour = colour.Multiply(1.4f).Darken(2.8f),
Blending = BlendingParameters.Additive,
Width = 1,
RelativeSizeAxes = Axes.Both,
},
new Box new Box
{ {
Alpha = 0.8f, Alpha = 0.8f,
Colour = colour, Colour = colour,
Width = 1, Width = 1,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
},
overlay = new Box
{
Alpha = 0,
Colour = colour.Multiply(1.4f),
Blending = BlendingParameters.Additive,
Width = 1,
RelativeSizeAxes = Axes.Both,
} }
} }
} }