mirror of
https://github.com/ppy/osu.git
synced 2025-02-26 06:02:59 +08:00
Fix formatting + Add tests + fix touch UI
This commit is contained in:
parent
09e45f39b2
commit
ff497c452f
45
osu.Game.Rulesets.Catch.Tests/TestSceneCatchTouchInput.cs
Normal file
45
osu.Game.Rulesets.Catch.Tests/TestSceneCatchTouchInput.cs
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -39,7 +39,6 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
KeyBindingInputManager.Add(new TouchInputField());
|
KeyBindingInputManager.Add(new TouchInputField());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override ReplayInputHandler CreateReplayInputHandler(Replay replay) => new CatchFramedReplayInputHandler(replay);
|
protected override ReplayInputHandler CreateReplayInputHandler(Replay replay) => new CatchFramedReplayInputHandler(replay);
|
||||||
|
|
||||||
protected override ReplayRecorder CreateReplayRecorder(Score score) => new CatchReplayRecorder(score, (CatchPlayfield)Playfield);
|
protected override ReplayRecorder CreateReplayRecorder(Score score) => new CatchReplayRecorder(score, (CatchPlayfield)Playfield);
|
||||||
|
@ -50,48 +50,70 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
// Container should handle input everywhere.
|
// Container should handle input everywhere.
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
mainContent = new Container
|
mainContent = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
RelativePositionAxes = Axes.Both,
|
RelativePositionAxes = Axes.Both,
|
||||||
|
Alpha = 0,
|
||||||
Children = new Drawable[]
|
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,
|
Origin = Anchor.CentreLeft,
|
||||||
X = 0,
|
Children = new Drawable[]
|
||||||
RelativePositionAxes = Axes.Both,
|
{
|
||||||
Size = new Vector2(100.0f, 100.0f)
|
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,
|
Origin = Anchor.CentreRight,
|
||||||
X = 0,
|
Children = new Drawable[]
|
||||||
RelativePositionAxes = Axes.Both,
|
{
|
||||||
Size = new Vector2(100.0f, 100.0f),
|
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 @@ 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.
|
||||||
Hide();
|
PopOut();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnMouseDown(MouseDownEvent e)
|
protected override bool OnMouseDown(MouseDownEvent e)
|
||||||
{
|
{
|
||||||
if (getTouchCatchActionFromInput(e.MousePosition) != TouchCatchAction.None)
|
if (getTouchCatchActionFromInput(e.ScreenSpaceMousePosition) == TouchCatchAction.None)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
handleDown(e.Button, e.ScreenSpaceMousePosition);
|
handleDown(e.Button, e.ScreenSpaceMousePosition);
|
||||||
@ -114,14 +136,15 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
|
|
||||||
protected override void OnMouseUp(MouseUpEvent e)
|
protected override void OnMouseUp(MouseUpEvent e)
|
||||||
{
|
{
|
||||||
if (getTouchCatchActionFromInput(e.MousePosition) != TouchCatchAction.None)
|
if (getTouchCatchActionFromInput(e.ScreenSpaceMousePosition) == TouchCatchAction.None)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
handleUp(e.Button);
|
handleUp(e.Button);
|
||||||
base.OnMouseUp(e);
|
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
|
// 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))
|
||||||
@ -132,7 +155,7 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
calculateActiveKeys();
|
calculateActiveKeys();
|
||||||
|
|
||||||
base.OnTouchMove(e);
|
base.OnTouchMove(e);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
protected override bool OnTouchDown(TouchDownEvent e)
|
protected override bool OnTouchDown(TouchDownEvent e)
|
||||||
{
|
{
|
||||||
@ -166,7 +189,7 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
|
|
||||||
private void handleDown(object source, Vector2 position)
|
private void handleDown(object source, Vector2 position)
|
||||||
{
|
{
|
||||||
Show();
|
PopIn();
|
||||||
|
|
||||||
TouchCatchAction catchAction = getTouchCatchActionFromInput(position);
|
TouchCatchAction catchAction = getTouchCatchActionFromInput(position);
|
||||||
|
|
||||||
@ -195,6 +218,7 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
return TouchCatchAction.MoveLeft;
|
return TouchCatchAction.MoveLeft;
|
||||||
if (rightBox.Contains(inputPosition))
|
if (rightBox.Contains(inputPosition))
|
||||||
return TouchCatchAction.MoveRight;
|
return TouchCatchAction.MoveRight;
|
||||||
|
|
||||||
return TouchCatchAction.None;
|
return TouchCatchAction.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +240,7 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
|
|
||||||
private readonly Dictionary<object, TouchCatchAction> trackedActions;
|
private readonly Dictionary<object, TouchCatchAction> trackedActions;
|
||||||
|
|
||||||
private bool isHiglighted = false;
|
private bool isHiglighted;
|
||||||
|
|
||||||
public ArrowHitbox(TouchCatchAction handledAction, ref Dictionary<object, TouchCatchAction> trackedActions, Color4 colour)
|
public ArrowHitbox(TouchCatchAction handledAction, ref Dictionary<object, TouchCatchAction> trackedActions, Color4 colour)
|
||||||
{
|
{
|
||||||
@ -228,7 +252,6 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
Width = 1,
|
Width = 1,
|
||||||
Height = 1,
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -237,13 +260,15 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
Colour = colour.Multiply(1.4f).Darken(2.8f),
|
Colour = colour.Multiply(1.4f).Darken(2.8f),
|
||||||
Blending = BlendingParameters.Additive,
|
Blending = BlendingParameters.Additive,
|
||||||
Size = new Vector2(100.0f, 100.0f),
|
Width = 1,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
Alpha = 0.5f,
|
Alpha = 0.8f,
|
||||||
Colour = colour,
|
Colour = colour,
|
||||||
Size = new Vector2(100.0f, 100.0f),
|
Width = 1,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,6 +282,7 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
isHiglighted = true;
|
isHiglighted = true;
|
||||||
overlay.FadeTo(0.5f, 80, Easing.OutQuint);
|
overlay.FadeTo(0.5f, 80, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user