Add touch input router for mobile (step 3)

Route each finger to UI, the attack button, a floating lower-left joystick or
the camera (drag rotate, pinch zoom, tap = world click). Touch mode is default
on Android/iOS and available on desktop via --touch / AVA2_TOUCH=1; it disables
SDL touch-to-mouse and drives app.ENABLE_MOBILE_HUD. The joystick feeds the
original camera-relative movement path and the attack button sets the same
attack-key state as player.SetAttackKeyState. New `touch` Python module; the
mobile HUD joystick and combat wheel become display-only.

Tests: ava2.touch_router, ava2.touch_game (GameWindow + mobile HUD).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 19:46:24 +09:00
co-authored by Claude Opus 5.5
parent 1dfdcba739
commit 5597842d90
18 changed files with 978 additions and 103 deletions
+20 -12
View File
@@ -972,11 +972,15 @@ void UseGuildSkill(int skillSlot) {
static bool s_isAtkKey = false;
static std::array<bool, 256> s_movementKeys{};
static bool s_joystickActive = false;
static float s_joystickX = 0.0f, s_joystickY = 0.0f;
bool GetPlayerMovementYaw(float cameraYaw, float& movementYaw) {
const int x = int(s_movementKeys[32] || s_movementKeys[205]) - int(s_movementKeys[30] || s_movementKeys[203]);
const int z = int(s_movementKeys[31] || s_movementKeys[208]) - int(s_movementKeys[17] || s_movementKeys[200]);
if (!x && !z) return false;
movementYaw = std::atan2(float(x), float(z)) * 180.0f / 3.14159265f - cameraYaw;
float x = float(int(s_movementKeys[32] || s_movementKeys[205]) - int(s_movementKeys[30] || s_movementKeys[203]));
float z = float(int(s_movementKeys[31] || s_movementKeys[208]) - int(s_movementKeys[17] || s_movementKeys[200]));
// Joystick screen-down is "back" like DIK_S, so it maps onto the same camera-relative axes.
if (s_joystickActive) { x = s_joystickX; z = s_joystickY; }
if (x == 0.0f && z == 0.0f) return false;
movementYaw = std::atan2(x, z) * 180.0f / 3.14159265f - cameraYaw;
movementYaw = std::fmod(movementYaw + 720.0f, 360.0f);
return true;
}
@@ -2513,7 +2517,9 @@ static int s_mouseFunc[8] = {0};
static int s_mouseState[8] = {0};
bool IsPlayerMouseMoving() { return s_mouseState[0] == 1 && (s_mouseFunc[0] == 0 || s_mouseFunc[0] == 1); }
bool IsPlayerCameraDragging() { return s_mouseState[1] == 1 && s_mouseFunc[1] == 2; }
void CancelPlayerMovement() { s_movementKeys.fill(false); std::fill(std::begin(s_mouseState),std::end(s_mouseState),0); }
void CancelPlayerMovement() { s_movementKeys.fill(false); s_joystickActive=false; std::fill(std::begin(s_mouseState),std::end(s_mouseState),0); }
void SetPlayerJoystick(bool active, float x, float y) { s_joystickActive=active; s_joystickX=active?x:0.0f; s_joystickY=active?y:0.0f; }
bool IsPlayerGameWindow(const void* handler) { return handler && handler==s_playerGameWindow; }
static int s_mouseMiddleButtonState = 0;
static bool s_playerVisible = true;
static bool s_levelLimit = false;
@@ -3182,16 +3188,18 @@ static PyObject* player_SendDragonSoulRefine(PyObject*, PyObject* args) {
return Py_BuildNone();
}
void SetPlayerAttackKey(bool pressed) {
if (pressed && IsMainActorFishingMode()) {
NEW_Fishing();
return;
}
s_isAtkKey = pressed;
}
static PyObject* player_SetAttackKeyState(PyObject*, PyObject* args) {
int pressed = 0;
if (!PyTuple_GetInteger(args, 0, &pressed)) return Py_BuildException();
if (pressed) {
if (IsMainActorFishingMode()) {
NEW_Fishing();
return Py_BuildNone();
}
}
s_isAtkKey = (pressed != 0);
SetPlayerAttackKey(pressed != 0);
return Py_BuildNone();
}