Guest User

specialstorage.py

a guest
May 18th, 2024
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.91 KB | None | 0 0
  1. import ui
  2. import player
  3. import mouseModule
  4. import net
  5. import app
  6. import snd
  7. import item
  8. import chat
  9. import uiScriptLocale
  10. import uiCommon
  11. import uiPrivateShopBuilder
  12. import uiPickMoney
  13. import localeInfo
  14. import constInfo
  15.  
  16. class SpecialStorageWindow(ui.ScriptWindow):
  17. UPGRADE_TYPE = 0
  18. BOOK_TYPE = 1
  19. STONE_TYPE = 2
  20.  
  21. interface = None
  22.  
  23. SLOT_WINDOW_TYPE = {
  24. UPGRADE_TYPE : {"window" : player.UPGRADE_INVENTORY, "slot" : player.SLOT_TYPE_UPGRADE_INVENTORY},
  25. BOOK_TYPE : {"window" : player.BOOK_INVENTORY, "slot" : player.SLOT_TYPE_BOOK_INVENTORY},
  26. STONE_TYPE : {"window" : player.STONE_INVENTORY, "slot" : player.SLOT_TYPE_STONE_INVENTORY}
  27. }
  28.  
  29. WINDOW_NAMES = {
  30. UPGRADE_TYPE : "Depozit Upgrade",
  31. BOOK_TYPE : "Depozit Carti",
  32. STONE_TYPE : "Depozit Pietre"
  33. }
  34.  
  35. def __init__(self):
  36. ui.ScriptWindow.__init__(self)
  37. self.questionDialog = None
  38. self.tooltipItem = None
  39. self.dlgSplitItems = None
  40. self.sellingSlotNumber = -1
  41. self.isLoaded = 0
  42. self.inventoryPageIndex = 0
  43. self.categoryPageIndex = 0
  44. self.SetWindowName("SpecialStorageWindow")
  45. self.__LoadWindow()
  46.  
  47. def __del__(self):
  48. ui.ScriptWindow.__del__(self)
  49.  
  50. def Show(self):
  51. self.__LoadWindow()
  52. ui.ScriptWindow.Show(self)
  53.  
  54. def BindInterfaceClass(self, interface):
  55. self.interface = interface
  56.  
  57. def __LoadWindow(self):
  58. if self.isLoaded == 1:
  59. return
  60.  
  61. self.isLoaded = 1
  62.  
  63. try:
  64. pyScrLoader = ui.PythonScriptLoader()
  65. pyScrLoader.LoadScriptFile(self, "UIScript/SpecialStorageWindow.py")
  66. except:
  67. import exception
  68. exception.Abort("SpecialStorageWindow.LoadWindow.LoadObject")
  69.  
  70. try:
  71. wndItem = self.GetChild("ItemSlot")
  72. self.GetChild("TitleBar").SetCloseEvent(ui.__mem_func__(self.Close))
  73. self.titleName = self.GetChild("TitleName")
  74. self.inventoryTab = []
  75. self.inventoryTab.append(self.GetChild("Inventory_Tab_01"))
  76. self.inventoryTab.append(self.GetChild("Inventory_Tab_02"))
  77.  
  78. self.categoryTab = []
  79. self.categoryTab.append(self.GetChild("Category_Tab_01"))
  80. self.categoryTab.append(self.GetChild("Category_Tab_02"))
  81. self.categoryTab.append(self.GetChild("Category_Tab_03"))
  82. except:
  83. import exception
  84. exception.Abort("SpecialStorageWindow.LoadWindow.BindObject")
  85.  
  86. ## Item
  87. wndItem.SetOverInItemEvent(ui.__mem_func__(self.OverInItem))
  88. wndItem.SetOverOutItemEvent(ui.__mem_func__(self.OverOutItem))
  89. wndItem.SetSelectItemSlotEvent(ui.__mem_func__(self.SelectItemSlot))
  90. wndItem.SetSelectEmptySlotEvent(ui.__mem_func__(self.SelectEmptySlot))
  91. wndItem.SetUnselectItemSlotEvent(ui.__mem_func__(self.UseItemSlot))
  92. wndItem.SetUseSlotEvent(ui.__mem_func__(self.UseItemSlot))
  93.  
  94. ## Grade button
  95. self.inventoryTab[0].SetEvent(lambda arg=0: self.SetInventoryPage(arg))
  96. self.inventoryTab[1].SetEvent(lambda arg=1: self.SetInventoryPage(arg))
  97. self.inventoryTab[0].Down()
  98.  
  99. self.categoryTab[0].SetEvent(lambda arg=0: self.SetCategoryPage(arg))
  100. self.categoryTab[1].SetEvent(lambda arg=1: self.SetCategoryPage(arg))
  101. self.categoryTab[2].SetEvent(lambda arg=2: self.SetCategoryPage(arg))
  102. self.categoryTab[0].Down()
  103.  
  104. ## Etc
  105. self.wndItem = wndItem
  106.  
  107. self.wndPopupDialog = uiCommon.PopupDialog()
  108.  
  109. self.dlgSplitItems = uiPickMoney.PickMoneyDialog()
  110. self.dlgSplitItems.LoadDialog()
  111. self.dlgSplitItems.Hide()
  112.  
  113. self.SetInventoryPage(0)
  114. self.SetCategoryPage(0)
  115. self.RefreshItemSlot()
  116. self.RefreshBagSlotWindow()
  117.  
  118. def Destroy(self):
  119. self.ClearDictionary()
  120. self.tooltipItem = None
  121. self.wndItem = 0
  122. self.questionDialog = None
  123. self.dlgSplitItems.Destroy()
  124. self.dlgSplitItems = None
  125. self.inventoryTab = []
  126. self.categoryTab = []
  127. self.titleName = None
  128.  
  129. self.interface = None
  130.  
  131. def Close(self):
  132. if None != self.tooltipItem:
  133. self.tooltipItem.HideToolTip()
  134. if self.dlgSplitItems:
  135. self.dlgSplitItems.Close()
  136. self.Hide()
  137.  
  138. def SetInventoryPage(self, page):
  139. self.inventoryTab[self.inventoryPageIndex].SetUp()
  140. self.inventoryPageIndex = page
  141. self.inventoryTab[self.inventoryPageIndex].Down()
  142.  
  143. self.RefreshBagSlotWindow()
  144.  
  145. def SetCategoryPage(self, page):
  146. self.categoryTab[self.categoryPageIndex].SetUp()
  147. self.categoryPageIndex = page
  148. self.categoryTab[self.categoryPageIndex].Down()
  149.  
  150. self.titleName.SetText(self.WINDOW_NAMES[self.categoryPageIndex])
  151. self.RefreshBagSlotWindow()
  152.  
  153. def SetItemToolTip(self, tooltipItem):
  154. self.tooltipItem = tooltipItem
  155.  
  156. def RefreshItemSlot(self):
  157. self.RefreshBagSlotWindow()
  158.  
  159. def RefreshStatus(self):
  160. self.RefreshItemSlot()
  161.  
  162. def __InventoryLocalSlotPosToGlobalSlotPos(self, localSlotPos):
  163. return self.inventoryPageIndex * player.SPECIAL_PAGE_SIZE + localSlotPos
  164.  
  165. def RefreshBagSlotWindow(self):
  166. getItemVNum=player.GetItemIndex
  167. getItemCount=player.GetItemCount
  168. setItemVnum=self.wndItem.SetItemSlot
  169.  
  170. for i in xrange(player.SPECIAL_PAGE_SIZE):
  171. self.wndItem.EnableSlot(i)
  172. slotNumber = self.__InventoryLocalSlotPosToGlobalSlotPos(i)
  173.  
  174. itemCount = getItemCount(self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], slotNumber)
  175. itemVnum = getItemVNum(self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], slotNumber)
  176.  
  177. if 0 == itemCount:
  178. self.wndItem.ClearSlot(i)
  179. continue
  180. elif 1 == itemCount:
  181. itemCount = 0
  182.  
  183. setItemVnum(i, itemVnum, itemCount)
  184.  
  185. if app.QUICK_SELL_SYSTEM:
  186. self.RefreshQuickSell()
  187.  
  188. # if app.QUICK_SELL_SYSTEM:
  189. # if slotNumber in constInfo.QUICK_SELL_ITEMS:
  190. # self.wndItem.SetSlotCoverImage(i, "d:/ymir work/ui/game/quick_sell/selected_icon.tga")
  191. # else:
  192. # self.wndItem.EnableSlotCoverImage(i, False)
  193.  
  194. self.wndItem.RefreshSlot()
  195.  
  196. def ShowToolTip(self, slotIndex):
  197. if None != self.tooltipItem:
  198. self.tooltipItem.SetInventoryItem(slotIndex, self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"])
  199.  
  200. def OnPressEscapeKey(self):
  201. self.Close()
  202. return True
  203.  
  204. def OnTop(self):
  205. if None != self.tooltipItem:
  206. self.tooltipItem.SetTop()
  207.  
  208. def OverOutItem(self):
  209. self.wndItem.SetUsableItem(False)
  210. if None != self.tooltipItem:
  211. self.tooltipItem.HideToolTip()
  212.  
  213. def OverInItem(self, overSlotPos):
  214. overSlotPos = self.__InventoryLocalSlotPosToGlobalSlotPos(overSlotPos)
  215.  
  216. self.wndItem.SetUsableItem(False)
  217. self.ShowToolTip(overSlotPos)
  218.  
  219. def OnPickItem(self, count):
  220. itemSlotIndex = self.dlgSplitItems.itemGlobalSlotIndex
  221. selectedItemVNum = player.GetItemIndex(self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], itemSlotIndex)
  222. mouseModule.mouseController.AttachObject(self, self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["slot"], itemSlotIndex, selectedItemVNum, count)
  223.  
  224. def SelectItemSlot(self, itemSlotIndex):
  225. if constInfo.GET_ITEM_QUESTION_DIALOG_STATUS() == 1:
  226. return
  227.  
  228. itemSlotIndex = self.__InventoryLocalSlotPosToGlobalSlotPos(itemSlotIndex)
  229. selectedItemVNum = player.GetItemIndex(self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], itemSlotIndex)
  230. itemCount = player.GetItemCount(self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], itemSlotIndex)
  231.  
  232. if mouseModule.mouseController.isAttached():
  233. attachedSlotType = mouseModule.mouseController.GetAttachedType()
  234. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  235. attachedItemVID = mouseModule.mouseController.GetAttachedItemIndex()
  236. attachedItemCount = mouseModule.mouseController.GetAttachedItemCount()
  237.  
  238. if self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["slot"] == attachedSlotType:
  239. if attachedItemVID == selectedItemVNum:
  240. net.SendItemMovePacket(self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], attachedSlotPos, self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], itemSlotIndex, 0) #This modifi: last value: attachedItemCount
  241. else:
  242. net.SendItemUseToItemPacket(self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], attachedSlotPos, self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], itemSlotIndex)
  243.  
  244. mouseModule.mouseController.DeattachObject()
  245. else:
  246. curCursorNum = app.GetCursor()
  247.  
  248. if app.SELL == curCursorNum:
  249. self.__SellItem(itemSlotIndex)
  250. elif app.BUY == curCursorNum:
  251. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_BUY_INFO)
  252. elif app.IsPressed(app.DIK_LALT):
  253. link = player.GetItemLink(itemSlotIndex)
  254. ime.PasteString(link)
  255.  
  256. elif app.IsPressed(app.DIK_LSHIFT):
  257. if itemCount > 1:
  258. self.dlgSplitItems.SetTitleName(localeInfo.PICK_ITEM_TITLE)
  259. self.dlgSplitItems.SetAcceptEvent(ui.__mem_func__(self.OnPickItem))
  260. self.dlgSplitItems.Open(itemCount)
  261. self.dlgSplitItems.itemGlobalSlotIndex = itemSlotIndex
  262. else:
  263. mouseModule.mouseController.AttachObject(self, self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["slot"], itemSlotIndex, selectedItemVNum, itemCount)
  264. self.wndItem.SetUseMode(False)
  265. snd.PlaySound("sound/ui/pick.wav")
  266.  
  267. def __SellItem(self, itemSlotPos):
  268. self.sellingSlotNumber = itemSlotPos
  269. itemIndex = player.GetItemIndex(self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], itemSlotPos)
  270. itemCount = player.GetItemCount(self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], itemSlotPos)
  271.  
  272. item.SelectItem(itemIndex)
  273.  
  274. if item.IsAntiFlag(item.ANTIFLAG_SELL):
  275. popup = uiCommon.PopupDialog()
  276. popup.SetText(localeInfo.SHOP_CANNOT_SELL_ITEM)
  277. popup.SetAcceptEvent(self.__OnClosePopupDialog)
  278. popup.Open()
  279. self.popup = popup
  280. return
  281.  
  282. itemPrice = item.GetISellItemPrice()
  283.  
  284. if item.Is1GoldItem():
  285. itemPrice = itemCount / itemPrice
  286. else:
  287. itemPrice = itemPrice * itemCount
  288.  
  289. item.GetItemName(itemIndex)
  290. itemName = item.GetItemName()
  291.  
  292. self.questionDialog = uiCommon.QuestionDialog()
  293. self.questionDialog.SetText(localeInfo.DO_YOU_SELL_ITEM(itemName, itemCount, itemPrice))
  294. self.questionDialog.SetAcceptEvent(ui.__mem_func__(self.SellItem))
  295. self.questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  296. self.questionDialog.Open()
  297. self.questionDialog.count = itemCount
  298.  
  299. def SellItem(self):
  300. net.SendShopSellPacketNew(self.sellingSlotNumber, self.questionDialog.count, self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"])
  301. snd.PlaySound("sound/ui/money.wav")
  302. self.OnCloseQuestionDialog()
  303.  
  304. def OnCloseQuestionDialog(self):
  305. if self.questionDialog:
  306. self.questionDialog.Close()
  307.  
  308. self.questionDialog = None
  309.  
  310. def __OnClosePopupDialog(self):
  311. self.pop = None
  312.  
  313. def SelectEmptySlot(self, selectedSlotPos):
  314. if constInfo.GET_ITEM_QUESTION_DIALOG_STATUS() == 1:
  315. return
  316.  
  317. selectedSlotPos = self.__InventoryLocalSlotPosToGlobalSlotPos(selectedSlotPos)
  318. if mouseModule.mouseController.isAttached():
  319.  
  320. attachedSlotType = mouseModule.mouseController.GetAttachedType()
  321. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  322. attachedItemCount = mouseModule.mouseController.GetAttachedItemCount()
  323. attachedItemIndex = mouseModule.mouseController.GetAttachedItemIndex()
  324.  
  325. attachedInvenType = player.SlotTypeToInvenType(attachedSlotType)
  326.  
  327. if player.SLOT_TYPE_PRIVATE_SHOP == attachedSlotType:
  328. mouseModule.mouseController.RunCallBack("INVENTORY")
  329.  
  330. elif player.SLOT_TYPE_SHOP == attachedSlotType:
  331. net.SendShopBuyPacket(attachedSlotPos)
  332.  
  333. elif player.SLOT_TYPE_SAFEBOX == attachedSlotType:
  334. net.SendSafeboxCheckoutPacket(attachedSlotPos, self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], selectedSlotPos)
  335. elif player.SLOT_TYPE_MALL == attachedSlotType:
  336. net.SendMallCheckoutPacket(attachedSlotPos, self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], selectedSlotPos)
  337. elif player.RESERVED_WINDOW != attachedInvenType:
  338. itemCount = player.GetItemCount(attachedInvenType, attachedSlotPos)
  339. attachedCount = mouseModule.mouseController.GetAttachedItemCount()
  340.  
  341. self.__SendMoveItemPacket(attachedInvenType, attachedSlotPos, self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], selectedSlotPos, attachedCount)
  342.  
  343. mouseModule.mouseController.DeattachObject()
  344.  
  345. def UseItemSlot(self, slotIndex):
  346. if constInfo.GET_ITEM_QUESTION_DIALOG_STATUS():
  347. return
  348. slotIndex = self.__InventoryLocalSlotPosToGlobalSlotPos(slotIndex)
  349.  
  350. if app.QUICK_SELL_SYSTEM:
  351. if app.IsPressed(app.DIK_LSHIFT):
  352. if slotIndex in constInfo.QUICK_SELL_ITEMS_STONE:
  353. self.interface.RemoveSellSlot(slotIndex)
  354. self.RefreshBagSlotWindow()
  355. return
  356. else:
  357. self.interface.AppendSellSlotSpecialInventory(slotIndex)
  358. self.RefreshBagSlotWindow()
  359. return
  360.  
  361. # if app.QUICK_SELL_SYSTEM:
  362. # itemVnum = player.GetItemIndex(self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], slotIndex)
  363. # blackList = [constInfo.IS_AUTO_POTION, constInfo.IS_OLD_PETSYSTEM, constInfo.IS_NEW_PETSYSTEM]
  364.  
  365. # if app.IsPressed(app.DIK_LSHIFT):
  366. # for func in blackList:
  367. # if func(itemVnum):
  368. # return
  369.  
  370. # if slotIndex in constInfo.QUICK_SELL_ITEMS:
  371. # self.interface.RemoveSellSlot(slotIndex)
  372. # self.RefreshBagSlotWindow()
  373. # return
  374. # elif not slotIndex in constInfo.QUICK_SELL_ITEMS:
  375. # self.interface.AppendSellSlot(slotIndex)
  376. # self.RefreshBagSlotWindow()
  377. # return
  378.  
  379.  
  380. #self.__UseItem(slotIndex)
  381. net.SendItemUsePacket(self.SLOT_WINDOW_TYPE[self.categoryPageIndex]["window"], slotIndex)
  382.  
  383. mouseModule.mouseController.DeattachObject()
  384. self.OverOutItem()
  385.  
  386. def __SendMoveItemPacket(self, srcSlotWindow, srcSlotPos, dstSlotWindow, dstSlotPos, srcItemCount):
  387. if uiPrivateShopBuilder.IsBuildingPrivateShop():
  388. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.MOVE_ITEM_FAILURE_PRIVATE_SHOP)
  389. return
  390.  
  391. net.SendItemMovePacket(srcSlotWindow , srcSlotPos, dstSlotWindow, dstSlotPos, srcItemCount)
  392.  
  393. if app.QUICK_SELL_SYSTEM:
  394. def RefreshQuickSell(self):
  395. for k in xrange(player.INVENTORY_PAGE_SIZE * 5):
  396. slotNumber = self.__InventoryLocalSlotPosToGlobalSlotPos(k)
  397. if slotNumber in constInfo.QUICK_SELL_ITEMS_STONE:
  398. self.wndItem.SetSlotCoverImage(k, "d:/ymir work/ui/game/quick_sell/selected_icon.tga")
  399. else:
  400. self.wndItem.EnableSlotCoverImage(k, False)
  401.  
Advertisement
Add Comment
Please, Sign In to add comment