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
Add Game::isNoCrosshairAllowed()
The rule about allowing no crosshair is moved into a method.
The (X, Y) calculation for updating shootline when using crosshair is removed for a specific case.
  • Loading branch information
srifqi committed Sep 28, 2022
commit 46aa095395ce75e53b60fdea24df8cbef2828e3f
8 changes: 5 additions & 3 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,9 @@ class Game {
#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;
Expand Down Expand Up @@ -3102,8 +3105,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
shootline.end = shootline.start + camera_direction * BS * d;

#ifdef HAVE_TOUCHSCREENGUI
if (g_touchscreengui && !m_touch_use_crosshair &&
camera->getCameraMode() == CAMERA_MODE_FIRST) {
if (g_touchscreengui && isNoCrosshairAllowed()) {
shootline = g_touchscreengui->getShootline();
// Scale shootline to the acual distance the player can reach
shootline.end = shootline.start +
Expand Down Expand Up @@ -4001,7 +4003,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_touch_use_crosshair && camera->getCameraMode() == CAMERA_MODE_FIRST)
if (isNoCrosshairAllowed())
draw_crosshair = false;
#endif
m_rendering_engine->draw_scene(skycolor, m_game_ui->m_flags.show_hud,
Expand Down
5 changes: 1 addition & 4 deletions src/gui/touchscreengui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,10 +855,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
m_camera_pitch = MYMIN(MYMAX(m_camera_pitch + (dy * d), -180), 180);

// update shootline
if (m_draw_crosshair) {
X = m_screensize.X / 2;
Y = m_screensize.Y / 2;
}
// no need to update (X, Y) when using crosshair since the shootline is not used
m_shootline = m_device
->getSceneManager()
->getSceneCollisionManager()
Expand Down