Fix formatting + Add tests + fix touch UI

This commit is contained in:
Josh 2022-08-15 17:23:29 +08:00
parent 09e45f39b2
commit ff497c452f
3 changed files with 110 additions and 40 deletions

View File

@ -0,0 +1,45 @@
// 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.
#nullable disable
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets.Catch.UI;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Catch.Tests
{
[TestFixture]
public class TestSceneCatchTouchInput : OsuTestScene
{
private TouchInputField touchInputField = null!;
[SetUpSteps]
public void SetUpSteps()
{
AddStep("create inputfield", () =>
{
Child = new CatchInputManager(new CatchRuleset().RulesetInfo)
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
touchInputField = new TouchInputField
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
}
}
};
});
}
[Test]
public void TestInputField()
{
AddStep("show inputfield", () => touchInputField.Show());
}
}
}

View File

@ -39,7 +39,6 @@ private void load()
KeyBindingInputManager.Add(new TouchInputField());
}
protected override ReplayInputHandler CreateReplayInputHandler(Replay replay) => new CatchFramedReplayInputHandler(replay);
protected override ReplayRecorder CreateReplayRecorder(Score score) => new CatchReplayRecorder(score, (CatchPlayfield)Playfield);

View File

@ -50,48 +50,70 @@ private void load(CatchInputManager catchInputManager, OsuColour colours)
// Container should handle input everywhere.
RelativeSizeAxes = Axes.Both;
Children = new Drawable[]
{
mainContent = new Container
{
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Alpha = 0,
Children = new Drawable[]
{
leftBox = new ArrowHitbox(TouchCatchAction.MoveLeft, ref trackedActions, colours.Blue)
new Container
{
Anchor = Anchor.TopLeft,
RelativeSizeAxes = Axes.Both,
Width = 0.15f,
Height = 1,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
X = 0,
RelativePositionAxes = Axes.Both,
Size = new Vector2(100.0f, 100.0f)
Children = new Drawable[]
{
leftBox = new ArrowHitbox(TouchCatchAction.MoveLeft, ref trackedActions, colours.Gray2)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Width = 0.5f,
},
leftDashBox = new ArrowHitbox(TouchCatchAction.DashLeft, ref trackedActions, colours.Gray3)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Width = 0.5f,
}
}
},
rightBox = new ArrowHitbox(TouchCatchAction.MoveRight, ref trackedActions, colours.Blue)
new Container
{
Anchor = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
Width = 0.15f,
Height = 1,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
X = 0,
RelativePositionAxes = Axes.Both,
Size = new Vector2(100.0f, 100.0f),
Children = new Drawable[]
{
rightBox = new ArrowHitbox(TouchCatchAction.MoveRight, ref trackedActions, colours.Gray2)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Width = 0.5f,
},
rightDashBox = new ArrowHitbox(TouchCatchAction.DashRight, ref trackedActions, colours.Gray3)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Width = 0.5f,
},
}
},
leftDashBox = new ArrowHitbox(TouchCatchAction.DashLeft, ref trackedActions, colours.Pink)
{
Anchor = Anchor.TopLeft,
Origin = Anchor.CentreLeft,
X = 0.1f,
RelativePositionAxes = Axes.Both,
Size = new Vector2(100.0f, 100.0f),
},
rightDashBox = new ArrowHitbox(TouchCatchAction.DashRight, ref trackedActions, colours.Pink)
{
Anchor = Anchor.TopRight,
Origin = Anchor.CentreRight,
X = -0.1f,
RelativePositionAxes = Axes.Both,
Size = new Vector2(100.0f, 100.0f),
},
}
},
},
};
}
@ -99,13 +121,13 @@ private void load(CatchInputManager catchInputManager, OsuColour colours)
protected override bool OnKeyDown(KeyDownEvent e)
{
// Hide whenever the keyboard is used.
Hide();
PopOut();
return false;
}
protected override bool OnMouseDown(MouseDownEvent e)
{
if (getTouchCatchActionFromInput(e.MousePosition) != TouchCatchAction.None)
if (getTouchCatchActionFromInput(e.ScreenSpaceMousePosition) == TouchCatchAction.None)
return false;
handleDown(e.Button, e.ScreenSpaceMousePosition);
@ -114,14 +136,15 @@ protected override bool OnMouseDown(MouseDownEvent e)
protected override void OnMouseUp(MouseUpEvent e)
{
if (getTouchCatchActionFromInput(e.MousePosition) != TouchCatchAction.None)
if (getTouchCatchActionFromInput(e.ScreenSpaceMousePosition) == TouchCatchAction.None)
return;
handleUp(e.Button);
base.OnMouseUp(e);
}
protected override void OnTouchMove(TouchMoveEvent e)
/* I plan to come back to this code to add touch support
* protected override void OnTouchMove(TouchMoveEvent e)
{
// I'm not sure if this is posible but let's be safe
if (!trackedActions.ContainsKey(e.Touch.Source))
@ -132,7 +155,7 @@ protected override void OnTouchMove(TouchMoveEvent e)
calculateActiveKeys();
base.OnTouchMove(e);
}
}*/
protected override bool OnTouchDown(TouchDownEvent e)
{
@ -166,7 +189,7 @@ private void calculateActiveKeys()
private void handleDown(object source, Vector2 position)
{
Show();
PopIn();
TouchCatchAction catchAction = getTouchCatchActionFromInput(position);
@ -195,6 +218,7 @@ private TouchCatchAction getTouchCatchActionFromInput(Vector2 inputPosition)
return TouchCatchAction.MoveLeft;
if (rightBox.Contains(inputPosition))
return TouchCatchAction.MoveRight;
return TouchCatchAction.None;
}
@ -216,7 +240,7 @@ private class ArrowHitbox : CompositeDrawable, IKeyBindingHandler<CatchAction>
private readonly Dictionary<object, TouchCatchAction> trackedActions;
private bool isHiglighted = false;
private bool isHiglighted;
public ArrowHitbox(TouchCatchAction handledAction, ref Dictionary<object, TouchCatchAction> trackedActions, Color4 colour)
{
@ -228,7 +252,6 @@ public ArrowHitbox(TouchCatchAction handledAction, ref Dictionary<object, TouchC
new Container
{
Width = 1,
Height = 1,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
@ -237,13 +260,15 @@ public ArrowHitbox(TouchCatchAction handledAction, ref Dictionary<object, TouchC
Alpha = 0,
Colour = colour.Multiply(1.4f).Darken(2.8f),
Blending = BlendingParameters.Additive,
Size = new Vector2(100.0f, 100.0f),
Width = 1,
RelativeSizeAxes = Axes.Both,
},
new Box
{
Alpha = 0.5f,
Alpha = 0.8f,
Colour = colour,
Size = new Vector2(100.0f, 100.0f),
Width = 1,
RelativeSizeAxes = Axes.Both,
}
}
}
@ -257,6 +282,7 @@ public bool OnPressed(KeyBindingPressEvent<CatchAction> _)
isHiglighted = true;
overlay.FadeTo(0.5f, 80, Easing.OutQuint);
}
return false;
}