diff --git a/docs/MOBILE-ARCHITECTURE.md b/docs/MOBILE-ARCHITECTURE.md index 23d67368..788ccf02 100644 --- a/docs/MOBILE-ARCHITECTURE.md +++ b/docs/MOBILE-ARCHITECTURE.md @@ -10,7 +10,7 @@ - 平台层已实现(`src/app/platform/`):资源根目录与配置目录;前后台切换(进后台时保存配置、暂停声音、取消输入、停止渲染,网络照常收发;Android 设 `SDL_ANDROID_BLOCK_ON_PAUSE=0`);安全区域按逻辑分辨率换算后放进触摸布局,HUD 用 `touch.GetSafeArea()` 内缩。低内存事件目前只记日志;HUD 只在创建时读安全区;均未真机验证。 - 触摸分流已实现(`src/app/input/touch_router.*`,见下文 `input/`):移动端或 `--touch` / `AVA2_TOUCH=1` 时关闭 SDL 触摸转鼠标,每个手指分到界面、攻击键、左下浮动摇杆或镜头(单指拖动转向、双指缩放、轻点=点地移动)。Python 模块 `touch` 供 HUD 设置攻击键位置并读取摇杆状态;`ui_mobile_joystick` / `ui_mobile_combat` 改为只做显示(`not_pick`)。多指同时操作尚未在真机验证。 - 出招已接通(PORT-PLAN「Mobile step 3b」):触摸攻击键和键盘共用 `ProcessPlayerAttack`,按原版连招时序出招,发送 FUNC_COMBO 移动包,命中检测后发 `CG_ATTACK`;尚未在真服验证,弓箭飞行、技能、PvP 规则等仍缺。 -- 原型 HUD 用到的 `taskbar/attack_button_0x.sub`、`quickslot_0x.sub` 不在资源包里:攻击键暂用色块,技能圈槽位不可见。 +- 手机 HUD 布局已实现(PORT-PLAN「Mobile step 4」):左上头像圆框 + 等级名字 + HP/SP/体力条,buff 图标在其下;顶部居中沿用原版目标栏;右上一排圆形入口(好友、角色、背包、菜单)+ 原版小地图 + 活动图标;左侧竖排按钮(任务、技能、表情、聊天)和原版提示按钮;右下攻击键 + 两圈 8 个快捷格(当前快捷页,可切第 1-3 页)+ 换页、上下马、拾取;底部药水栏(第 4 快捷页,全局格 24-31)和经验细条。移动模式下 PC 任务栏隐藏。圆框由原生 `CDisc`(`wndMgr.RegisterDisc`)几何绘制,图标只用 AVA2 自己的贴图,不用其他服的美术。小地图仍是原版圆形、按钮文字为英文、未真机验证。 - 软键盘已改为仅在输入框获得焦点(`ime.EnableCaptureInput`)或聊天打开时弹出。 - `src/app/main.cpp` 共 2418 行,启动、主循环、登录和调试参数都在其中。 - Android 默认渲染缩放 0.75。 diff --git a/docs/PORT-PLAN.md b/docs/PORT-PLAN.md index 842be151..cae6da39 100644 --- a/docs/PORT-PLAN.md +++ b/docs/PORT-PLAN.md @@ -1255,3 +1255,49 @@ Outstanding: no device run (background/resume, surface recreation, audio resume, server keepalive while paused); low memory only logs (no cache purge); the HUD reads the insets only when it is built; iOS lifecycle needs the event watch to do the save work synchronously. + +### 2026-10-12 Mobile step 4 — mobile HUD layout + +The touch HUD (`upstream/python-root/ui_mobile_*.py`, mobile mode only) now +follows the planned phone layout instead of the step-3 prototype: + +- Native `UI::CDisc` (`wndMgr.RegisterDisc` / `SetDiscColors` / + `SetDiscArc`, `WT_DISC`): radial-gradient disc with a bevelled rim and an + optional clockwise pie arc, drawn with `SDL_RenderGeometry`. All round + frames are procedural; icons come only from AVA2's own taskbar / skill / + item / face textures. +- `ui_mobile_widgets.py`: `Disc`, `RoundButton` (icon or label, fires on + release inside), `QuickSlotDisc` (one `ui.SlotWindow` slot inside a disc; + tap uses it, tap while dragging adds or moves into it — the + `uitaskbar.AddQuickSlot` logic; refresh is a one-slot + `TaskBar.RefreshQuickSlot`). +- Layout (inset by `touch.GetSafeArea()`): top-left face disc + (`uiCharacter.FACE_IMAGE_DICT`) + "Lv. name" + HP/SP/stamina gauges with + the original `AffectShower` below; original `uiTarget.TargetBoard` stays top + centre; top-right row Messenger / Status / Inventory / Menu (menu panel: + Skill, Quest, Guild, System) with the original minimap and event icon under + it; left column Quest / Skill / Emote / Chat plus the original + `GameButtonWindow` hint buttons in a second column; bottom-right attack disc + (r 60, `touch.SetAttackButton`) with 8 quickslots on two rings (current + quickslot page, cycles pages 1-3) and page / ride (`/ride`, the Ctrl+G + command) / pick-up buttons; bottom centre potion belt = quickslot page 4 + (global 24-31); 3 px experience bar at the bottom edge. +- `interfaceModule.ShowDefaultWindows` / `ShowAllWindows` call + `MobileHUD.AdoptDefaultWindows`: hides the PC taskbar (and its TOP_MOST + HP/SP/EXP tooltips, which only the taskbar's OnUpdate hides), expanded + taskbars and energy bar, moves the minimap, chat and game hint buttons. + `game.GameWindow` calls `AdoptGameWindows` after the event icon opens. +- New `player.RequestUseGlobalQuickSlot` / `RequestAddGlobalQuickSlot` / + `RequestMoveGlobalQuickSlotToGlobalQuickSlot` (global < 32, same + CG_QUICKSLOT packets as the local variants) for the belt; switching + `SetQuickPage` was not usable because it refreshes the inventory. + +Verified: `ava2.touch_game` (taskbar hidden, belt = globals 24-31, minimap +under the top row, HUD buttons are UI while open world / joystick / attack are +not, attack disc pixels drawn, insets move the player panel), +`ava2.python` (global quickslot packets and range limits), 53/53 desktop +tests, desktop screenshot reviewed, Android APK builds. +Outstanding: no device run; minimap is still the original round one; labels +are English; chat input line can overlap the wheel's page button while typing; +no auto-hunt / target-lock buttons; Android keeps the 1024x768 letterboxed +logical size (step 5 scaling); the HUD reads the safe area only when built. diff --git a/src/eter_ui/PythonWindow.cpp b/src/eter_ui/PythonWindow.cpp index 320935f4..3d6aefd7 100644 --- a/src/eter_ui/PythonWindow.cpp +++ b/src/eter_ui/PythonWindow.cpp @@ -5,7 +5,10 @@ #include "eter_render/CRenderTarget.h" #include "shared/common/CRC32.h" #include +#include #include +#include +#include namespace UI { @@ -775,6 +778,69 @@ namespace UI SDL_RenderLine(renderer, (float)m_rect.right, (float)m_rect.top, (float)m_rect.right, (float)m_rect.bottom); } + DWORD CDisc::Type() { static DWORD s = GetCRC32("CDisc", 5); return s; } + BOOL CDisc::OnIsType(DWORD t) { return t == Type() || CWindow::OnIsType(t); } + + void CDisc::OnRender() + { + if (!IsShow()) return; + CGraphicDevice* pDevice = CGraphicDevice::InstancePtr(); + if (!pDevice) return; + SDL_Renderer* renderer = pDevice->GetRenderer(); + if (!renderer) return; + + const float radius = std::min(GetWidth(), GetHeight()) * 0.5f; + if (radius <= 0.5f) return; + const float cx = m_rect.left + GetWidth() * 0.5f, cy = m_rect.top + GetHeight() * 0.5f; + const float rim = std::clamp(m_fRimWidth, 0.0f, radius); + const float inner = radius - rim; + const int segments = std::clamp(int(radius * 0.8f), 24, 96); + auto color = [](DWORD c) { + return SDL_FColor{ ((c >> 16) & 0xFF) / 255.0f, ((c >> 8) & 0xFF) / 255.0f, (c & 0xFF) / 255.0f, ((c >> 24) & 0xFF) / 255.0f }; + }; + auto lerp = [](SDL_FColor a, SDL_FColor b, float t) { + return SDL_FColor{ a.r + (b.r - a.r) * t, a.g + (b.g - a.g) * t, a.b + (b.b - a.b) * t, a.a + (b.a - a.a) * t }; + }; + // Angle 0 = 12 o'clock, clockwise (screen y grows downwards). + auto at = [&](float r, float angle) { + return SDL_FPoint{ cx + r * std::sin(angle), cy - r * std::cos(angle) }; + }; + constexpr float kTau = 6.28318530718f; + std::vector v; + v.reserve(size_t(segments) * 12); + const SDL_FColor cInner = color(m_dwInner), cOuter = color(m_dwOuter); + const SDL_FColor cTop = color(m_dwRimTop), cBottom = color(m_dwRimBottom); + for (int i = 0; i < segments; ++i) { + const float a0 = kTau * i / segments, a1 = kTau * (i + 1) / segments; + if (inner > 0.0f) { + v.push_back({ { cx, cy }, cInner, {} }); + v.push_back({ at(inner, a0), cOuter, {} }); + v.push_back({ at(inner, a1), cOuter, {} }); + } + if (rim > 0.0f) { + // Light from the top: t = 0 at 12 o'clock, 1 at 6 o'clock. + const SDL_FColor k0 = lerp(cTop, cBottom, (1.0f - std::cos(a0)) * 0.5f); + const SDL_FColor k1 = lerp(cTop, cBottom, (1.0f - std::cos(a1)) * 0.5f); + const SDL_FPoint i0 = at(inner, a0), i1 = at(inner, a1), o0 = at(radius, a0), o1 = at(radius, a1); + v.push_back({ i0, k0, {} }); v.push_back({ o0, k0, {} }); v.push_back({ o1, k1, {} }); + v.push_back({ i0, k0, {} }); v.push_back({ o1, k1, {} }); v.push_back({ i1, k1, {} }); + } + } + const float arc = std::clamp(m_fArc, 0.0f, 1.0f); + if (arc > 0.0f && inner > 0.0f) { + const SDL_FColor cArc = color(m_dwArc); + const int arcSegments = std::max(1, int(std::ceil(segments * arc))); + for (int i = 0; i < arcSegments; ++i) { + const float a0 = kTau * arc * i / arcSegments, a1 = kTau * arc * (i + 1) / arcSegments; + v.push_back({ { cx, cy }, cArc, {} }); + v.push_back({ at(inner, a0), cArc, {} }); + v.push_back({ at(inner, a1), cArc, {} }); + } + } + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); + SDL_RenderGeometry(renderer, nullptr, v.data(), int(v.size()), nullptr, 0); + } + void CGraphicTextInstance::Render() { CGraphicDevice* pDevice = CGraphicDevice::InstancePtr(); diff --git a/src/eter_ui/PythonWindow.h b/src/eter_ui/PythonWindow.h index a0c352b6..a7f4383b 100644 --- a/src/eter_ui/PythonWindow.h +++ b/src/eter_ui/PythonWindow.h @@ -330,6 +330,25 @@ namespace UI DWORD m_dwLeftColor, m_dwRightColor, m_dwCenterColor; }; + // Mobile HUD (docs/MOBILE-ARCHITECTURE.md step 4): a round frame drawn with geometry instead of + // textures. A disc filled with a radial gradient, a bevelled rim (top colour fading to bottom + // colour) and an optional clockwise pie from 12 o'clock for cooldowns and gauges. + class CDisc : public CWindow + { + public: + static DWORD Type(); + CDisc(PyObject * ppyObject) : CWindow(ppyObject) {} + virtual ~CDisc() {} + void SetDiscColors(DWORD inner, DWORD outer, DWORD rimTop, DWORD rimBottom, float rimWidth) + { m_dwInner = inner; m_dwOuter = outer; m_dwRimTop = rimTop; m_dwRimBottom = rimBottom; m_fRimWidth = rimWidth; } + void SetDiscArc(float fraction, DWORD color) { m_fArc = fraction; m_dwArc = color; } + protected: + void OnRender() override; + BOOL OnIsType(DWORD dwType) override; + DWORD m_dwInner = 0xC0202028, m_dwOuter = 0xC0101014, m_dwRimTop = 0xFFC8A060, m_dwRimBottom = 0xFF604020, m_dwArc = 0xA0000000; + float m_fRimWidth = 3.0f, m_fArc = 0.0f; + }; + class CTextLine : public CWindow { public: diff --git a/src/eter_ui/PythonWindowManager.cpp b/src/eter_ui/PythonWindowManager.cpp index bbe6619a..e19f23c3 100644 --- a/src/eter_ui/PythonWindowManager.cpp +++ b/src/eter_ui/PythonWindowManager.cpp @@ -164,6 +164,7 @@ namespace UI case WT_LINE: return new CLine(po); case WT_BAR3D: return new CBar3D(po); case WT_NUMLINE: return new CNumberLine(po); + case WT_DISC: return new CDisc(po); default: break; } return new CWindow(po); @@ -194,6 +195,7 @@ namespace UI CWindow * CWindowManager::RegisterLine(PyObject * po, const char * c_szLayer) { return RegisterTypeWindow(po, WT_LINE, c_szLayer); } CWindow * CWindowManager::RegisterBar3D(PyObject * po, const char * c_szLayer) { return RegisterTypeWindow(po, WT_BAR3D, c_szLayer); } CWindow * CWindowManager::RegisterNumberLine(PyObject * po, const char * c_szLayer) { return RegisterTypeWindow(po, WT_NUMLINE, c_szLayer); } + CWindow * CWindowManager::RegisterDisc(PyObject * po, const char * c_szLayer) { return RegisterTypeWindow(po, WT_DISC, c_szLayer); } CWindow * CWindowManager::RegisterRenderTarget(PyObject * po, const char * c_szLayer) { if (m_LayerWindowMap.find(c_szLayer) == m_LayerWindowMap.end()) return nullptr; diff --git a/src/eter_ui/PythonWindowManager.h b/src/eter_ui/PythonWindowManager.h index badcea59..194d985f 100644 --- a/src/eter_ui/PythonWindowManager.h +++ b/src/eter_ui/PythonWindowManager.h @@ -61,6 +61,7 @@ namespace UI WT_LINE, WT_BAR3D, WT_NUMLINE, + WT_DISC, }; CWindow * RegisterWindow(PyObject * po, const char * c_szLayer); @@ -82,6 +83,7 @@ namespace UI CWindow * RegisterLine(PyObject * po, const char * c_szLayer); CWindow * RegisterBar3D(PyObject * po, const char * c_szLayer); CWindow * RegisterNumberLine(PyObject * po, const char * c_szLayer); + CWindow * RegisterDisc(PyObject * po, const char * c_szLayer); void DestroyWindow(CWindow * pWin); void NotifyDestroyWindow(CWindow * pWindow); diff --git a/src/scripting/python_gameplay_modules.cpp b/src/scripting/python_gameplay_modules.cpp index 63436720..5fea659f 100644 --- a/src/scripting/python_gameplay_modules.cpp +++ b/src/scripting/python_gameplay_modules.cpp @@ -195,23 +195,46 @@ static PyObject* player_RequestAddLocalQuickSlot(PyObject*, PyObject* args) { Py_RETURN_NONE; } +static bool use_global_quick_slot(int global) { + if (global >= 0 && global < (int)s_playerQuickSlots.size()) { + if(s_playerQuickSlots[global].type==1) PythonNetworkStream::Instance().SendItemUsePacket(1,uint16_t(s_playerQuickSlots[global].pos)); + else if(s_playerQuickSlots[global].type==3) { + if(!player_window_call("BINARY_ActEmotion",Py_BuildValue("(i)",s_playerQuickSlots[global].pos))) return false; + } + else if (s_playerQuickSlots[global].type == 2) { // Skill + int skillSlot = s_playerQuickSlots[global].pos; + ClickSkillSlot(skillSlot); + } + } + return true; +} + static PyObject* player_RequestUseLocalQuickSlot(PyObject*, PyObject* args) { int slot = 0; if (!PyArg_ParseTuple(args, "i", &slot)) return nullptr; - { - if(slot<0 || slot>=8) Py_RETURN_NONE; - int global=s_quickPage*8+slot; - if (global >= 0 && global < (int)s_playerQuickSlots.size()) { - if(s_playerQuickSlots[global].type==1) PythonNetworkStream::Instance().SendItemUsePacket(1,uint16_t(s_playerQuickSlots[global].pos)); - else if(s_playerQuickSlots[global].type==3) { - if(!player_window_call("BINARY_ActEmotion",Py_BuildValue("(i)",s_playerQuickSlots[global].pos))) return nullptr; - } - else if (s_playerQuickSlots[global].type == 2) { // Skill - int skillSlot = s_playerQuickSlots[global].pos; - ClickSkillSlot(skillSlot); - } - } - } + if(slot<0 || slot>=8) Py_RETURN_NONE; + if(!use_global_quick_slot(s_quickPage*8+slot)) return nullptr; + Py_RETURN_NONE; +} + +// Mobile HUD potion belt (ui_mobile_hud.py): a fixed quickslot page shown next to the current +// one, so it addresses global slots. Not in the original player module; same packets as the +// local variants. +static PyObject* player_RequestUseGlobalQuickSlot(PyObject*, PyObject* args) { + int global = 0; + if (!PyArg_ParseTuple(args, "i", &global)) return nullptr; + if(global<0 || global>=32) Py_RETURN_NONE; + if(!use_global_quick_slot(global)) return nullptr; + Py_RETURN_NONE; +} +static PyObject* player_RequestAddGlobalQuickSlot(PyObject*, PyObject* args) { + int global,type,pos;if(!PyArg_ParseTuple(args,"iii",&global,&type,&pos)) return nullptr; + if(uint32_t(global)<32 && !quick_send({HEADER_CG_QUICKSLOT_ADD,uint8_t(global),uint8_t(type),uint8_t(pos)})) return nullptr; + Py_RETURN_NONE; +} +static PyObject* player_MoveQuickGlobal(PyObject*,PyObject* args) { + int source,target;if(!PyArg_ParseTuple(args,"ii",&source,&target)) return nullptr; + if(uint32_t(source)<32 && uint32_t(target)<32 && !quick_send({HEADER_CG_QUICKSLOT_SWAP,uint8_t(source),uint8_t(target)})) return nullptr; Py_RETURN_NONE; } @@ -3595,6 +3618,9 @@ void initPlayer() { {"RequestDeleteGlobalQuickSlot", player_DeleteQuick, METH_VARARGS, nullptr}, {"RequestMoveGlobalQuickSlotToLocalQuickSlot", player_MoveQuick, METH_VARARGS, nullptr}, {"RequestUseLocalQuickSlot", player_RequestUseLocalQuickSlot, METH_VARARGS, nullptr}, + {"RequestUseGlobalQuickSlot", player_RequestUseGlobalQuickSlot, METH_VARARGS, nullptr}, + {"RequestAddGlobalQuickSlot", player_RequestAddGlobalQuickSlot, METH_VARARGS, nullptr}, + {"RequestMoveGlobalQuickSlotToGlobalQuickSlot", player_MoveQuickGlobal, METH_VARARGS, nullptr}, {"LocalQuickSlotIndexToGlobalQuickSlotIndex", player_LocalQuickIndex, METH_VARARGS, nullptr}, {"GetQuickPage", player_GetQuickPage, METH_VARARGS, nullptr}, {"SetQuickPage", player_SetQuickPage, METH_VARARGS, nullptr}, diff --git a/src/scripting/python_wndmgr.cpp b/src/scripting/python_wndmgr.cpp index 35c43d62..4735fdd0 100644 --- a/src/scripting/python_wndmgr.cpp +++ b/src/scripting/python_wndmgr.cpp @@ -2146,6 +2146,55 @@ PyObject * wndBarSetColor(PyObject * poSelf, PyObject * poArgs) return Py_BuildNone(); } +// Mobile HUD round frame (UI::CDisc); not part of the original wndMgr. +PyObject * wndMgrRegisterDisc(PyObject * poSelf, PyObject * poArgs) +{ + PyObject * po; + if (!PyTuple_GetObject(poArgs, 0, &po)) + return Py_BuildException(); + char * szLayer; + if (!PyTuple_GetString(poArgs, 1, &szLayer)) + return Py_BuildException(); + + UI::CWindow * pWindow = UI::CWindowManager::Instance().RegisterDisc(po, szLayer); + return Py_BuildPointer(pWindow); +} + +// SetDiscColors(hwnd, inner, outer, rimTop, rimBottom, rimWidth) +PyObject * wndDiscSetColors(PyObject * poSelf, PyObject * poArgs) +{ + UI::CWindow * pWindow; + if (!PyTuple_GetWindow(poArgs, 0, &pWindow)) + return Py_BuildException(); + int colors[4]; + for (int i = 0; i < 4; ++i) + if (!PyTuple_GetInteger(poArgs, 1 + i, &colors[i])) + return Py_BuildException(); + float rimWidth; + if (!PyTuple_GetFloat(poArgs, 5, &rimWidth)) + return Py_BuildException(); + if (pWindow->IsType(UI::CDisc::Type())) + ((UI::CDisc *)pWindow)->SetDiscColors(DWORD(colors[0]), DWORD(colors[1]), DWORD(colors[2]), DWORD(colors[3]), rimWidth); + return Py_BuildNone(); +} + +// SetDiscArc(hwnd, fraction, color): clockwise pie from 12 o'clock, 0 hides it. +PyObject * wndDiscSetArc(PyObject * poSelf, PyObject * poArgs) +{ + UI::CWindow * pWindow; + if (!PyTuple_GetWindow(poArgs, 0, &pWindow)) + return Py_BuildException(); + float fraction; + if (!PyTuple_GetFloat(poArgs, 1, &fraction)) + return Py_BuildException(); + int color; + if (!PyTuple_GetInteger(poArgs, 2, &color)) + return Py_BuildException(); + if (pWindow->IsType(UI::CDisc::Type())) + ((UI::CDisc *)pWindow)->SetDiscArc(fraction, DWORD(color)); + return Py_BuildNone(); +} + // SetSlotID -> wndMgrSetSlotID PyObject * wndMgrSetSlotID(PyObject * poSelf, PyObject * poArgs) { @@ -3197,6 +3246,9 @@ void initwndMgr() { {"RegisterLine", wndMgrRegisterLine, METH_VARARGS, nullptr}, {"RegisterBar3D", wndMgrRegisterBar3D, METH_VARARGS, nullptr}, {"RegisterNumberLine", wndMgrRegisterNumberLine, METH_VARARGS, nullptr}, + {"RegisterDisc", wndMgrRegisterDisc, METH_VARARGS, nullptr}, + {"SetDiscColors", wndDiscSetColors, METH_VARARGS, nullptr}, + {"SetDiscArc", wndDiscSetArc, METH_VARARGS, nullptr}, {"Destroy", wndMgrDestroy, METH_VARARGS, nullptr}, {"AddFlag", wndMgrAddFlag, METH_VARARGS, nullptr}, {"IsRTL", wndMgrIsRTL, METH_VARARGS, nullptr}, diff --git a/tests/python_test.cpp b/tests/python_test.cpp index 4eb2eb1e..bc7f2361 100644 --- a/tests/python_test.cpp +++ b/tests/python_test.cpp @@ -684,6 +684,10 @@ int main(int argc,char** argv) { if(netStream.PopSendBytes()!=std::vector{17,10,17,35}) throw std::runtime_error("remove by value missed hidden server quickslot"); python.execute("player.RequestUseLocalQuickSlot(2)\n"); if(netStream.PopSendBytes()!=std::vector{11,1,7,0}) throw std::runtime_error("inventory quickslot use mismatch"); + // Mobile HUD potion belt addresses global slots directly (any page, < 32), same packets. + python.execute("player.RequestUseGlobalQuickSlot(10)\nplayer.RequestAddGlobalQuickSlot(25,2,6)\nplayer.RequestMoveGlobalQuickSlotToGlobalQuickSlot(10,26)\n" + "player.RequestUseGlobalQuickSlot(35)\nplayer.RequestAddGlobalQuickSlot(32,2,6)\nplayer.RequestMoveGlobalQuickSlotToGlobalQuickSlot(10,32)\n"); + if(netStream.PopSendBytes()!=std::vector{11,1,7,0,16,25,2,6,18,10,26}) throw std::runtime_error("global quickslot request mismatch"); python.execute("net.SendItemDropPacket(7)\nnet.SendItemDropPacketNew(1,7,70000)\n"); if(netStream.PopSendBytes()!=std::vector{224,1,7,0,0,0,0,0,20,1,7,0,0,0,0,0,0x70,0x11,1,0}) throw std::runtime_error("AVA2 old/new drop wire or DWORD count mismatch"); diff --git a/tests/touch_game_test.cpp b/tests/touch_game_test.cpp index 8d9bf370..920bb584 100644 --- a/tests/touch_game_test.cpp +++ b/tests/touch_game_test.cpp @@ -1,5 +1,5 @@ // Touch mode in the original GameWindow: the mobile HUD must leave the joystick / attack zones and -// open world to the touch router, while real UI (taskbar) still takes the finger. +// open world to the touch router, while real UI (HUD buttons) still takes the finger. #include "python_runtime.h" #include "python_gameplay_modules.h" #include "app/input/touch_router.h" @@ -10,6 +10,7 @@ #include "eter_net/PythonNetworkStream.h" #include #include +#include #include #include #include @@ -54,7 +55,7 @@ int main(int argc, char** argv) { CGraphicDevice device; device.Init(renderer); runtime.execute( - "import app, touch, localeInfo, networkModule, introLoading, net\n" + "import app, touch, localeInfo, networkModule, introLoading, net, player\n" "assert app.ENABLE_MOBILE_HUD == 1 and touch.IsEnabled()\n" "net.SendSelectCharacterPacket=lambda slot: None\n" "introLoading.__main__()\n" @@ -81,10 +82,15 @@ int main(int argc, char** argv) { assert(!sink.IsUiAt(W * 0.6f, H * 0.4f)); assert(!sink.IsUiAt(160.0f, H - 180.0f)); assert(!sink.IsUiAt(layout.attack_x, layout.attack_y)); - // The taskbar along the bottom edge is real UI. - runtime.execute("tb = game.interface.wndTaskBar\n" - "touch_tb = tb.GetGlobalPosition()\n" - "touch_tb = (touch_tb[0] + tb.GetWidth() / 2, touch_tb[1] + tb.GetHeight() / 2)\n" + // Mobile mode hides the PC taskbar; the HUD buttons (here the combat wheel's page button) + // are real UI. The quick belt is quickslot page 4 and the minimap sits under the top-right row. + runtime.execute("assert not game.interface.wndTaskBar.IsShow()\n" + "assert [s.globalIndex for s in hud.quick_slots] == range(24, 32)\n" + "mm = game.interface.wndMiniMap\n" + "assert mm.GetGlobalPosition()[1] >= hud.drawer.GetGlobalPosition()[1] + hud.drawer.GetRowHeight()\n" + "pb = hud.combat_wheel.page_button\n" + "touch_tb = pb.GetGlobalPosition()\n" + "touch_tb = (touch_tb[0] + pb.GetWidth() / 2, touch_tb[1] + pb.GetHeight() / 2)\n" ); PyObject* main = PyImport_AddModule("__main__"); PyObject* tb = PyDict_GetItemString(PyModule_GetDict(main), "touch_tb"); @@ -110,7 +116,7 @@ int main(int argc, char** argv) { router.FingerUp(1, 160.0f + layout.joy_radius, H - 180.0f, 220); assert(!sink.attack && !ava2::GetPlayerMovementYaw(0.0f, yaw)); - // Taskbar taps go to the window manager, open world taps become world clicks. + // HUD button taps go to the window manager, open world taps become world clicks. router.FingerDown(3, tb_x, tb_y, 300); router.FingerUp(3, tb_x, tb_y, 350); assert(sink.ui_downs == 1); @@ -126,12 +132,22 @@ int main(int argc, char** argv) { "safe_hud = ui_mobile_hud.MobileHUD(game.interface)\n" "(ax, ay, ar), joy = touch.GetLayout()\n" "assert (ax, ay, ar) == (1024 - 30 - 120, 768 - 20 - 120, 60), (ax, ay, ar)\n" - "assert safe_hud.player_hud.GetGlobalPosition()[0] == 40 + 25\n" + "assert safe_hud.player_hud.GetGlobalPosition()[0] == 40 + 12\n" "safe_hud.Hide()\nsafe_hud = None\n"); router.SetLayout(layout); SDL_FillSurfaceRect(surface, nullptr, 0xff10141e); wm->Render(); SDL_RenderPresent(renderer); + // CDisc geometry: the attack disc is dark red between the icon and the rim; empty screen is not. + auto pixel = [&](int x, int y) { + Uint8 r = 0, g = 0, b = 0, a = 0; + SDL_ReadSurfacePixel(surface, x, y, &r, &g, &b, &a); + return std::array{r, g, b}; + }; + const auto disc = pixel(int(layout.attack_x), int(layout.attack_y) + 45); + assert(disc[0] > 80 && disc[0] > disc[2] * 2); + const auto empty = pixel(int(W * 0.6f), int(H * 0.4f)); + assert(empty[0] < 40); if (argc > 3) SDL_SaveBMP(surface, argv[3]); router.SetSink(nullptr); runtime.execute("stream.Destroy()\n"); diff --git a/upstream/python-root/game.py b/upstream/python-root/game.py index 0f23d03d..3f38a94a 100644 --- a/upstream/python-root/game.py +++ b/upstream/python-root/game.py @@ -244,6 +244,8 @@ class GameWindow(ui.ScriptWindow): self.notificationItem.SetEvent(self.__ClickCalendarioButton) #self.notificationItem.SetPosition(100, 10) self.notificationItem.Open() + if self.interface.wndMobileHUD: + self.interface.wndMobileHUD.AdoptGameWindows(self) ## self.cantDestroyItemDialog = uiCantDestroyItem.CantDestroyItemDialog() diff --git a/upstream/python-root/interfacemodule.py b/upstream/python-root/interfacemodule.py index 535b8154..d45b6ab9 100644 --- a/upstream/python-root/interfacemodule.py +++ b/upstream/python-root/interfacemodule.py @@ -1823,6 +1823,7 @@ class Interface(object): self.wndMiniMap.ShowMiniMap() if self.wndEnergyBar: self.wndEnergyBar.Show() + if hasattr(self, "wndMobileHUD") and self.wndMobileHUD: self.wndMobileHUD.AdoptDefaultWindows() def ShowAllWindows(self): self.wndTaskBar.Show() @@ -1850,6 +1851,9 @@ class Interface(object): self.wnd12ziTimer.Show() if self.wnd12ziReward: self.wnd12ziReward.Show() + if hasattr(self, "wndMobileHUD") and self.wndMobileHUD: + self.wndMobileHUD.Show() + self.wndMobileHUD.AdoptDefaultWindows() def HideAllWindows(self): if self.wndTaskBar: diff --git a/upstream/python-root/ui_mobile_combat.py b/upstream/python-root/ui_mobile_combat.py index 67d5693e..75f7f8f1 100644 --- a/upstream/python-root/ui_mobile_combat.py +++ b/upstream/python-root/ui_mobile_combat.py @@ -1,105 +1,142 @@ # -*- coding: utf-8 -*- import ui -import grp import math import player +import net import app import wndMgr import touch +import constInfo +import ui_mobile_widgets as widgets 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) + """ + 移动端战斗轮盘(屏幕右下角) + - 大攻击键:按下由原生触摸分流器判定(touch.SetAttackButton),按住等同键盘攻击键; + 本窗口只画圆框并显示按下状态 + - 攻击键外两圈共 8 个快捷格 = 当前快捷页的 8 格(PC 任务栏 1-4 / F1-F4 同一份数据), + 第 4 页留给底部药水栏,所以这里只在第 1-3 页间切换 + - 小按钮:快捷页切换、上下马(原版 Ctrl+G 的 /ride)、拾取(原版 ` / Z 键) + """ + ATTACK_RADIUS = 60 + SLOT_DIAMETER = 50 + SMALL_DIAMETER = 40 + # (半径, 角度):角度从 +x 逆时针,内外圈各 4 格,外圈错开半格;相邻格间距大于格子直径 + SLOT_LAYOUT = [(108, 90), (108, 120), (108, 150), (108, 180), + (172, 97.5), (172, 122.5), (172, 147.5), (172, 172.5)] + RING_PAGE_COUNT = 3 + WINDOW_EXTENT = 200 - def __init__(self, origin_x=None, origin_y=None): - ui.Window.__init__(self) - self.SetWindowName("MobileCombatWheel") - # 轮盘本身不拦截触摸,否则会盖住攻击键热区和世界点击;技能槽按钮仍可点 - self.AddFlag("not_pick") + 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 + 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.origin_x = origin_x - self.origin_y = origin_y + # 窗口左上角 = 圆心 - WINDOW_EXTENT;右下留出攻击键与小按钮 + ext = self.WINDOW_EXTENT + self.SetPosition(origin_x - ext, origin_y - ext) + self.SetSize(ext + 120, ext + 120) + cx = cy = ext - self.SetPosition(origin_x - 260, origin_y - 260) - self.SetSize(380, 380) + # 1. 攻击键 + r = self.ATTACK_RADIUS + self.attack_disc = widgets.MakeDisc(self, cx - r, cy - r, r * 2, widgets.STYLE_ATTACK) + self.attack_icon = ui.ExpandedImageBox() + self.attack_icon.SetParent(self) + self.attack_icon.AddFlag("not_pick") + try: + self.attack_icon.LoadImage("d:/ymir work/ui/game/taskbar/mouse_button_attack_01.sub") + self.attack_icon.SetScale(2.0, 2.0) + self.attack_icon.SetPosition(cx - self.attack_icon.GetWidth() / 2, cy - self.attack_icon.GetHeight() / 2) + self.attack_icon.Show() + except: + pass + self.attack_pressed = False + touch.SetAttackButton(origin_x, origin_y, r) - # 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.slots = [] + half = self.SLOT_DIAMETER / 2 + for i, (radius, angle) in enumerate(self.SLOT_LAYOUT): + rad = math.radians(angle) + x = int(cx + radius * math.cos(rad)) - half + y = int(cy - radius * math.sin(rad)) - half + slot = widgets.QuickSlotDisc(self.SLOT_DIAMETER, localIndex=i) + slot.SetParent(self) + slot.SetPosition(x, y) + slot.Show() + self.slots.append(slot) - # 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) + # 3. 小按钮(攻击键左下 / 右上) + d = self.SMALL_DIAMETER + self.page_button = self.__MakeSmall(cx - 150 - d / 2, cy + 40 - d / 2, ui.__mem_func__(self.__OnNextPage)) + self.page_button.SetLabel("1") + self.mount_button = self.__MakeSmall(cx + 62 - d / 2, cy - 92 - d / 2, ui.__mem_func__(self.__OnMount)) + self.mount_button.SetLabel("Ride") + self.pickup_button = self.__MakeSmall(cx - 86 - d / 2, cy + 82 - d / 2, ui.__mem_func__(self.__OnPickUp)) + self.pickup_button.SetLabel("Pick") - 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() + self.page = -1 + self.lastRefresh = 0 + self.Refresh() - # CD 遮罩 - cd_text = ui.TextLine() - cd_text.SetParent(slot) - cd_text.SetPosition(15, 20) - cd_text.SetText("") - cd_text.Show() + def __del__(self): + ui.Window.__del__(self) - self.skills.append({'btn': slot, 'cd_text': cd_text, 'slot': i}) + def __MakeSmall(self, x, y, event): + button = widgets.RoundButton(self.SMALL_DIAMETER) + button.SetParent(self) + button.SetPosition(x, y) + button.SetEvent(event) + button.Show() + return button - def __del__(self): - ui.Window.__del__(self) + def __OnNextPage(self): + # game.__SelectQuickPage 同一路径(player.SetQuickPage) + player.SetQuickPage((player.GetQuickPage() + 1) % self.RING_PAGE_COUNT) + self.Refresh() - def __OnSkillCast(self, index): - # 释放技能 (对应 Metin2 技能槽 1~4) - player.ClickSkillSlot(index + 1) + def __OnMount(self): + net.SendChatPacket("/ride") - 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) + def __OnPickUp(self): + game = constInfo.GetGameInstance() + if game: + game.PickUpItem() + else: + player.PickCloseItem() - # 刷新技能冷却状态 - 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("") + def Refresh(self): + page = player.GetQuickPage() + if page >= self.RING_PAGE_COUNT: + # 第 4 页是药水栏,PC 端切到那里时轮盘回到第 1 页 + player.SetQuickPage(0) + page = 0 + if page != self.page: + self.page = page + self.page_button.label.SetText(str(page + 1)) + for slot in self.slots: + slot.Refresh() + + def OnUpdate(self): + pressed = touch.IsAttackPressed() + if pressed != self.attack_pressed: + self.attack_pressed = pressed + self.attack_disc.SetStyle(widgets.STYLE_ATTACK_DOWN if pressed else widgets.STYLE_ATTACK) + + # 与 uitaskbar.TaskBar.OnUpdate 相同的 500 ms 刷新(冷却、数量、激活状态) + if app.GetGlobalTime() - self.lastRefresh > 500: + self.lastRefresh = app.GetGlobalTime() + self.Refresh() diff --git a/upstream/python-root/ui_mobile_drawer.py b/upstream/python-root/ui_mobile_drawer.py index 6b895b7f..ffb74781 100644 --- a/upstream/python-root/ui_mobile_drawer.py +++ b/upstream/python-root/ui_mobile_drawer.py @@ -3,109 +3,130 @@ import ui import grp import wndMgr import touch +import ui_mobile_widgets as widgets class MobileDrawer(ui.Window): - """ - 移动端系统抽屉菜单与顶部快捷导航 - - 位于屏幕右上角 - - 包含:通知、邮件、战力属性、背包、汉堡折叠按钮 - - 点击汉堡按钮自右侧滑出二级扩展菜单 (设置/角色/公会/离线挂机等) - """ - def __init__(self, interface=None): - ui.Window.__init__(self) - self.SetWindowName("MobileDrawer") - self.interface = interface + """ + 移动端右上角入口 + - 一排圆形入口按钮(图标用 AVA2 任务栏自己的贴图):好友、角色、背包、菜单 + - 菜单按钮展开二级面板:技能、任务、公会、系统设置 + - 原版小地图由 MobileHUD.AdoptDefaultWindows 挪到这一排下面 + """ + BUTTON_DIAMETER = 44 + BUTTON_STEP = 52 + TASKBAR = "d:/ymir work/ui/game/taskbar/" - sw = wndMgr.GetScreenWidth() - self.sw = sw - safe_l, safe_t, safe_r, safe_b = touch.GetSafeArea() - self.SetPosition(sw - safe_r - 380, safe_t + 15) - self.SetSize(360, 240) - self.AddFlag("attach") + def __init__(self, interface=None): + ui.Window.__init__(self) + self.SetWindowName("MobileDrawer") + self.AddFlag("not_pick") + self.interface = interface - self.is_menu_open = False - self.__BuildUI() + sw = wndMgr.GetScreenWidth() + safe_l, safe_t, safe_r, safe_b = touch.GetSafeArea() + self.width = 4 * self.BUTTON_STEP + self.SetPosition(sw - safe_r - self.width - 8, safe_t + 8) + self.SetSize(self.width, self.BUTTON_DIAMETER) - def __del__(self): - ui.Window.__del__(self) + self.is_menu_open = False + self.__BuildUI() - def __BuildUI(self): - # 1. 一级横向快捷按钮组 (直径 48px) - btn_data = [ - ("Inv", self.__OnClickInventory), - ("Stat", self.__OnClickStatus), - ("Mail", self.__OnClickMail), - ("Menu", self.__OnToggleMenu) - ] + def __del__(self): + ui.Window.__del__(self) - 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) + def GetRowHeight(self): + return self.BUTTON_DIAMETER - # 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() + def __BuildUI(self): + # 1. 入口按钮(自右向左:菜单、背包、角色、好友) + btn_data = [ + ("community_button_01.sub", "Friend", self.__OnClickMessenger), + ("character_button_01.sub", "Char", self.__OnClickStatus), + ("inventory_button_01.sub", "Bag", self.__OnClickInventory), + ("system_button_01.sub", "Menu", self.__OnToggleMenu), + ] + self.quick_buttons = [] + for i, (icon, label, callback) in enumerate(btn_data): + btn = widgets.RoundButton(self.BUTTON_DIAMETER) + btn.SetParent(self) + btn.SetPosition(i * self.BUTTON_STEP + (self.BUTTON_STEP - self.BUTTON_DIAMETER), 0) + if not btn.SetIcon(self.TASKBAR + icon): + btn.SetLabel(label) + btn.SetEvent(ui.__mem_func__(callback)) + btn.Show() + self.quick_buttons.append(btn) - menu_items = [ - ("Character", self.__OnClickStatus), - ("Messenger", self.__OnClickMessenger), - ("System Option", self.__OnClickSystem), - ("Exit Game", self.__OnClickExit) - ] + # 2. 二级面板(默认隐藏),挂在 HUD 根窗口下,展开在入口行左下方 + self.drawer_panel = ui.Bar() + self.drawer_panel.SetColor(grp.GenerateColor(0.08, 0.07, 0.06, 0.88)) + self.drawer_panel.SetSize(180, 15 + 5 * 40) + self.drawer_panel.Hide() - 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) + menu_items = [ + ("Skill", self.__OnClickSkill), + ("Quest", self.__OnClickQuest), + ("Guild", self.__OnClickGuild), + ("System", self.__OnClickSystem), + ("Close", self.__OnToggleMenu), + ] + 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 AttachPanel(self, parent): + (x, y) = self.GetLocalPosition() + self.drawer_panel.SetParent(parent) + self.drawer_panel.SetPosition(x + self.width - 180 - self.BUTTON_STEP, y + self.BUTTON_DIAMETER + 6) - def __OnClickStatus(self): - if self.interface: - self.interface.ToggleCharacterWindowStatusPage() + def __CloseMenu(self): + self.is_menu_open = False + self.drawer_panel.Hide() - def __OnClickMail(self): - if self.interface and hasattr(self.interface, 'OpenMail'): - self.interface.OpenMail() + def __OnClickInventory(self): + if self.interface: + self.interface.ToggleInventoryWindow() - def __OnClickMessenger(self): - if self.interface: - self.interface.ToggleMessenger() + def __OnClickStatus(self): + if self.interface: + self.interface.ToggleCharacterWindowStatusPage() - def __OnClickSystem(self): - if self.interface: - self.interface.ToggleSystemDialog() + def __OnClickMessenger(self): + if self.interface: + self.interface.ToggleMessenger() - def __OnClickExit(self): - if self.interface: - self.interface.ToggleSystemDialog() + def __OnClickSkill(self): + self.__CloseMenu() + if self.interface: + self.interface.ToggleCharacterWindow("SKILL") - 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() + def __OnClickQuest(self): + self.__CloseMenu() + if self.interface: + self.interface.ToggleCharacterWindow("QUEST") + + def __OnClickGuild(self): + self.__CloseMenu() + if self.interface: + self.interface.ToggleGuildWindow() + + def __OnClickSystem(self): + self.__CloseMenu() + 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() + self.drawer_panel.SetTop() + else: + self.drawer_panel.Hide() diff --git a/upstream/python-root/ui_mobile_hud.py b/upstream/python-root/ui_mobile_hud.py index 3e6dfb73..5433cc08 100644 --- a/upstream/python-root/ui_mobile_hud.py +++ b/upstream/python-root/ui_mobile_hud.py @@ -2,222 +2,279 @@ import ui import grp import player -import chr -import chrmgr +import net import app import wndMgr -import math import ui_mobile_joystick import ui_mobile_combat import ui_mobile_drawer +import ui_mobile_widgets as widgets import touch +import uiCharacter + +def unsigned32(n): + return n & 0xFFFFFFFFL 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 + """ + 移动端战斗 HUD(docs/MOBILE-ARCHITECTURE.md 第 4 步),按安全区内缩: + 1. 左上:头像圆框 + 名字等级 + HP/SP/体力条;原版 buff 图标(AffectShower)挪到其下方 + 2. 顶部居中:沿用原版目标栏 uiTarget.TargetBoard(本来就在顶部居中) + 3. 右上:圆形入口按钮行 + 菜单面板(MobileDrawer);原版小地图挪到其下方 + 4. 左侧:竖排功能按钮(任务、技能、表情、聊天) + 5. 右下:攻击键 + 当前快捷页 8 格(MobileCombatWheel) + 6. 底部居中:药水栏 = 第 4 快捷页 8 格;最底一条经验条 + 7. 左下:浮动摇杆显示层(MobileJoystick) + 移动模式下隐藏 PC 任务栏(AdoptDefaultWindows)。快捷栏数据与 PC 端完全相同。 + """ + BELT_PAGE = 3 + BELT_DIAMETER = 46 + BELT_STEP = 50 + SIDE_DIAMETER = 48 + SIDE_STEP = 58 + FACE_DIAMETER = 64 + HP_WIDTH = 190 + SP_WIDTH = 170 + ST_WIDTH = 150 - sw = wndMgr.GetScreenWidth() - sh = wndMgr.GetScreenHeight() - self.SetPosition(0, 0) - self.SetSize(sw, sh) - self.AddFlag("attach") - self.AddFlag("not_pick") + def __init__(self, interface=None): + ui.Window.__init__(self) + self.SetWindowName("MobileHUD") + self.interface = interface - self.safe_area = touch.GetSafeArea() - self.__BuildUI(sw, sh) + sw = wndMgr.GetScreenWidth() + sh = wndMgr.GetScreenHeight() + self.SetPosition(0, 0) + self.SetSize(sw, sh) + self.AddFlag("attach") + self.AddFlag("not_pick") - def __del__(self): - ui.Window.__del__(self) + self.safe_area = touch.GetSafeArea() + self.race = -1 + self.lastBeltRefresh = 0 + self.__BuildUI(sw, sh) - 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() + def __del__(self): + ui.Window.__del__(self) - # 头像框背景底板 - 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() + def __Container(self, x, y, w, h): + wnd = ui.Window() + wnd.SetParent(self) + wnd.AddFlag("not_pick") + wnd.SetPosition(x, y) + wnd.SetSize(w, h) + wnd.Show() + return wnd - # 角色名称 - 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() + def __Gauge(self, parent, x, y, w, h, back, front): + bg = ui.Bar() + bg.SetParent(parent) + bg.AddFlag("not_pick") + bg.SetPosition(x, y) + bg.SetSize(w, h) + bg.SetColor(back) + bg.Show() + bar = ui.Bar() + bar.SetParent(parent) + bar.AddFlag("not_pick") + bar.SetPosition(x, y) + bar.SetSize(w, h) + bar.SetColor(front) + bar.Show() + frame = ui.Box() + frame.SetParent(parent) + frame.AddFlag("not_pick") + frame.SetPosition(x - 1, y - 1) + frame.SetSize(w + 2, h + 2) + frame.SetColor(grp.GenerateColor(0.55, 0.42, 0.25, 0.9)) + frame.Show() + return bar - # 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() + def __BuildUI(self, w, h): + safe_l, safe_t, safe_r, safe_b = self.safe_area - 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() + # 1. 左上:主角状态 + self.player_hud = self.__Container(safe_l + 12, safe_t + 8, 300, self.FACE_DIAMETER + 4) + self.face_disc = widgets.MakeDisc(self.player_hud, 0, 0, self.FACE_DIAMETER, widgets.STYLE_FRAME) + self.face_image = ui.ExpandedImageBox() + self.face_image.SetParent(self.player_hud) + self.face_image.AddFlag("not_pick") - # 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.text_name = ui.TextLine() + self.text_name.SetParent(self.player_hud) + self.text_name.AddFlag("not_pick") + self.text_name.SetPosition(self.FACE_DIAMETER + 8, 2) + self.text_name.SetOutline() + self.text_name.SetText("") + self.text_name.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() + gx = self.FACE_DIAMETER + 8 + self.hp_bar = self.__Gauge(self.player_hud, gx, 22, self.HP_WIDTH, 12, + grp.GenerateColor(0.20, 0.05, 0.05, 0.75), grp.GenerateColor(0.85, 0.12, 0.12, 0.95)) + self.mp_bar = self.__Gauge(self.player_hud, gx, 38, self.SP_WIDTH, 9, + grp.GenerateColor(0.05, 0.10, 0.25, 0.75), grp.GenerateColor(0.15, 0.45, 0.95, 0.95)) + self.sp_bar = self.__Gauge(self.player_hud, gx, 51, self.ST_WIDTH, 5, + grp.GenerateColor(0.20, 0.18, 0.05, 0.75), grp.GenerateColor(0.90, 0.80, 0.10, 0.85)) - # 体力/耐力条 - 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. 右上:入口按钮行 + 菜单面板 + self.drawer = ui_mobile_drawer.MobileDrawer(self.interface) + self.drawer.SetParent(self) + self.drawer.Show() + self.drawer.AttachPanel(self) - # --------------------------------------------------------------------- - # 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) + # 3. 左侧竖排按钮 + side = [ + ("Quest", None, lambda: self.__ToggleCharacter("QUEST")), + ("Skill", "d:/ymir work/ui/game/taskbar/mouse_button_skill_01.sub", lambda: self.__ToggleCharacter("SKILL")), + ("Emote", None, lambda: self.__ToggleCharacter("EMOTICON")), + ("Chat", "d:/ymir work/ui/game/taskbar/chat_button_01.sub", self.__ToggleChat), + ] + self.side_buttons = [] + top = safe_t + 8 + self.FACE_DIAMETER + 48 + for i, (label, icon, event) in enumerate(side): + btn = widgets.RoundButton(self.SIDE_DIAMETER) + btn.SetParent(self) + btn.SetPosition(safe_l + 12, top + i * self.SIDE_STEP) + if not icon or not btn.SetIcon(icon): + btn.SetLabel(label) + btn.SetEvent(event) + btn.Show() + self.side_buttons.append(btn) - 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() + # 4. 左下:摇杆显示层 + self.joystick = ui_mobile_joystick.MobileJoystick(base_x=safe_l + 160, base_y=h - safe_b - 180) + self.joystick.SetParent(self) + self.joystick.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() + # 5. 右下:战斗轮盘 + 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() - 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() + # 6. 底部:药水栏(第 4 快捷页)与经验条 + count = 8 + beltWidth = (count - 1) * self.BELT_STEP + self.BELT_DIAMETER + self.quick_belt = self.__Container((w - beltWidth) / 2, h - safe_b - self.BELT_DIAMETER - 10, beltWidth, self.BELT_DIAMETER) + self.quick_slots = [] + for i in xrange(count): + slot = widgets.QuickSlotDisc(self.BELT_DIAMETER, globalIndex=self.BELT_PAGE * 8 + i) + slot.SetParent(self.quick_belt) + slot.SetPosition(i * self.BELT_STEP, 0) + slot.Show() + self.quick_slots.append(slot) - 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() + self.exp_width = w - safe_l - safe_r + self.exp_bar = self.__Gauge(self, safe_l, h - safe_b - 4, self.exp_width, 3, + grp.GenerateColor(0.05, 0.05, 0.05, 0.6), grp.GenerateColor(0.85, 0.70, 0.25, 0.9)) - # --------------------------------------------------------------------- - # 3. 右上角:系统抽屉菜单与导航 (Mobile Drawer) - # --------------------------------------------------------------------- - self.drawer = ui_mobile_drawer.MobileDrawer(self.interface) - self.drawer.SetParent(self) - self.drawer.Show() + def __ToggleCharacter(self, state): + if self.interface: + self.interface.ToggleCharacterWindow(state) - # --------------------------------------------------------------------- - # 4. 左下角:虚拟摇杆 (Mobile Joystick) - # --------------------------------------------------------------------- - self.joystick = ui_mobile_joystick.MobileJoystick(base_x=160, base_y=h - 180) - self.joystick.SetParent(self) - self.joystick.Show() + def __ToggleChat(self): + if self.interface: + self.interface.ToggleChat() - # --------------------------------------------------------------------- - # 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() + # 由 interfaceModule.ShowDefaultWindows / ShowAllWindows 调用:PC 任务栏隐藏, + # 小地图挪到右上入口行下面,聊天窗抬到药水栏上方。 + def AdoptDefaultWindows(self): + interface = self.interface + if not interface: + return + safe_l, safe_t, safe_r, safe_b = self.safe_area + sw = wndMgr.GetScreenWidth() + sh = wndMgr.GetScreenHeight() + for name in ("wndTaskBar", "wndExpandedTaskBar", "wndEnergyBar", "wndExpandedMoneyTaskBar"): + wnd = getattr(interface, name, None) + if wnd: + wnd.Hide() + minimap = getattr(interface, "wndMiniMap", None) + if minimap: + minimap.SetPosition(sw - safe_r - minimap.GetWidth(), safe_t + 8 + self.drawer.GetRowHeight() + 4) + # 任务栏的 HP/SP/经验悬浮提示是独立 TOP_MOST 窗口,平时由任务栏 OnUpdate 隐藏; + # 任务栏不显示时它们会一直挂在最后的鼠标位置 + taskbar = getattr(interface, "wndTaskBar", None) + for name in ("tooltipHP", "tooltipSP", "tooltipST", "tooltipEXP", "tooltipGift"): + tip = getattr(taskbar, name, None) + if tip: + tip.Hide() + self.__AdoptGameButtons(getattr(interface, "wndGameButton", None)) + chat = getattr(interface, "wndChat", None) + if chat: + chat.SetPosition(sw / 2 - chat.CHAT_WINDOW_WIDTH / 2, sh - safe_b - chat.EDIT_LINE_HEIGHT - self.BELT_DIAMETER - 24) - # --------------------------------------------------------------------- - # 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() + # 由 game.GameWindow 调用(活动图标创建之后):原版 buff 图标放在头像状态栏下面, + # 活动日历图标放在小地图左边 + # 原版提示按钮(帮助、加点、任务、礼物、活动入口……)原来贴在 PC 任务栏上方两角, + # 移动端排成左侧按钮列右边的第二列;原来共用一个位置的按钮这里也共用一行 + GAME_BUTTON_ROWS = (("HELP",), ("STATUS",), ("SKILL", "QUEST", "BUILD", "EXIT_OBSERVER"), ("GIFT",), + ("COMBAT_ZONE", "BOSS_EVENT"), ("METIN_EVENT",)) - 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 __AdoptGameButtons(self, wndGameButton): + buttons = getattr(wndGameButton, "gameButtonDict", None) + if not buttons: + return + safe_l, safe_t, safe_r, safe_b = self.safe_area + x = safe_l + 12 + self.SIDE_DIAMETER + 14 + top = safe_t + 8 + self.FACE_DIAMETER + 48 + for row, names in enumerate(self.GAME_BUTTON_ROWS): + for name in names: + btn = buttons.get(name) + if btn: + btn.SetPosition(x, top + row * self.SIDE_STEP) - 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) + def AdoptGameWindows(self, game): + safe_l, safe_t, safe_r, safe_b = self.safe_area + game.affectShower.SetPosition(safe_l + 12 + self.FACE_DIAMETER + 8, safe_t + 8 + 62) + notification = getattr(game, "notificationItem", None) + if notification: + sw = wndMgr.GetScreenWidth() + minimap = getattr(self.interface, "wndMiniMap", None) if self.interface else None + right = sw - safe_r - (minimap.GetWidth() if minimap else 0) + notification.SetPosition(right - notification.GetWidth() - 4, safe_t + 8 + self.drawer.GetRowHeight() + 4) - 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) + def __RefreshFace(self): + race = net.GetMainActorRace() + if race == self.race: + return + self.race = race + # 头像与角色窗口同一张表 + name = uiCharacter.FACE_IMAGE_DICT.get(race) + if not name: + self.face_image.Hide() + return + try: + self.face_image.LoadImage(name) + except: + self.face_image.Hide() + return + size = max(self.face_image.GetWidth(), self.face_image.GetHeight(), 1) + inner = self.FACE_DIAMETER - 16 + scale = float(inner) / float(size) + self.face_image.SetScale(scale, scale) + off = (self.FACE_DIAMETER - int(size * scale)) / 2 + self.face_image.SetPosition(off, off) + self.face_image.Show() - 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) + def __SetGauge(self, bar, width, height, cur, maximum): + if maximum > 0: + pct = min(1.0, max(0.0, float(cur) / float(maximum))) + bar.SetSize(int(width * pct), height) - # 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() + def OnUpdate(self): + # 1. 主角状态 + self.__SetGauge(self.hp_bar, self.HP_WIDTH, 12, player.GetStatus(player.HP), player.GetStatus(player.MAX_HP)) + self.__SetGauge(self.mp_bar, self.SP_WIDTH, 9, player.GetStatus(player.SP), player.GetStatus(player.MAX_SP)) + self.__SetGauge(self.sp_bar, self.ST_WIDTH, 5, player.GetStatus(player.STAMINA), player.GetStatus(player.MAX_STAMINA)) + self.__SetGauge(self.exp_bar, self.exp_width, 3, + unsigned32(player.GetStatus(player.EXP)), unsigned32(player.GetStatus(player.NEXT_EXP))) + self.text_name.SetText("Lv.%d %s" % (player.GetStatus(player.LEVEL), player.GetName())) + self.__RefreshFace() - # 3. 子组件状态刷新 - if hasattr(self, 'joystick') and self.joystick: - self.joystick.OnUpdate() - if hasattr(self, 'combat_wheel') and self.combat_wheel: - self.combat_wheel.OnUpdate() + # 2. 子组件 + self.joystick.OnUpdate() + self.combat_wheel.OnUpdate() + if app.GetGlobalTime() - self.lastBeltRefresh > 500: + self.lastBeltRefresh = app.GetGlobalTime() + for slot in self.quick_slots: + slot.Refresh() diff --git a/upstream/python-root/ui_mobile_joystick.py b/upstream/python-root/ui_mobile_joystick.py index 38077768..ab560661 100644 --- a/upstream/python-root/ui_mobile_joystick.py +++ b/upstream/python-root/ui_mobile_joystick.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import ui -import grp import touch +import ui_mobile_widgets as widgets class MobileJoystick(ui.Window): """ @@ -21,22 +21,9 @@ class MobileJoystick(ui.Window): self.knob_radius = knob_radius self.SetSize(radius * 2, radius * 2) - # 外圈底盘 - self.base_bar = ui.Bar() - self.base_bar.SetParent(self) - self.base_bar.AddFlag("not_pick") - self.base_bar.SetPosition(0, 0) - 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) - self.knob.AddFlag("not_pick") - 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() + # 外圈底盘与摇杆头:原生圆框(ui_mobile_widgets.Disc) + self.base_bar = widgets.MakeDisc(self, 0, 0, radius * 2, widgets.STYLE_JOY_BASE) + self.knob = widgets.MakeDisc(self, 0, 0, knob_radius * 2, widgets.STYLE_JOY_KNOB) # 未按下时停在默认位置,提示摇杆区 if base_y is None: diff --git a/upstream/python-root/ui_mobile_widgets.py b/upstream/python-root/ui_mobile_widgets.py new file mode 100644 index 00000000..5fd32519 --- /dev/null +++ b/upstream/python-root/ui_mobile_widgets.py @@ -0,0 +1,230 @@ +# -*- coding: utf-8 -*- +# 移动端 HUD 的通用控件(docs/MOBILE-ARCHITECTURE.md 第 4 步)。 +# 圆形边框由原生 wndMgr.RegisterDisc 用几何绘制(渐变底 + 上亮下暗的立体边),不依赖贴图; +# 图标只用 AVA2 自己的 UI/技能/物品贴图。 +import ui +import grp +import wndMgr +import player +import skill +import item +import constInfo +import mouseModule + + +def Color(r, g, b, a=1.0): + return grp.GenerateColor(r, g, b, a) + +# 配色:暗底 + 古铜边,按下变亮;攻击键暗红 +STYLE_FRAME = (Color(0.16, 0.14, 0.13, 0.80), Color(0.05, 0.04, 0.04, 0.85), Color(0.85, 0.68, 0.40), Color(0.32, 0.22, 0.12), 3.0) +STYLE_FRAME_DOWN = (Color(0.40, 0.32, 0.22, 0.90), Color(0.12, 0.09, 0.06, 0.90), Color(1.0, 0.85, 0.50), Color(0.45, 0.32, 0.16), 3.0) +STYLE_ATTACK = (Color(0.55, 0.12, 0.08, 0.85), Color(0.18, 0.03, 0.02, 0.90), Color(0.92, 0.74, 0.42), Color(0.36, 0.22, 0.10), 5.0) +STYLE_ATTACK_DOWN = (Color(0.90, 0.30, 0.15, 0.95), Color(0.40, 0.08, 0.04, 0.95), Color(1.0, 0.90, 0.55), Color(0.50, 0.32, 0.14), 5.0) +STYLE_JOY_BASE = (Color(0.10, 0.10, 0.12, 0.25), Color(0.05, 0.05, 0.06, 0.45), Color(0.80, 0.66, 0.42, 0.55), Color(0.30, 0.22, 0.12, 0.55), 3.0) +STYLE_JOY_KNOB = (Color(0.75, 0.66, 0.50, 0.70), Color(0.35, 0.28, 0.18, 0.75), Color(1.0, 0.88, 0.60, 0.85), Color(0.40, 0.30, 0.16, 0.85), 2.0) +COOLDOWN_COLOR = Color(0.0, 0.0, 0.0, 0.55) + + +class Disc(ui.Window): + """圆形边框(原生 CDisc)。不接收点击。""" + def __init__(self, layer="UI"): + ui.Window.__init__(self, layer) + self.AddFlag("not_pick") + + def __del__(self): + ui.Window.__del__(self) + + def RegisterWindow(self, layer): + self.hWnd = wndMgr.RegisterDisc(self, layer) + + def SetStyle(self, style): + inner, outer, rimTop, rimBottom, rimWidth = style + wndMgr.SetDiscColors(self.hWnd, inner, outer, rimTop, rimBottom, float(rimWidth)) + + def SetArc(self, fraction, color=COOLDOWN_COLOR): + wndMgr.SetDiscArc(self.hWnd, float(fraction), color) + + +def MakeDisc(parent, x, y, diameter, style): + disc = Disc() + disc.SetParent(parent) + disc.SetPosition(x, y) + disc.SetSize(diameter, diameter) + disc.SetStyle(style) + disc.Show() + return disc + + +class RoundButton(ui.Window): + """圆形按钮:圆框 + 居中图标(AVA2 贴图)或短文字。按下变亮,松开时在按钮内才触发。""" + def __init__(self, diameter, style=STYLE_FRAME, downStyle=STYLE_FRAME_DOWN): + ui.Window.__init__(self) + self.SetSize(diameter, diameter) + self.diameter = diameter + self.style = style + self.downStyle = downStyle + self.event = None + self.disc = MakeDisc(self, 0, 0, diameter, style) + self.icon = None + self.label = None + + def __del__(self): + ui.Window.__del__(self) + + def SetIcon(self, fileName, scale=1.0): + icon = ui.ExpandedImageBox() + icon.SetParent(self) + icon.AddFlag("not_pick") + try: + icon.LoadImage(fileName) + except: + return False + if scale != 1.0: + icon.SetScale(scale, scale) + # ExpandedImageBox.SetScale 已把窗口尺寸换成缩放后的大小 + w = icon.GetWidth() + h = icon.GetHeight() + icon.SetPosition((self.diameter - w) / 2, (self.diameter - h) / 2) + icon.Show() + self.icon = icon + return True + + def SetLabel(self, text): + label = ui.TextLine() + label.SetParent(self) + label.AddFlag("not_pick") + label.SetPosition(self.diameter / 2, self.diameter / 2 - 6) + label.SetHorizontalAlignCenter() + label.SetOutline() + label.SetText(text) + label.Show() + self.label = label + + def SetEvent(self, event): + self.event = event + + def OnMouseLeftButtonDown(self): + self.disc.SetStyle(self.downStyle) + return True + + def OnMouseLeftButtonUp(self): + self.disc.SetStyle(self.style) + if self.IsIn() and self.event: + self.event() + return True + + +class QuickSlotDisc(ui.Window): + """一个快捷栏格子:圆框 + 原版 SlotWindow 绘制技能/物品/表情图标、数量和冷却。 + slotIndex 为 None 时显示当前快捷页的 localIndex(与 PC 任务栏 1-4/F1-F4 同一份数据); + 否则为固定的全局格子(药水栏)。轻点直接使用;手上拖着图标时轻点则放入该格。""" + SLOT_SIZE = 32 + + def __init__(self, diameter, localIndex=None, globalIndex=None): + ui.Window.__init__(self) + self.AddFlag("not_pick") + self.SetSize(diameter, diameter) + self.localIndex = localIndex + self.globalIndex = globalIndex + self.disc = MakeDisc(self, 0, 0, diameter, STYLE_FRAME) + + off = (diameter - self.SLOT_SIZE) / 2 + slot = ui.SlotWindow() + slot.SetParent(self) + slot.SetPosition(0, 0) + slot.SetSize(diameter, diameter) + slot.AppendSlot(0, off, off, self.SLOT_SIZE, self.SLOT_SIZE) + slot.SetSlotStyle(wndMgr.SLOT_STYLE_NONE) + slot.SetSelectEmptySlotEvent(ui.__mem_func__(self.__OnSelectEmpty)) + slot.SetSelectItemSlotEvent(ui.__mem_func__(self.__OnSelectItem)) + slot.Show() + self.slot = slot + + def __del__(self): + ui.Window.__del__(self) + + def GetQuickSlot(self): + if self.globalIndex is not None: + return player.GetGlobalQuickSlot(self.globalIndex) + return player.GetLocalQuickSlot(self.localIndex) + + def __Use(self): + if self.globalIndex is not None: + player.RequestUseGlobalQuickSlot(self.globalIndex) + else: + player.RequestUseLocalQuickSlot(self.localIndex) + + # uitaskbar.TaskBar.AddQuickSlot,目标换成本格 + def __Add(self): + attachedType = mouseModule.mouseController.GetAttachedType() + attachedSlot = mouseModule.mouseController.GetAttachedSlotNumber() + attachedItem = mouseModule.mouseController.GetAttachedItemIndex() + if player.SLOT_TYPE_QUICK_SLOT == attachedType: + if self.globalIndex is not None: + player.RequestMoveGlobalQuickSlotToGlobalQuickSlot(attachedSlot, self.globalIndex) + else: + player.RequestMoveGlobalQuickSlotToLocalQuickSlot(attachedSlot, self.localIndex) + else: + pos = attachedItem if player.SLOT_TYPE_EMOTION == attachedType else attachedSlot + if player.SLOT_TYPE_INVENTORY == attachedType and not item.CanAddToQuickSlotItem(player.GetItemIndex(attachedSlot)): + pos = None + if pos is not None: + if self.globalIndex is not None: + player.RequestAddGlobalQuickSlot(self.globalIndex, attachedType, pos) + else: + player.RequestAddLocalQuickSlot(self.localIndex, attachedType, pos) + mouseModule.mouseController.DeattachObject() + self.Refresh() + + def __OnSelectEmpty(self, slotIndex): + if mouseModule.mouseController.isAttached(): + self.__Add() + + def __OnSelectItem(self, slotIndex): + if mouseModule.mouseController.isAttached(): + self.__Add() + else: + self.__Use() + + # uitaskbar.TaskBar.RefreshQuickSlot 的单格版本 + def Refresh(self): + slot = self.slot + (Type, Position) = self.GetQuickSlot() + if player.SLOT_TYPE_NONE == Type: + slot.ClearSlot(0) + elif player.SLOT_TYPE_INVENTORY == Type: + itemIndex = player.GetItemIndex(Position) + itemCount = player.GetItemCount(Position) + if itemCount <= 1: + itemCount = 0 + if constInfo.IS_AUTO_POTION(itemIndex): + if 0 != int(player.GetItemMetinSocket(Position, 0)): + slot.ActivateSlot(0) + else: + slot.DeactivateSlot(0) + slot.SetItemSlot(0, itemIndex, itemCount) + elif player.SLOT_TYPE_SKILL == Type: + skillIndex = player.GetSkillIndex(Position) + if 0 == skillIndex: + slot.ClearSlot(0) + else: + if skill.SKILL_TYPE_GUILD == skill.GetSkillType(skillIndex): + import guild + skillGrade = 0 + skillLevel = guild.GetSkillLevel(Position) + else: + skillGrade = player.GetSkillGrade(Position) + skillLevel = player.GetSkillLevel(Position) + slot.SetSkillSlotNew(0, skillIndex, skillGrade, skillLevel) + slot.SetSlotCountNew(0, skillGrade, skillLevel) + if player.IsSkillCoolTime(Position): + (coolTime, elapsedTime) = player.GetSkillCoolTime(Position) + slot.SetSlotCoolTime(0, coolTime, elapsedTime) + if player.IsSkillActive(Position): + slot.ActivateSlot(0) + else: + slot.DeactivateSlot(0) + elif player.SLOT_TYPE_EMOTION == Type: + slot.SetEmotionSlot(0, Position) + slot.SetSlotCount(0, 0) + slot.RefreshSlot()