Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crosshair support for Android #7865

Merged
merged 7 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove touch target setting
Crosshair is for all touch screen GUI (not necessarily Android).
Rename variable: m_android_use_crosshair -> m_touch_use_crosshair
  • Loading branch information
srifqi committed Sep 28, 2022
commit 0ea601dd50befb716c78d4b2ecbf0e04261abed5
4 changes: 0 additions & 4 deletions builtin/mainmenu/tab_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,6 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
core.show_keys_menu()
return true
end
if fields["cb_touchscreen_target"] then
core.settings:set("touchtarget", fields["cb_touchscreen_target"])
return true
end

--Note dropdowns have to be handled LAST!
local ddhandled = false
Expand Down
2 changes: 1 addition & 1 deletion builtin/settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ mouse_sensitivity (Mouse sensitivity) float 0.2 0.001 10.0
# The length in pixels it takes for touch screen interaction to start.
touchscreen_threshold (Touch screen threshold) int 20 0 100

# (Android) Use crosshair to select object instead of whole screen.
# Use crosshair to select object instead of whole screen.
# If enabled, a crosshair will be shown and will be used for selecting object.
touch_use_crosshair (Use crosshair for touch screen) bool false

Expand Down
12 changes: 5 additions & 7 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,7 @@ class Game {

#ifdef HAVE_TOUCHSCREENGUI
bool m_cache_hold_aux1;
bool m_android_touchtarget;
bool m_android_use_crosshair;
bool m_touch_use_crosshair;
#endif
#ifdef __ANDROID__
bool m_android_chat_open;
Expand Down Expand Up @@ -1054,8 +1053,7 @@ bool Game::startup(bool *kill,
m_first_loop_after_window_activation = true;

#ifdef HAVE_TOUCHSCREENGUI
m_android_touchtarget = g_settings->getBool("touchtarget");
m_android_use_crosshair = g_settings->getBool("touch_use_crosshair");
m_touch_use_crosshair = g_settings->getBool("touch_use_crosshair");
#endif

g_client_translations->clear();
Expand Down Expand Up @@ -2990,7 +2988,7 @@ void Game::updateCamera(f32 dtime)

#ifdef HAVE_TOUCHSCREENGUI
if (g_touchscreengui)
g_touchscreengui->setUseCrosshair(m_android_use_crosshair ||
g_touchscreengui->setUseCrosshair(m_touch_use_crosshair ||
camera->getCameraMode() == CAMERA_MODE_THIRD);
srifqi marked this conversation as resolved.
Show resolved Hide resolved
#endif

Expand Down Expand Up @@ -3104,7 +3102,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
shootline.end = shootline.start + camera_direction * BS * d;

#ifdef HAVE_TOUCHSCREENGUI
if (m_android_touchtarget && g_touchscreengui && !m_android_use_crosshair &&
if (g_touchscreengui && !m_touch_use_crosshair &&
camera->getCameraMode() == CAMERA_MODE_FIRST) {
shootline = g_touchscreengui->getShootline();
// Scale shootline to the acual distance the player can reach
Expand Down Expand Up @@ -4003,7 +4001,7 @@ 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
if (!m_android_use_crosshair && camera->getCameraMode() == CAMERA_MODE_FIRST)
if (!m_touch_use_crosshair && camera->getCameraMode() == CAMERA_MODE_FIRST)
TurkeyMcMac marked this conversation as resolved.
Show resolved Hide resolved
draw_crosshair = false;
#endif
m_rendering_engine->draw_scene(skycolor, m_game_ui->m_flags.show_hud,
Expand Down
1 change: 0 additions & 1 deletion src/defaultsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ void set_default_settings()
#endif

#ifdef HAVE_TOUCHSCREENGUI
settings->setDefault("touchtarget", "true");
settings->setDefault("touchscreen_threshold","20");
settings->setDefault("touch_use_crosshair", "false");
settings->setDefault("fixed_virtual_joystick", "false");
Expand Down
1 change: 0 additions & 1 deletion src/gui/touchscreengui.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "client/tile.h"
#include "client/game.h"
#include "client/camera.h"

using namespace irr;
using namespace irr::core;
Expand Down