thanato1994

UIPRIVATESHOP.PY

Dec 7th, 2020 (edited)
11
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import ui
  2. import snd
  3. import shop
  4. import mouseModule
  5. import player
  6. import chr
  7. import net
  8. import uiCommon
  9. import localeInfo
  10. import chat
  11. import item
  12. import systemSetting #김준호
  13. import player #김준호
  14.  
  15. g_isBuildingPrivateShop = False
  16.  
  17. g_itemPriceDict={}
  18.  
  19. g_privateShopAdvertisementBoardDict={}
  20.  
  21. def Clear():
  22. global g_itemPriceDict
  23. global g_isBuildingPrivateShop
  24. g_itemPriceDict={}
  25. g_isBuildingPrivateShop = False
  26. # @fixme007 BEGIN
  27. global g_privateShopAdvertisementBoardDict
  28. g_privateShopAdvertisementBoardDict={}
  29. # @fixme007 END
  30.  
  31. def IsPrivateShopItemPriceList():
  32. global g_itemPriceDict
  33. if g_itemPriceDict:
  34. return True
  35. else:
  36. return False
  37.  
  38. def IsBuildingPrivateShop():
  39. global g_isBuildingPrivateShop
  40. if player.IsOpenPrivateShop() or g_isBuildingPrivateShop:
  41. return True
  42. else:
  43. return False
  44.  
  45. def SetPrivateShopItemPrice(itemVNum, itemPrice):
  46. global g_itemPriceDict
  47. g_itemPriceDict[int(itemVNum)]=itemPrice
  48.  
  49. def GetPrivateShopItemPrice(itemVNum):
  50. try:
  51. global g_itemPriceDict
  52. return g_itemPriceDict[itemVNum]
  53. except KeyError:
  54. return 0
  55.  
  56. def UpdateADBoard():
  57. for key in g_privateShopAdvertisementBoardDict.keys():
  58. g_privateShopAdvertisementBoardDict[key].Show()
  59.  
  60. def DeleteADBoard(vid):
  61. if not g_privateShopAdvertisementBoardDict.has_key(vid):
  62. return
  63.  
  64. del g_privateShopAdvertisementBoardDict[vid]
  65.  
  66.  
  67. class PrivateShopAdvertisementBoard(ui.ThinBoard):
  68. def __init__(self):
  69. ui.ThinBoard.__init__(self, "UI_BOTTOM")
  70. self.vid = None
  71. self.__MakeTextLine()
  72.  
  73. def __del__(self):
  74. ui.ThinBoard.__del__(self)
  75.  
  76. def __MakeTextLine(self):
  77. self.textLine = ui.TextLine()
  78. self.textLine.SetParent(self)
  79. self.textLine.SetWindowHorizontalAlignCenter()
  80. self.textLine.SetWindowVerticalAlignCenter()
  81. self.textLine.SetHorizontalAlignCenter()
  82. self.textLine.SetVerticalAlignCenter()
  83. self.textLine.Show()
  84.  
  85. def Open(self, vid, text):
  86. self.vid = vid
  87.  
  88. self.textLine.SetText(text)
  89. self.textLine.UpdateRect()
  90. self.SetSize(len(text)*6 + 10*2, 20)
  91. self.Show()
  92.  
  93. g_privateShopAdvertisementBoardDict[vid] = self
  94.  
  95. def OnMouseLeftButtonUp(self):
  96. if not self.vid:
  97. return
  98. net.SendOnClickPacket(self.vid)
  99.  
  100. return True
  101.  
  102. def OnUpdate(self):
  103. if not self.vid:
  104. return
  105.  
  106. if systemSetting.IsShowSalesText():
  107. self.Show()
  108. x, y = chr.GetProjectPosition(self.vid, 220)
  109. self.SetPosition(x - self.GetWidth()/2, y - self.GetHeight()/2)
  110.  
  111. else:
  112. for key in g_privateShopAdvertisementBoardDict.keys():
  113. if player.GetMainCharacterIndex() == key: #상점풍선을 안보이게 감추는 경우에도, 플레이어 자신의 상점 풍선은 보이도록 함. by 김준호
  114. g_privateShopAdvertisementBoardDict[key].Show()
  115. x, y = chr.GetProjectPosition(player.GetMainCharacterIndex(), 220)
  116. g_privateShopAdvertisementBoardDict[key].SetPosition(x - self.GetWidth()/2, y - self.GetHeight()/2)
  117. else:
  118. g_privateShopAdvertisementBoardDict[key].Hide()
  119.  
  120. class PrivateShopBuilder(ui.ScriptWindow):
  121.  
  122. def __init__(self):
  123. #print "NEW MAKE_PRIVATE_SHOP_WINDOW ----------------------------------------------------------------"
  124. ui.ScriptWindow.__init__(self)
  125.  
  126. self.__LoadWindow()
  127. self.itemStock = {}
  128. self.tooltipItem = None
  129. self.priceInputBoard = None
  130. self.title = ""
  131.  
  132. def __del__(self):
  133. #print "------------------------------------------------------------- DELETE MAKE_PRIVATE_SHOP_WINDOW"
  134. ui.ScriptWindow.__del__(self)
  135.  
  136. def __LoadWindow(self):
  137. try:
  138. pyScrLoader = ui.PythonScriptLoader()
  139. pyScrLoader.LoadScriptFile(self, "UIScript/PrivateShopBuilder.py")
  140. except:
  141. import exception
  142. exception.Abort("PrivateShopBuilderWindow.LoadWindow.LoadObject")
  143.  
  144. try:
  145. GetObject = self.GetChild
  146. self.nameLine = GetObject("NameLine")
  147. self.itemSlot = GetObject("ItemSlot")
  148. self.btnOk = GetObject("OkButton")
  149. self.btnClose = GetObject("CloseButton")
  150. self.titleBar = GetObject("TitleBar")
  151. except:
  152. import exception
  153. exception.Abort("PrivateShopBuilderWindow.LoadWindow.BindObject")
  154.  
  155. self.btnOk.SetEvent(ui.__mem_func__(self.OnOk))
  156. self.btnClose.SetEvent(ui.__mem_func__(self.OnClose))
  157. self.titleBar.SetCloseEvent(ui.__mem_func__(self.OnClose))
  158.  
  159. self.itemSlot.SetSelectEmptySlotEvent(ui.__mem_func__(self.OnSelectEmptySlot))
  160. self.itemSlot.SetSelectItemSlotEvent(ui.__mem_func__(self.OnSelectItemSlot))
  161. self.itemSlot.SetOverInItemEvent(ui.__mem_func__(self.OnOverInItem))
  162. self.itemSlot.SetOverOutItemEvent(ui.__mem_func__(self.OnOverOutItem))
  163.  
  164. def Destroy(self):
  165. self.ClearDictionary()
  166.  
  167. self.nameLine = None
  168. self.itemSlot = None
  169. self.btnOk = None
  170. self.btnClose = None
  171. self.titleBar = None
  172. self.priceInputBoard = None
  173.  
  174. def Open(self, title):
  175.  
  176. self.title = title
  177.  
  178. if len(title) > 25:
  179. title = title[:22] + "..."
  180.  
  181. self.itemStock = {}
  182. shop.ClearPrivateShopStock()
  183. self.nameLine.SetText(title)
  184. self.SetCenterPosition()
  185. self.Refresh()
  186. self.Show()
  187.  
  188. global g_isBuildingPrivateShop
  189. g_isBuildingPrivateShop = True
  190.  
  191. def Close(self):
  192. global g_isBuildingPrivateShop
  193. g_isBuildingPrivateShop = False
  194.  
  195. self.title = ""
  196. self.itemStock = {}
  197. shop.ClearPrivateShopStock()
  198. self.Hide()
  199.  
  200. def SetItemToolTip(self, tooltipItem):
  201. self.tooltipItem = tooltipItem
  202.  
  203. def Refresh(self):
  204. getitemVNum=player.GetItemIndex
  205. getItemCount=player.GetItemCount
  206. setitemVNum=self.itemSlot.SetItemSlot
  207. delItem=self.itemSlot.ClearSlot
  208.  
  209. for i in xrange(shop.SHOP_SLOT_COUNT):
  210.  
  211. if not self.itemStock.has_key(i):
  212. delItem(i)
  213. continue
  214.  
  215. pos = self.itemStock[i]
  216.  
  217. itemCount = getItemCount(*pos)
  218. if itemCount <= 1:
  219. itemCount = 0
  220. setitemVNum(i, getitemVNum(*pos), itemCount)
  221.  
  222. self.itemSlot.RefreshSlot()
  223.  
  224. def OnSelectEmptySlot(self, selectedSlotPos):
  225.  
  226. isAttached = mouseModule.mouseController.isAttached()
  227. if isAttached:
  228. attachedSlotType = mouseModule.mouseController.GetAttachedType()
  229. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  230. mouseModule.mouseController.DeattachObject()
  231.  
  232. if player.SLOT_TYPE_INVENTORY != attachedSlotType and player.SLOT_TYPE_DRAGON_SOUL_INVENTORY != attachedSlotType:
  233. return
  234. attachedInvenType = player.SlotTypeToInvenType(attachedSlotType)
  235.  
  236. itemVNum = player.GetItemIndex(attachedInvenType, attachedSlotPos)
  237. item.SelectItem(itemVNum)
  238.  
  239. if item.IsAntiFlag(item.ANTIFLAG_GIVE) or item.IsAntiFlag(item.ANTIFLAG_MYSHOP):
  240. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.PRIVATE_SHOP_CANNOT_SELL_ITEM)
  241. return
  242.  
  243. priceInputBoard = uiCommon.MoneyInputDialog()
  244. priceInputBoard.SetTitle(localeInfo.PRIVATE_SHOP_INPUT_PRICE_DIALOG_TITLE)
  245. priceInputBoard.SetAcceptEvent(ui.__mem_func__(self.AcceptInputPrice))
  246. priceInputBoard.SetCancelEvent(ui.__mem_func__(self.CancelInputPrice))
  247. priceInputBoard.Open()
  248.  
  249. itemPrice=GetPrivateShopItemPrice(itemVNum)
  250.  
  251. if itemPrice>0:
  252. priceInputBoard.SetValue(itemPrice)
  253.  
  254. self.priceInputBoard = priceInputBoard
  255. self.priceInputBoard.itemVNum = itemVNum
  256. self.priceInputBoard.sourceWindowType = attachedInvenType
  257. self.priceInputBoard.sourceSlotPos = attachedSlotPos
  258. self.priceInputBoard.targetSlotPos = selectedSlotPos
  259.  
  260. def OnSelectItemSlot(self, selectedSlotPos):
  261.  
  262. isAttached = mouseModule.mouseController.isAttached()
  263. if isAttached:
  264. snd.PlaySound("sound/ui/loginfail.wav")
  265. mouseModule.mouseController.DeattachObject()
  266.  
  267. else:
  268. if not selectedSlotPos in self.itemStock:
  269. return
  270.  
  271. invenType, invenPos = self.itemStock[selectedSlotPos]
  272. shop.DelPrivateShopItemStock(invenType, invenPos)
  273. snd.PlaySound("sound/ui/drop.wav")
  274.  
  275. del self.itemStock[selectedSlotPos]
  276.  
  277. self.Refresh()
  278.  
  279. def AcceptInputPrice(self):
  280.  
  281. if not self.priceInputBoard:
  282. return True
  283.  
  284. text = self.priceInputBoard.GetText()
  285.  
  286. if not text:
  287. return True
  288.  
  289. if not text.isdigit():
  290. return True
  291.  
  292. if long(text) <= 0:
  293. return True
  294.  
  295. attachedInvenType = self.priceInputBoard.sourceWindowType
  296. sourceSlotPos = self.priceInputBoard.sourceSlotPos
  297. targetSlotPos = self.priceInputBoard.targetSlotPos
  298.  
  299. for privatePos, (itemWindowType, itemSlotIndex) in self.itemStock.items():
  300. if itemWindowType == attachedInvenType and itemSlotIndex == sourceSlotPos:
  301. shop.DelPrivateShopItemStock(itemWindowType, itemSlotIndex)
  302. del self.itemStock[privatePos]
  303.  
  304. price = int(self.priceInputBoard.GetText())
  305.  
  306. if IsPrivateShopItemPriceList():
  307. SetPrivateShopItemPrice(self.priceInputBoard.itemVNum, price)
  308.  
  309. shop.AddPrivateShopItemStock(attachedInvenType, sourceSlotPos, targetSlotPos, price)
  310. self.itemStock[targetSlotPos] = (attachedInvenType, sourceSlotPos)
  311. snd.PlaySound("sound/ui/drop.wav")
  312.  
  313. self.Refresh()
  314.  
  315. #####
  316.  
  317. self.priceInputBoard = None
  318. return True
  319.  
  320. def CancelInputPrice(self):
  321. self.priceInputBoard = None
  322. return True
  323.  
  324. def OnOk(self):
  325.  
  326. if not self.title:
  327. return
  328.  
  329. if 0 == len(self.itemStock):
  330. return
  331.  
  332. shop.BuildPrivateShop(self.title)
  333. self.Close()
  334.  
  335. def OnClose(self):
  336. self.Close()
  337.  
  338. def OnPressEscapeKey(self):
  339. self.Close()
  340. return True
  341.  
  342. def OnOverInItem(self, slotIndex):
  343.  
  344. if self.tooltipItem:
  345. if self.itemStock.has_key(slotIndex):
  346. self.tooltipItem.SetPrivateShopBuilderItem(*self.itemStock[slotIndex] + (slotIndex,))
  347.  
  348. def OnOverOutItem(self):
  349.  
  350. if self.tooltipItem:
  351. self.tooltipItem.HideToolTip()
  352.  
RAW Paste Data