Guest User

uishop

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