Guest User

Untitled

a guest
May 9th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 15.47 KB | None | 0 0
  1. import app
  2. import net
  3. import player
  4. import item
  5. import ui
  6. import uiToolTip
  7. import mouseModule
  8. import localeInfo
  9. import uiCommon
  10. import constInfo
  11. import snd
  12. import wndMgr
  13. import chat
  14. import uiScriptLocale
  15.  
  16. class RefineDialog(ui.ScriptWindow):
  17.  
  18.     makeSocketSuccessPercentage = ( 100, 33, 20, 15, 10, 5, 0 )
  19.     upgradeStoneSuccessPercentage = ( 30, 29, 28, 27, 26, 25, 24, 23, 22 )
  20.     upgradeArmorSuccessPercentage = ( 99, 66, 33, 33, 33, 33, 33, 33, 33 )
  21.     upgradeAccessorySuccessPercentage = ( 99, 88, 77, 66, 33, 33, 33, 33, 33 )
  22.     upgradeSuccessPercentage = ( 99, 66, 33, 33, 33, 33, 33, 33, 33 )
  23.  
  24.     def __init__(self):
  25.         ui.ScriptWindow.__init__(self)
  26.         self.__LoadScript()
  27.  
  28.         self.scrollItemPos = 0
  29.         self.targetItemPos = 0
  30.  
  31.     def __LoadScript(self):
  32.  
  33.         self.__LoadQuestionDialog()
  34.  
  35.         try:
  36.             pyScrLoader = ui.PythonScriptLoader()
  37.             pyScrLoader.LoadScriptFile(self, "uiscript/refinedialog.py")
  38.  
  39.         except:
  40.             import exception
  41.             exception.Abort("RefineDialog.__LoadScript.LoadObject")
  42.  
  43.         try:
  44.             self.board = self.GetChild("Board")
  45.             self.titleBar = self.GetChild("TitleBar")
  46.             self.successPercentage = self.GetChild("SuccessPercentage")
  47.             self.GetChild("AcceptButton").SetEvent(self.OpenQuestionDialog)
  48.             self.GetChild("CancelButton").SetEvent(self.Close)
  49.         except:
  50.             import exception
  51.             exception.Abort("RefineDialog.__LoadScript.BindObject")
  52.  
  53.         # if constInfo.ENABLE_REFINE_PCT:
  54.             # self.successPercentage.Show()
  55.         # else:
  56.         self.successPercentage.Hide()
  57.  
  58.         toolTip = uiToolTip.ItemToolTip()
  59.         toolTip.SetParent(self)
  60.         toolTip.SetPosition(15, 38)
  61.         toolTip.SetFollow(FALSE)
  62.         toolTip.Show()
  63.         self.toolTip = toolTip
  64.  
  65.         self.titleBar.SetCloseEvent(ui.__mem_func__(self.Close))
  66.  
  67.     def __del__(self):
  68.         ui.ScriptWindow.__del__(self)
  69.  
  70.     def __LoadQuestionDialog(self):
  71.         self.dlgQuestion = ui.ScriptWindow()
  72.  
  73.         try:
  74.             pyScrLoader = ui.PythonScriptLoader()
  75.             pyScrLoader.LoadScriptFile(self.dlgQuestion, "uiscript/questiondialog2.py")
  76.         except:
  77.             import exception
  78.             exception.Abort("RefineDialog.__LoadQuestionDialog.LoadScript")
  79.  
  80.         try:
  81.             GetObject=self.dlgQuestion.GetChild
  82.             GetObject("message1").SetText(localeInfo.REFINE_DESTROY_WARNING)
  83.             GetObject("message2").SetText(localeInfo.REFINE_WARNING2)
  84.             GetObject("accept").SetEvent(ui.__mem_func__(self.Accept))
  85.             GetObject("cancel").SetEvent(ui.__mem_func__(self.dlgQuestion.Hide))
  86.         except:
  87.             import exception
  88.             exception.Abort("SelectCharacterWindow.__LoadQuestionDialog.BindObject")
  89.  
  90.     def Destroy(self):
  91.         self.ClearDictionary()
  92.         self.board = 0
  93.         self.successPercentage = 0
  94.         self.titleBar = 0
  95.         self.toolTip = 0
  96.         self.dlgQuestion = 0
  97.  
  98.     def GetRefineSuccessPercentage(self, scrollSlotIndex, itemSlotIndex):
  99.  
  100.         if -1 != scrollSlotIndex:
  101.             if player.IsRefineGradeScroll(scrollSlotIndex):
  102.                 curGrade = player.GetItemGrade(itemSlotIndex)
  103.                 itemIndex = player.GetItemIndex(itemSlotIndex)
  104.  
  105.                 item.SelectItem(itemIndex)
  106.                 itemType = item.GetItemType()
  107.                 itemSubType = item.GetItemSubType()
  108.  
  109.                 if item.ITEM_TYPE_METIN == itemType:
  110.  
  111.                     if curGrade >= len(self.upgradeStoneSuccessPercentage):
  112.                         return 0
  113.                     return self.upgradeStoneSuccessPercentage[curGrade]
  114.  
  115.                 elif item.ITEM_TYPE_ARMOR == itemType:
  116.  
  117.                     if item.ARMOR_BODY == itemSubType:
  118.                         if curGrade >= len(self.upgradeArmorSuccessPercentage):
  119.                             return 0
  120.                         return self.upgradeArmorSuccessPercentage[curGrade]
  121.                     else:
  122.                         if curGrade >= len(self.upgradeAccessorySuccessPercentage):
  123.                             return 0
  124.                         return self.upgradeAccessorySuccessPercentage[curGrade]
  125.  
  126.                 else:
  127.  
  128.                     if curGrade >= len(self.upgradeSuccessPercentage):
  129.                         return 0
  130.                     return self.upgradeSuccessPercentage[curGrade]
  131.  
  132.         for i in xrange(player.METIN_SOCKET_MAX_NUM+1):
  133.             if 0 == player.GetItemMetinSocket(itemSlotIndex, i):
  134.                 break
  135.  
  136.         return self.makeSocketSuccessPercentage[i]
  137.  
  138.     def Open(self, scrollItemPos, targetItemPos):
  139.         self.scrollItemPos = scrollItemPos
  140.         self.targetItemPos = targetItemPos
  141.  
  142.         percentage = self.GetRefineSuccessPercentage(scrollItemPos, targetItemPos)
  143.         if 0 == percentage:
  144.             return
  145.         self.successPercentage.SetText(localeInfo.REFINE_SUCCESS_PROBALITY % (percentage))
  146.  
  147.         itemIndex = player.GetItemIndex(targetItemPos)
  148.  
  149.  
  150.         self.toolTip.ClearToolTip()
  151.  
  152.         if app.WJ_ENABLE_TRADABLE_ICON:
  153.             self.SetCantMouseEventSlot(targetItemPos)
  154.            
  155.         metinSlot = []
  156.         for i in xrange(player.METIN_SOCKET_MAX_NUM):
  157.             metinSlot.append(player.GetItemMetinSocket(targetItemPos, i))
  158.         self.toolTip.AddItemData(itemIndex, metinSlot)
  159.  
  160.         self.UpdateDialog()
  161.         self.SetTop()
  162.         self.Show()
  163.  
  164.     def UpdateDialog(self):
  165.         newWidth = self.toolTip.GetWidth() + 30
  166.         newHeight = self.toolTip.GetHeight() + 98
  167.         self.board.SetSize(newWidth, newHeight)
  168.         self.titleBar.SetWidth(newWidth-15)
  169.         self.SetSize(newWidth, newHeight)
  170.  
  171.         (x, y) = self.GetLocalPosition()
  172.         self.SetPosition(x, y)
  173.  
  174.     def OpenQuestionDialog(self):
  175.         percentage = self.GetRefineSuccessPercentage(-1, self.targetItemPos)
  176.         if 100 == percentage:
  177.             self.Accept()
  178.             return
  179.  
  180.         self.dlgQuestion.SetTop()
  181.         self.dlgQuestion.Show()
  182.  
  183.     def Accept(self):
  184.         net.SendItemUseToItemPacket(self.scrollItemPos, self.targetItemPos)
  185.  
  186.     def Close(self):
  187.         if self.dlgQuestion:
  188.             self.dlgQuestion.Close()
  189.  
  190.         self.dlgQuestion = None
  191.         self.Hide()
  192.                
  193.     def OnPressEscapeKey(self):
  194.         self.Close()
  195.         return TRUE
  196.  
  197. class RefineDialogNew(ui.ScriptWindow):
  198.     def __init__(self):
  199.         ui.ScriptWindow.__init__(self)
  200.         self.__Initialize()
  201.         self.isLoaded = FALSE
  202.         if app.WJ_ENABLE_TRADABLE_ICON:
  203.             self.wndInventory = None
  204.  
  205.     def __Initialize(self):
  206.         self.dlgQuestion = None
  207.         self.children = []
  208.         self.vnum = 0
  209.         self.targetItemPos = 0
  210.         self.dialogHeight = 0
  211.         self.percentage = 0
  212.         self.total_percentage = 0
  213.         self.cost = 0
  214.         self.type = 0
  215.         if app.WJ_ENABLE_TRADABLE_ICON:
  216.             self.lockedItem = (-1,-1)
  217.  
  218.     def __LoadScript(self):
  219.  
  220.         try:
  221.             pyScrLoader = ui.PythonScriptLoader()
  222.             pyScrLoader.LoadScriptFile(self, "uiscript/refinedialog.py")
  223.  
  224.         except:
  225.             import exception
  226.             exception.Abort("RefineDialog.__LoadScript.LoadObject")
  227.  
  228.         try:
  229.             self.board = self.GetChild("Board")
  230.             self.titleBar = self.GetChild("TitleBar")
  231.             self.probText = self.GetChild("SuccessPercentage")
  232.             self.costText = self.GetChild("Cost")
  233.             self.successPercentage = self.GetChild("SuccessPercentage")
  234.             self.GetChild("AcceptButton").SetEvent(self.OpenQuestionDialog)
  235.             self.GetChild("CancelButton").SetEvent(self.CancelRefine)
  236.         except:
  237.             import exception
  238.             exception.Abort("RefineDialog.__LoadScript.BindObject")
  239.            
  240.         ## 936 : °³·® È®·ü Ç¥½Ã ¾ÈÇÔ
  241.         ##if 936 == app.GetDefaultCodePage():
  242.         self.successPercentage.Hide()
  243.  
  244.         toolTip = uiToolTip.ItemToolTip()
  245.         toolTip.SetParent(self)
  246.         toolTip.SetFollow(FALSE)
  247.         toolTip.SetPosition(15, 38)
  248.         toolTip.Show()
  249.         self.toolTip = toolTip
  250.  
  251.         self.slotList = []
  252.         for i in xrange(3):
  253.             slot = self.__MakeSlot()
  254.             slot.SetParent(toolTip)
  255.             slot.SetWindowVerticalAlignCenter()
  256.             self.slotList.append(slot)
  257.  
  258.         itemImage = self.__MakeItemImage()
  259.         itemImage.SetParent(toolTip)
  260.         itemImage.SetWindowVerticalAlignCenter()
  261.         itemImage.SetPosition(-35, 0)
  262.         self.itemImage = itemImage
  263.  
  264.         self.titleBar.SetCloseEvent(ui.__mem_func__(self.CancelRefine))
  265.  
  266.         if app.ENABLE_REFINE_RENEWAL:
  267.             self.checkBox = ui.CheckBox()
  268.             self.checkBox.SetParent(self)
  269.             self.checkBox.SetPosition(0, 90)
  270.             self.checkBox.SetWindowHorizontalAlignCenter()
  271.             self.checkBox.SetWindowVerticalAlignBottom()
  272.             self.checkBox.SetEvent(ui.__mem_func__(self.AutoRefine), "ON_CHECK", True)
  273.             self.checkBox.SetEvent(ui.__mem_func__(self.AutoRefine), "ON_UNCKECK", False)
  274.             self.checkBox.SetCheckStatus(constInfo.IS_AUTO_REFINE)
  275.             self.checkBox.SetTextInfo("Fenster offen lassen")
  276.             self.checkBox.Show()
  277.  
  278.         self.isLoaded = TRUE
  279.  
  280.     def __del__(self):
  281.         ui.ScriptWindow.__del__(self)
  282.  
  283.     def __MakeSlot(self):
  284.         slot = ui.ImageBox()
  285.         slot.LoadImage("d:/ymir work/ui/public/slot_base.sub")
  286.         slot.Show()
  287.         self.children.append(slot)
  288.         return slot
  289.  
  290.     def __MakeItemImage(self):
  291.         itemImage = ui.ImageBox()
  292.         itemImage.Show()
  293.         self.children.append(itemImage)
  294.         return itemImage
  295.  
  296.     def __MakeThinBoard(self):
  297.         thinBoard = ui.ThinBoard()
  298.         thinBoard.SetParent(self)
  299.         thinBoard.Show()
  300.         self.children.append(thinBoard)
  301.         return thinBoard
  302.  
  303.     def Destroy(self):
  304.         self.ClearDictionary()
  305.         self.dlgQuestion = None
  306.         self.board = 0
  307.         self.probText = 0
  308.         self.costText = 0
  309.         self.titleBar = 0
  310.         self.toolTip = 0
  311.         self.successPercentage = None
  312.         self.slotList = []
  313.         self.children = []
  314.  
  315.         if app.WJ_ENABLE_TRADABLE_ICON:
  316.             self.wndInventory = None
  317.             self.lockedItem = (-1,-1)
  318.  
  319.     if app.ENABLE_REFINE_RENEWAL:
  320.         def __InitializeOpen(self):
  321.             self.children = []
  322.             self.vnum = 0
  323.             self.targetItemPos = 0
  324.             self.dialogHeight = 0
  325.             self.cost = 0
  326.             self.percentage = 0
  327.             self.type = 0
  328.             self.xRefineStart = 0
  329.             self.yRefineStart = 0  
  330.  
  331.     def Open(self, targetItemPos, nextGradeItemVnum, cost, prob, type):
  332.  
  333.         if FALSE == self.isLoaded:
  334.             self.__LoadScript()
  335.  
  336.         if app.ENABLE_REFINE_RENEWAL:
  337.             self.__InitializeOpen()
  338.         else:
  339.             self.__Initialize()
  340.  
  341.         self.targetItemPos = targetItemPos
  342.         self.vnum = nextGradeItemVnum
  343.         self.cost = cost
  344.         self.percentage = prob
  345.         self.type = type
  346.  
  347.         self.probText.SetText(localeInfo.REFINE_SUCCESS_PROBALITY % (self.percentage))
  348.         self.costText.SetText(localeInfo.REFINE_COST % (self.cost))
  349.  
  350.         self.toolTip.ClearToolTip()
  351.         metinSlot = []
  352.         for i in xrange(player.METIN_SOCKET_MAX_NUM):
  353.             metinSlot.append(player.GetItemMetinSocket(targetItemPos, i))
  354.  
  355.         attrSlot = []
  356.         for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM):
  357.             attrSlot.append(player.GetItemAttribute(targetItemPos, i))
  358.         self.toolTip.AddRefineItemData(nextGradeItemVnum, metinSlot, attrSlot)
  359.  
  360.         item.SelectItem(nextGradeItemVnum)
  361.         self.itemImage.LoadImage(item.GetIconImageFileName())
  362.         xSlotCount, ySlotCount = item.GetItemSize()
  363.         for slot in self.slotList:
  364.             slot.Hide()
  365.         for i in xrange(min(3, ySlotCount)):
  366.             self.slotList[i].SetPosition(-35, i*32 - (ySlotCount-1)*16)
  367.             self.slotList[i].Show()
  368.  
  369.         self.dialogHeight = self.toolTip.GetHeight() + 46
  370.         self.UpdateDialog()
  371.  
  372.         self.SetTop()
  373.         self.Show()
  374.  
  375.     def Close(self):
  376.         self.dlgQuestion = None
  377.         self.Hide()
  378.  
  379.     def AppendMaterial(self, vnum, count):
  380.         slot = self.__MakeSlot()
  381.         slot.SetParent(self)
  382.         slot.SetPosition(15, self.dialogHeight)
  383.  
  384.         itemImage = self.__MakeItemImage()
  385.         itemImage.SetParent(slot)
  386.         item.SelectItem(vnum)
  387.         itemImage.LoadImage(item.GetIconImageFileName())
  388.  
  389.         thinBoard = self.__MakeThinBoard()
  390.         thinBoard.SetPosition(50, self.dialogHeight)
  391.         thinBoard.SetSize(191, 20)
  392.  
  393.         textLine = ui.TextLine()
  394.         textLine.SetParent(thinBoard)
  395.         textLine.SetFontName(localeInfo.UI_DEF_FONT)
  396.         textLine.SetPackedFontColor(0xffdddddd)
  397.         textLine.SetText("%s x %02d" % (item.GetItemName(), count))
  398.         textLine.SetOutline()
  399.         textLine.SetFeather(FALSE)
  400.         textLine.SetWindowVerticalAlignCenter()
  401.         textLine.SetVerticalAlignCenter()
  402.  
  403.         if localeInfo.IsARABIC():
  404.             (x,y) = textLine.GetTextSize()
  405.             textLine.SetPosition(x, 0)
  406.         else:
  407.             textLine.SetPosition(15, 0)
  408.  
  409.         textLine.Show()
  410.         self.children.append(textLine)
  411.  
  412.         self.dialogHeight += 34
  413.         self.UpdateDialog()
  414.  
  415.     def UpdateDialog(self):
  416.         newWidth = self.toolTip.GetWidth() + 60
  417.         newHeight = self.dialogHeight + 69 + 10
  418.  
  419.         newHeight -= 8
  420.  
  421.         if localeInfo.IsARABIC():
  422.             self.board.SetPosition( newWidth, 0 )
  423.  
  424.             (x, y) = self.titleBar.GetLocalPosition()
  425.             self.titleBar.SetPosition( newWidth - 15, y )
  426.  
  427.         self.board.SetSize(newWidth, newHeight)
  428.         self.toolTip.SetPosition(15 + 35, 38)
  429.         self.titleBar.SetWidth(newWidth-15)
  430.         self.SetSize(newWidth, newHeight)
  431.  
  432.         (x, y) = self.GetLocalPosition()
  433.         self.SetPosition(x, y)
  434.  
  435.     def OpenQuestionDialog(self):
  436.  
  437.         if 100 == self.percentage:
  438.             self.Accept()
  439.             return
  440.  
  441.         if 5 == self.type: ## ¹«½ÅÀÇ Ãູ¼­
  442.             self.Accept()
  443.             return
  444.  
  445.         dlgQuestion = uiCommon.QuestionDialog2()
  446.         dlgQuestion.SetText2(localeInfo.REFINE_WARNING2)
  447.         dlgQuestion.SetAcceptEvent(ui.__mem_func__(self.Accept))
  448.         dlgQuestion.SetCancelEvent(ui.__mem_func__(dlgQuestion.Close))
  449.  
  450.         if 3 == self.type: ## Çöö
  451.             dlgQuestion.SetText1(localeInfo.REFINE_DESTROY_WARNING_WITH_BONUS_PERCENT_1)
  452.             dlgQuestion.SetText2(localeInfo.REFINE_DESTROY_WARNING_WITH_BONUS_PERCENT_2)
  453.         elif 2 == self.type: ## Ãູ¼­
  454.             dlgQuestion.SetText1(localeInfo.REFINE_DOWN_GRADE_WARNING)
  455.         else:
  456.             dlgQuestion.SetText1(localeInfo.REFINE_DESTROY_WARNING)
  457.  
  458.         dlgQuestion.Open()
  459.         self.dlgQuestion = dlgQuestion
  460.  
  461.     def Accept(self):
  462.         if app.ENABLE_REFINE_RENEWAL:
  463.             net.SendRefinePacket(self.targetItemPos, self.type)
  464.         else:
  465.             net.SendRefinePacket(self.targetItemPos, self.type)
  466.             self.Close()
  467.  
  468.     if app.ENABLE_REFINE_RENEWAL:  
  469.         def AutoRefine(self, checkType, autoFlag):
  470.             constInfo.IS_AUTO_REFINE = autoFlag
  471.        
  472.         def CheckRefine(self, isFail):
  473.             if constInfo.IS_AUTO_REFINE == True:
  474.                 if constInfo.AUTO_REFINE_TYPE == 1:
  475.                     if constInfo.AUTO_REFINE_DATA["ITEM"][0] != -1 and constInfo.AUTO_REFINE_DATA["ITEM"][1] != -1:
  476.                         scrollIndex = player.GetItemIndex(constInfo.AUTO_REFINE_DATA["ITEM"][0])
  477.                         itemIndex = player.GetItemIndex(constInfo.AUTO_REFINE_DATA["ITEM"][1])
  478.                        
  479.                         # chat.AppendChat(chat.CHAT_TYPE_INFO, "%d %d" % (itemIndex, int(itemIndex %10)))
  480.                         if scrollIndex == 0 or (itemIndex % 10 == 8 and not isFail):
  481.                             self.Close()
  482.                         else:
  483.                             net.SendItemUseToItemPacket(constInfo.AUTO_REFINE_DATA["ITEM"][0], constInfo.AUTO_REFINE_DATA["ITEM"][1])
  484.                 elif constInfo.AUTO_REFINE_TYPE == 2:
  485.                     npcData = constInfo.AUTO_REFINE_DATA["NPC"]
  486.                     if npcData[0] != 0 and npcData[1] != -1 and npcData[2] != -1 and npcData[3] != 0:
  487.                         itemIndex = player.GetItemIndex(npcData[1], npcData[2])
  488.                         if (itemIndex % 10 == 8 and not isFail) or isFail:
  489.                             self.Close()
  490.                         else:
  491.                             net.SendGiveItemPacket(npcData[0], npcData[1], npcData[2], npcData[3])
  492.                 else:
  493.                     self.Close()
  494.             else:
  495.                 self.Close()
  496.  
  497.     def CancelRefine(self):
  498.         net.SendRefinePacket(255, 255, 0, 0, 0, 0)
  499.         self.Close()
  500.         if app.ENABLE_REFINE_RENEWAL:
  501.             constInfo.AUTO_REFINE_TYPE = 0
  502.             constInfo.AUTO_REFINE_DATA = {
  503.                 "ITEM" : [-1, -1],
  504.                 "NPC" : [0, -1, -1, 0]
  505.             }
  506.  
  507.     def OnPressEscapeKey(self):
  508.         self.CancelRefine()
  509.         return TRUE
  510.  
  511.     if app.WJ_ENABLE_TRADABLE_ICON:
  512.         def SetCanMouseEventSlot(self, slotIndex):
  513.             itemInvenPage = slotIndex / player.INVENTORY_PAGE_SIZE
  514.             localSlotPos = slotIndex - (itemInvenPage * player.INVENTORY_PAGE_SIZE)
  515.             self.lockedItem = (-1, -1)
  516.  
  517.             if itemInvenPage == self.wndInventory.GetInventoryPageIndex():
  518.                 self.wndInventory.wndItem.SetCanMouseEventSlot(localSlotPos)
  519.  
  520.         def SetCantMouseEventSlot(self, slotIndex):
  521.             itemInvenPage = slotIndex / player.INVENTORY_PAGE_SIZE
  522.             localSlotPos = slotIndex - (itemInvenPage * player.INVENTORY_PAGE_SIZE)
  523.             self.lockedItem = (itemInvenPage, localSlotPos)
  524.  
  525.             if itemInvenPage == self.wndInventory.GetInventoryPageIndex():
  526.                 self.wndInventory.wndItem.SetCantMouseEventSlot(localSlotPos)
  527.  
  528.         def SetInven(self, wndInventory):
  529.             from _weakref import proxy
  530.             self.wndInventory = proxy(wndInventory)
  531.  
  532.         def RefreshLockedSlot(self):
  533.             if self.wndInventory:
  534.                 itemInvenPage, itemSlotPos = self.lockedItem
  535.                 if self.wndInventory.GetInventoryPageIndex() == itemInvenPage:
  536.                     self.wndInventory.wndItem.SetCantMouseEventSlot(itemSlotPos)
  537.  
  538.                 self.wndInventory.wndItem.RefreshSlot()
Advertisement
Add Comment
Please, Sign In to add comment