8
8
using osu . Framework . Input ;
9
9
using osu . Framework . Testing ;
10
10
using osu . Game . Beatmaps ;
11
+ using osu . Game . Rulesets . Osu . Edit . Blueprints . Sliders ;
11
12
using osu . Game . Rulesets . Osu . Objects ;
12
13
using osu . Game . Rulesets . UI ;
13
14
using osu . Game . Screens . Edit . Components . RadioButtons ;
@@ -24,38 +25,93 @@ public partial class TestSceneSliderDrawing : TestSceneOsuEditor
24
25
protected override IBeatmap CreateBeatmap ( RulesetInfo ruleset ) => new TestBeatmap ( ruleset , false ) ;
25
26
26
27
[ Test ]
27
- public void TestTouchInputAfterTouchingComposeArea ( )
28
+ public void TestTouchInputPlaceHitCircleDirectly ( )
29
+ {
30
+ AddStep ( "tap circle" , ( ) => tap ( this . ChildrenOfType < EditorRadioButton > ( ) . Single ( b => b . Button . Label == "HitCircle" ) ) ) ;
31
+
32
+ AddStep ( "tap to place circle" , ( ) => tap ( this . ChildrenOfType < Playfield > ( ) . Single ( ) ) ) ;
33
+ AddAssert ( "circle placed correctly" , ( ) =>
34
+ {
35
+ var circle = ( HitCircle ) EditorBeatmap . HitObjects . Single ( h => h . StartTime == EditorClock . CurrentTimeAccurate ) ;
36
+ Assert . Multiple ( ( ) =>
37
+ {
38
+ Assert . That ( circle . Position . X , Is . EqualTo ( 256f ) . Within ( 0.01f ) ) ;
39
+ Assert . That ( circle . Position . Y , Is . EqualTo ( 192f ) . Within ( 0.01f ) ) ;
40
+ } ) ;
41
+
42
+ return true ;
43
+ } ) ;
44
+ }
45
+
46
+ [ Test ]
47
+ public void TestTouchInputPlaceCircleAfterTouchingComposeArea ( )
28
48
{
29
49
AddStep ( "tap circle" , ( ) => tap ( this . ChildrenOfType < EditorRadioButton > ( ) . Single ( b => b . Button . Label == "HitCircle" ) ) ) ;
30
50
31
- // this input is just for interacting with compose area
32
51
AddStep ( "tap playfield" , ( ) => tap ( this . ChildrenOfType < Playfield > ( ) . Single ( ) ) ) ;
52
+ AddAssert ( "circle placed" , ( ) => EditorBeatmap . HitObjects . Single ( h => h . StartTime == EditorClock . CurrentTimeAccurate ) is HitCircle ) ;
33
53
34
- AddStep ( "move current time " , ( ) => InputManager . Key ( Key . Right ) ) ;
54
+ AddStep ( "move forward " , ( ) => InputManager . Key ( Key . Right ) ) ;
35
55
36
- AddStep ( "tap to place circle" , ( ) => tap ( this . ChildrenOfType < Playfield > ( ) . Single ( ) . ToScreenSpace ( new Vector2 ( 10 , 10 ) ) ) ) ;
56
+ AddStep ( "tap to place circle" , ( ) => tap ( this . ChildrenOfType < Playfield > ( ) . Single ( ) ) ) ;
37
57
AddAssert ( "circle placed correctly" , ( ) =>
38
58
{
39
59
var circle = ( HitCircle ) EditorBeatmap . HitObjects . Single ( h => h . StartTime == EditorClock . CurrentTimeAccurate ) ;
40
60
Assert . Multiple ( ( ) =>
41
61
{
42
- Assert . That ( circle . Position . X , Is . EqualTo ( 10f ) . Within ( 0.01f ) ) ;
43
- Assert . That ( circle . Position . Y , Is . EqualTo ( 10f ) . Within ( 0.01f ) ) ;
62
+ Assert . That ( circle . Position . X , Is . EqualTo ( 256f ) . Within ( 0.01f ) ) ;
63
+ Assert . That ( circle . Position . Y , Is . EqualTo ( 192f ) . Within ( 0.01f ) ) ;
64
+ } ) ;
65
+
66
+ return true ;
67
+ } ) ;
68
+ }
69
+
70
+ [ Test ]
71
+ public void TestTouchInputPlaceSliderDirectly ( )
72
+ {
73
+ AddStep ( "tap slider" , ( ) => tap ( this . ChildrenOfType < EditorRadioButton > ( ) . Single ( b => b . Button . Label == "Slider" ) ) ) ;
74
+
75
+ AddStep ( "hold to draw slider" , ( ) => InputManager . BeginTouch ( new Touch ( TouchSource . Touch1 , this . ChildrenOfType < Playfield > ( ) . Single ( ) . ToScreenSpace ( new Vector2 ( 50 , 20 ) ) ) ) ) ;
76
+ AddStep ( "drag to draw" , ( ) => InputManager . MoveTouchTo ( new Touch ( TouchSource . Touch1 , this . ChildrenOfType < Playfield > ( ) . Single ( ) . ToScreenSpace ( new Vector2 ( 200 , 50 ) ) ) ) ) ;
77
+ AddAssert ( "selection not initiated" , ( ) => this . ChildrenOfType < DragBox > ( ) . All ( d => d . State == Visibility . Hidden ) ) ;
78
+ AddAssert ( "blueprint visible" , ( ) => this . ChildrenOfType < SliderPlacementBlueprint > ( ) . Single ( ) . Alpha > 0 ) ;
79
+ AddStep ( "end" , ( ) => InputManager . EndTouch ( new Touch ( TouchSource . Touch1 , InputManager . CurrentState . Touch . GetTouchPosition ( TouchSource . Touch1 ) ! . Value ) ) ) ;
80
+ AddAssert ( "slider placed correctly" , ( ) =>
81
+ {
82
+ var slider = ( Slider ) EditorBeatmap . HitObjects . Single ( h => h . StartTime == EditorClock . CurrentTimeAccurate ) ;
83
+ Assert . Multiple ( ( ) =>
84
+ {
85
+ Assert . That ( slider . Position . X , Is . EqualTo ( 50f ) . Within ( 0.01f ) ) ;
86
+ Assert . That ( slider . Position . Y , Is . EqualTo ( 20f ) . Within ( 0.01f ) ) ;
87
+ Assert . That ( slider . Path . ControlPoints . Count , Is . EqualTo ( 2 ) ) ;
88
+ Assert . That ( slider . Path . ControlPoints [ 0 ] . Position , Is . EqualTo ( Vector2 . Zero ) ) ;
89
+
90
+ // the final position may be slightly off from the mouse position when drawing, account for that.
91
+ Assert . That ( slider . Path . ControlPoints [ 1 ] . Position . X , Is . EqualTo ( 150 ) . Within ( 5 ) ) ;
92
+ Assert . That ( slider . Path . ControlPoints [ 1 ] . Position . Y , Is . EqualTo ( 30 ) . Within ( 5 ) ) ;
44
93
} ) ;
45
94
46
95
return true ;
47
96
} ) ;
97
+ }
48
98
99
+ [ Test ]
100
+ public void TestTouchInputPlaceSliderAfterTouchingComposeArea ( )
101
+ {
49
102
AddStep ( "tap slider" , ( ) => tap ( this . ChildrenOfType < EditorRadioButton > ( ) . Single ( b => b . Button . Label == "Slider" ) ) ) ;
50
103
51
- // this input is just for interacting with compose area
52
104
AddStep ( "tap playfield" , ( ) => tap ( this . ChildrenOfType < Playfield > ( ) . Single ( ) ) ) ;
105
+ AddStep ( "tap and hold another spot" , ( ) => hold ( this . ChildrenOfType < Playfield > ( ) . Single ( ) , new Vector2 ( 50 , 0 ) ) ) ;
106
+ AddUntilStep ( "wait for slider placement" , ( ) => EditorBeatmap . HitObjects . SingleOrDefault ( h => h . StartTime == EditorClock . CurrentTimeAccurate ) is Slider ) ;
107
+ AddStep ( "end" , ( ) => InputManager . EndTouch ( new Touch ( TouchSource . Touch1 , InputManager . CurrentState . Touch . GetTouchPosition ( TouchSource . Touch1 ) ! . Value ) ) ) ;
53
108
54
- AddStep ( "move current time " , ( ) => InputManager . Key ( Key . Right ) ) ;
109
+ AddStep ( "move forward " , ( ) => InputManager . Key ( Key . Right ) ) ;
55
110
56
111
AddStep ( "hold to draw slider" , ( ) => InputManager . BeginTouch ( new Touch ( TouchSource . Touch1 , this . ChildrenOfType < Playfield > ( ) . Single ( ) . ToScreenSpace ( new Vector2 ( 50 , 20 ) ) ) ) ) ;
57
112
AddStep ( "drag to draw" , ( ) => InputManager . MoveTouchTo ( new Touch ( TouchSource . Touch1 , this . ChildrenOfType < Playfield > ( ) . Single ( ) . ToScreenSpace ( new Vector2 ( 200 , 50 ) ) ) ) ) ;
58
113
AddAssert ( "selection not initiated" , ( ) => this . ChildrenOfType < DragBox > ( ) . All ( d => d . State == Visibility . Hidden ) ) ;
114
+ AddAssert ( "blueprint visible" , ( ) => this . ChildrenOfType < SliderPlacementBlueprint > ( ) . Single ( ) . IsPresent ) ;
59
115
AddStep ( "end" , ( ) => InputManager . EndTouch ( new Touch ( TouchSource . Touch1 , InputManager . CurrentState . Touch . GetTouchPosition ( TouchSource . Touch1 ) ! . Value ) ) ) ;
60
116
AddAssert ( "slider placed correctly" , ( ) =>
61
117
{
@@ -76,12 +132,19 @@ public void TestTouchInputAfterTouchingComposeArea()
76
132
} ) ;
77
133
}
78
134
79
- private void tap ( Drawable drawable ) => tap ( drawable . ScreenSpaceDrawQuad . Centre ) ;
135
+ private void tap ( Drawable drawable , Vector2 offset = default ) => tap ( drawable . ToScreenSpace ( drawable . LayoutRectangle . Centre + offset ) ) ;
80
136
81
137
private void tap ( Vector2 position )
82
138
{
83
- InputManager . BeginTouch ( new Touch ( TouchSource . Touch1 , position ) ) ;
139
+ hold ( position ) ;
84
140
InputManager . EndTouch ( new Touch ( TouchSource . Touch1 , position ) ) ;
85
141
}
142
+
143
+ private void hold ( Drawable drawable , Vector2 offset = default ) => hold ( drawable . ToScreenSpace ( drawable . LayoutRectangle . Centre + offset ) ) ;
144
+
145
+ private void hold ( Vector2 position )
146
+ {
147
+ InputManager . BeginTouch ( new Touch ( TouchSource . Touch1 , position ) ) ;
148
+ }
86
149
}
87
150
}
0 commit comments