Files
metin2-client/src/platform/ScriptLib/ItemActionsScript.inc
T
shenleiandClaude Opus 5.5 fc98e6e2b4 Port the AVA2 switchbot window and switchbot module
PythonSwitchbot + PythonNetworkStreamPhaseGameSwitchbot from AVA2 (CG/GC 171,
SWITCHBOT window 7, SLOT_TYPE_SWITCHBOT), uiswitchbot.py verbatim in
SwitchbotScript.inc plus its ENABLE_SWITCHBOT glue (tooltip, mouse/inventory
drag-back, interface/game hooks, zh strings, server switchbot_* messages).
Entry is the minimap 洗练 button; F9 stays with auto-hunt. The client version
timestamp is now "mt20261016" so the server enables the switchbot.
50348/50349 no longer open the window. Adds docs/AVA2-PARITY-PLAN.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 20:26:06 +09:00

100 lines
3.3 KiB
C++

// PORT: touch equivalents of AVA2's inventory preview / chest shortcuts.
// Native touch selection invokes ShowInventory; no synthetic modifier keys.
static const char c_szItemActionsScript[] = R"PY(# -*- coding: utf-8 -*-
import game
import grp
import player
import ui
import uiInventory
import weakref
import wndMgr
from mt_biolog import Action
g_window=None
class ItemActions(ui.Window):
def __init__(self):
ui.Window.__init__(self);self.AddFlag('float');self.SetWindowName('TouchItemActions')
self.snapshot=None;self.buttons=[];self.Hide()
def Clear(self):
self.Hide();self.snapshot=None
for button in self.buttons:button.Hide();button.event=None
self.buttons=[]
def Valid(self):
if not self.snapshot:return False
try:
owner,page,cell,vnum,count=self.snapshot
return (owner.IsShow() and owner.inventoryPageIndex==page and
player.GetItemIndex(cell)==vnum and player.GetItemCount(cell)==count)
except ReferenceError:return False
def Select(self,owner,cell):
self.Clear()
vnum=player.GetItemIndex(cell)
if not vnum:return
self.snapshot=(weakref.proxy(owner),owner.inventoryPageIndex,cell,vnum,player.GetItemCount(cell))
import mt_preview
import mt_chest
import mt_wiki
choices=[('百科',lambda:mt_wiki.OpenItem(vnum))]
if mt_preview.ItemSpec(vnum):choices.append(('模型预览',lambda:mt_preview.Preview('item',vnum)))
if mt_chest.g_window and mt_chest.Batchable(vnum):
choices.append(('批量开箱',lambda:mt_chest.g_window.Select(cell,vnum)))
choices.append(('关闭',self.Clear))
for i,(label,action) in enumerate(choices):
self.buttons.append(Action(self,8+i*108,6,100,label,lambda action=action:self.Run(action)))
self.SetSize(16+len(choices)*108,60)
x,y=owner.GetGlobalPosition()
self.SetPosition(max(0,min(x,wndMgr.GetScreenWidth()-self.GetWidth())),
max(0,min(y+owner.GetHeight(),wndMgr.GetScreenHeight()-self.GetHeight())))
self.Show();self.SetTop()
def Run(self,action):
valid=self.Valid();self.Clear()
if valid:action()
def OnUpdate(self):
if self.IsShow() and not self.Valid():self.Clear()
def OnRender(self):
x,y=self.GetGlobalPosition();grp.SetColor(0xf51b1916);grp.RenderBar(x,y,self.GetWidth(),self.GetHeight())
def OnPressEscapeKey(self):self.Clear();return True
def ShowInventory(owner,cell):
if g_window:g_window.Select(owner,cell)
_open=game.GameWindow.Open
_close=game.GameWindow.Close
def Open(self):
global g_window
_open(self);g_window=ItemActions()
def Close(self):
global g_window
if g_window:g_window.Clear();g_window=None
_close(self)
game.GameWindow.Open=Open
game.GameWindow.Close=Close
_use=uiInventory.InventoryWindow.UseItemSlot
def UseItemSlot(self,slot):
cell=self._InventoryWindow__InventoryLocalSlotPosToGlobalSlotPos(slot)
vnum=player.GetItemIndex(cell)
if 25150<=vnum<=25161:
import mt_battlepass
if mt_battlepass.g_window:mt_battlepass.g_window.OfferTicket(cell,vnum)
return
return _use(self,slot)
uiInventory.InventoryWindow.UseItemSlot=UseItemSlot
)PY";