Complete attribute lock links and active switchbot tooltips

This commit is contained in:
shen
2026-10-18 22:08:48 -07:00
parent e9c26b86c1
commit 62b61bafd0
8 changed files with 273 additions and 5 deletions
@@ -0,0 +1,148 @@
// AVA2 lock presentation with the port's separate mask; no classic packet layout changes.
static const char c_szAttrLockSnapshotsScript[] = R"PY(# -*- coding: utf-8 -*-
import app,player,chat,game,net,uiToolTip,mt_switchbot,mt_attr_lock as core,weakref
_cache={}
_link=player.GetItemLink
_relay=chat.GetLinkFromHyperlink
_hyper=uiToolTip.HyperlinkItemToolTip.SetHyperlinkItem
_command=game.GameWindow.BINARY_ServerCommand_Run
_close=game.GameWindow.Close
_open=game.GameWindow.Open
_gameUpdate=game.GameWindow.OnUpdate
_over=mt_switchbot.SwitchbotItemTab.OverInItem
_update=uiToolTip.ItemToolTip.OnUpdate
_clear=uiToolTip.ItemToolTip.ClearToolTip
def Key(window,cell):
return (player.INVENTORY if window==player.EQUIPMENT else window,cell)
def Cached(window,cell):
window,cell=Key(window,cell)
value=_cache.get((window,cell))
return value if value and value[0]==core.Snapshot(window,cell) else None
def Command(self,line):
words=line.split()
if words==['AttrLockSync']:
self.attrLockSynced=True
return 1
if words and words[0]=='AttrLockItem':
if len(words)!=5:return 1
try:window,cell,vnum,mask=map(int,words[1:])
except (ValueError,OverflowError):return 1
if window not in (player.INVENTORY,player.EQUIPMENT,player.SWITCHBOT) or not 0<=cell<65536 or not -1<=mask<=31:return 1
key=Key(window,cell);_cache.pop(key,None)
snapshot=core.Snapshot(*key)
if vnum and snapshot[0]==vnum and mask>=0:_cache[key]=(snapshot,mask)
return 1
return _command(self,line)
def GetItemLink(*args):
link=_link(*args)
if len(args)==1:window,cell=player.INVENTORY,args[0]
elif len(args)==2:window,cell=args
else:return link
cached=Cached(window,cell)
if not link or not cached or not cached[1]:return link
# Fixed seven slots preserve holes and therefore the lock's attribute index.
start=link.find('|H');end=link.find('|h',start+2)
if start<0 or end<0:return link
head=link[start+2:end].split(':')[:6]
if len(head)!=6 or head[0]!='item':return link
for kind,value in cached[0][1]:head.extend(('%x'%kind,str(value)))
head.extend(('mtlock1',str(cached[1])))
return link[:start+2]+':'.join(head)+link[end:]
def Decode(tokens):
if len(tokens)!=22 or tokens[0]!='item' or tokens[20]!='mtlock1':return None
try:
mask=int(tokens[21]);vnum=int(tokens[1],16);flags=int(tokens[2],16)
sockets=[int(v,16) for v in tokens[3:6]]
attrs=[(int(tokens[i],16),int(tokens[i+1])) for i in xrange(6,20,2)]
if not 0<=mask<=31 or not 0<vnum<=0xffffffff or not 0<=flags<=0xffffffff:return None
if any(not 0<=v<=0xffffffff for v in sockets):return None
if any(not 0<=k<=255 or not -32768<=v<=32767 for k,v in attrs):return None
return vnum,sockets,attrs,mask
except (ValueError,OverflowError):return None
def Hyperlink(self,tokens):
if 'mtlock1' not in tokens:return _hyper(self,tokens)
data=Decode(tokens)
self.ClearToolTip()
if not data:self.HideToolTip();return
vnum,sockets,attrs,mask=data
self.attrLockMask=mask
self.AddItemData(vnum,sockets,attrs)
self.ShowToolTip()
uiToolTip.ItemToolTip.OnUpdate(self)
# A chat link is an immutable sender snapshot, never a live item lookup.
def Relay(payload):
tokens=payload.split(':')
if 'mtlock1' not in tokens:return _relay(payload)
if Decode(tokens) is None:return ''
ordinary=_relay(':'.join(tokens[:20]))
start=ordinary.find('|H');end=ordinary.find('|h',start+2)
return ordinary[:start+2]+payload+ordinary[end:] if start>=0 and end>=0 else ''
def Clear(self):
self.attrLockActive=None
return _clear(self)
def Active(self,tab):
self.ClearToolTip()
cached=Cached(player.SWITCHBOT,tab.slot_num)
self.SetSwitchBotItem(player.GetItemIndex(player.SWITCHBOT,tab.slot_num))
if cached and cached[1]:
self.attrLockMask=cached[1]
self.AppendSpace(5)
core.AppendAttributes(self,[a if i<5 and cached[1]&(1<<i) else (0,0) for i,a in enumerate(cached[0][1])])
# The EU word wrapper cannot split Chinese words. Use ToolTip's measured-width
# convention (AutoAppendTextLine) so the localized active message fits its board.
width=max([self.toolTipWidth]+[line.GetTextSize()[0]+40 for line in self.childrenList if hasattr(line,'GetTextSize')])
if width>self.toolTipWidth:
self.toolTipWidth=width;self.AlignHorizonalCenter()
self.attrLockActive=(weakref.ref(tab),core.Snapshot(player.SWITCHBOT,tab.slot_num),cached)
self.ShowToolTip()
def Over(self,slot):
if self.IsEmpty() or not self.IsActive():return _over(self,slot)
self.itemSlot.SetUsableItem(True)
if self.tooltipItem:Active(self.tooltipItem,self)
def Update(self):
_update(self)
active=getattr(self,'attrLockActive',None)
if not self.IsShow() or not active:return
tab=active[0]()
if not tab or tab.IsEmpty() or core.Snapshot(player.SWITCHBOT,tab.slot_num)!=active[1]:
self.ClearToolTip();self.HideToolTip();return
if not tab.IsActive():self.SetInventoryItem(tab.slot_num,player.SWITCHBOT)
elif Cached(player.SWITCHBOT,tab.slot_num)!=active[2]:Active(self,tab)
def Close(self):
_cache.clear()
return _close(self)
def Open(self):
result=_open(self)
self.attrLockSynced=False;self.attrLockSyncTries=0;self.attrLockSyncNext=app.GetTime()+1
return result
def GameUpdate(self):
_gameUpdate(self)
if not getattr(self,'attrLockSynced',True) and self.attrLockSyncTries<3 and app.GetTime()>=self.attrLockSyncNext:
self.attrLockSyncTries+=1;self.attrLockSyncNext=app.GetTime()+2.25
net.SendChatPacket('/attr_lock_sync')
player.GetItemLink=GetItemLink
chat.GetLinkFromHyperlink=Relay
uiToolTip.HyperlinkItemToolTip.SetHyperlinkItem=Hyperlink
uiToolTip.ItemToolTip.ClearToolTip=Clear
uiToolTip.ItemToolTip.OnUpdate=Update
mt_switchbot.SwitchbotItemTab.OverInItem=Over
game.GameWindow.BINARY_ServerCommand_Run=Command
game.GameWindow.Close=Close
game.GameWindow.Open=Open
game.GameWindow.OnUpdate=GameUpdate
)PY";
+2
View File
@@ -1043,6 +1043,7 @@ namespace PythonBoot
#include "ItemActionsScript.inc"
#include "AttrLockScript.inc"
#include "AttrLockViewsScript.inc"
#include "AttrLockSnapshotsScript.inc"
#include "LiveEndpointScript.inc"
#include "NativeChannelScript.inc"
#include "MinimapOuterRingScript.inc"
@@ -1150,6 +1151,7 @@ bool RunMainScript(const char* lpCmdLine, std::string* error)
install_script_module("mt_item_actions", c_szItemActionsScript);
install_script_module("mt_attr_lock", c_szAttrLockScript);
install_script_module("mt_attr_lock_views", c_szAttrLockViewsScript);
install_script_module("mt_attr_lock_snapshots", c_szAttrLockSnapshotsScript);
install_script_module("mt_live_endpoint", c_szLiveEndpointScript);
install_script_module("mt_native_channel", c_szNativeChannelScript);
install_script_module("mt_minimap_buttons", c_szMinimapOuterRingScript);