Files
metin2-client/src/platform/ScriptLib/MobileInventoryScript.inc
T
shenandshen 507e687867 feat: add MeshPort overlay networking, item actions window, and AVA2 client enhancements
- add MeshPort peer-to-peer overlay networking SDK, C++ integration, and Python bindings
- add item actions quick use/split/delete/lock overlay window (mt_item_actions)
- add shop name range and NPC name visibility settings to system display options
- support battlepass ticket activation and month validation in mt_battlepass
- support boss tracking teleport destination button in mt_bosses
- support asynchronous account registration cancellation and pending login cancellation
- update AVA2 item conversion for attr lock scrolls and battlepass tickets
- update .gitignore for local build outputs and caches
2026-10-16 01:29:57 -07:00

129 lines
4.0 KiB
C++

// PORT: touch inventory gestures; original methods own use, move and sale requests.
static const char c_szMobileInventoryScript[] = R"PY(# -*- coding: utf-8 -*-
import app
import constInfo
import game
import mouseModule
import player
import shop
import uiInventory
import uiShop
# These flags are scoped by the native touch controller, never by desktop mouse input.
tap = False
double_tap = False
dragging = False
touch_target = 48
_last = None
_last_time = -1
_drag = None
_OriginalSelect = uiInventory.InventoryWindow.SelectItemSlot
_OriginalUse = uiInventory.InventoryWindow.UseItemSlot
_OriginalShopLoad = uiShop.ShopDialog.LoadDialog
def _ShopLoad(self):
result = _OriginalShopLoad(self)
# The original loader names child windows but leaves this root unnamed.
self.SetWindowName("ShopDialog")
return result
def _Snapshot(owner, slot):
import weakref
cell = owner._InventoryWindow__InventoryLocalSlotPosToGlobalSlotPos(slot)
return (owner if isinstance(owner, weakref.ProxyTypes) else weakref.proxy(owner), owner.inventoryPageIndex, cell,
player.GetItemIndex(cell), player.GetItemCount(cell))
def _Valid(snapshot):
if not snapshot:
return False
try:
owner, page, cell, vnum, count = snapshot
return (owner.IsShow() and owner.inventoryPageIndex == page and vnum != 0 and
player.GetItemIndex(cell) == vnum and player.GetItemCount(cell) == count and
not constInfo.GET_ITEM_QUESTION_DIALOG_STATUS())
except ReferenceError:
return False
def _Select(self, slot):
global _last, _last_time, _drag
mouse = mouseModule.mouseController
if tap and not mouse.isAttached() and not constInfo.GET_ITEM_QUESTION_DIALOG_STATUS() and app.GetCursor() not in (app.SELL, app.BUY):
_last = _Snapshot(self, slot)
_last_time = app.GetTime()
if _last[3]:
self.ShowToolTip(_last[2])
import sys
actions = sys.modules.get('mt_item_actions')
if actions:actions.ShowInventory(self, _last[2])
return
snapshot = _Snapshot(self, slot) if dragging and not mouse.isAttached() else None
result = _OriginalSelect(self, slot)
if snapshot and mouse.isAttached() and mouse.GetAttachedType() == player.SLOT_TYPE_INVENTORY:
_drag = snapshot
return result
def _Use(self, slot):
global _last
if double_tap:
snapshot = _last
_last = None
if (not _Valid(snapshot) or not 0 <= app.GetTime()-_last_time <= .5 or
snapshot != _Snapshot(self, slot)):
return
return _OriginalUse(self, slot)
def SetDrag(active):
global dragging, _drag, _last
dragging = active
_drag = None
_last = None
def Drop(shop_target):
"""Consume stale inventory drags and NPC-shop drops; other targets use the normal UI path."""
global _drag
mouse = mouseModule.mouseController
if not _drag or not mouse.isAttached():
return False
snapshot = _drag
if (not _Valid(snapshot) or mouse.GetAttachedType() != player.SLOT_TYPE_INVENTORY or
mouse.GetAttachedSlotNumber() != snapshot[2] or mouse.GetAttachedItemIndex() != snapshot[3] or
mouse.GetAttachedItemCount() != snapshot[4]):
mouse.DeattachObject()
_drag = None
return True
if not shop_target or not shop.IsOpen() or shop.IsPrivateShop():
return False
# Always use the original inventory sale dialog, including anti-sell checks and identity recheck.
owner, page, cell, vnum, count = snapshot
mouse.DeattachObject()
_drag = None
owner._InventoryWindow__SellItem(cell)
return True
def Reset():
global tap, double_tap, dragging, _last, _drag
tap = double_tap = dragging = False
_last = _drag = None
_Close = game.GameWindow.Close
def Close(self):
Reset()
_Close(self)
uiInventory.InventoryWindow.SelectItemSlot = _Select
uiInventory.InventoryWindow.UseItemSlot = _Use
uiShop.ShopDialog.LoadDialog = _ShopLoad
game.GameWindow.Close = Close
)PY";