Guest User

quicksell.py

a guest
May 18th, 2024
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. import ui
  2. import net
  3. import localeInfo
  4. import player
  5. import item
  6. import constInfo
  7.  
  8. import uiSpecialStorage
  9.  
  10.  
  11.  
  12. class QuickSell(ui.Window):
  13. QUICK_SELL_WIDTH = 133
  14. def __init__(self):
  15. ui.Window.__init__(self)
  16. self.cancelButton = None
  17. self.sellPrice = None
  18. self.sellItemSelectedCount = None
  19. self.sellPriceBG = None
  20. self.sellItemSelectedCountBG = None
  21. self.sellButton = None
  22. self.SetSize(133, 37)
  23. self.SetCenterPosition()
  24. self.AddFlag("float")
  25. self.Hide()
  26. self.BoardInterface()
  27.  
  28. self.wndSpecialStorage = uiSpecialStorage.SpecialStorageWindow()
  29.  
  30.  
  31. def __del__(self):
  32. ui.Window.__del__(self)
  33.  
  34. def Destroy(self):
  35. self.Hide()
  36. self.ResetWindow()
  37. player.RefreshInventory()
  38.  
  39. def Close(self):
  40. self.Hide()
  41. self.ResetWindow()
  42. player.RefreshInventory()
  43.  
  44. def Open(self):
  45. self.SetTop()
  46. self.Show()
  47.  
  48. def ResetWindow(self):
  49. constInfo.QUICK_SELL_ITEMS = []
  50. constInfo.QUICK_SELL_ITEMS_STONE = []
  51. self.UpdatePrice()
  52.  
  53.  
  54. def __InventoryLocalSlotPosToGlobalSlotPos(self, slotIndex):
  55. return self.wndSpecialStorage.inventoryPageIndex * player.SPECIAL_PAGE_SIZE + slotIndex
  56.  
  57. def AppendSellSlot(self, slotIndex):
  58. if slotIndex in constInfo.QUICK_SELL_ITEMS:
  59. return
  60.  
  61. if slotIndex in constInfo.QUICK_SELL_ITEMS_STONE:
  62. return
  63.  
  64. if player.IsEquipmentSlot(slotIndex):
  65. return
  66.  
  67.  
  68.  
  69.  
  70. if player.GetItemIndex(player.INVENTORY, slotIndex) != 0:
  71. itemVnum = player.GetItemIndex(player.INVENTORY, slotIndex)
  72. inventory_type = player.INVENTORY
  73. slot_list = constInfo.QUICK_SELL_ITEMS
  74. elif player.GetItemIndex(player.STONE_INVENTORY, slotIndex) != 0:
  75. itemVnum = player.GetItemIndex(player.STONE_INVENTORY, slotIndex)
  76. inventory_type = player.STONE_INVENTORY
  77. slot_list = constInfo.QUICK_SELL_ITEMS_STONE
  78.  
  79. # Normal Inventory
  80. # itemVnum = player.GetItemIndex(player.INVENTORY, slotIndex)
  81.  
  82. # Special Inventory
  83. # itemVnum = player.GetItemIndex(player.STONE_INVENTORY, slotIndex)
  84.  
  85.  
  86. if itemVnum == 0:
  87. return
  88.  
  89. item.SelectItem(itemVnum)
  90.  
  91. if item.IsAntiFlag(item.ITEM_ANTIFLAG_SELL):
  92. return
  93.  
  94. if not self.IsShow():
  95. self.Open()
  96.  
  97. slot_list.append(slotIndex)
  98.  
  99. def RemoveSellSlot(self, slotIndex):
  100. if slotIndex in constInfo.QUICK_SELL_ITEMS:
  101. constInfo.QUICK_SELL_ITEMS.remove(slotIndex)
  102. if len(constInfo.QUICK_SELL_ITEMS) == 0:
  103. self.Close()
  104. elif slotIndex in constInfo.QUICK_SELL_ITEMS_STONE:
  105. constInfo.QUICK_SELL_ITEMS_STONE.remove(slotIndex)
  106. if len(constInfo.QUICK_SELL_ITEMS_STONE) == 0:
  107. self.Close()
  108.  
  109. def BoardInterface(self):
  110. self.Board = ui.MakeImageBox(self, "d:/ymir work/ui/game/quick_sell/quick_sell_base_board.tga", 0, 0)
  111.  
  112. self.sellButton = ui.MakeButton(self, self.QUICK_SELL_WIDTH / 2 - 52, 100 - 81, "", "d:/ymir work/ui/game/quick_sell/", "accept_1.tga", "accept_2.tga", "accept_3.tga")
  113. self.sellButton.SetEvent(self.__OnClickSellButton)
  114.  
  115. self.cancelButton = ui.MakeButton(self, self.QUICK_SELL_WIDTH / 2 + 27, 100 - 81, "","d:/ymir work/ui/game/quick_sell/", "cancel_1.tga","cancel_2.tga", "cancel_3.tga")
  116. self.cancelButton.SetEvent(self.Close)
  117.  
  118. self.sellPrice = ui.MakeTextLineNew(self, 0, 2, "")
  119. self.sellPrice.SetWindowHorizontalAlignCenter()
  120. self.sellPrice.SetHorizontalAlignCenter()
  121.  
  122. def AdjustPosition(self, x, y):
  123. self.SetPosition(x, y)
  124.  
  125. def UpdatePrice(self):
  126. price = 0
  127. selected_count = 0
  128.  
  129.  
  130. # Normal Inventory
  131. for itemSlotIndex in constInfo.QUICK_SELL_ITEMS:
  132. itemIndex = player.GetItemIndex(player.INVENTORY, itemSlotIndex)
  133. if itemIndex == 0:
  134. continue
  135. item.SelectItem(itemIndex)
  136. itemPrice = item.GetISellItemPrice()
  137. itemCount = player.GetItemCount(player.INVENTORY, itemSlotIndex)
  138.  
  139. if item.Is1GoldItem():
  140. itemPrice = itemCount / itemPrice
  141. else:
  142. itemPrice = itemPrice * max(1, itemCount)
  143.  
  144. price += itemPrice
  145. selected_count += 1
  146.  
  147. # Special Inventory
  148. for itemSlotIndex in constInfo.QUICK_SELL_ITEMS_STONE:
  149. itemIndex = player.GetItemIndex(player.STONE_INVENTORY, itemSlotIndex)
  150. if itemIndex == 0:
  151. continue
  152. item.SelectItem(itemIndex)
  153. itemPrice = item.GetISellItemPrice()
  154. itemCount = player.GetItemCount(player.STONE_INVENTORY, itemSlotIndex)
  155.  
  156. if item.Is1GoldItem():
  157. itemPrice = itemCount / itemPrice
  158. else:
  159. itemPrice = itemPrice * max(1, itemCount)
  160.  
  161. price += itemPrice
  162. selected_count += 1
  163.  
  164.  
  165. self.sellPrice.SetText("|Eemoji/key_selected_sell|e " + "%d " % selected_count + "|Eemoji/key_money_icon|e "+localeInfo.NumberToDecimalStringQuickSell(price))
  166. self.sellPrice.SetHorizontalAlignCenter()
  167.  
  168. def __OnClickSellButton(self):
  169.  
  170.  
  171. # Normal Inventory
  172. for itemSlotIndex in constInfo.QUICK_SELL_ITEMS:
  173. self.sellingSlotNumber = itemSlotIndex
  174. itemIndex = player.GetItemIndex(player.INVENTORY, itemSlotIndex)
  175. itemCount = player.GetItemCount(player.INVENTORY, itemSlotIndex)
  176.  
  177. self.sellingSlotitemIndex = itemIndex
  178. self.sellingSlotitemCount = itemCount
  179.  
  180. net.SendShopSellPacketNew(self.sellingSlotNumber, self.sellingSlotitemCount, player.INVENTORY)
  181.  
  182. # Special Inventory
  183. for itemSlotIndex in constInfo.QUICK_SELL_ITEMS_STONE:
  184. self.sellingSlotNumber = itemSlotIndex
  185. itemIndex = player.GetItemIndex(player.STONE_INVENTORY, itemSlotIndex)
  186. itemCount = player.GetItemCount(player.STONE_INVENTORY, itemSlotIndex)
  187.  
  188. self.sellingSlotitemIndex = itemIndex
  189. self.sellingSlotitemCount = itemCount
  190.  
  191. net.SendShopSellPacketNew(self.sellingSlotNumber, self.sellingSlotitemCount, player.STONE_INVENTORY)
  192.  
  193.  
  194. constInfo.QUICK_SELL_ITEMS = []
  195. constInfo.QUICK_SELL_ITEMS_STONE = []
  196. self.Close()
  197. player.RefreshInventory()
  198.  
  199. def OnPressEscapeKey(self):
  200. self.Close()
  201. player.RefreshInventory()
  202. return True
  203.  
  204. def OnPressExitKey(self):
  205. self.Close()
  206. player.RefreshInventory()
  207. return True
  208.  
Add Comment
Please, Sign In to add comment