Files
m2dev-client/assets/root/uiAutopickup.py
2026-04-16 19:28:16 +02:00

146 lines
3.9 KiB
Python

import net
import ui
STATE_ENABLED = 0
STATE_MODE = 0
STATE_MASK = 31
STATE_VIP = 0
OPEN_WINDOWS = []
FILTERS = (
(1, "Weapons"),
(2, "Armor"),
(4, "Yang"),
(8, "Stones"),
(16, "Materials"),
)
def SetAutoPickupState(enabled, mode, mask, vip):
global STATE_ENABLED
global STATE_MODE
global STATE_MASK
global STATE_VIP
STATE_ENABLED = 1 if int(enabled) else 0
STATE_MODE = 1 if int(mode) else 0
STATE_MASK = int(mask) & 31
STATE_VIP = 1 if int(vip) else 0
for window in OPEN_WINDOWS:
try:
window.ApplyState()
except:
pass
class AutoPickupWindow(ui.BoardWithTitleBar):
def __init__(self):
ui.BoardWithTitleBar.__init__(self)
OPEN_WINDOWS.append(self)
self.filterButtons = {}
self.AddFlag("float")
self.AddFlag("movable")
self.SetSize(280, 248)
self.SetTitleName("Auto Pickup")
self.SetCloseEvent(self.Hide)
self.__CreateChildren()
self.Hide()
def __del__(self):
if self in OPEN_WINDOWS:
OPEN_WINDOWS.remove(self)
ui.BoardWithTitleBar.__del__(self)
def Destroy(self):
if self in OPEN_WINDOWS:
OPEN_WINDOWS.remove(self)
self.ClearDictionary()
self.filterButtons = {}
def __CreateChildren(self):
self.statusLine = self.__CreateLine(15, 36)
self.rangeLine = self.__CreateLine(15, 56)
self.modeLine = self.__CreateLine(15, 76)
self.noteLine = self.__CreateLine(15, 96)
self.enableButton = self.__CreateButton(170, 34, 90, "Enable")
self.enableButton.SetEvent(self.__ToggleEnabled)
self.whitelistButton = self.__CreateButton(15, 118, 118, "Whitelist")
self.whitelistButton.SetEvent(self.__SetMode, 0)
self.blacklistButton = self.__CreateButton(142, 118, 118, "Blacklist")
self.blacklistButton.SetEvent(self.__SetMode, 1)
for index, filterData in enumerate(FILTERS):
(bit, label) = filterData
button = self.__CreateButton(15, 150 + index * 18, 245, label)
button.SetEvent(self.__ToggleFilter, bit)
self.filterButtons[bit] = button
def __CreateLine(self, x, y):
textLine = ui.TextLine()
textLine.SetParent(self)
textLine.SetPosition(x, y)
textLine.SetOutline()
textLine.Show()
return textLine
def __CreateButton(self, x, y, width, text):
button = ui.Button()
button.SetParent(self)
button.SetPosition(x, y)
button.SetUpVisual("d:/ymir work/ui/public/small_thin_button_01.sub")
button.SetOverVisual("d:/ymir work/ui/public/small_thin_button_02.sub")
button.SetDownVisual("d:/ymir work/ui/public/small_thin_button_03.sub")
button.SetDisableVisual("d:/ymir work/ui/public/small_thin_button_01.sub")
button.SetSize(width, 17)
button.SetText(text)
button.Show()
return button
def __Send(self, command):
net.SendChatPacket(command, 0)
def __ToggleEnabled(self):
SetAutoPickupState(0 if STATE_ENABLED else 1, STATE_MODE, STATE_MASK, STATE_VIP)
self.__Send("/autopickup enable %d" % STATE_ENABLED)
def __SetMode(self, mode):
SetAutoPickupState(STATE_ENABLED, mode, STATE_MASK, STATE_VIP)
self.__Send("/autopickup mode %s" % ("blacklist" if mode else "whitelist"))
def __ToggleFilter(self, bit):
mask = STATE_MASK ^ bit
SetAutoPickupState(STATE_ENABLED, STATE_MODE, mask, STATE_VIP)
self.__Send("/autopickup mask %d" % STATE_MASK)
def ApplyState(self):
self.statusLine.SetText("Status: %s" % ("Enabled" if STATE_ENABLED else "Disabled"))
self.rangeLine.SetText("Range: %s" % ("VIP 300 / Free 220" if STATE_VIP else "Free 220"))
self.modeLine.SetText("Mode: %s" % ("Blacklist" if STATE_MODE else "Whitelist"))
self.noteLine.SetText("Only nearby owned drops are valid")
self.enableButton.SetText("Disable" if STATE_ENABLED else "Enable")
if STATE_MODE == 0:
self.whitelistButton.Down()
self.blacklistButton.SetUp()
else:
self.whitelistButton.SetUp()
self.blacklistButton.Down()
for (bit, label) in FILTERS:
prefix = "[x]" if (STATE_MASK & bit) else "[ ]"
self.filterButtons[bit].SetText("%s %s" % (prefix, label))
def Show(self):
self.__Send("/autopickup sync")
self.ApplyState()
ui.BoardWithTitleBar.Show(self)