Guest User

Untitled

a guest
Aug 8th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.52 KB | None | 0 0
  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 app
  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.  
  27. def IsPrivateShopItemPriceList():
  28.     global g_itemPriceDict
  29.     if g_itemPriceDict:
  30.         return True
  31.     else:
  32.         return False
  33.  
  34. def IsBuildingPrivateShop():
  35.     global g_isBuildingPrivateShop
  36.     if player.IsOpenPrivateShop() or g_isBuildingPrivateShop:
  37.         return True
  38.     else:
  39.         return False
  40.  
  41. def SetPrivateShopItemPrice(itemVNum, itemPrice):
  42.     global g_itemPriceDict
  43.     g_itemPriceDict[int(itemVNum)]=itemPrice
  44.    
  45. def GetPrivateShopItemPrice(itemVNum):
  46.     try:
  47.         global g_itemPriceDict
  48.         return g_itemPriceDict[itemVNum]
  49.     except KeyError:
  50.         return 0
  51.  
  52. def UpdateADBoard():
  53.     for key in g_privateShopAdvertisementBoardDict.keys():
  54.         g_privateShopAdvertisementBoardDict[key].Show()
  55.  
  56. def DeleteADBoard(vid):
  57.     if not g_privateShopAdvertisementBoardDict.has_key(vid):
  58.         return
  59.  
  60.     del g_privateShopAdvertisementBoardDict[vid]
  61.  
  62. class PrivateShopAdvertisementBoard(ui.ThinBoard):
  63.     def __init__(self):
  64.         ui.ThinBoard.__init__(self, "UI_BOTTOM")
  65.         self.vid = None
  66.         self.__MakeTextLine()
  67.  
  68.         self.shopNameHighlight = []
  69.  
  70.     def __del__(self):
  71.         ui.ThinBoard.__del__(self)
  72.  
  73.     def __MakeTextLine(self):
  74.         self.textLine = ui.TextLine()
  75.         self.textLine.SetParent(self)
  76.         self.textLine.SetWindowHorizontalAlignCenter()
  77.         self.textLine.SetWindowVerticalAlignCenter()
  78.         self.textLine.SetHorizontalAlignCenter()
  79.         self.textLine.SetVerticalAlignCenter()
  80.         self.textLine.Show()
  81.  
  82.     def Open(self, vid, text):
  83.         self.vid = vid
  84.  
  85.         self.textLine.SetText(text)
  86.         if vid in self.shopNameHighlight:
  87.             self.textLine.SetFontColor(1.0, 0.5, 0.1)
  88.         self.textLine.UpdateRect()
  89.         self.SetSize(len(text)*6 + 10*2, 20)
  90.         self.Show()
  91.  
  92.         g_privateShopAdvertisementBoardDict[vid] = self
  93.  
  94.     def OnMouseLeftButtonUp(self):
  95.         if not self.vid:
  96.             return
  97.         net.SendOnClickPacket(self.vid)
  98.        
  99.         if self.vid != player.GetMainCharacterIndex():
  100.             self.textLine.SetFontColor(1.0, 0.5, 0.1)
  101.             self.shopNameHighlight.append(self.vid)
  102.            
  103.         return True
  104.  
  105.     def OnUpdate(self):
  106.         if not self.vid:
  107.             return
  108.  
  109.         if systemSetting.IsShowSalesText():
  110.             self.Show()
  111.             x, y = chr.GetProjectPosition(self.vid, 220)
  112.             self.SetPosition(x - self.GetWidth()/2, y - self.GetHeight()/2)
  113.        
  114.         else:
  115.             for key in g_privateShopAdvertisementBoardDict.keys():
  116.                 if player.GetMainCharacterIndex() == key:  #»óÁˇÇłĽ±Ŕ» ľČş¸ŔĚ°Ô °¨Ăß´Â °ćżěżˇµµ, ÇĂ·ąŔĚľî ŔÚ˝ĹŔÇ »óÁˇ ÇłĽ±Ŕş ş¸Ŕ̵µ·Ď ÇÔ. by ±čÁŘČŁ
  117.                     g_privateShopAdvertisementBoardDict[key].Show()    
  118.                     x, y = chr.GetProjectPosition(player.GetMainCharacterIndex(), 220)
  119.                     g_privateShopAdvertisementBoardDict[key].SetPosition(x - self.GetWidth()/2, y - self.GetHeight()/2)
  120.                 else:
  121.                     g_privateShopAdvertisementBoardDict[key].Hide()
  122.  
  123. class PrivateShopBuilder(ui.ScriptWindow):
  124.  
  125.     def __init__(self):
  126.         #print "NEW MAKE_PRIVATE_SHOP_WINDOW ----------------------------------------------------------------"
  127.         ui.ScriptWindow.__init__(self)
  128.  
  129.         self.__LoadWindow()
  130.         self.itemStock = {}
  131.         self.tooltipItem = None
  132.         self.priceInputBoard = None
  133.         self.title = ""
  134.         if app.WJ_ENABLE_TRADABLE_ICON:
  135.             self.interface = None
  136.             self.wndInventory = None
  137.             self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  138.  
  139.     def __del__(self):
  140.         ui.ScriptWindow.__del__(self)
  141.  
  142.     def __LoadWindow(self):
  143.         try:
  144.             pyScrLoader = ui.PythonScriptLoader()
  145.             pyScrLoader.LoadScriptFile(self, "UIScript/PrivateShopBuilder.py")
  146.         except:
  147.             import exception
  148.             exception.Abort("PrivateShopBuilderWindow.LoadWindow.LoadObject")
  149.  
  150.         try:
  151.             GetObject = self.GetChild
  152.             self.nameLine = GetObject("NameLine")
  153.             self.itemSlot = GetObject("ItemSlot")
  154.             self.btnOk = GetObject("OkButton")
  155.             self.btnClose = GetObject("CloseButton")
  156.             self.titleBar = GetObject("TitleBar")
  157.         except:
  158.             import exception
  159.             exception.Abort("PrivateShopBuilderWindow.LoadWindow.BindObject")
  160.  
  161.         self.btnOk.SetEvent(ui.__mem_func__(self.OnOk))
  162.         self.btnClose.SetEvent(ui.__mem_func__(self.OnClose))
  163.         self.titleBar.SetCloseEvent(ui.__mem_func__(self.OnClose))
  164.  
  165.         self.itemSlot.SetSelectEmptySlotEvent(ui.__mem_func__(self.OnSelectEmptySlot))
  166.         self.itemSlot.SetSelectItemSlotEvent(ui.__mem_func__(self.OnSelectItemSlot))
  167.         self.itemSlot.SetOverInItemEvent(ui.__mem_func__(self.OnOverInItem))
  168.         self.itemSlot.SetOverOutItemEvent(ui.__mem_func__(self.OnOverOutItem))
  169.  
  170.     def Destroy(self):
  171.         self.ClearDictionary()
  172.  
  173.         self.nameLine = None
  174.         self.itemSlot = None
  175.         self.btnOk = None
  176.         self.btnClose = None
  177.         self.titleBar = None
  178.         self.priceInputBoard = None
  179.         if app.WJ_ENABLE_TRADABLE_ICON:
  180.             self.interface = None
  181.             self.wndInventory = None
  182.             self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  183.  
  184.     def Open(self, title):
  185.  
  186.         self.title = title
  187.  
  188.         if len(title) > 25:
  189.             title = title[:22] + "..."
  190.  
  191.         self.itemStock = {}
  192.         shop.ClearPrivateShopStock()
  193.         self.nameLine.SetText(title)
  194.         self.SetCenterPosition()
  195.         self.Refresh()
  196.         self.Show()
  197.         if app.WJ_ENABLE_TRADABLE_ICON:
  198.             self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  199.             if self.interface:
  200.                 self.interface.SetOnTopWindow(player.ON_TOP_WND_PRIVATE_SHOP)
  201.                 self.interface.RefreshMarkInventoryBag()
  202.  
  203.         global g_isBuildingPrivateShop
  204.         g_isBuildingPrivateShop = True
  205.  
  206.     def Close(self):
  207.         global g_isBuildingPrivateShop
  208.         g_isBuildingPrivateShop = False
  209.  
  210.         self.title = ""
  211.         self.itemStock = {}
  212.         shop.ClearPrivateShopStock()
  213.         self.Hide()
  214.         if self.priceInputBoard:
  215.             self.priceInputBoard.Close()
  216.             self.priceInputBoard = None
  217.  
  218.         if app.WJ_ENABLE_TRADABLE_ICON:
  219.             for privatePos, (itemInvenPage, itemSlotPos) in self.lockedItems.items():
  220.                 if itemInvenPage == self.wndInventory.GetInventoryPageIndex():
  221.                     self.wndInventory.wndItem.SetCanMouseEventSlot(itemSlotPos)
  222.  
  223.             self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  224.             self.interface.SetOnTopWindow(player.ON_TOP_WND_NONE)
  225.             self.interface.RefreshMarkInventoryBag()
  226.  
  227.     def SetItemToolTip(self, tooltipItem):
  228.         self.tooltipItem = tooltipItem
  229.  
  230.     def Refresh(self):
  231.         getitemVNum=player.GetItemIndex
  232.         getItemCount=player.GetItemCount
  233.         setitemVNum=self.itemSlot.SetItemSlot
  234.         delItem=self.itemSlot.ClearSlot
  235.  
  236.         for i in xrange(shop.SHOP_SLOT_COUNT):
  237.  
  238.             if not self.itemStock.has_key(i):
  239.                 delItem(i)
  240.                 continue
  241.  
  242.             pos = self.itemStock[i]
  243.  
  244.             itemCount = getItemCount(*pos)
  245.             if itemCount <= 1:
  246.                 itemCount = 0
  247.             setitemVNum(i, getitemVNum(*pos), itemCount)
  248.  
  249.         self.itemSlot.RefreshSlot()
  250.         if app.WJ_ENABLE_TRADABLE_ICON:
  251.             self.RefreshLockedSlot()
  252.  
  253.     def OnSelectEmptySlot(self, selectedSlotPos):
  254.  
  255.         isAttached = mouseModule.mouseController.isAttached()
  256.         if isAttached:
  257.             attachedSlotType = mouseModule.mouseController.GetAttachedType()
  258.             attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  259.             mouseModule.mouseController.DeattachObject()
  260.  
  261.             if player.SLOT_TYPE_INVENTORY != attachedSlotType and player.SLOT_TYPE_DRAGON_SOUL_INVENTORY != attachedSlotType:
  262.                 return
  263.             attachedInvenType = player.SlotTypeToInvenType(attachedSlotType)
  264.                
  265.             itemVNum = player.GetItemIndex(attachedInvenType, attachedSlotPos)
  266.             item.SelectItem(itemVNum)
  267.  
  268.             if item.IsAntiFlag(item.ITEM_ANTIFLAG_GIVE) or item.IsAntiFlag(item.ITEM_ANTIFLAG_MYSHOP):
  269.                 chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.PRIVATE_SHOP_CANNOT_SELL_ITEM)
  270.                 return
  271.             if app.WJ_ENABLE_TRADABLE_ICON and player.SLOT_TYPE_INVENTORY == attachedSlotType:
  272.                 self.CantTradableItem(selectedSlotPos, attachedSlotPos)
  273.             priceInputBoard = uiCommon.MoneyInputDialog()
  274.             priceInputBoard.SetTitle(localeInfo.PRIVATE_SHOP_INPUT_PRICE_DIALOG_TITLE)
  275.             priceInputBoard.SetAcceptEvent(ui.__mem_func__(self.AcceptInputPrice))
  276.             priceInputBoard.SetCancelEvent(ui.__mem_func__(self.CancelInputPrice))
  277.             priceInputBoard.Open()
  278.  
  279.             itemPrice=GetPrivateShopItemPrice(itemVNum)
  280.  
  281.             if itemPrice>0:
  282.                 priceInputBoard.SetValue(itemPrice)
  283.            
  284.             self.priceInputBoard = priceInputBoard
  285.             self.priceInputBoard.itemVNum = itemVNum
  286.             self.priceInputBoard.sourceWindowType = attachedInvenType
  287.             self.priceInputBoard.sourceSlotPos = attachedSlotPos
  288.             self.priceInputBoard.targetSlotPos = selectedSlotPos
  289.  
  290.     def OnSelectItemSlot(self, selectedSlotPos):
  291.  
  292.         isAttached = mouseModule.mouseController.isAttached()
  293.         if isAttached:
  294.             snd.PlaySound("sound/ui/loginfail.wav")
  295.             mouseModule.mouseController.DeattachObject()
  296.  
  297.         else:
  298.             if not selectedSlotPos in self.itemStock:
  299.                 return
  300.  
  301.             invenType, invenPos = self.itemStock[selectedSlotPos]
  302.             shop.DelPrivateShopItemStock(invenType, invenPos)
  303.             snd.PlaySound("sound/ui/drop.wav")
  304.             if app.WJ_ENABLE_TRADABLE_ICON:
  305.                 (itemInvenPage, itemSlotPos) = self.lockedItems[selectedSlotPos]
  306.                 if itemInvenPage == self.wndInventory.GetInventoryPageIndex():
  307.                     self.wndInventory.wndItem.SetCanMouseEventSlot(itemSlotPos)
  308.  
  309.                 self.lockedItems[selectedSlotPos] = (-1, -1)
  310.  
  311.             del self.itemStock[selectedSlotPos]
  312.  
  313.             self.Refresh()
  314.  
  315.     def AcceptInputPrice(self):
  316.  
  317.         if not self.priceInputBoard:
  318.             return True
  319.  
  320.         text = self.priceInputBoard.GetText()
  321.  
  322.         if not text:
  323.             return True
  324.  
  325.         if not text.isdigit():
  326.             return True
  327.  
  328.         if int(text) <= 0:
  329.             return True
  330.  
  331.         attachedInvenType = self.priceInputBoard.sourceWindowType
  332.         sourceSlotPos = self.priceInputBoard.sourceSlotPos
  333.         targetSlotPos = self.priceInputBoard.targetSlotPos
  334.  
  335.         for privatePos, (itemWindowType, itemSlotIndex) in self.itemStock.items():
  336.             if itemWindowType == attachedInvenType and itemSlotIndex == sourceSlotPos:
  337.                 shop.DelPrivateShopItemStock(itemWindowType, itemSlotIndex)
  338.                 del self.itemStock[privatePos]
  339.  
  340.         price = int(self.priceInputBoard.GetText())
  341.  
  342.         if IsPrivateShopItemPriceList():
  343.             SetPrivateShopItemPrice(self.priceInputBoard.itemVNum, price)
  344.  
  345.         shop.AddPrivateShopItemStock(attachedInvenType, sourceSlotPos, targetSlotPos, price)
  346.         self.itemStock[targetSlotPos] = (attachedInvenType, sourceSlotPos)
  347.         snd.PlaySound("sound/ui/drop.wav")
  348.  
  349.         self.Refresh()     
  350.  
  351.         #####
  352.  
  353.         self.priceInputBoard = None
  354.         return True
  355.  
  356.     def CancelInputPrice(self):
  357.         if app.WJ_ENABLE_TRADABLE_ICON:
  358.             itemInvenPage = self.priceInputBoard.sourceSlotPos / player.INVENTORY_PAGE_SIZE
  359.             itemSlotPos = self.priceInputBoard.sourceSlotPos - (itemInvenPage * player.INVENTORY_PAGE_SIZE)
  360.             if self.wndInventory.GetInventoryPageIndex() == itemInvenPage:
  361.                 self.wndInventory.wndItem.SetCanMouseEventSlot(itemSlotPos)
  362.  
  363.             self.lockedItems[self.priceInputBoard.targetSlotPos] = (-1, -1)
  364.  
  365.         if self.priceInputBoard:
  366.             self.priceInputBoard.Close()
  367.         self.priceInputBoard = None
  368.         return 1
  369.  
  370.     def OnOk(self):
  371.  
  372.         if not self.title:
  373.             return
  374.  
  375.         if 0 == len(self.itemStock):
  376.             return
  377.  
  378.         shop.BuildPrivateShop(self.title)
  379.         self.Close()
  380.        
  381.     def OnClose(self):
  382.         self.Close()
  383.  
  384.     def OnPressEscapeKey(self):
  385.         self.Close()
  386.         return True
  387.  
  388.     def OnOverInItem(self, slotIndex):
  389.         if self.tooltipItem:
  390.             if self.itemStock.has_key(slotIndex):
  391.                 self.tooltipItem.SetPrivateShopBuilderItem(self.itemStock[slotIndex], slotIndex)
  392.  
  393.     def OnOverOutItem(self):
  394.         if self.tooltipItem:
  395.             self.tooltipItem.HideToolTip()
  396.  
  397.     if app.WJ_ENABLE_TRADABLE_ICON:
  398.         def CantTradableItem(self, destSlotIndex, srcSlotIndex):
  399.             itemInvenPage = srcSlotIndex / player.INVENTORY_PAGE_SIZE
  400.             localSlotPos = srcSlotIndex - (itemInvenPage * player.INVENTORY_PAGE_SIZE)
  401.             self.lockedItems[destSlotIndex] = (itemInvenPage, localSlotPos)
  402.             if self.wndInventory.GetInventoryPageIndex() == itemInvenPage:
  403.                 self.wndInventory.wndItem.SetCantMouseEventSlot(localSlotPos)
  404.  
  405.         def RefreshLockedSlot(self):
  406.             if self.wndInventory:
  407.                 for privatePos, (itemInvenPage, itemSlotPos) in self.lockedItems.items():
  408.                     if self.wndInventory.GetInventoryPageIndex() == itemInvenPage:
  409.                         self.wndInventory.wndItem.SetCantMouseEventSlot(itemSlotPos)
  410.  
  411.                 self.wndInventory.wndItem.RefreshSlot()
  412.  
  413.         def BindInterface(self, interface):
  414.             self.interface = interface
  415.  
  416.         def OnTop(self):
  417.             if self.interface:
  418.                 self.interface.SetOnTopWindow(player.ON_TOP_WND_PRIVATE_SHOP)
  419.                 self.interface.RefreshMarkInventoryBag()
  420.  
  421.         def SetInven(self, wndInventory):
  422.             from _weakref import proxy
  423.             self.wndInventory = proxy(wndInventory)
  424.  
Advertisement
Add Comment
Please, Sign In to add comment