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
+24 -11
View File
@@ -5,18 +5,25 @@ import math
import player
import app
import wndMgr
import touch
class MobileCombatWheel(ui.Window):
"""
移动端核心战斗轮盘 (Combat Radial Controller)
- 位于屏幕右下角
- 超大普攻按钮 (长按/轻点)
- 超大普攻按钮 (长按/轻点):按下由原生触摸分流器判定(touch.SetAttackButton),
按住期间等同键盘攻击键 player.SetAttackKeyState,本按钮只做按下显示
- 环绕式扇形技能槽位 (带 CD 倒计时遮罩与等阶显示)
- 辅助功能按键 (自动锁定、上下马等)
"""
ATTACK_IDLE_COLOR = grp.GenerateColor(0.6, 0.15, 0.1, 0.45)
ATTACK_DOWN_COLOR = grp.GenerateColor(0.95, 0.35, 0.2, 0.75)
def __init__(self, origin_x=None, origin_y=None):
ui.Window.__init__(self)
self.SetWindowName("MobileCombatWheel")
# 轮盘本身不拦截触摸,否则会盖住攻击键热区和世界点击;技能槽按钮仍可点
self.AddFlag("not_pick")
sw = wndMgr.GetScreenWidth()
sh = wndMgr.GetScreenHeight()
@@ -32,14 +39,16 @@ class MobileCombatWheel(ui.Window):
self.SetSize(380, 380)
# 1. 普通攻击主键 (超大圆形热区)
self.attack_btn = ui.Button()
# 包内没有 taskbar/attack_button_0x.sub,先用半透明色块标出热区(与摇杆同风格)
self.attack_btn = ui.Bar()
self.attack_btn.SetParent(self)
self.attack_btn.SetPosition(260 - 55, 260 - 55)
self.attack_btn.SetUpVisual("d:/ymir work/ui/game/taskbar/attack_button_01.sub")
self.attack_btn.SetOverVisual("d:/ymir work/ui/game/taskbar/attack_button_02.sub")
self.attack_btn.SetDownVisual("d:/ymir work/ui/game/taskbar/attack_button_03.sub")
self.attack_btn.SetEvent(ui.__mem_func__(self.__OnAttackClick))
self.attack_btn.AddFlag("not_pick")
self.attack_btn.SetPosition(260 - 60, 260 - 60)
self.attack_btn.SetSize(120, 120)
self.attack_btn.SetColor(self.ATTACK_IDLE_COLOR)
self.attack_btn.Show()
self.attack_pressed = False
touch.SetAttackButton(origin_x, origin_y, 60)
# 2. 扇形技能槽位群
self.skills = []
@@ -71,15 +80,19 @@ class MobileCombatWheel(ui.Window):
def __del__(self):
ui.Window.__del__(self)
def __OnAttackClick(self):
player.SetAttackKeyState(True)
app.RegisterDelayedCall(0.15, lambda: player.SetAttackKeyState(False))
def __OnSkillCast(self, index):
# 释放技能 (对应 Metin2 技能槽 1~4)
player.ClickSkillSlot(index + 1)
def OnUpdate(self):
pressed = touch.IsAttackPressed()
if pressed != self.attack_pressed:
self.attack_pressed = pressed
if pressed:
self.attack_btn.SetColor(self.ATTACK_DOWN_COLOR)
else:
self.attack_btn.SetColor(self.ATTACK_IDLE_COLOR)
# 刷新技能冷却状态
for item in self.skills:
slot_idx = item['slot'] + 1