@@ -50,18 +50,23 @@ MobileController::MobileController() :
50
50
m_right(false ),
51
51
m_jump(false ),
52
52
m_action(false ),
53
+ m_cheats(false ),
54
+ m_debug(false ),
53
55
m_escape(false ),
54
- m_bak_escape(false ),
55
56
m_old_up(false ),
56
57
m_old_down(false ),
57
58
m_old_left(false ),
58
59
m_old_right(false ),
59
60
m_old_jump(false ),
60
61
m_old_action(false ),
62
+ m_old_cheats(false ),
63
+ m_old_debug(false ),
61
64
m_old_escape(false ),
62
65
m_rect_directions(16 .f, -144 .f, 144 .f, -16 .f),
63
66
m_rect_jump(-160 .f, -80 .f, -96 .f, -16 .f),
64
67
m_rect_action(-80 .f, -80 .f, -16 .f, -16 .f),
68
+ m_rect_cheats(-160 .f, 16 .f, -96 .f, 80 .f),
69
+ m_rect_debug(-80 .f, 16 .f, -16 .f, 80 .f),
65
70
m_rect_escape(16 .f, 16 .f, 64 .f, 64 .f),
66
71
m_tex_dirs(Surface::from_file(" /images/engine/mobile/direction.png" )),
67
72
m_tex_btn(Surface::from_file(" /images/engine/mobile/button.png" )),
@@ -73,6 +78,8 @@ MobileController::MobileController() :
73
78
m_tex_rgt(Surface::from_file(" /images/engine/mobile/direction_hightlight_right.png" )),
74
79
m_tex_jump(Surface::from_file(" /images/engine/mobile/jump.png" )),
75
80
m_tex_action(Surface::from_file(" /images/engine/mobile/action.png" )),
81
+ m_tex_cheats(Surface::from_file(" /images/engine/mobile/cheats.png" )),
82
+ m_tex_debug(Surface::from_file(" /images/engine/mobile/debug.png" )),
76
83
m_screen_width(),
77
84
m_screen_height()
78
85
{
@@ -87,25 +94,34 @@ MobileController::draw(DrawingContext& context)
87
94
m_screen_width = context.get_width ();
88
95
m_screen_height = context.get_height ();
89
96
90
- context.color ().draw_surface_scaled (m_tex_dirs, apply_corner (m_rect_directions, m_screen_width, m_screen_height), 1650 );
97
+ context.color ().draw_surface_scaled (m_tex_dirs, apply_corner (m_rect_directions, m_screen_width, m_screen_height), LAYER_GUI + 99 );
91
98
92
99
if (m_up)
93
- context.color ().draw_surface_scaled (m_tex_up, apply_corner (m_rect_directions, m_screen_width, m_screen_height), 1651 );
100
+ context.color ().draw_surface_scaled (m_tex_up, apply_corner (m_rect_directions, m_screen_width, m_screen_height), LAYER_GUI + 99 );
94
101
if (m_down)
95
- context.color ().draw_surface_scaled (m_tex_dwn, apply_corner (m_rect_directions, m_screen_width, m_screen_height), 1651 );
102
+ context.color ().draw_surface_scaled (m_tex_dwn, apply_corner (m_rect_directions, m_screen_width, m_screen_height), LAYER_GUI + 99 );
96
103
if (m_left)
97
- context.color ().draw_surface_scaled (m_tex_lft, apply_corner (m_rect_directions, m_screen_width, m_screen_height), 1651 );
104
+ context.color ().draw_surface_scaled (m_tex_lft, apply_corner (m_rect_directions, m_screen_width, m_screen_height), LAYER_GUI + 99 );
98
105
if (m_right)
99
- context.color ().draw_surface_scaled (m_tex_rgt, apply_corner (m_rect_directions, m_screen_width, m_screen_height), 1651 );
106
+ context.color ().draw_surface_scaled (m_tex_rgt, apply_corner (m_rect_directions, m_screen_width, m_screen_height), LAYER_GUI + 99 );
100
107
101
- context.color ().draw_surface_scaled (m_action ? m_tex_btn_press : m_tex_btn, apply_corner (m_rect_action, m_screen_width, m_screen_height), 1650 );
102
- context.color ().draw_surface_scaled (m_tex_action, apply_corner (m_rect_action, m_screen_width, m_screen_height), 1651 );
108
+ context.color ().draw_surface_scaled (m_action ? m_tex_btn_press : m_tex_btn, apply_corner (m_rect_action, m_screen_width, m_screen_height), LAYER_GUI + 99 );
109
+ context.color ().draw_surface_scaled (m_tex_action, apply_corner (m_rect_action, m_screen_width, m_screen_height), LAYER_GUI + 99 );
103
110
104
- context.color ().draw_surface_scaled (m_jump ? m_tex_btn_press : m_tex_btn, apply_corner (m_rect_jump, m_screen_width, m_screen_height), 1650 );
105
- context.color ().draw_surface_scaled (m_tex_jump, apply_corner (m_rect_jump, m_screen_width, m_screen_height), 1651 );
111
+ context.color ().draw_surface_scaled (m_jump ? m_tex_btn_press : m_tex_btn, apply_corner (m_rect_jump, m_screen_width, m_screen_height), LAYER_GUI + 99 );
112
+ context.color ().draw_surface_scaled (m_tex_jump, apply_corner (m_rect_jump, m_screen_width, m_screen_height), LAYER_GUI + 99 );
106
113
107
- context.color ().draw_surface_scaled (m_bak_escape ? m_tex_btn_press : m_tex_btn, apply_corner (m_rect_escape, m_screen_width, m_screen_height), 1650 );
108
- context.color ().draw_surface_scaled (m_tex_pause, apply_corner (m_rect_escape, m_screen_width, m_screen_height).grown (-8 .f ), 1650 );
114
+ context.color ().draw_surface_scaled (m_escape ? m_tex_btn_press : m_tex_btn, apply_corner (m_rect_escape, m_screen_width, m_screen_height), LAYER_GUI + 99 );
115
+ context.color ().draw_surface_scaled (m_tex_pause, apply_corner (m_rect_escape, m_screen_width, m_screen_height).grown (-8 .f ), LAYER_GUI + 99 );
116
+
117
+ if (g_config->developer_mode )
118
+ {
119
+ context.color ().draw_surface_scaled (m_cheats ? m_tex_btn_press : m_tex_btn, apply_corner (m_rect_cheats, m_screen_width, m_screen_height), LAYER_GUI + 99 );
120
+ context.color ().draw_surface_scaled (m_tex_cheats, apply_corner (m_rect_cheats, m_screen_width, m_screen_height), LAYER_GUI + 99 );
121
+
122
+ context.color ().draw_surface_scaled (m_debug ? m_tex_btn_press : m_tex_btn, apply_corner (m_rect_debug, m_screen_width, m_screen_height), LAYER_GUI + 99 );
123
+ context.color ().draw_surface_scaled (m_tex_debug, apply_corner (m_rect_debug, m_screen_width, m_screen_height), LAYER_GUI + 99 );
124
+ }
109
125
}
110
126
111
127
void
@@ -120,9 +136,19 @@ MobileController::update()
120
136
m_old_right = m_right;
121
137
m_old_jump = m_jump;
122
138
m_old_action = m_action;
139
+ m_old_cheats = m_cheats;
140
+ m_old_debug = m_debug;
123
141
m_old_escape = m_escape;
124
142
125
- m_up = m_down = m_left = m_right = m_jump = m_action = m_escape = false ;
143
+ m_up = m_down = m_left = m_right = m_jump = m_action = m_cheats = m_debug = m_escape = false ;
144
+
145
+ // Allow using on-screen controls with the mouse
146
+ int x, y;
147
+ auto buttons = SDL_GetMouseState (&x, &y);
148
+ if ((buttons & SDL_BUTTON_LMASK) != 0 )
149
+ {
150
+ activate_widget_at_pos (static_cast <float >(x), static_cast <float >(y));
151
+ }
126
152
127
153
// FIXME: This assumes that 1) there is only one touchscreen and 2) SuperTux
128
154
// fills the whole screen
@@ -136,12 +162,6 @@ MobileController::update()
136
162
137
163
int num_touches = SDL_GetNumTouchFingers (device);
138
164
139
- // FIXME: There's some weird problem with the escape button specifically, which
140
- // I had to patch a weird way. If someone in the future finds a fix to handle
141
- // escaping on mobile properly, don't forget to remove those lines.
142
- if (num_touches == 0 )
143
- m_bak_escape = false ;
144
-
145
165
for (int i = 0 ; i < num_touches; i++)
146
166
{
147
167
SDL_Finger* finger = SDL_GetTouchFinger (device, i);
@@ -159,13 +179,24 @@ MobileController::apply(Controller& controller) const
159
179
if (!g_config->mobile_controls )
160
180
return ;
161
181
162
- controller.set_control (Control::UP, m_up || (!m_old_up && controller.hold (Control::UP)));
163
- controller.set_control (Control::DOWN, m_down || (!m_old_down && controller.hold (Control::DOWN)));
164
- controller.set_control (Control::LEFT, m_left || (!m_old_left && controller.hold (Control::LEFT)));
165
- controller.set_control (Control::RIGHT, m_right || (!m_old_right && controller.hold (Control::RIGHT)));
166
- controller.set_control (Control::JUMP, m_jump || (!m_old_jump && controller.hold (Control::JUMP)));
167
- controller.set_control (Control::ACTION, m_action || (!m_old_action && controller.hold (Control::ACTION)));
168
- controller.set_control (Control::ESCAPE, m_escape || (!m_old_escape && controller.hold (Control::ESCAPE)));
182
+ if (m_up != m_old_up)
183
+ controller.set_control (Control::UP, m_up);
184
+ if (m_down != m_old_down)
185
+ controller.set_control (Control::DOWN, m_down);
186
+ if (m_left != m_old_left)
187
+ controller.set_control (Control::LEFT, m_left);
188
+ if (m_right != m_old_right)
189
+ controller.set_control (Control::RIGHT, m_right);
190
+ if (m_jump != m_old_jump)
191
+ controller.set_control (Control::JUMP, m_jump);
192
+ if (m_action != m_old_action)
193
+ controller.set_control (Control::ACTION, m_action);
194
+ if (m_cheats != m_old_cheats)
195
+ controller.set_control (Control::CHEAT_MENU, m_cheats);
196
+ if (m_debug != m_old_debug)
197
+ controller.set_control (Control::DEBUG_MENU, m_debug);
198
+ if (m_escape != m_old_escape)
199
+ controller.set_control (Control::ESCAPE, m_escape);
169
200
}
170
201
171
202
void
@@ -182,20 +213,18 @@ MobileController::activate_widget_at_pos(float x, float y)
182
213
if (apply_corner (m_rect_action, m_screen_width, m_screen_height).contains (pos))
183
214
m_action = true ;
184
215
185
- // FIXME: Why do I need an extra variable (m_bak_escape) just for this one?
186
- // Without it, pressing escape will toggle pressed() (not hold(), pressed())
187
- // every single frame, apparently
188
- if (apply_corner (m_rect_escape, m_screen_width, m_screen_height).contains (pos))
189
- {
190
- if (!m_bak_escape)
191
- m_escape = true ;
192
- m_bak_escape = true ;
193
- }
194
- else
216
+ if (g_config->developer_mode )
195
217
{
196
- m_bak_escape = false ;
218
+ if (apply_corner (m_rect_cheats, m_screen_width, m_screen_height).contains (pos))
219
+ m_cheats = true ;
220
+
221
+ if (apply_corner (m_rect_debug, m_screen_width, m_screen_height).contains (pos))
222
+ m_debug = true ;
197
223
}
198
224
225
+ if (apply_corner (m_rect_escape, m_screen_width, m_screen_height).contains (pos))
226
+ m_escape = true ;
227
+
199
228
Rectf applied = apply_corner (m_rect_directions, m_screen_width, m_screen_height);
200
229
Rectf up = applied;
201
230
up.set_bottom (up.get_bottom () - up.get_height () * 2 .f / 3 .f );
0 commit comments