aboutsummaryrefslogtreecommitdiff
path: root/src/client/game.cpp
diff options
context:
space:
mode:
authorMuhammad Rifqi Priyo Susanto <muhammadrifqipriyosusanto@gmail.com>2022-09-30 01:30:33 +0700
committerGitHub <noreply@github.com>2022-09-29 20:30:33 +0200
commit3978b9b8ed1c318c3f9a088beb331c26bca6de6b (patch)
tree1745718c8c7995ac6fdcaa2b7acf356c86506a2c /src/client/game.cpp
parentb1233056b76aa803123cc304d323887ad5fdfbae (diff)
downloadminetest-3978b9b8ed1c318c3f9a088beb331c26bca6de6b.tar.xz
Add crosshair support for Android (#7865)
If enabled, a crosshair will be shown to select object. This will give Android players a way to play like they play on desktop. On third-person back camera mode, player is forced to use crosshair. On third-person front camera mode, player is unable to select anything. Co-authored-by: ROllerozxa <temporaryemail4meh+github@gmail.com> Co-authored-by: rubenwardy <rw@rubenwardy.com>
Diffstat (limited to 'src/client/game.cpp')
-rw-r--r--src/client/game.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/client/game.cpp b/src/client/game.cpp
index acf54d557..d484e8193 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -920,6 +920,10 @@ private:
#ifdef HAVE_TOUCHSCREENGUI
bool m_cache_hold_aux1;
+ bool m_touch_use_crosshair;
+ inline bool isNoCrosshairAllowed() {
+ return !m_touch_use_crosshair && camera->getCameraMode() == CAMERA_MODE_FIRST;
+ }
#endif
#ifdef __ANDROID__
bool m_android_chat_open;
@@ -1051,6 +1055,10 @@ bool Game::startup(bool *kill,
m_invert_mouse = g_settings->getBool("invert_mouse");
m_first_loop_after_window_activation = true;
+#ifdef HAVE_TOUCHSCREENGUI
+ m_touch_use_crosshair = g_settings->getBool("touch_use_crosshair");
+#endif
+
g_client_translations->clear();
// address can change if simple_singleplayer_mode
@@ -2981,6 +2989,11 @@ void Game::updateCamera(f32 dtime)
camera->toggleCameraMode();
+#ifdef HAVE_TOUCHSCREENGUI
+ if (g_touchscreengui)
+ g_touchscreengui->setUseCrosshair(!isNoCrosshairAllowed());
+#endif
+
// Make the player visible depending on camera mode.
playercao->updateMeshCulling();
playercao->setChildrenVisible(camera->getCameraMode() > CAMERA_MODE_FIRST);
@@ -3091,16 +3104,14 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
shootline.end = shootline.start + camera_direction * BS * d;
#ifdef HAVE_TOUCHSCREENGUI
-
- if ((g_settings->getBool("touchtarget")) && (g_touchscreengui)) {
+ if (g_touchscreengui && isNoCrosshairAllowed()) {
shootline = g_touchscreengui->getShootline();
// Scale shootline to the acual distance the player can reach
- shootline.end = shootline.start
- + shootline.getVector().normalize() * BS * d;
+ shootline.end = shootline.start +
+ shootline.getVector().normalize() * BS * d;
shootline.start += intToFloat(camera_offset, BS);
shootline.end += intToFloat(camera_offset, BS);
}
-
#endif
PointedThing pointed = updatePointedThing(shootline,
@@ -3991,10 +4002,8 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
(player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
(camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT));
#ifdef HAVE_TOUCHSCREENGUI
- try {
- draw_crosshair = !g_settings->getBool("touchtarget");
- } catch (SettingNotFoundException) {
- }
+ if (isNoCrosshairAllowed())
+ draw_crosshair = false;
#endif
m_rendering_engine->draw_scene(skycolor, m_game_ui->m_flags.show_hud,
m_game_ui->m_flags.show_minimap, draw_wield_tool, draw_crosshair);