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>
224 lines
8.6 KiB
Python
224 lines
8.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
import ui
|
|
import grp
|
|
import player
|
|
import chr
|
|
import chrmgr
|
|
import app
|
|
import wndMgr
|
|
import math
|
|
import ui_mobile_joystick
|
|
import ui_mobile_combat
|
|
import ui_mobile_drawer
|
|
import touch
|
|
|
|
class MobileHUD(ui.Window):
|
|
"""
|
|
ava2-client 移动端全屏战斗 HUD (完整集成版)
|
|
自适应 2376 x 1080 横屏规范
|
|
包含:
|
|
1. 左上角主角状态 HUD (圆形头像 + HP/MP/体力条)
|
|
2. 顶部悬浮目标血条 HUD (Monster Name, Level, HP Gauge)
|
|
3. 右上角导航快捷入口与小地图挂载抽屉 (MobileDrawer)
|
|
4. 底部药水/消耗品快捷轮盘 (Quick Belt)
|
|
5. 右下角核心战斗轮盘 (MobileCombatWheel: 大普攻 + 扇形技能槽)
|
|
6. 左下角虚拟摇杆触控层 (MobileJoystick)
|
|
"""
|
|
def __init__(self, interface=None):
|
|
ui.Window.__init__(self)
|
|
self.SetWindowName("MobileHUD")
|
|
self.interface = interface
|
|
|
|
sw = wndMgr.GetScreenWidth()
|
|
sh = wndMgr.GetScreenHeight()
|
|
self.SetPosition(0, 0)
|
|
self.SetSize(sw, sh)
|
|
self.AddFlag("attach")
|
|
self.AddFlag("not_pick")
|
|
|
|
self.safe_area = touch.GetSafeArea()
|
|
self.__BuildUI(sw, sh)
|
|
|
|
def __del__(self):
|
|
ui.Window.__del__(self)
|
|
|
|
def __BuildUI(self, w, h):
|
|
# ---------------------------------------------------------------------
|
|
# 1. 左上角:主角状态 (Player HUD)
|
|
# ---------------------------------------------------------------------
|
|
self.player_hud = ui.Window()
|
|
self.player_hud.SetParent(self)
|
|
safe_l, safe_t, safe_r, safe_b = self.safe_area
|
|
self.player_hud.SetPosition(safe_l + 25, safe_t + 20)
|
|
self.player_hud.SetSize(320, 100)
|
|
self.player_hud.Show()
|
|
|
|
# 头像框背景底板
|
|
self.avatar_bg = ui.Bar()
|
|
self.avatar_bg.SetParent(self.player_hud)
|
|
self.avatar_bg.SetPosition(0, 0)
|
|
self.avatar_bg.SetSize(72, 72)
|
|
self.avatar_bg.SetColor(grp.GenerateColor(0.15, 0.15, 0.22, 0.85))
|
|
self.avatar_bg.Show()
|
|
|
|
# 角色名称
|
|
self.text_name = ui.TextLine()
|
|
self.text_name.SetParent(self.player_hud)
|
|
self.text_name.SetPosition(80, 2)
|
|
self.text_name.SetText("Player")
|
|
self.text_name.Show()
|
|
|
|
# HP 条背景与前景
|
|
self.hp_bar_bg = ui.Bar()
|
|
self.hp_bar_bg.SetParent(self.player_hud)
|
|
self.hp_bar_bg.SetPosition(80, 22)
|
|
self.hp_bar_bg.SetSize(210, 14)
|
|
self.hp_bar_bg.SetColor(grp.GenerateColor(0.2, 0.05, 0.05, 0.75))
|
|
self.hp_bar_bg.Show()
|
|
|
|
self.hp_bar = ui.Bar()
|
|
self.hp_bar.SetParent(self.player_hud)
|
|
self.hp_bar.SetPosition(80, 22)
|
|
self.hp_bar.SetSize(210, 14)
|
|
self.hp_bar.SetColor(grp.GenerateColor(0.85, 0.12, 0.12, 0.95))
|
|
self.hp_bar.Show()
|
|
|
|
# MP 条背景与前景
|
|
self.mp_bar_bg = ui.Bar()
|
|
self.mp_bar_bg.SetParent(self.player_hud)
|
|
self.mp_bar_bg.SetPosition(80, 40)
|
|
self.mp_bar_bg.SetSize(180, 10)
|
|
self.mp_bar_bg.SetColor(grp.GenerateColor(0.05, 0.1, 0.25, 0.75))
|
|
self.mp_bar_bg.Show()
|
|
|
|
self.mp_bar = ui.Bar()
|
|
self.mp_bar.SetParent(self.player_hud)
|
|
self.mp_bar.SetPosition(80, 40)
|
|
self.mp_bar.SetSize(180, 10)
|
|
self.mp_bar.SetColor(grp.GenerateColor(0.15, 0.45, 0.95, 0.95))
|
|
self.mp_bar.Show()
|
|
|
|
# 体力/耐力条
|
|
self.sp_bar = ui.Bar()
|
|
self.sp_bar.SetParent(self.player_hud)
|
|
self.sp_bar.SetPosition(80, 54)
|
|
self.sp_bar.SetSize(150, 6)
|
|
self.sp_bar.SetColor(grp.GenerateColor(0.9, 0.8, 0.1, 0.85))
|
|
self.sp_bar.Show()
|
|
|
|
# ---------------------------------------------------------------------
|
|
# 2. 顶部居中:目标血条 (Target HUD)
|
|
# ---------------------------------------------------------------------
|
|
self.target_hud = ui.Window()
|
|
self.target_hud.SetParent(self)
|
|
self.target_hud.SetPosition((w - 420) / 2, safe_t + 20)
|
|
self.target_hud.SetSize(420, 50)
|
|
|
|
self.target_bg = ui.Bar()
|
|
self.target_bg.SetParent(self.target_hud)
|
|
self.target_bg.SetPosition(0, 18)
|
|
self.target_bg.SetSize(420, 16)
|
|
self.target_bg.SetColor(grp.GenerateColor(0.2, 0.05, 0.05, 0.75))
|
|
self.target_bg.Show()
|
|
|
|
self.target_bar = ui.Bar()
|
|
self.target_bar.SetParent(self.target_hud)
|
|
self.target_bar.SetPosition(0, 18)
|
|
self.target_bar.SetSize(420, 16)
|
|
self.target_bar.SetColor(grp.GenerateColor(0.9, 0.1, 0.1, 0.95))
|
|
self.target_bar.Show()
|
|
|
|
self.target_name = ui.TextLine()
|
|
self.target_name.SetParent(self.target_hud)
|
|
self.target_name.SetPosition(10, 0)
|
|
self.target_name.SetText("Target")
|
|
self.target_name.Show()
|
|
|
|
self.target_pct = ui.TextLine()
|
|
self.target_pct.SetParent(self.target_hud)
|
|
self.target_pct.SetPosition(370, 0)
|
|
self.target_pct.SetText("100%")
|
|
self.target_pct.Show()
|
|
self.target_hud.Hide()
|
|
|
|
# ---------------------------------------------------------------------
|
|
# 3. 右上角:系统抽屉菜单与导航 (Mobile Drawer)
|
|
# ---------------------------------------------------------------------
|
|
self.drawer = ui_mobile_drawer.MobileDrawer(self.interface)
|
|
self.drawer.SetParent(self)
|
|
self.drawer.Show()
|
|
|
|
# ---------------------------------------------------------------------
|
|
# 4. 左下角:虚拟摇杆 (Mobile Joystick)
|
|
# ---------------------------------------------------------------------
|
|
self.joystick = ui_mobile_joystick.MobileJoystick(base_x=160, base_y=h - 180)
|
|
self.joystick.SetParent(self)
|
|
self.joystick.Show()
|
|
|
|
# ---------------------------------------------------------------------
|
|
# 5. 右下角:核心战斗轮盘 (Mobile Combat Wheel)
|
|
# ---------------------------------------------------------------------
|
|
self.combat_wheel = ui_mobile_combat.MobileCombatWheel(origin_x=w - safe_r - 120, origin_y=h - safe_b - 120)
|
|
self.combat_wheel.SetParent(self)
|
|
self.combat_wheel.Show()
|
|
|
|
# ---------------------------------------------------------------------
|
|
# 6. 底部居中:药水快捷滑盘 (Quick Belt)
|
|
# ---------------------------------------------------------------------
|
|
self.quick_belt = ui.Window()
|
|
self.quick_belt.SetParent(self)
|
|
self.quick_belt.SetPosition((w - 360) / 2, h - safe_b - 70)
|
|
self.quick_belt.SetSize(360, 60)
|
|
self.quick_belt.Show()
|
|
|
|
self.quick_slots = []
|
|
for i in range(5):
|
|
slot = ui.Bar()
|
|
slot.SetParent(self.quick_belt)
|
|
slot.SetPosition(i * 70, 0)
|
|
slot.SetSize(60, 60)
|
|
slot.SetColor(grp.GenerateColor(0.1, 0.1, 0.15, 0.6))
|
|
slot.Show()
|
|
self.quick_slots.append(slot)
|
|
|
|
def OnUpdate(self):
|
|
# 1. 刷新主角状态
|
|
cur_hp = player.GetStatus(player.HP)
|
|
max_hp = player.GetStatus(player.MAX_HP)
|
|
if max_hp > 0:
|
|
pct = min(1.0, max(0.0, float(cur_hp) / float(max_hp)))
|
|
self.hp_bar.SetSize(int(210 * pct), 14)
|
|
|
|
cur_mp = player.GetStatus(player.SP)
|
|
max_mp = player.GetStatus(player.MAX_SP)
|
|
if max_mp > 0:
|
|
pct = min(1.0, max(0.0, float(cur_mp) / float(max_mp)))
|
|
self.mp_bar.SetSize(int(180 * pct), 10)
|
|
|
|
cur_sp = player.GetStatus(player.STAMINA)
|
|
max_sp = player.GetStatus(player.MAX_STAMINA)
|
|
if max_sp > 0:
|
|
pct = min(1.0, max(0.0, float(cur_sp) / float(max_sp)))
|
|
self.sp_bar.SetSize(int(150 * pct), 6)
|
|
|
|
# 2. 刷新目标状态
|
|
target_vid = player.GetTargetVID()
|
|
if target_vid != 0 and chr.GetInstanceType(target_vid) != chr.INSTANCE_TYPE_PLAYER:
|
|
self.target_hud.Show()
|
|
name = chr.GetNameByVID(target_vid)
|
|
self.target_name.SetText(name if name else "Target")
|
|
target_hp = chr.GetHP(target_vid) if hasattr(chr, 'GetHP') else 100
|
|
target_max_hp = chr.GetMaxHP(target_vid) if hasattr(chr, 'GetMaxHP') else 100
|
|
if target_max_hp > 0:
|
|
pct = min(1.0, max(0.0, float(target_hp) / float(target_max_hp)))
|
|
self.target_bar.SetSize(int(420 * pct), 16)
|
|
self.target_pct.SetText("%d%%" % int(pct * 100))
|
|
else:
|
|
self.target_hud.Hide()
|
|
|
|
# 3. 子组件状态刷新
|
|
if hasattr(self, 'joystick') and self.joystick:
|
|
self.joystick.OnUpdate()
|
|
if hasattr(self, 'combat_wheel') and self.combat_wheel:
|
|
self.combat_wheel.OnUpdate()
|