ZorkeOfficial

uishop.py

Jan 15th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.13 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.         if self.itemBuyQuestionDialog:
  135.             self.itemBuyQuestionDialog.Close()
  136.             self.itemBuyQuestionDialog = None      
  137.             constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(0)
  138.         if self.questionDialog:
  139.             self.OnCloseQuestionDialog()
  140.         shop.Close()
  141.         net.SendShopEndPacket()
  142.         self.CancelShopping()
  143.         self.tooltipItem.HideToolTip()
  144.         self.Hide()
  145.  
  146.     def AskClosePrivateShop(self):
  147.         questionDialog = uiCommon.QuestionDialog()
  148.         questionDialog.SetText(localeInfo.PRIVATE_SHOP_CLOSE_QUESTION)
  149.         questionDialog.SetAcceptEvent(ui.__mem_func__(self.OnClosePrivateShop))
  150.         questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  151.         questionDialog.Open()
  152.         self.questionDialog = questionDialog
  153.  
  154.         return TRUE
  155.  
  156.     def OnClosePrivateShop(self):
  157.         net.SendChatPacket("/close_shop")
  158.         self.OnCloseQuestionDialog()
  159.         return TRUE
  160.  
  161.     def OnPressEscapeKey(self):
  162.         self.Close()
  163.         return TRUE
  164.  
  165.     def OnPressExitKey(self):
  166.         self.Close()
  167.         return TRUE
  168.  
  169.     def OnBuy(self):
  170.         chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_BUY_INFO)
  171.         app.SetCursor(app.BUY)
  172.         self.btnSell.SetUp()
  173.  
  174.     def OnSell(self):
  175.         chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  176.         app.SetCursor(app.SELL)
  177.         self.btnBuy.SetUp()
  178.  
  179.     def CancelShopping(self):
  180.         self.btnBuy.SetUp()
  181.         self.btnSell.SetUp()
  182.         app.SetCursor(app.NORMAL)
  183.  
  184.     def __OnClosePopupDialog(self):
  185.         self.pop = None
  186.  
  187.     def SellAttachedItem(self):
  188.  
  189.         if shop.IsPrivateShop():
  190.             mouseModule.mouseController.DeattachObject()
  191.             return
  192.  
  193.         attachedSlotType = mouseModule.mouseController.GetAttachedType()
  194.         attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  195.         attachedCount = mouseModule.mouseController.GetAttachedItemCount()
  196.         if player.SLOT_TYPE_INVENTORY == attachedSlotType:
  197.  
  198.             itemIndex = player.GetItemIndex(attachedSlotPos)
  199.             item.SelectItem(itemIndex)
  200.  
  201.             if item.IsAntiFlag(item.ANTIFLAG_SELL):
  202.                 popup = uiCommon.PopupDialog()
  203.                 popup.SetText(localeInfo.SHOP_CANNOT_SELL_ITEM)
  204.                 popup.SetAcceptEvent(self.__OnClosePopupDialog)
  205.                 popup.Open()
  206.                 self.popup = popup
  207.  
  208.             elif player.IsValuableItem(attachedSlotPos):
  209.  
  210.                 itemPrice = item.GetISellItemPrice()
  211.  
  212.                 if item.Is1GoldItem():
  213.                     itemPrice = attachedCount / itemPrice / 5
  214.                 else:
  215.                     itemPrice = itemPrice * max(1, attachedCount) / 5
  216.  
  217.                 itemName = item.GetItemName()
  218.  
  219.                 questionDialog = uiCommon.QuestionDialog()
  220.                 questionDialog.SetText(localeInfo.DO_YOU_SELL_ITEM(itemName, attachedCount, itemPrice))
  221.  
  222.                 questionDialog.SetAcceptEvent(lambda arg1=attachedSlotPos, arg2=attachedCount: self.OnSellItem(arg1, arg2))
  223.                 questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  224.                 questionDialog.Open()
  225.                 self.questionDialog = questionDialog
  226.  
  227.             else:
  228.                 self.OnSellItem(attachedSlotPos, attachedCount)
  229.  
  230.         else:
  231.             snd.PlaySound("sound/ui/loginfail.wav")
  232.  
  233.         mouseModule.mouseController.DeattachObject()
  234.  
  235.     def OnSellItem(self, slotPos, count):
  236.         net.SendShopSellPacketNew(slotPos, count)
  237.         snd.PlaySound("sound/ui/money.wav")
  238.         self.OnCloseQuestionDialog()
  239.  
  240.     def OnCloseQuestionDialog(self):
  241.         if self.questionDialog:
  242.             self.questionDialog.Close()
  243.  
  244.         self.questionDialog = None
  245.  
  246.     def SelectEmptySlot(self, selectedSlotPos):
  247.  
  248.         isAttached = mouseModule.mouseController.isAttached()
  249.         if isAttached:
  250.             self.SellAttachedItem()
  251.  
  252.     def UnselectItemSlot(self, selectedSlotPos):
  253.         if shop.IsPrivateShop():
  254.             self.AskBuyItem(selectedSlotPos)
  255.         else:
  256.             net.SendShopBuyPacket(selectedSlotPos)
  257.  
  258.     def SelectItemSlot(self, selectedSlotPos):
  259.  
  260.         isAttached = mouseModule.mouseController.isAttached()
  261.         if isAttached:
  262.             self.SellAttachedItem()
  263.  
  264.         else:
  265.  
  266.             if TRUE == shop.IsMainPlayerPrivateShop():
  267.                 return
  268.  
  269.             curCursorNum = app.GetCursor()
  270.             if app.BUY == curCursorNum:
  271.                 self.AskBuyItem(selectedSlotPos)
  272.  
  273.             elif app.SELL == curCursorNum:
  274.                 chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SHOP_SELL_INFO)
  275.  
  276.             else:
  277.                 selectedItemID = shop.GetItemID(selectedSlotPos)
  278.                 itemCount = shop.GetItemCount(selectedSlotPos)
  279.  
  280.                 type = player.SLOT_TYPE_SHOP
  281.                 if shop.IsPrivateShop():
  282.                     type = player.SLOT_TYPE_PRIVATE_SHOP
  283.  
  284.                 mouseModule.mouseController.AttachObject(self, type, selectedSlotPos, selectedItemID, itemCount)
  285.                 mouseModule.mouseController.SetCallBack("INVENTORY", ui.__mem_func__(self.DropToInventory))
  286.                 snd.PlaySound("sound/ui/pick.wav")
  287.  
  288.     def DropToInventory(self):
  289.         attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  290.         self.AskBuyItem(attachedSlotPos)
  291.  
  292.     def AskBuyItem(self, slotPos):
  293.         itemIndex = shop.GetItemID(slotPos)
  294.         itemPrice = shop.GetItemPrice(slotPos)
  295.         itemCount = shop.GetItemCount(slotPos)
  296.  
  297.         item.SelectItem(itemIndex)
  298.         itemName = item.GetItemName()
  299.  
  300.         itemBuyQuestionDialog = uiCommon.QuestionDialog()
  301.         itemBuyQuestionDialog.SetText(localeInfo.DO_YOU_BUY_ITEM(itemName, itemCount, localeInfo.NumberToMoneyString(itemPrice)))
  302.         itemBuyQuestionDialog.SetAcceptEvent(lambda arg=TRUE: self.AnswerBuyItem(arg))
  303.         itemBuyQuestionDialog.SetCancelEvent(lambda arg=FALSE: self.AnswerBuyItem(arg))
  304.         itemBuyQuestionDialog.Open()
  305.         itemBuyQuestionDialog.pos = slotPos
  306.         self.itemBuyQuestionDialog = itemBuyQuestionDialog
  307.  
  308.     def AnswerBuyItem(self, flag):
  309.  
  310.         if flag:
  311.             pos = self.itemBuyQuestionDialog.pos
  312.             net.SendShopBuyPacket(pos)
  313.  
  314.         self.itemBuyQuestionDialog.Close()
  315.         self.itemBuyQuestionDialog = None
  316.  
  317.     def SetItemToolTip(self, tooltipItem):
  318.         self.tooltipItem = tooltipItem
  319.  
  320.     def OverInItem(self, slotIndex):
  321.         if mouseModule.mouseController.isAttached():
  322.             return
  323.  
  324.         if 0 != self.tooltipItem:
  325.             self.tooltipItem.SetShopItem(slotIndex)
  326.  
  327.     def OverOutItem(self):
  328.         if 0 != self.tooltipItem:
  329.             self.tooltipItem.HideToolTip()
  330.  
  331.     def OnUpdate(self):
  332.  
  333.         USE_SHOP_LIMIT_RANGE = 1000
  334.  
  335.         (x, y, z) = player.GetMainCharacterPosition()
  336.         if abs(x - self.xShopStart) > USE_SHOP_LIMIT_RANGE or abs(y - self.yShopStart) > USE_SHOP_LIMIT_RANGE:
  337.             self.Close()
  338.  
  339.  
  340. class MallPageDialog(ui.ScriptWindow):
  341.     def __init__(self):
  342.         ui.ScriptWindow.__init__(self)
  343.  
  344.     def __del__(self):
  345.         ui.ScriptWindow.__del__(self)
  346.  
  347.     def Destroy(self):
  348.         self.ClearDictionary()
  349.  
  350.     def Open(self):
  351.         scriptLoader = ui.PythonScriptLoader()
  352.         scriptLoader.LoadScriptFile(self, "uiscript/mallpagedialog.py")
  353.  
  354.         self.GetChild("titlebar").SetCloseEvent(ui.__mem_func__(self.Close))
  355.        
  356.         (x, y)=self.GetGlobalPosition()
  357.         x+=10
  358.         y+=30
  359.        
  360.         MALL_PAGE_WIDTH = 600
  361.         MALL_PAGE_HEIGHT = 480
  362.        
  363.         app.ShowWebPage(
  364.             "http://metin2.co.kr/08_mall/game_mall/login_fail.htm",
  365.             (x, y, x+MALL_PAGE_WIDTH, y+MALL_PAGE_HEIGHT))
  366.  
  367.         self.Lock()
  368.         self.Show()
  369.        
  370.     def Close(self):           
  371.         app.HideWebPage()
  372.         self.Unlock()
  373.         self.Hide()
  374.        
  375.     def OnPressEscapeKey(self):
  376.         self.Close()
  377.         return TRUE
Advertisement
Add Comment
Please, Sign In to add comment