Files
AVA2/upstream/python-root/ui_mobile_combat.py
T
shenleiandClaude Opus 5.5 b79fbce0b0 Add platform layer: lifecycle, data dirs, safe area (mobile step 2)
Move the macOS/Android data and config directory code out of main.cpp
into src/app/platform. Handle background/foreground: save config and
interface status, pause audio, cancel touch input and skip rendering
while keeping the network pumped. Map the window safe area through the
letterboxed presentation into TouchLayout and expose touch.GetSafeArea()
so the mobile HUD stays clear of notches and gesture bars.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 20:45:07 +09:00

106 lines
3.8 KiB
Python

# -*- coding: utf-8 -*-
import ui
import grp
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()
# 安全区(刘海/圆角/手势条)内缩,桌面为 0
safe_l, safe_t, safe_r, safe_b = touch.GetSafeArea()
if origin_x is None:
origin_x = sw - safe_r - 120
if origin_y is None:
origin_y = sh - safe_b - 120
self.origin_x = origin_x
self.origin_y = origin_y
self.SetPosition(origin_x - 260, origin_y - 260)
self.SetSize(380, 380)
# 1. 普通攻击主键 (超大圆形热区)
# 包内没有 taskbar/attack_button_0x.sub,先用半透明色块标出热区(与摇杆同风格)
self.attack_btn = ui.Bar()
self.attack_btn.SetParent(self)
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 = []
angles = [180, 150, 120, 90] # 左上四个扇区
radius = 150
for i, ang in enumerate(angles):
rad = math.radians(ang)
sx = int(260 + radius * math.cos(rad) - 30)
sy = int(260 - radius * math.sin(rad) - 30)
slot = ui.Button()
slot.SetParent(self)
slot.SetPosition(sx, sy)
slot.SetUpVisual("d:/ymir work/ui/game/taskbar/quickslot_01.sub")
slot.SetOverVisual("d:/ymir work/ui/game/taskbar/quickslot_02.sub")
slot.SetDownVisual("d:/ymir work/ui/game/taskbar/quickslot_03.sub")
slot.SetEvent(lambda s=i: self.__OnSkillCast(s))
slot.Show()
# CD 遮罩
cd_text = ui.TextLine()
cd_text.SetParent(slot)
cd_text.SetPosition(15, 20)
cd_text.SetText("")
cd_text.Show()
self.skills.append({'btn': slot, 'cd_text': cd_text, 'slot': i})
def __del__(self):
ui.Window.__del__(self)
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
if player.IsSkillCoolTime(slot_idx):
remaining = player.GetSkillCoolTime(slot_idx)
item['cd_text'].SetText("%.1f" % remaining)
else:
item['cd_text'].SetText("")