Fix cross-platform rendering and optimize frame performance

Correct selection orientation, game-entry lifecycle, mounted NPCs, labels and skill panels. Add the native GPU scene path, resident geometry, bounded texture and Python caches, and collision broad phase.

Pin the independently maintained Metin2 SDK through a submodule and document reproducible setup. Include rendering regressions and macOS packaging improvements.

Validation: client Debug build and 12 targeted client tests passed; SDK build and all 14 SDK tests passed.
This commit is contained in:
shen
2026-10-11 17:55:53 -07:00
parent 08cc8865be
commit 281418f351
101 changed files with 6244 additions and 1877 deletions
+6
View File
@@ -17,6 +17,7 @@ import guild
import net
import item
import uiCards
import ui_mobile_hud
if app.RENEWAL_MISSION_BOOKS:
import uiMission
@@ -331,6 +332,10 @@ class Interface(object):
wndGiftBox=uiGift.GiftDialog()
wndGiftBox.Hide()
self.wndGiftBox=wndGiftBox
self.wndMobileHUD = None
if getattr(app, "ENABLE_MOBILE_HUD", 0):
self.wndMobileHUD = ui_mobile_hud.MobileHUD(self)
self.wndMobileHUD.Show()
wndTaskBar = uiTaskBar.TaskBar()
wndTaskBar.LoadWindow()
@@ -1813,6 +1818,7 @@ class Interface(object):
## Show & Hide
def ShowDefaultWindows(self):
self.wndTaskBar.Show()
if hasattr(self, "wndMobileHUD") and self.wndMobileHUD: self.wndMobileHUD.Show()
self.wndMiniMap.Show()
self.wndMiniMap.ShowMiniMap()
if self.wndEnergyBar:
+54 -39
View File
@@ -325,13 +325,13 @@ class LoginWindow(ui.ScriptWindow):
print "---------------------------------------------------------------------------- CLOSE LOGIN WINDOW "
#
# selectMusic이 없으면 BGM이 끊기므로 두개 다 체크한다.
# selectMusic이 없으면 BGM이 끊기므로 두개 다 체크한다.
#
if musicInfo.loginMusic != "" and musicInfo.selectMusic != "":
snd.FadeOutMusic("BGM/"+musicInfo.loginMusic)
## NOTE : idEditLine와 pwdEditLine은 이벤트가 서로 연결 되어있어서
## Event를 강제로 초기화 해주어야만 합니다 - [levites]
## NOTE : idEditLine와 pwdEditLine은 이벤트가 서로 연결 되어있어서
## Event를 강제로 초기화 해주어야만 합니다 - [levites]
self.idEditLine.SetTabEvent(0)
self.idEditLine.SetReturnEvent(0)
self.pwdEditLine.SetReturnEvent(0)
@@ -435,11 +435,11 @@ class LoginWindow(ui.ScriptWindow):
def SetPasswordEditLineFocus(self):
if localeInfo.IsEUROPE():
if self.idEditLine != None: #0000862: [M2EU] 로그인창 팝업 에러: 종료시 먼저 None 설정됨
if self.idEditLine != None: #0000862: [M2EU] 로그인창 팝업 에러: 종료시 먼저 None 설정됨
self.idEditLine.SetText("")
self.idEditLine.SetFocus() #0000685: [M2EU] 아이디/비밀번호 유추 가능 버그 수정: 무조건 아이디로 포커스가 가게 만든다
self.idEditLine.SetFocus() #0000685: [M2EU] 아이디/비밀번호 유추 가능 버그 수정: 무조건 아이디로 포커스가 가게 만든다
if self.pwdEditLine != None: #0000862: [M2EU] 로그인창 팝업 에러: 종료시 먼저 None 설정됨
if self.pwdEditLine != None: #0000862: [M2EU] 로그인창 팝업 에러: 종료시 먼저 None 설정됨
self.pwdEditLine.SetText("")
else:
if self.pwdEditLine != None:
@@ -497,7 +497,7 @@ class LoginWindow(ui.ScriptWindow):
loginFailureMsg = localeInfo.LOGIN_FAILURE_UNKNOWN + error
#0000685: [M2EU] 아이디/비밀번호 유추 가능 버그 수정: 무조건 패스워드로 포커스가 가게 만든다
#0000685: [M2EU] 아이디/비밀번호 유추 가능 버그 수정: 무조건 패스워드로 포커스가 가게 만든다
loginFailureFunc=self.loginFailureFuncDict.get(error, self.SetPasswordEditLineFocus)
if app.loggined:
@@ -864,6 +864,7 @@ class LoginWindow(ui.ScriptWindow):
def __OnClickExitButton(self):
self.stream.SetPhaseWindow(0)
app.Exit()
def __SetServerInfo(self, name):
net.SetServerInfo(name.strip())
@@ -876,18 +877,18 @@ class LoginWindow(ui.ScriptWindow):
execfile(loginInfoFileName, loginInfo)
except IOError:
print(\
"자동 로그인을 하시려면" + loginInfoFileName + "파일을 작성해주세요\n"\
"자동 로그인을 하시려면" + loginInfoFileName + "파일을 작성해주세요\n"\
"\n"\
"내용:\n"\
"내용:\n"\
"================================================================\n"\
"addr=주소\n"\
"port=포트\n"\
"id=아이디\n"\
"pwd=비밀번호\n"\
"slot=캐릭터 선택 인덱스 (없거나 -1이면 자동 선택 안함)\n"\
"autoLogin=자동 접속 여부\n"
"autoSelect=자동 접속 여부\n"
"localeInfo=(ymir) LC_Ymir 일경우 ymir로 작동. 지정하지 않으면 korea로 작동\n"
"addr=주소\n"\
"port=포트\n"\
"id=아이디\n"\
"pwd=비밀번호\n"\
"slot=캐릭터 선택 인덱스 (없거나 -1이면 자동 선택 안함)\n"\
"autoLogin=자동 접속 여부\n"
"autoSelect=자동 접속 여부\n"
"localeInfo=(ymir) LC_Ymir 일경우 ymir로 작동. 지정하지 않으면 korea로 작동\n"
);
id=loginInfo.get("id", "")
@@ -904,7 +905,7 @@ class LoginWindow(ui.ScriptWindow):
net.SetMarkServer(addr, port)
if localeInfo == "ymir" :
net.SetServerInfo("천마 서버")
net.SetServerInfo("천마 서버")
self.serverInfo.SetText("Y:"+addr+":"+str(port))
else:
net.SetServerInfo(addr+":"+str(port))
@@ -937,7 +938,7 @@ class LoginWindow(ui.ScriptWindow):
self.Connect(id, pwd)
print "=================================================================================="
print "자동 로그인: %s - %s:%d %s" % (loginInfoFileName, addr, port, id)
print "자동 로그인: %s - %s:%d %s" % (loginInfoFileName, addr, port, id)
print "=================================================================================="
@@ -1071,9 +1072,9 @@ class LoginWindow(ui.ScriptWindow):
self.stream.popupWindow.Close()
# CHINA_MATRIX_CARD_BUG_FIX
## A~Z 까지 26 이내의 값이 들어있어야만 한다.
## Python Exception Log 에서 그 이상의 값이 들어있어서 에러 방지
## 헌데 왜 한국쪽 로그에서 이게 활용되는지는 모르겠음
## A~Z 까지 26 이내의 값이 들어있어야만 한다.
## Python Exception Log 에서 그 이상의 값이 들어있어서 에러 방지
## 헌데 왜 한국쪽 로그에서 이게 활용되는지는 모르겠음
row1 = min(30, row1)
row2 = min(30, row2)
row3 = min(30, row3)
@@ -1126,6 +1127,7 @@ class LoginWindow(ui.ScriptWindow):
def OnPressExitKey(self):
self.stream.popupWindow.Close()
self.stream.SetPhaseWindow(0)
app.Exit()
return True
def OnExit(self):
@@ -1193,15 +1195,16 @@ class LoginWindow(ui.ScriptWindow):
# NEWCIBN_PASSPOD_AUTH_END
if serverIndex < 0:
serverIndex = 0
if channelIndex < 0:
channelIndex = 0
self.serverList.SelectItem(serverIndex)
self.__OnSelectServer()
self.channelList.SelectItem(channelIndex)
if localeInfo.IsEUROPE():
self.channelList.SelectItem(app.GetRandom(0, self.channelList.GetItemCount()))
else:
if channelIndex >= 0:
self.channelList.SelectItem(channelIndex)
## Show/Hide 코드에 문제가 있어서 임시 - [levites]
## Show/Hide
self.serverBoard.SetPosition(self.xServerBoard, self.yServerBoard)
self.serverBoard.Show()
self.connectBoard.Hide()
@@ -1209,6 +1212,8 @@ class LoginWindow(ui.ScriptWindow):
self.BoardSaveAccount.Hide()
self.BoardLenguaje.Hide()
self.serverExitButton.SetEvent(ui.__mem_func__(self.__OnClickExitButton))
if self.virtualKeyboard:
self.virtualKeyboard.Hide()
@@ -1313,7 +1318,7 @@ class LoginWindow(ui.ScriptWindow):
# END_OF_SEVER_LIST_BUG_FIX
def __OnSelectServer(self):
def __OnSelectServer(self, *args):
self.__OnCloseInputDialog()
self.__RequestServerStateList()
self.__RefreshServerStateList()
@@ -1356,7 +1361,8 @@ class LoginWindow(ui.ScriptWindow):
channelState = channelDataDict["state"]
self.channelList.InsertItem(channelID, " %s %s" % (channelName, channelState))
self.channelList.SelectItem(bakChannelID-1)
selIndex = (bakChannelID - 1) if bakChannelID > 0 else 0
self.channelList.SelectItem(selIndex)
def __GetChannelName(self, regionID, selServerID, selChannelID):
try:
@@ -1423,6 +1429,15 @@ class LoginWindow(ui.ScriptWindow):
serverID = self.__GetServerID()
channelID = self.__GetChannelID()
if serverID <= 0:
self.serverList.SelectItem(0)
self.__OnSelectServer()
serverID = self.__GetServerID()
if channelID <= 0:
self.channelList.SelectItem(0)
channelID = self.__GetChannelID()
if (not serverInfo.REGION_DICT.has_key(regionID)):
self.PopupNotifyMessage(localeInfo.CHANNEL_SELECT_REGION)
return
@@ -1442,7 +1457,7 @@ class LoginWindow(ui.ScriptWindow):
self.PopupNotifyMessage(localeInfo.CHANNEL_SELECT_CHANNEL)
return
# 상태가 FULL 과 같으면 진입 금지
# 상태가 FULL 과 같으면 진입 금지
if state == serverInfo.STATE_DICT[3]:
self.PopupNotifyMessage(localeInfo.CHANNEL_NOTIFY_FULL)
return
@@ -1454,9 +1469,9 @@ class LoginWindow(ui.ScriptWindow):
channelName = serverInfo.REGION_DICT[regionID][serverID]["channel"][channelID]["name"]
addrKey = serverInfo.REGION_DICT[regionID][serverID]["channel"][channelID]["key"]
if "천마 서버" == serverName:
if "천마 서버" == serverName:
app.ForceSetlocaleInfo("ymir", "localeInfo/ymir")
elif "쾌도 서버" == serverName:
elif "쾌도 서버" == serverName:
app.ForceSetlocaleInfo("we_korea", "localeInfo/we_korea")
except:
@@ -1471,7 +1486,7 @@ class LoginWindow(ui.ScriptWindow):
tcp_port = serverInfo.REGION_DICT[regionID][serverID]["channel"][channelID]["tcp_port"]
except:
import exception
exception.Abort("LoginWindow.__OnClickSelectServerButton - 서버 선택 실패")
exception.Abort("LoginWindow.__OnClickSelectServerButton - 서버 선택 실패")
try:
account_ip = serverInfo.REGION_AUTH_SERVER_DICT[regionID][serverID]["ip"]
@@ -1491,13 +1506,13 @@ class LoginWindow(ui.ScriptWindow):
except:
import exception
exception.Abort("LoginWindow.__OnClickSelectServerButton - 마크 정보 없음")
exception.Abort("LoginWindow.__OnClickSelectServerButton - 마크 정보 없음")
if app.USE_OPENID and not app.OPENID_TEST :
## 2012.07.19 OpenID : 김용욱
# 채널 선택 화면에서 "확인"(SelectServerButton) 을 눌렀을때,
# 로그인 화면으로 넘어가지 않고 바로 서버에 OpenID 인증키를 보내도록 수정
## 2012.07.19 OpenID : 김용욱
# 채널 선택 화면에서 "확인"(SelectServerButton) 을 눌렀을때,
# 로그인 화면으로 넘어가지 않고 바로 서버에 OpenID 인증키를 보내도록 수정
self.stream.SetConnectInfo(ip, tcp_port, account_ip, account_port)
#net.SetServerInfoPort(tcp_port)
self.Connect(0, 0)
@@ -1,8 +1,9 @@
[DELAY value;0]
By virtue of their heavy[ENTER]
armour, weapons and skills,[ENTER]
Warriors play a crucial role[ENTER]
in close combat situations.[ENTER]
armour, weapons and[ENTER]
skills, Warriors play[ENTER]
a crucial role in close[ENTER]
combat situations.[ENTER]
Their two aims in life are[ENTER]
[WAIT]
for raw physical strength[ENTER]
@@ -146,7 +146,7 @@ window = {
"name" : "Shadow",
"type" : "expanded_image",
"x" : SCREEN_WIDTH/2 - (64)*SHADOW_SCALE_X,
"y" : SCREEN_HEIGHT - SCREEN_HEIGHT*(70)/600.0 - (88)*SHADOW_SCALE_Y/2.0,
"y" : (SCREEN_HEIGHT * 575 / 768.0) - (88)*SHADOW_SCALE_Y/2.0,
"x_scale" : SHADOW_SCALE_X, "y_scale" : SHADOW_SCALE_Y,
"image" : LOCALE_PATH + "shadow/shadow.tga",
},
+2 -2
View File
@@ -4,7 +4,7 @@ app.ServerName = None
SRV1 = {
"name":localeInfo.SERVERNAME,
"host":"192.168.1.100",
"host":"192.168.21.205",
"auth1":30001,
"ch1":13002,
# "ch2":13102,
@@ -14,7 +14,7 @@ SRV1 = {
SRV2 = {
"name":localeInfo.SERVERNAMETEST,
"host":"192.168.1.100",
"host":"192.168.21.205",
"auth1":30001,
"ch1":13002,
# "ch2":13102,
+1 -1
View File
@@ -3466,7 +3466,7 @@ class ThinBoardCircle(Window):
CORNER_HEIGHT = 4
LINE_WIDTH = 4
LINE_HEIGHT = 4
BOARD_COLOR = grp.GenerateColor(255.0, 255.0, 255.0, 1.0)
BOARD_COLOR = grp.GenerateColor(0.0, 0.0, 0.0, 0.51)
LT = 0
LB = 1
+90
View File
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-
import ui
import grp
import math
import player
import app
import wndMgr
class MobileCombatWheel(ui.Window):
"""
移动端核心战斗轮盘 (Combat Radial Controller)
- 位于屏幕右下角
- 超大普攻按钮 (长按/轻点)
- 环绕式扇形技能槽位 (带 CD 倒计时遮罩与等阶显示)
- 辅助功能按键 (自动锁定、上下马等)
"""
def __init__(self, origin_x=None, origin_y=None):
ui.Window.__init__(self)
self.SetWindowName("MobileCombatWheel")
sw = wndMgr.GetScreenWidth()
sh = wndMgr.GetScreenHeight()
if origin_x is None:
origin_x = sw - 120
if origin_y is None:
origin_y = sh - 120
self.origin_x = origin_x
self.origin_y = origin_y
self.SetPosition(origin_x - 260, origin_y - 260)
self.SetSize(380, 380)
# 1. 普通攻击主键 (超大圆形热区)
self.attack_btn = ui.Button()
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.Show()
# 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 __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):
# 刷新技能冷却状态
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("")
+109
View File
@@ -0,0 +1,109 @@
# -*- coding: utf-8 -*-
import ui
import grp
import wndMgr
class MobileDrawer(ui.Window):
"""
移动端系统抽屉菜单与顶部快捷导航
- 位于屏幕右上角
- 包含:通知、邮件、战力属性、背包、汉堡折叠按钮
- 点击汉堡按钮自右侧滑出二级扩展菜单 (设置/角色/公会/离线挂机等)
"""
def __init__(self, interface=None):
ui.Window.__init__(self)
self.SetWindowName("MobileDrawer")
self.interface = interface
sw = wndMgr.GetScreenWidth()
self.sw = sw
self.SetPosition(sw - 380, 15)
self.SetSize(360, 240)
self.AddFlag("attach")
self.is_menu_open = False
self.__BuildUI()
def __del__(self):
ui.Window.__del__(self)
def __BuildUI(self):
# 1. 一级横向快捷按钮组 (直径 48px)
btn_data = [
("Inv", self.__OnClickInventory),
("Stat", self.__OnClickStatus),
("Mail", self.__OnClickMail),
("Menu", self.__OnToggleMenu)
]
self.quick_buttons = []
for i, (label, callback) in enumerate(btn_data):
btn = ui.Button()
btn.SetParent(self)
btn.SetPosition(i * 65 + 100, 0)
btn.SetUpVisual("d:/ymir work/ui/public/middle_button_01.sub")
btn.SetOverVisual("d:/ymir work/ui/public/middle_button_02.sub")
btn.SetDownVisual("d:/ymir work/ui/public/middle_button_03.sub")
btn.SetText(label)
btn.SetEvent(ui.__mem_func__(callback))
btn.Show()
self.quick_buttons.append(btn)
# 2. 二级抽屉面板 (默认隐藏)
self.drawer_panel = ui.Bar()
self.drawer_panel.SetParent(self)
self.drawer_panel.SetPosition(120, 50)
self.drawer_panel.SetSize(240, 180)
self.drawer_panel.SetColor(grp.GenerateColor(0.08, 0.08, 0.12, 0.88))
self.drawer_panel.Hide()
menu_items = [
("Character", self.__OnClickStatus),
("Messenger", self.__OnClickMessenger),
("System Option", self.__OnClickSystem),
("Exit Game", self.__OnClickExit)
]
self.drawer_buttons = []
for i, (text, action) in enumerate(menu_items):
item_btn = ui.Button()
item_btn.SetParent(self.drawer_panel)
item_btn.SetPosition(20, 15 + i * 40)
item_btn.SetUpVisual("d:/ymir work/ui/public/large_button_01.sub")
item_btn.SetOverVisual("d:/ymir work/ui/public/large_button_02.sub")
item_btn.SetDownVisual("d:/ymir work/ui/public/large_button_03.sub")
item_btn.SetText(text)
item_btn.SetEvent(ui.__mem_func__(action))
item_btn.Show()
self.drawer_buttons.append(item_btn)
def __OnClickInventory(self):
if self.interface:
self.interface.ToggleInventoryWindow()
def __OnClickStatus(self):
if self.interface:
self.interface.ToggleCharacterWindowStatusPage()
def __OnClickMail(self):
if self.interface and hasattr(self.interface, 'OpenMail'):
self.interface.OpenMail()
def __OnClickMessenger(self):
if self.interface:
self.interface.ToggleMessenger()
def __OnClickSystem(self):
if self.interface:
self.interface.ToggleSystemDialog()
def __OnClickExit(self):
if self.interface:
self.interface.ToggleSystemDialog()
def __OnToggleMenu(self):
self.is_menu_open = not self.is_menu_open
if self.is_menu_open:
self.drawer_panel.Show()
else:
self.drawer_panel.Hide()
+220
View File
@@ -0,0 +1,220 @@
# -*- 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
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.__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)
self.player_hud.SetPosition(25, 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, 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 - 120, origin_y=h - 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 - 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()
+101
View File
@@ -0,0 +1,101 @@
# -*- coding: utf-8 -*-
import ui
import grp
import math
import net
import chr
import player
import app
import wndMgr
class MobileJoystick(ui.Window):
"""
移动端专用虚拟摇杆 (Virtual Joystick)
- 位于屏幕左下角
- 支持手指按下、滑动拖拽、松开自动回中
- 动态计算移动向量与航向角,同步触发移动网络包
"""
def __init__(self, base_x=160, base_y=None, radius=75, knob_radius=35):
ui.Window.__init__(self)
self.SetWindowName("MobileJoystick")
sw = wndMgr.GetScreenWidth()
sh = wndMgr.GetScreenHeight()
if base_y is None:
base_y = sh - 180
self.base_x = base_x
self.base_y = base_y
self.radius = radius
self.knob_radius = knob_radius
self.knob_x = base_x
self.knob_y = base_y
self.is_dragging = False
self.SetPosition(base_x - radius - 20, base_y - radius - 20)
self.SetSize((radius + 20) * 2, (radius + 20) * 2)
# 外圈底盘
self.base_bar = ui.Bar()
self.base_bar.SetParent(self)
self.base_bar.SetPosition(20, 20)
self.base_bar.SetSize(radius * 2, radius * 2)
self.base_bar.SetColor(grp.GenerateColor(0.1, 0.1, 0.15, 0.4))
self.base_bar.Show()
# 内部活动摇杆
self.knob = ui.Bar()
self.knob.SetParent(self)
offset_k = radius - knob_radius + 20
self.knob.SetPosition(offset_k, offset_k)
self.knob.SetSize(knob_radius * 2, knob_radius * 2)
self.knob.SetColor(grp.GenerateColor(0.8, 0.8, 0.9, 0.6))
self.knob.Show()
def __del__(self):
ui.Window.__del__(self)
def OnMouseLeftButtonDown(self):
self.is_dragging = True
return True
def OnMouseLeftButtonUp(self):
self.is_dragging = False
# 松手回中
offset_k = self.radius - self.knob_radius + 20
self.knob.SetPosition(offset_k, offset_k)
return True
def OnUpdate(self):
if not self.is_dragging:
return
# 采样当前鼠标/触控位置
mx, my = wndMgr.GetMousePosition()
dx = mx - self.base_x
dy = my - self.base_y
dist = math.hypot(dx, dy)
if dist > self.radius:
dx = (dx / dist) * self.radius
dy = (dy / dist) * self.radius
# 更新摇杆视觉位置
offset_k = self.radius - self.knob_radius + 20
self.knob.SetPosition(offset_k + int(dx), offset_k + int(dy))
# 若达到死区阈值,计算朝向并向服务器发包同步
if dist > 15:
angle_rad = math.atan2(dy, dx)
yaw_deg = math.degrees(angle_rad)
# 获取主角当前坐标
main_vid = net.GetMainActorVID() if hasattr(net, 'GetMainActorVID') else 0
if main_vid != 0:
cur_x, cur_y, cur_z = chr.GetPixelPosition(main_vid) if hasattr(chr, 'GetPixelPosition') else (0, 0, 0)
# 计算步进
step = 250
target_x = cur_x + int(step * math.cos(angle_rad))
target_y = cur_y + int(step * math.sin(angle_rad))
if hasattr(net, 'SendCharacterMovePacket'):
net.SendCharacterMovePacket(1, 0, int(yaw_deg), int(target_x), int(target_y))