Complete own-item attribute lock selection and tooltip flow

This commit is contained in:
shen
2026-10-18 16:28:16 -07:00
parent 5decc93798
commit 95f1c30be2
13 changed files with 342 additions and 4 deletions
+118
View File
@@ -0,0 +1,118 @@
// AVA2 lock material selection uses socket 0; lock highlights follow original uitooltip.py.
// The existing port stores masks outside the seven-attribute packet, so own-item tooltips query them read-only.
static const char c_szAttrLockScript[] = R"PY(# -*- coding: utf-8 -*-
import app,chat,game,net,player,uiToolTip,weakref,mt_switchbot
L=player.AutoHuntLocalize
Tip=uiToolTip.ItemToolTip
_clear=Tip.ClearToolTip
_inventory=Tip.SetInventoryItem
_append=Tip._ItemToolTip__AppendAttributeInformation
_add=Tip.AddItemData
_update=Tip.OnUpdate
_command=game.GameWindow.BINARY_ServerCommand_Run
_close=game.GameWindow.Close
_pending={}
_serial=0
def Snapshot(window,cell):
return (player.GetItemIndex(window,cell),
tuple(player.GetItemAttribute(window,cell,i) for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM)),
tuple(player.GetItemMetinSocket(window,cell,i) for i in xrange(player.METIN_SOCKET_MAX_NUM)))
def Clear(self):
if not getattr(self,'attrLockRendering',False):
self.attrLockContext=None;self.attrLockMask=0
_clear(self)
def Query(self):
global _serial
context=getattr(self,'attrLockContext',None)
if not context:return
window,cell,snapshot=context
if Snapshot(window,cell)!=snapshot:
self.attrLockContext=None;self.attrLockMask=0
return
_serial=(_serial%2147483646)+1
self.attrLockNext=app.GetTime()+1.25
# A tooltip can be rebuilt frequently during rolling; retain no old requests or windows.
_pending.clear();_pending[_serial]=(weakref.ref(self),context)
net.SendChatPacket('/attr_lock_info %d %d %d'%(_serial,window,cell))
def Inventory(self,cell,window_type=player.INVENTORY):
_inventory(self,cell,window_type)
snapshot=Snapshot(window_type,cell)
if not snapshot[0] or not any(a[0] for a in snapshot[1][:5]):return
self.attrLockContext=(window_type,cell,snapshot)
Query(self)
def Rebuild(self):
context=getattr(self,'attrLockContext',None)
if not context:return
window,cell,snapshot=context
if Snapshot(window,cell)!=snapshot:return
self.attrLockRendering=True
try:_inventory(self,cell,window)
finally:self.attrLockRendering=False
def Update(self):
_update(self)
if self.IsShow() and getattr(self,'attrLockContext',None) and app.GetTime()>=getattr(self,'attrLockNext',0):Query(self)
def AppendAttributes(self,attrs):
mask=getattr(self,'attrLockMask',0)
if not mask or getattr(self,'mtSash',None):return _append(self,attrs)
# Original AVA2: locked lines are enclosed in << >> and use SPECIAL_TITLE_COLOR.
for index,(kind,value) in enumerate(attrs):
if not value:continue
text=self._ItemToolTip__GetAffectString(kind,value)
if text:
if index<5 and mask&(1<<index):self.AppendTextLine('<<'+text+'>>',self.SPECIAL_TITLE_COLOR)
else:self.AppendTextLine(text,self._ItemToolTip__GetAttributeColor(index,value))
def AddItemData(self,vnum,metinSlot=0,attrSlot=0,*args,**kwargs):
_add(self,vnum,metinSlot,attrSlot,*args,**kwargs)
if vnum in (50348,50349):
index=int(metinSlot[0]) if metinSlot else 0
self.AppendSpace(5)
self.AppendTextLine(L('已选择第%d条普通属性'%index if 1<=index<=5 else '先使用此符选择属性序号'),self.SPECIAL_TITLE_COLOR)
self.ShowToolTip()
def Command(self,line):
words=line.split()
if words and words[0]=='AttrLockResult':
messages={'ok':'属性锁定状态已更新','item':'请使用未穿戴且未被交易或占用的装备','material':'请使用对应的锁定符或解锁符','slot':'请先使用此符选择有效的属性序号','five_attr':'装备需要五条普通属性','max':'最多可锁定两组普通属性','db':'保存失败,本次未消耗材料'}
if len(words)==2:chat.AppendChat(chat.CHAT_TYPE_INFO,L(messages.get(words[1],'属性锁定失败')))
return 1
if words and words[0]=='AttrLockInfo':
if len(words)!=6:return 1
try:token,window,cell,vnum,mask=map(int,words[1:])
except (ValueError,OverflowError):return 1
request=_pending.pop(token,None)
if request and -1<=mask<=31:
owner,context=request;tip=owner()
if tip and tip.IsShow() and getattr(tip,'attrLockContext',None)==context:
if (window,cell)==context[:2] and vnum==context[2][0] and Snapshot(window,cell)==context[2]:
if mask>=0 and mask!=getattr(tip,'attrLockMask',0):
tip.attrLockMask=mask;Rebuild(tip)
return 1
return _command(self,line)
def Close(self):
_pending.clear()
return _close(self)
_switchOver=mt_switchbot.SwitchbotItemTab.OverInItem
def SwitchOver(self,slot):
if self.IsEmpty() or self.IsActive():return _switchOver(self,slot)
self.itemSlot.SetUsableItem(True)
if self.tooltipItem:self.tooltipItem.SetInventoryItem(self.slot_num,player.SWITCHBOT)
Tip.ClearToolTip=Clear
Tip.SetInventoryItem=Inventory
Tip._ItemToolTip__AppendAttributeInformation=AppendAttributes
Tip.AddItemData=AddItemData
Tip.OnUpdate=Update
mt_switchbot.SwitchbotItemTab.OverInItem=SwitchOver
game.GameWindow.BINARY_ServerCommand_Run=Command
game.GameWindow.Close=Close
)PY";
+2
View File
@@ -1041,6 +1041,7 @@ namespace PythonBoot
#include "PendantScript.inc"
#include "RingsScript.inc"
#include "ItemActionsScript.inc"
#include "AttrLockScript.inc"
#include "MinimapOuterRingScript.inc"
#ifdef MT_HAS_MESHPORT
#include "MeshPortScript.inc"
@@ -1144,6 +1145,7 @@ bool RunMainScript(const char* lpCmdLine, std::string* error)
install_script_module("mt_pendant", c_szPendantScript);
install_script_module("mt_rings", c_szRingsScript);
install_script_module("mt_item_actions", c_szItemActionsScript);
install_script_module("mt_attr_lock", c_szAttrLockScript);
install_script_module("mt_minimap_buttons", c_szMinimapOuterRingScript);
if (g_touch_input)
install_script_module("mt_mobile_hud", c_szMobileHUDScript);