Skip to content

Commit fc3d6c1

Browse files
authored
Place nodes with single tap on Android (+ bugfix) (#13187)
Don't place nodes when closing button bars. Update docs (also in-game). Rename "Default controls" -> "Controls" in Android pause menu since players can't change them (normally), so calling them "default" doesn't make sense.
1 parent 6832bf0 commit fc3d6c1

File tree

4 files changed

+23
-56
lines changed

4 files changed

+23
-56
lines changed

doc/android.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
**This document is based on the Minetest 5.6.1 version for Android**
2-
31
# Minetest Android build
42
All Minetest builds, including the Android variant, are based on the same code.
53
However, additional Java code is used for proper Android integration.
@@ -11,8 +9,8 @@ due to limited capabilities of common devices. What can be done is described bel
119
While you're playing the game normally (that is, no menu or inventory is
1210
shown), the following controls are available:
1311
* Look around: touch screen and slide finger
14-
* Double tap: Place a node
15-
* Long tap: Dig node or use the holding item
12+
* Tap: Place a node
13+
* Long tap: Dig node or use the held item
1614
* Press back: Pause menu
1715
* Touch buttons: Press button
1816
* Buttons:
@@ -33,9 +31,8 @@ When a menu or inventory is displayed:
3331
--> places a single item from dragged stack into current (first touched) slot. If a stack is selected, the stack will be split as half and one of the splitted stack will be selected
3432

3533
### Limitations
36-
* Android player have to double tap to place node, this can be annoying in some game/mod
3734
* Some old Android device only support 2 touch at a time, some game/mod contain button combination that need 3 touch (example: jump + Aux1 + hold)
38-
* Complicated control like pick up an cart in MTG can be difficult or impossible on Android device
35+
* Complicated control can be difficult or impossible on Android device
3936

4037
## File Path
4138
There are some settings especially useful for Android users. The Minetest-wide

src/client/game.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4335,14 +4335,14 @@ void Game::showDeathFormspec()
43354335
void Game::showPauseMenu()
43364336
{
43374337
#ifdef HAVE_TOUCHSCREENGUI
4338-
static const std::string control_text = strgettext("Default Controls:\n"
4339-
"No menu visible:\n"
4340-
"- single tap: button activate\n"
4341-
"- double tap: place/use\n"
4338+
static const std::string control_text = strgettext("Controls:\n"
4339+
"No menu open:\n"
43424340
"- slide finger: look around\n"
4343-
"Menu/Inventory visible:\n"
4341+
"- tap: place/use\n"
4342+
"- long tap: dig/punch/use\n"
4343+
"Menu/inventory open:\n"
43444344
"- double tap (outside):\n"
4345-
" -->close\n"
4345+
" --> close\n"
43464346
"- touch stack, touch slot:\n"
43474347
" --> move stack\n"
43484348
"- touch&drag, tap 2nd finger\n"

src/gui/touchscreengui.cpp

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,8 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id)
692692
}
693693
m_receiver->OnEvent(*translated);
694694
delete translated;
695-
} else {
696-
// do double tap detection
697-
doubleTapDetection();
695+
} else if (!m_move_has_really_moved) {
696+
doRightClick();
698697
}
699698
}
700699

@@ -773,8 +772,11 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
773772
// already handled in isSettingsBarButton()
774773
} else {
775774
// handle non button events
776-
m_settingsbar.deactivate();
777-
m_rarecontrolsbar.deactivate();
775+
if (m_settingsbar.active() || m_rarecontrolsbar.active()) {
776+
m_settingsbar.deactivate();
777+
m_rarecontrolsbar.deactivate();
778+
return;
779+
}
778780

779781
s32 dxj = event.TouchInput.X - button_size * 5.0f / 2.0f;
780782
s32 dyj = event.TouchInput.Y - (s32)m_screensize.Y + button_size * 5.0f / 2.0f;
@@ -999,29 +1001,9 @@ void TouchScreenGUI::handleChangedButton(const SEvent &event)
9991001
event.TouchInput.ID, true);
10001002
}
10011003

1002-
bool TouchScreenGUI::doubleTapDetection()
1004+
bool TouchScreenGUI::doRightClick()
10031005
{
1004-
m_key_events[0].down_time = m_key_events[1].down_time;
1005-
m_key_events[0].x = m_key_events[1].x;
1006-
m_key_events[0].y = m_key_events[1].y;
1007-
m_key_events[1].down_time = m_move_downtime;
1008-
m_key_events[1].x = m_move_downlocation.X;
1009-
m_key_events[1].y = m_move_downlocation.Y;
1010-
1011-
u64 delta = porting::getDeltaMs(m_key_events[0].down_time, porting::getTimeMs());
1012-
if (delta > 400)
1013-
return false;
1014-
1015-
double distance = sqrt(
1016-
(m_key_events[0].x - m_key_events[1].x) *
1017-
(m_key_events[0].x - m_key_events[1].x) +
1018-
(m_key_events[0].y - m_key_events[1].y) *
1019-
(m_key_events[0].y - m_key_events[1].y));
1020-
1021-
if (distance > (20 + m_touchscreen_threshold))
1022-
return false;
1023-
1024-
v2s32 mPos = v2s32(m_key_events[0].x, m_key_events[0].y);
1006+
v2s32 mPos = v2s32(m_move_downlocation.X, m_move_downlocation.Y);
10251007
if (m_draw_crosshair) {
10261008
mPos.X = m_screensize.X / 2;
10271009
mPos.Y = m_screensize.Y / 2;
@@ -1111,10 +1093,6 @@ void TouchScreenGUI::step(float dtime)
11111093
if (!button.ids.empty()) {
11121094
button.repeatcounter += dtime;
11131095

1114-
// in case we're moving around digging does not happen
1115-
if (m_has_move_id)
1116-
m_move_has_really_moved = true;
1117-
11181096
if (button.repeatcounter < button.repeatdelay)
11191097
continue;
11201098

src/gui/touchscreengui.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class AutoHideButtonBar
130130
// step handler
131131
void step(float dtime);
132132

133+
// return whether the button bar is active
134+
bool active() { return m_active; }
135+
133136
// deactivate button bar
134137
void deactivate();
135138

@@ -284,29 +287,18 @@ class TouchScreenGUI
284287
// handle pressed hud buttons
285288
bool isHUDButton(const SEvent &event);
286289

287-
// handle double taps
288-
bool doubleTapDetection();
290+
// do a right-click
291+
bool doRightClick();
289292

290293
// handle release event
291294
void handleReleaseEvent(size_t evt_id);
292295

293296
// apply joystick status
294297
void applyJoystickStatus();
295298

296-
// double-click detection variables
297-
struct key_event
298-
{
299-
u64 down_time;
300-
s32 x;
301-
s32 y;
302-
};
303-
304299
// array for saving last known position of a pointer
305300
std::map<size_t, v2s32> m_pointerpos;
306301

307-
// array for double tap detection
308-
key_event m_key_events[2];
309-
310302
// settings bar
311303
AutoHideButtonBar m_settingsbar;
312304

0 commit comments

Comments
 (0)