Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.94 KB | None | 0 0
  1. import net
  2. import player
  3. import item
  4. import snd
  5. import shop
  6. import net
  7. import wndMgr
  8. import app
  9. import chat
  10.  
  11. import ui
  12. import uiCommon
  13. import mouseModule
  14. import localeInfo
  15.  
  16. ###################################################################################################
  17. ## Shop
  18. class ShopDialog(ui.ScriptWindow):
  19.  
  20. def __init__(self):
  21. ui.ScriptWindow.__init__(self)
  22. self.tooltipItem = 0
  23. self.xShopStart = 0
  24. self.yShopStart = 0
  25. self.questionDialog = None
  26. self.popup = None
  27. self.itemBuyQuestionDialog = None
  28.  
  29. def __del__(self):
  30. ui.ScriptWindow.__del__(self)
  31.  
  32. def Refresh(self):
  33. getItemID=shop.GetItemID
  34. getItemCount=shop.GetItemCount
  35. setItemID=self.itemSlotWindow.SetItemSlot
  36. for i in xrange(shop.SHOP_SLOT_COUNT):
  37. itemCount = getItemCount(i)
  38. if itemCount <= 1:
  39. itemCount = 0
  40. setItemID(i, getItemID(i), itemCount)
  41.  
  42. wndMgr.RefreshSlot(self.itemSlotWindow.GetWindowHandle())
  43.  
  44. def SetItemData(self, pos, itemID, itemCount, itemPrice):
  45. shop.SetItemData(pos, itemID, itemCount, itemPrice)
  46.  
  47. def LoadDialog(self):
  48. try:
  49. PythonScriptLoader = ui.PythonScriptLoader()
  50. PythonScriptLoader.LoadScriptFile(self, "UIScript/shopdialog.py")
  51. except:
  52. import exception
  53. exception.Abort("ShopDialog.LoadDialog.LoadObject")
  54.  
  55. try:
  56. GetObject = self.GetChild
  57. self.itemSlotWindow = GetObject("ItemSlot")
  58. self.btnBuy = GetObject("BuyButton")
  59. self.btnSell = GetObject("SellButton")
  60. self.btnClose = GetObject("CloseButton")
  61. self.titleBar = GetObject("TitleBar")
  62. except:
  63. import exception
  64. exception.Abort("ShopDialog.LoadDialog.BindObject")
  65.  
  66. self.itemSlotWindow.SetSlotStyle(wndMgr.SLOT_STYLE_NONE)
  67. self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EMPTY", self.SelectEmptySlot)
  68. self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EXIST", self.SelectItemSlot)
  69. self.itemSlotWindow.SAFE_SetButtonEvent("RIGHT", "EXIST", self.UnselectItemSlot)
  70.  
  71. self.itemSlotWindow.SetOverInItemEvent(ui.__mem_func__(self.OverInItem))
  72. self.itemSlotWindow.SetOverOutItemEvent(ui.__mem_func__(self.OverOutItem))
  73.  
  74. self.btnBuy.SetToggleUpEvent(ui.__mem_func__(self.CancelShopping))
  75. self.btnBuy.SetToggleDownEvent(ui.__mem_func__(self.OnBuy))
  76.  
  77. self.btnSell.SetToggleUpEvent(ui.__mem_func__(self.CancelShopping))
  78. self.btnSell.SetToggleDownEvent(ui.__mem_func__(self.OnSell))
  79.  
  80. self.btnClose.SetEvent(ui.__mem_func__(self.AskClosePrivateShop))
  81.  
  82. self.titleBar.SetCloseEvent(ui.__mem_func__(self.Close))
  83.  
  84. self.Refresh()
  85.  
  86. def Destroy(self):
  87. self.Close()
  88. self.ClearDictionary()
  89.  
  90. self.tooltipItem = 0
  91. self.itemSlotWindow = 0
  92. self.btnBuy = 0
  93. self.btnSell = 0
  94. self.btnClose = 0
  95. self.titleBar = 0
  96. self.questionDialog = None
  97. self.popup = None
  98.  
  99. def Open(self, vid):
  100.  
  101. isPrivateShop = FALSE
  102. isMainPlayerPrivateShop = FALSE
  103.  
  104. import chr
  105. if chr.IsNPC(vid):
  106. isPrivateShop = FALSE
  107. else:
  108. isPrivateShop = TRUE
  109.  
  110. if player.IsMainCharacterIndex(vid):
  111.  
  112. isMainPlayerPrivateShop = TRUE
  113.  
  114. self.btnBuy.Hide()
  115. self.btnSell.Hide()
  116. self.btnClose.Show()
  117.  
  118. else:
  119.  
  120. isMainPlayerPrivateShop = FALSE
  121.  
  122. self.btnBuy.Show()
  123. self.btnSell.Show()
  124. self.btnClose.Hide()
  125.  
  126. shop.Open(isPrivateShop, isMainPlayerPrivateShop)
  127. self.Refresh()
  128. self.SetTop()
  129. self.Show()
  130.  
  131. (self.xShopStart, self.yShopStart, z) = player.GetMainCharacterPosition()
  132.  
  133. def Close(self):
  134. self.OnCloseQuestionDialog()
  135. shop.Close()
  136. net.SendShopEndPacket()
  137. self.CancelShopping()
  138. self.tooltipItem.HideToolTip()
  139. self.Hide()
  140.  
  141. def AskClosePrivateShop(self):
  142. questionDialog = uiCommon.QuestionDialog()
  143. questionDialog.SetText(localeInfo.PRIVATE_SHOP_CLOSE_QUESTION)
  144. questionDialog.SetAcceptEvent(ui.__mem_func__(self.OnClosePrivateShop))
  145. questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  146. questionDialog.Open()
  147. self.questionDialog = questionDialog
  148.  
  149. return TRUE
  150.  
  151. def OnClosePrivateShop(self):
  152. net.SendChatPacket("/close_shop")
  153. self.OnCloseQuestionDialog()
  154. return TRUE
  155.  
  156. def OnPressEscapeKey(self):
  157. self.Close()
  158. return TRUE
  159.  
  160. def OnPressExitKey(self):
  161. self.Close()
  162. return TRUE
  163.  
  164. def OnBuy(self):
  165. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_BUY_INFO)
  166. app.SetCursor(app.BUY)
  167. self.btnSell.SetUp()
  168.  
  169. def OnSell(self):
  170. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  171. app.SetCursor(app.SELL)
  172. self.btnBuy.SetUp()
  173.  
  174. def CancelShopping(self):
  175. self.btnBuy.SetUp()
  176. self.btnSell.SetUp()
  177. app.SetCursor(app.NORMAL)
  178.  
  179. def __OnClosePopupDialog(self):
  180. self.pop = None
  181.  
  182. def SellAttachedItem(self):
  183.  
  184. if shop.IsPrivateShop():
  185. mouseModule.mouseController.DeattachObject()
  186. return
  187.  
  188. attachedSlotType = mouseModule.mouseController.GetAttachedType()
  189. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  190. attachedCount = mouseModule.mouseController.GetAttachedItemCount()
  191. if player.SLOT_TYPE_INVENTORY == attachedSlotType:
  192.  
  193. itemIndex = player.GetItemIndex(attachedSlotPos)
  194. item.SelectItem(itemIndex)
  195.  
  196. if item.IsAntiFlag(item.ANTIFLAG_SELL):
  197. popup = uiCommon.PopupDialog()
  198. popup.SetText(localeInfo.SHOP_CANNOT_SELL_ITEM)
  199. popup.SetAcceptEvent(self.__OnClosePopupDialog)
  200. popup.Open()
  201. self.popup = popup
  202.  
  203. elif player.IsValuableItem(attachedSlotPos):
  204.  
  205. itemPrice = item.GetISellItemPrice()
  206.  
  207. if item.Is1GoldItem():
  208. itemPrice = attachedCount / itemPrice / 1
  209. else:
  210. itemPrice = itemPrice * max(1, attachedCount) / 1
  211.  
  212. itemName = item.GetItemName()
  213.  
  214. questionDialog = uiCommon.QuestionDialog()
  215. questionDialog.SetText(localeInfo.DO_YOU_SELL_ITEM(itemName, attachedCount, itemPrice))
  216.  
  217. questionDialog.SetAcceptEvent(lambda arg1=attachedSlotPos, arg2=attachedCount: self.OnSellItem(arg1, arg2))
  218. questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  219. questionDialog.Open()
  220. self.questionDialog = questionDialog
  221.  
  222. else:
  223. self.OnSellItem(attachedSlotPos, attachedCount)
  224.  
  225. else:
  226. snd.PlaySound("sound/ui/loginfail.wav")
  227.  
  228. mouseModule.mouseController.DeattachObject()
  229.  
  230. def OnSellItem(self, slotPos, count):
  231. net.SendShopSellPacketNew(slotPos, count)
  232. snd.PlaySound("sound/ui/money.wav")
  233. self.OnCloseQuestionDialog()
  234.  
  235. def OnCloseQuestionDialog(self):
  236. if self.questionDialog:
  237. self.questionDialog.Close()
  238.  
  239. self.questionDialog = None
  240.  
  241. def SelectEmptySlot(self, selectedSlotPos):
  242.  
  243. isAttached = mouseModule.mouseController.isAttached()
  244. if isAttached:
  245. self.SellAttachedItem()
  246.  
  247. def UnselectItemSlot(self, selectedSlotPos):
  248. if shop.IsPrivateShop():
  249. self.AskBuyItem(selectedSlotPos)
  250. else:
  251. net.SendShopBuyPacket(selectedSlotPos)
  252.  
  253. def SelectItemSlot(self, selectedSlotPos):
  254.  
  255. isAttached = mouseModule.mouseController.isAttached()
  256. if isAttached:
  257. self.SellAttachedItem()
  258.  
  259. else:
  260.  
  261. if TRUE == shop.IsMainPlayerPrivateShop():
  262. return
  263.  
  264. curCursorNum = app.GetCursor()
  265. if app.BUY == curCursorNum:
  266. self.AskBuyItem(selectedSlotPos)
  267.  
  268. elif app.SELL == curCursorNum:
  269. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  270.  
  271. else:
  272. selectedItemID = shop.GetItemID(selectedSlotPos)
  273. itemCount = shop.GetItemCount(selectedSlotPos)
  274.  
  275. type = player.SLOT_TYPE_SHOP
  276. if shop.IsPrivateShop():
  277. type = player.SLOT_TYPE_PRIVATE_SHOP
  278.  
  279. mouseModule.mouseController.AttachObject(self, type, selectedSlotPos, selectedItemID, itemCount)
  280. mouseModule.mouseController.SetCallBack("INVENTORY", ui.__mem_func__(self.DropToInventory))
  281. snd.PlaySound("sound/ui/pick.wav")
  282.  
  283. def DropToInventory(self):
  284. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  285. self.AskBuyItem(attachedSlotPos)
  286.  
  287. def AskBuyItem(self, slotPos):
  288. itemIndex = shop.GetItemID(slotPos)
  289. itemPrice = shop.GetItemPrice(slotPos)
  290. itemCount = shop.GetItemCount(slotPos)
  291.  
  292. item.SelectItem(itemIndex)
  293. itemName = item.GetItemName()
  294.  
  295. itemBuyQuestionDialog = uiCommon.QuestionDialog()
  296. itemBuyQuestionDialog.SetText(localeInfo.DO_YOU_BUY_ITEM(itemName, itemCount, localeInfo.NumberToMoneyString(itemPrice)))
  297. itemBuyQuestionDialog.SetAcceptEvent(lambda arg=TRUE: self.AnswerBuyItem(arg))
  298. itemBuyQuestionDialog.SetCancelEvent(lambda arg=FALSE: self.AnswerBuyItem(arg))
  299. itemBuyQuestionDialog.Open()
  300. itemBuyQuestionDialog.pos = slotPos
  301. self.itemBuyQuestionDialog = itemBuyQuestionDialog
  302.  
  303. def AnswerBuyItem(self, flag):
  304.  
  305. if flag:
  306. pos = self.itemBuyQuestionDialog.pos
  307. net.SendShopBuyPacket(pos)
  308.  
  309. self.itemBuyQuestionDialog.Close()
  310. self.itemBuyQuestionDialog = None
  311.  
  312. def SetItemToolTip(self, tooltipItem):
  313. self.tooltipItem = tooltipItem
  314.  
  315. def OverInItem(self, slotIndex):
  316. if mouseModule.mouseController.isAttached():
  317. return
  318.  
  319. if 0 != self.tooltipItem:
  320. self.tooltipItem.SetShopItem(slotIndex)
  321.  
  322. def OverOutItem(self):
  323. if 0 != self.tooltipItem:
  324. self.tooltipItem.HideToolTip()
  325.  
  326. def OnUpdate(self):
  327.  
  328. USE_SHOP_LIMIT_RANGE = 1000
  329.  
  330. (x, y, z) = player.GetMainCharacterPosition()
  331. if abs(x - self.xShopStart) > USE_SHOP_LIMIT_RANGE or abs(y - self.yShopStart) > USE_SHOP_LIMIT_RANGE:
  332. self.Close()
  333.  
  334.  
  335. class MallPageDialog(ui.ScriptWindow):
  336. def __init__(self):
  337. ui.ScriptWindow.__init__(self)
  338.  
  339. def __del__(self):
  340. ui.ScriptWindow.__del__(self)
  341.  
  342. def Destroy(self):
  343. self.ClearDictionary()
  344.  
  345. def Open(self):
  346. scriptLoader = ui.PythonScriptLoader()
  347. scriptLoader.LoadScriptFile(self, "uiscript/mallpagedialog.py")
  348.  
  349. self.GetChild("titlebar").SetCloseEvent(ui.__mem_func__(self.Close))
  350.  
  351. (x, y)=self.GetGlobalPosition()
  352. x+=10
  353. y+=30
  354.  
  355. MALL_PAGE_WIDTH = 600
  356. MALL_PAGE_HEIGHT = 480
  357.  
  358. app.ShowWebPage(
  359. "http://metin2.co.kr/08_mall/game_mall/login_fail.htm",
  360. (x, y, x+MALL_PAGE_WIDTH, y+MALL_PAGE_HEIGHT))
  361.  
  362. self.Lock()
  363. self.Show()
  364.  
  365. def Close(self):
  366. app.HideWebPage()
  367. self.Unlock()
  368. self.Hide()
  369.  
  370. def OnPressEscapeKey(self):
  371. self.Close()
  372. return TRUE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement