Guest User

uishop..py

a guest
Nov 4th, 2024
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.95 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. import constInfo
  16.  
  17. ###################################################################################################
  18. ## Shop
  19. class ShopDialog(ui.ScriptWindow):
  20.  
  21. def __init__(self):
  22. ui.ScriptWindow.__init__(self)
  23. self.tooltipItem = 0
  24. self.xShopStart = 0
  25. self.yShopStart = 0
  26. self.questionDialog = None
  27. self.popup = None
  28. self.itemBuyQuestionDialog = None
  29.  
  30. def __del__(self):
  31. ui.ScriptWindow.__del__(self)
  32.  
  33. def __GetRealIndex(self, i):
  34. return self.tabIdx * shop.SHOP_SLOT_COUNT + i
  35.  
  36. def Refresh(self):
  37. getItemID=shop.GetItemID
  38. getItemCount=shop.GetItemCount
  39. setItemID=self.itemSlotWindow.SetItemSlot
  40. for i in xrange(shop.SHOP_SLOT_COUNT):
  41. idx = self.__GetRealIndex(i)
  42. itemCount = getItemCount(idx)
  43. if itemCount <= 1:
  44. itemCount = 0
  45. setItemID(i, getItemID(idx), itemCount)
  46.  
  47. wndMgr.RefreshSlot(self.itemSlotWindow.GetWindowHandle())
  48.  
  49. def SetItemData(self, pos, itemID, itemCount, itemPrice):
  50. shop.SetItemData(pos, itemID, itemCount, itemPrice)
  51.  
  52. def LoadDialog(self):
  53. try:
  54. PythonScriptLoader = ui.PythonScriptLoader()
  55. PythonScriptLoader.LoadScriptFile(self, "UIScript/shopdialog.py")
  56. except:
  57. import exception
  58. exception.Abort("ShopDialog.LoadDialog.LoadObject")
  59.  
  60.  
  61. try:
  62. GetObject = self.GetChild
  63. self.itemSlotWindow = GetObject("ItemSlot")
  64. self.btnBuy = GetObject("BuyButton")
  65. self.btnSell = GetObject("SellButton")
  66. self.btnClose = GetObject("CloseButton")
  67. self.titleBar = GetObject("TitleBar")
  68. except:
  69. import exception
  70. exception.Abort("ShopDialog.LoadDialog.BindObject")
  71.  
  72. self.itemSlotWindow.SetSlotStyle(wndMgr.SLOT_STYLE_NONE)
  73. self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EMPTY", self.SelectEmptySlot)
  74. self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EXIST", self.SelectItemSlot)
  75. self.itemSlotWindow.SAFE_SetButtonEvent("RIGHT", "EXIST", self.UnselectItemSlot)
  76.  
  77. self.itemSlotWindow.SetOverInItemEvent(ui.__mem_func__(self.OverInItem))
  78. self.itemSlotWindow.SetOverOutItemEvent(ui.__mem_func__(self.OverOutItem))
  79.  
  80. self.btnBuy.SetToggleUpEvent(ui.__mem_func__(self.CancelShopping))
  81. self.btnBuy.SetToggleDownEvent(ui.__mem_func__(self.OnBuy))
  82.  
  83. self.btnSell.SetToggleUpEvent(ui.__mem_func__(self.CancelShopping))
  84. self.btnSell.SetToggleDownEvent(ui.__mem_func__(self.OnSell))
  85.  
  86. self.btnClose.SetEvent(ui.__mem_func__(self.AskClosePrivateShop))
  87.  
  88. self.titleBar.SetCloseEvent(ui.__mem_func__(self.Close))
  89.  
  90. self.tabIdx = 0
  91. self.coinType = shop.SHOP_COIN_TYPE_GOLD
  92.  
  93. self.Refresh()
  94.  
  95. def __ShowBuySellButton(self):
  96. self.btnBuy.Show()
  97. self.btnSell.Show()
  98.  
  99.  
  100. def __HideBuySellButton(self):
  101. self.btnBuy.Hide()
  102. self.btnSell.Hide()
  103.  
  104. def Destroy(self):
  105. self.Close()
  106. self.ClearDictionary()
  107.  
  108. self.tooltipItem = 0
  109. self.itemSlotWindow = 0
  110. self.btnBuy = 0
  111. self.btnSell = 0
  112. self.btnClose = 0
  113. self.titleBar = 0
  114. self.questionDialog = None
  115. self.popup = None
  116. def Open(self, vid, type=0):
  117. self.vid=int(vid)
  118. isPrivateShop = False
  119. isMainPlayerPrivateShop = False
  120. myshop=False
  121. for i in xrange(len(constInfo.MyShops)):
  122. if int(constInfo.MyShops[i]["vid"]) == int(self.vid):
  123. myshop=True
  124. self.vid=int(constInfo.MyShops[i]["id"])
  125. chr.SelectInstance(self.vid)
  126. if chr.GetRace() == 30000 or not chr.IsNPC(self.vid):
  127. isPrivateShop = True
  128. if player.IsMainCharacterIndex(self.vid):
  129. myshop=True
  130. self.vid=""
  131. if myshop == True:
  132. isMainPlayerPrivateShop = True
  133.  
  134. self.btnBuy.Hide()
  135. self.btnSell.Hide()
  136. self.btnClose.Show()
  137.  
  138. else:
  139.  
  140. isMainPlayerPrivateShop = False
  141.  
  142. self.btnBuy.Show()
  143. self.btnSell.Show()
  144. self.btnClose.Hide()
  145. shop.Open(isPrivateShop, isMainPlayerPrivateShop)
  146.  
  147. def Open(self, vid):
  148.  
  149. isPrivateShop = False
  150. isMainPlayerPrivateShop = False
  151.  
  152. import chr
  153. if chr.IsNPC(vid):
  154. isPrivateShop = False
  155. else:
  156. isPrivateShop = True
  157.  
  158. if player.IsMainCharacterIndex(vid):
  159.  
  160. isMainPlayerPrivateShop = True
  161.  
  162. self.btnBuy.Hide()
  163. self.btnSell.Hide()
  164. self.btnClose.Show()
  165.  
  166. else:
  167.  
  168. isMainPlayerPrivateShop = False
  169. self.btnBuy.Show()
  170. self.btnSell.Show()
  171. self.btnClose.Hide()
  172.  
  173. shop.Open(isPrivateShop, isMainPlayerPrivateShop)
  174.  
  175. self.tabIdx = 0
  176.  
  177. if isPrivateShop:
  178. self.__HideMiddleTabs()
  179. else:
  180. if shop.GetTabCount() == 1:
  181. self.__ShowBuySellButton()
  182. elif shop.GetTabCount() == 2:
  183. self.__HideBuySellButton()
  184. self.__ShowMiddleTabs()
  185. self.__SetTabNames()
  186. self.middleRadioButtonGroup.OnClick(0)
  187. elif shop.GetTabCount() == 3:
  188. self.__HideBuySellButton()
  189. self.__HideMiddleTabs()
  190. self.__ShowSmallTabs()
  191. self.__SetTabNames()
  192. self.smallRadioButtonGroup.OnClick(0)
  193.  
  194. self.Refresh()
  195. self.SetTop()
  196.  
  197. self.Show()
  198.  
  199. (self.xShopStart, self.yShopStart, z) = player.GetMainCharacterPosition()
  200.  
  201. def Close(self):
  202. if self.itemBuyQuestionDialog:
  203. self.itemBuyQuestionDialog.Close()
  204. self.itemBuyQuestionDialog = None
  205. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(0)
  206. if self.questionDialog:
  207. self.OnCloseQuestionDialog()
  208. shop.Close()
  209. net.SendShopEndPacket()
  210. self.CancelShopping()
  211. self.tooltipItem.HideToolTip()
  212. self.Hide()
  213.  
  214. def GetIndexFromSlotPos(self, slotPos):
  215. return self.tabIdx * shop.SHOP_SLOT_COUNT + slotPos
  216.  
  217. def OnClickTabButton(self, idx):
  218. self.tabIdx = idx
  219. self.Refresh()
  220.  
  221. def AskClosePrivateShop(self):
  222. questionDialog = uiCommon.QuestionDialog()
  223. questionDialog.SetText(localeInfo.PRIVATE_SHOP_CLOSE_QUESTION)
  224. questionDialog.SetAcceptEvent(ui.__mem_func__(self.OnClosePrivateShop))
  225. questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  226. questionDialog.Open()
  227. self.questionDialog = questionDialog
  228.  
  229. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(1)
  230.  
  231.  
  232.  
  233. def OnClosePrivateShop(self):
  234. net.SendChatPacket("/close_shop "+str(self.vid))
  235. self.OnCloseQuestionDialog()
  236. return True
  237.  
  238. def OnClosePrivateShop(self):
  239. net.SendChatPacket("/close_shop")
  240. self.OnCloseQuestionDialog()
  241. return True
  242.  
  243. def OnPressEscapeKey(self):
  244. self.Close()
  245. return True
  246.  
  247. def OnPressExitKey(self):
  248. self.Close()
  249. return True
  250.  
  251. def OnBuy(self):
  252. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_BUY_INFO)
  253. app.SetCursor(app.BUY)
  254. self.btnSell.SetUp()
  255.  
  256. def OnSell(self):
  257. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  258. app.SetCursor(app.SELL)
  259. self.btnBuy.SetUp()
  260.  
  261. def CancelShopping(self):
  262. self.btnBuy.SetUp()
  263. self.btnSell.SetUp()
  264. app.SetCursor(app.NORMAL)
  265.  
  266. def __OnClosePopupDialog(self):
  267. self.pop = None
  268. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(0)
  269.  
  270. ## ��ȥ�� �ȸ��� ��� �߰�.
  271. def SellAttachedItem(self):
  272.  
  273. if shop.IsPrivateShop():
  274. mouseModule.mouseController.DeattachObject()
  275. return
  276.  
  277. attachedSlotType = mouseModule.mouseController.GetAttachedType()
  278. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  279. attachedCount = mouseModule.mouseController.GetAttachedItemCount()
  280. attachedItemIndex = mouseModule.mouseController.GetAttachedItemIndex()
  281. if player.SLOT_TYPE_INVENTORY == attachedSlotType or player.SLOT_TYPE_SKILL_BOOK_INVENTORY == attachedSlotType or player.SLOT_TYPE_UPGRADE_ITEMS_INVENTORY == attachedSlotType or player.SLOT_TYPE_BOX_INVENTORY == attachedSlotType or player.SLOT_TYPE_EFSUN_INVENTORY == attachedSlotType == attachedSlotType or player.SLOT_TYPE_CICEK_INVENTORY == attachedSlotType:
  282.  
  283. item.SelectItem(attachedItemIndex)
  284.  
  285. if item.IsAntiFlag(item.ANTIFLAG_SELL):
  286. mouseModule.mouseController.DeattachObject()
  287.  
  288. popup = uiCommon.PopupDialog()
  289. popup.SetText(localeInfo.SHOP_CANNOT_SELL_ITEM)
  290. popup.SetAcceptEvent(self.__OnClosePopupDialog)
  291. popup.Open()
  292. self.popup = popup
  293. return
  294.  
  295. itemtype = player.INVENTORY
  296.  
  297. if player.SLOT_TYPE_DRAGON_SOUL_INVENTORY == attachedSlotType:
  298. itemtype = player.DRAGON_SOUL_INVENTORY
  299.  
  300. if player.IsValuableItem(itemtype, attachedSlotPos):
  301.  
  302. itemPrice = item.GetISellItemPrice()
  303.  
  304. if item.Is1GoldItem():
  305. itemPrice = attachedCount / itemPrice / 5
  306. else:
  307. itemPrice = itemPrice * max(1, attachedCount) / 5
  308.  
  309. itemName = item.GetItemName()
  310.  
  311. questionDialog = uiCommon.QuestionDialog()
  312. questionDialog.SetText(localeInfo.DO_YOU_SELL_ITEM(itemName, attachedCount, itemPrice))
  313.  
  314. questionDialog.SetAcceptEvent(lambda arg1=attachedSlotPos, arg2=attachedCount, arg3 = itemtype: self.OnSellItem(arg1, arg2, arg3))
  315. questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  316. questionDialog.Open()
  317. self.questionDialog = questionDialog
  318.  
  319. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(1)
  320.  
  321. else:
  322. self.OnSellItem(attachedSlotPos, attachedCount, itemtype)
  323.  
  324. else:
  325. snd.PlaySound("sound/ui/loginfail.wav")
  326.  
  327. mouseModule.mouseController.DeattachObject()
  328.  
  329. def OnSellItem(self, slotPos, count, itemtype):
  330. net.SendShopSellPacketNew(slotPos, count, itemtype)
  331. snd.PlaySound("sound/ui/money.wav")
  332. self.OnCloseQuestionDialog()
  333.  
  334. def OnCloseQuestionDialog(self):
  335. if not self.questionDialog:
  336. return
  337.  
  338. self.questionDialog.Close()
  339. self.questionDialog = None
  340. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(0)
  341.  
  342. def SelectEmptySlot(self, selectedSlotPos):
  343.  
  344. isAttached = mouseModule.mouseController.isAttached()
  345. if isAttached:
  346. self.SellAttachedItem()
  347.  
  348. def UnselectItemSlot(self, selectedSlotPos):
  349. if constInfo.GET_ITEM_QUESTION_DIALOG_STATUS() == 1:
  350. return
  351. if shop.IsPrivateShop():
  352. self.AskBuyItem(selectedSlotPos)
  353. else:
  354. net.SendShopBuyPacket(self.__GetRealIndex(selectedSlotPos))
  355.  
  356. def SelectItemSlot(self, selectedSlotPos):
  357. if constInfo.GET_ITEM_QUESTION_DIALOG_STATUS() == 1:
  358. return
  359.  
  360. isAttached = mouseModule.mouseController.isAttached()
  361. selectedSlotPos = self.__GetRealIndex(selectedSlotPos)
  362. if isAttached:
  363. self.SellAttachedItem()
  364.  
  365. else:
  366.  
  367. if True == shop.IsMainPlayerPrivateShop():
  368. return
  369.  
  370. curCursorNum = app.GetCursor()
  371. if app.BUY == curCursorNum:
  372. self.AskBuyItem(selectedSlotPos)
  373.  
  374. elif app.SELL == curCursorNum:
  375. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  376.  
  377. else:
  378. selectedItemID = shop.GetItemID(selectedSlotPos)
  379. itemCount = shop.GetItemCount(selectedSlotPos)
  380.  
  381. type = player.SLOT_TYPE_SHOP
  382. if shop.IsPrivateShop():
  383. type = player.SLOT_TYPE_PRIVATE_SHOP
  384.  
  385. mouseModule.mouseController.AttachObject(self, type, selectedSlotPos, selectedItemID, itemCount)
  386. mouseModule.mouseController.SetCallBack("INVENTORY", ui.__mem_func__(self.DropToInventory))
  387. snd.PlaySound("sound/ui/pick.wav")
  388.  
  389. def DropToInventory(self):
  390. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  391. self.AskBuyItem(attachedSlotPos)
  392.  
  393. def AskBuyItem(self, slotPos):
  394. slotPos = self.__GetRealIndex(slotPos)
  395.  
  396. itemIndex = shop.GetItemID(slotPos)
  397. itemPrice = shop.GetItemPrice(slotPos)
  398. itemCount = shop.GetItemCount(slotPos)
  399.  
  400. item.SelectItem(itemIndex)
  401. itemName = item.GetItemName()
  402.  
  403. itemBuyQuestionDialog = uiCommon.QuestionDialog()
  404. itemBuyQuestionDialog.SetText(localeInfo.DO_YOU_BUY_ITEM(itemName, itemCount, localeInfo.NumberToMoneyString(itemPrice)))
  405. itemBuyQuestionDialog.SetAcceptEvent(lambda arg=True: self.AnswerBuyItem(arg))
  406. itemBuyQuestionDialog.SetCancelEvent(lambda arg=False: self.AnswerBuyItem(arg))
  407. itemBuyQuestionDialog.Open()
  408. itemBuyQuestionDialog.pos = slotPos
  409. self.itemBuyQuestionDialog = itemBuyQuestionDialog
  410.  
  411. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(1)
  412.  
  413. def AnswerBuyItem(self, flag):
  414.  
  415. if flag:
  416. pos = self.itemBuyQuestionDialog.pos
  417. net.SendShopBuyPacket(pos)
  418.  
  419. self.itemBuyQuestionDialog.Close()
  420. self.itemBuyQuestionDialog = None
  421.  
  422. constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(0)
  423.  
  424. def SetItemToolTip(self, tooltipItem):
  425. self.tooltipItem = tooltipItem
  426.  
  427. def OverInItem(self, slotIndex):
  428. slotIndex = self.__GetRealIndex(slotIndex)
  429. if mouseModule.mouseController.isAttached():
  430. return
  431.  
  432. if 0 != self.tooltipItem:
  433. if shop.SHOP_COIN_TYPE_GOLD == shop.GetTabCoinType(self.tabIdx):
  434. self.tooltipItem.SetShopItem(slotIndex)
  435. else:
  436. self.tooltipItem.SetShopItemBySecondaryCoin(slotIndex)
  437. def OverOutItem(self):
  438. if 0 != self.tooltipItem:
  439. self.tooltipItem.HideToolTip()
  440.  
  441. def OnUpdate(self):
  442.  
  443. USE_SHOP_LIMIT_RANGE = 1000
  444.  
  445. (x, y, z) = player.GetMainCharacterPosition()
  446. if abs(x - self.xShopStart) > USE_SHOP_LIMIT_RANGE or abs(y - self.yShopStart) > USE_SHOP_LIMIT_RANGE:
  447. self.Close()
  448.  
  449.  
  450. class MallPageDialog(ui.ScriptWindow):
  451. def __init__(self):
  452. ui.ScriptWindow.__init__(self)
  453.  
  454. def __del__(self):
  455. ui.ScriptWindow.__del__(self)
  456.  
  457. def Destroy(self):
  458. self.ClearDictionary()
  459.  
  460. def Open(self):
  461. scriptLoader = ui.PythonScriptLoader()
  462. scriptLoader.LoadScriptFile(self, "uiscript/mallpagedialog.py")
  463.  
  464. self.GetChild("titlebar").SetCloseEvent(ui.__mem_func__(self.Close))
  465.  
  466. (x, y)=self.GetGlobalPosition()
  467. x+=10
  468. y+=30
  469.  
  470. MALL_PAGE_WIDTH = 600
  471. MALL_PAGE_HEIGHT = 480
  472.  
  473. app.ShowWebPage(
  474. "http://metin2.co.kr/08_mall/game_mall/login_fail.htm",
  475. (x, y, x+MALL_PAGE_WIDTH, y+MALL_PAGE_HEIGHT))
  476.  
  477. self.Lock()
  478. self.Show()
  479.  
  480. def Close(self):
  481. app.HideWebPage()
  482. self.Unlock()
  483. self.Hide()
  484.  
  485. def OnPressEscapeKey(self):
  486. self.Close()
  487. return True
  488.  
  489. class ShopDialog2(ui.ScriptWindow):
  490.  
  491. def __init__(self):
  492. ui.ScriptWindow.__init__(self)
  493. self.tooltipItem = 0
  494. self.xShopStart = 0
  495. self.yShopStart = 0
  496. self.questionDialog = None
  497. self.popup = None
  498. self.itemBuyQuestionDialog = None
  499.  
  500. def __del__(self):
  501. ui.ScriptWindow.__del__(self)
  502.  
  503. def Refresh(self):
  504. getItemID=shop.GetItemID
  505. getItemCount=shop.GetItemCount
  506. setItemID=self.itemSlotWindow.SetItemSlot
  507. for i in xrange(shop.SHOP_SLOT_COUNT):
  508. itemCount = getItemCount(i)
  509. if itemCount <= 1:
  510. itemCount = 0
  511. setItemID(i, getItemID(i), itemCount)
  512.  
  513. wndMgr.RefreshSlot(self.itemSlotWindow.GetWindowHandle())
  514.  
  515. def SetItemData(self, pos, itemID, itemCount, itemPrice):
  516. shop.SetItemData(pos, itemID, itemCount, itemPrice)
  517.  
  518. def LoadDialog(self):
  519. try:
  520. PythonScriptLoader = ui.PythonScriptLoader()
  521. PythonScriptLoader.LoadScriptFile(self, "UIScript/shopdialog2.py")
  522. except:
  523. import exception
  524. exception.Abort("ShopDialog.LoadDialog.LoadObject")
  525.  
  526. try:
  527. GetObject = self.GetChild
  528. self.itemSlotWindow = GetObject("ItemSlot")
  529. self.btnBuy = GetObject("BuyButton")
  530. self.btnSell = GetObject("SellButton")
  531. self.btnClose = GetObject("CloseButton")
  532. self.titleBar = GetObject("TitleBar")
  533. except:
  534. import exception
  535. exception.Abort("ShopDialog.LoadDialog.BindObject")
  536.  
  537. self.itemSlotWindow.SetSlotStyle(wndMgr.SLOT_STYLE_NONE)
  538. self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EMPTY", self.SelectEmptySlot)
  539. self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EXIST", self.SelectItemSlot)
  540. self.itemSlotWindow.SAFE_SetButtonEvent("RIGHT", "EXIST", self.UnselectItemSlot)
  541.  
  542. self.itemSlotWindow.SetOverInItemEvent(ui.__mem_func__(self.OverInItem))
  543. self.itemSlotWindow.SetOverOutItemEvent(ui.__mem_func__(self.OverOutItem))
  544.  
  545. self.btnBuy.SetToggleUpEvent(ui.__mem_func__(self.CancelShopping))
  546. self.btnBuy.SetToggleDownEvent(ui.__mem_func__(self.OnBuy))
  547.  
  548. self.btnSell.SetToggleUpEvent(ui.__mem_func__(self.CancelShopping))
  549. self.btnSell.SetToggleDownEvent(ui.__mem_func__(self.OnSell))
  550.  
  551. self.btnClose.SetEvent(ui.__mem_func__(self.AskClosePrivateShop))
  552.  
  553. self.titleBar.SetCloseEvent(ui.__mem_func__(self.Close))
  554.  
  555. self.Refresh()
  556.  
  557. def Destroy(self):
  558. self.Close()
  559. self.ClearDictionary()
  560.  
  561. self.tooltipItem = 0
  562. self.itemSlotWindow = 0
  563. self.btnBuy = 0
  564. self.btnSell = 0
  565. self.btnClose = 0
  566. self.titleBar = 0
  567. self.questionDialog = None
  568. self.popup = None
  569.  
  570. def Open(self, vid):
  571.  
  572. isPrivateShop = FALSE
  573. isMainPlayerPrivateShop = FALSE
  574.  
  575. import chr
  576. if chr.IsNPC(vid):
  577. isPrivateShop = FALSE
  578. else:
  579. isPrivateShop = TRUE
  580.  
  581. if player.IsMainCharacterIndex(vid):
  582.  
  583. isMainPlayerPrivateShop = TRUE
  584.  
  585. self.btnBuy.Hide()
  586. self.btnSell.Hide()
  587. self.btnClose.Show()
  588.  
  589. else:
  590.  
  591. isMainPlayerPrivateShop = FALSE
  592.  
  593. self.btnBuy.Show()
  594. self.btnSell.Show()
  595. self.btnClose.Hide()
  596.  
  597. shop.Open(isPrivateShop, isMainPlayerPrivateShop)
  598. self.Refresh()
  599. self.SetTop()
  600. self.Show()
  601.  
  602. (self.xShopStart, self.yShopStart, z) = player.GetMainCharacterPosition()
  603.  
  604. def Close(self):
  605. self.OnCloseQuestionDialog()
  606. shop.Close()
  607. net.SendShopEndPacket()
  608. self.CancelShopping()
  609. self.tooltipItem.HideToolTip()
  610. self.Hide()
  611.  
  612. def AskClosePrivateShop(self):
  613. questionDialog = uiCommon.QuestionDialog()
  614. questionDialog.SetText(localeInfo.PRIVATE_SHOP_CLOSE_QUESTION)
  615. questionDialog.SetAcceptEvent(ui.__mem_func__(self.OnClosePrivateShop))
  616. questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  617. questionDialog.Open()
  618. self.questionDialog = questionDialog
  619.  
  620. return TRUE
  621.  
  622. def OnClosePrivateShop(self):
  623. net.SendChatPacket("/close_shop")
  624. self.OnCloseQuestionDialog()
  625. return TRUE
  626.  
  627. def OnPressEscapeKey(self):
  628. self.Close()
  629. return TRUE
  630.  
  631. def OnPressExitKey(self):
  632. self.Close()
  633. return TRUE
  634.  
  635. def OnBuy(self):
  636. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_BUY_INFO)
  637. app.SetCursor(app.BUY)
  638. self.btnSell.SetUp()
  639.  
  640. def OnSell(self):
  641. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  642. app.SetCursor(app.SELL)
  643. self.btnBuy.SetUp()
  644.  
  645. def CancelShopping(self):
  646. self.btnBuy.SetUp()
  647. self.btnSell.SetUp()
  648. app.SetCursor(app.NORMAL)
  649.  
  650. def __OnClosePopupDialog(self):
  651. self.pop = None
  652.  
  653. def SellAttachedItem(self):
  654.  
  655. if shop.IsPrivateShop():
  656. mouseModule.mouseController.DeattachObject()
  657. return
  658.  
  659. attachedSlotType = mouseModule.mouseController.GetAttachedType()
  660. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  661. attachedCount = mouseModule.mouseController.GetAttachedItemCount()
  662. if player.SLOT_TYPE_INVENTORY == attachedSlotType:
  663.  
  664. itemIndex = player.GetItemIndex(attachedSlotPos)
  665. item.SelectItem(itemIndex)
  666.  
  667. if item.IsAntiFlag(item.ANTIFLAG_SELL):
  668. popup = uiCommon.PopupDialog()
  669. popup.SetText(localeInfo.SHOP_CANNOT_SELL_ITEM)
  670. popup.SetAcceptEvent(self.__OnClosePopupDialog)
  671. popup.Open()
  672. self.popup = popup
  673.  
  674. elif player.IsValuableItem(attachedSlotPos):
  675.  
  676. itemPrice = item.GetISellItemPrice()
  677.  
  678. if item.Is1GoldItem():
  679. itemPrice = attachedCount / itemPrice / 5
  680. else:
  681. itemPrice = itemPrice * max(1, attachedCount) / 5
  682.  
  683. itemName = item.GetItemName()
  684.  
  685. questionDialog = uiCommon.QuestionDialog()
  686. questionDialog.SetText(localeInfo.DO_YOU_SELL_ITEM(itemName, attachedCount, itemPrice))
  687.  
  688. questionDialog.SetAcceptEvent(lambda arg1=attachedSlotPos, arg2=attachedCount: self.OnSellItem(arg1, arg2))
  689. questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  690. questionDialog.Open()
  691. self.questionDialog = questionDialog
  692.  
  693. else:
  694. self.OnSellItem(attachedSlotPos, attachedCount)
  695.  
  696. else:
  697. snd.PlaySound("sound/ui/loginfail.wav")
  698.  
  699. mouseModule.mouseController.DeattachObject()
  700.  
  701. def OnSellItem(self, slotPos, count):
  702. net.SendShopSellPacketNew(slotPos, count)
  703. snd.PlaySound("sound/ui/money.wav")
  704. self.OnCloseQuestionDialog()
  705.  
  706. def OnCloseQuestionDialog(self):
  707. if self.questionDialog:
  708. self.questionDialog.Close()
  709.  
  710. self.questionDialog = None
  711.  
  712. def SelectEmptySlot(self, selectedSlotPos):
  713.  
  714. isAttached = mouseModule.mouseController.isAttached()
  715. if isAttached:
  716. self.SellAttachedItem()
  717.  
  718. def UnselectItemSlot(self, selectedSlotPos):
  719. if shop.IsPrivateShop():
  720. self.AskBuyItem(selectedSlotPos)
  721. else:
  722. net.SendShopBuyPacket(selectedSlotPos)
  723.  
  724. def SelectItemSlot(self, selectedSlotPos):
  725.  
  726. isAttached = mouseModule.mouseController.isAttached()
  727. if isAttached:
  728. self.SellAttachedItem()
  729.  
  730. else:
  731.  
  732. if TRUE == shop.IsMainPlayerPrivateShop():
  733. return
  734.  
  735. curCursorNum = app.GetCursor()
  736. if app.BUY == curCursorNum:
  737. self.AskBuyItem(selectedSlotPos)
  738.  
  739. elif app.SELL == curCursorNum:
  740. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  741.  
  742. else:
  743. selectedItemID = shop.GetItemID(selectedSlotPos)
  744. itemCount = shop.GetItemCount(selectedSlotPos)
  745.  
  746. type = player.SLOT_TYPE_SHOP
  747. if shop.IsPrivateShop():
  748. type = player.SLOT_TYPE_PRIVATE_SHOP
  749.  
  750. mouseModule.mouseController.AttachObject(self, type, selectedSlotPos, selectedItemID, itemCount)
  751. mouseModule.mouseController.SetCallBack("INVENTORY", ui.__mem_func__(self.DropToInventory))
  752. snd.PlaySound("sound/ui/pick.wav")
  753.  
  754. def DropToInventory(self):
  755. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  756. self.AskBuyItem(attachedSlotPos)
  757.  
  758. def AskBuyItem(self, slotPos):
  759. itemIndex = shop.GetItemID(slotPos)
  760. itemPrice = shop.GetItemPrice(slotPos)
  761. itemCount = shop.GetItemCount(slotPos)
  762.  
  763. item.SelectItem(itemIndex)
  764. itemName = item.GetItemName()
  765.  
  766. itemBuyQuestionDialog = uiCommon.QuestionDialog()
  767. itemBuyQuestionDialog.SetText(localeInfo.DO_YOU_BUY_ITEM(itemName, itemCount, localeInfo.NumberToMoneyString(itemPrice)))
  768. itemBuyQuestionDialog.SetAcceptEvent(lambda arg=TRUE: self.AnswerBuyItem(arg))
  769. itemBuyQuestionDialog.SetCancelEvent(lambda arg=FALSE: self.AnswerBuyItem(arg))
  770. itemBuyQuestionDialog.Open()
  771. itemBuyQuestionDialog.pos = slotPos
  772. self.itemBuyQuestionDialog = itemBuyQuestionDialog
  773.  
  774. def AnswerBuyItem(self, flag):
  775.  
  776. if flag:
  777. pos = self.itemBuyQuestionDialog.pos
  778. net.SendShopBuyPacket(pos)
  779.  
  780. self.itemBuyQuestionDialog.Close()
  781. self.itemBuyQuestionDialog = None
  782.  
  783. def SetItemToolTip(self, tooltipItem):
  784. self.tooltipItem = tooltipItem
  785.  
  786. def OverInItem(self, slotIndex):
  787. if mouseModule.mouseController.isAttached():
  788. return
  789.  
  790. if 0 != self.tooltipItem:
  791. self.tooltipItem.SetShopItem(slotIndex)
  792.  
  793. def OverOutItem(self):
  794. if 0 != self.tooltipItem:
  795. self.tooltipItem.HideToolTip()
  796.  
  797. def OnUpdate(self):
  798.  
  799. USE_SHOP_LIMIT_RANGE = 1000
  800.  
  801. (x, y, z) = player.GetMainCharacterPosition()
  802. if abs(x - self.xShopStart) > USE_SHOP_LIMIT_RANGE or abs(y - self.yShopStart) > USE_SHOP_LIMIT_RANGE:
  803. self.Close()
  804.  
Advertisement
Add Comment
Please, Sign In to add comment