Advertisement
P3NG3R

uiEquipmentDialog.py

Sep 10th, 2014
1,310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.39 KB | None | 0 0
  1. import ui
  2. import chr
  3. import player
  4.  
  5. class CostumeEquipmentDialog(ui.ScriptWindow):
  6.     def __init__(self, wndEquipment):
  7.         if not wndEquipment:
  8.             import exception
  9.             exception.Abort("wndEquipment parameter must be set to CostumeEquipmentDialog")
  10.             return
  11.  
  12.         ui.ScriptWindow.__init__(self)
  13.  
  14.         self.isLoaded = 0
  15.         self.wndEquipment = wndEquipment;
  16.  
  17.         self.wndCostumeEquipmentLayer = None
  18.         self.wndCostumeEquipmentSlot = None
  19.         self.expandBtn = None
  20.         self.minBtn = None
  21.  
  22.         self.__LoadWindow()
  23.  
  24.     def __del__(self):
  25.         ui.ScriptWindow.__del__(self)
  26.  
  27.     def Show(self):
  28.         self.__LoadWindow()
  29.         ui.ScriptWindow.Show(self)
  30.  
  31.         self.CloseCostumeEquipment()
  32.  
  33.     def Close(self):
  34.         self.Hide()
  35.  
  36.     def IsOpenedCostumeEquipment(self):
  37.         return self.wndCostumeEquipmentLayer.IsShow()
  38.  
  39.     def OpenCostumeEquipment(self):
  40.         self.wndCostumeEquipmentLayer.Show()
  41.         self.expandBtn.Hide()
  42.  
  43.         self.AdjustPositionAndSize()
  44.         self.RefreshSlot()
  45.  
  46.     def CloseCostumeEquipment(self):
  47.         self.wndCostumeEquipmentLayer.Hide()
  48.         self.expandBtn.Show()
  49.  
  50.         self.AdjustPositionAndSize()
  51.  
  52.     def GetBasePosition(self):
  53.         x, y = self.wndEquipment.GetGlobalPosition()
  54.         return x - 139, y + 30
  55.  
  56.     def AdjustPositionAndSize(self):
  57.         bx, by = self.GetBasePosition()
  58.  
  59.         if self.IsOpenedCostumeEquipment():
  60.             self.SetPosition(bx, by)
  61.             self.SetSize(self.ORIGINAL_WIDTH, self.GetHeight())
  62.  
  63.         else:
  64.             self.SetPosition(bx + 129, by);
  65.             self.SetSize(10, self.GetHeight())
  66.  
  67.     def __LoadWindow(self):
  68.         if self.isLoaded == 1:
  69.             return
  70.  
  71.         self.isLoaded = 1
  72.  
  73.         try:
  74.             pyScrLoader = ui.PythonScriptLoader()
  75.             pyScrLoader.LoadScriptFile(self, "UIScript/CostumeEquipmentDialog.py")
  76.         except:
  77.             import exception
  78.             exception.Abort("CostumeEquipmentDialog.LoadWindow.LoadObject")
  79.  
  80.         try:
  81.             self.ORIGINAL_WIDTH = self.GetWidth()
  82.             wndCostumeEquipmentSlot = self.GetChild("CostumeEquipmentSlot")
  83.             self.wndCostumeEquipmentLayer = self.GetChild("CostumeEquipmentLayer")
  84.             self.expandBtn = self.GetChild("ExpandButton")
  85.             self.minBtn = self.GetChild("MinimizeButton")
  86.  
  87.             self.expandBtn.SetEvent(ui.__mem_func__(self.OpenCostumeEquipment))
  88.             self.minBtn.SetEvent(ui.__mem_func__(self.CloseCostumeEquipment))
  89.  
  90.         except:
  91.             import exception
  92.             exception.Abort("CostumeEquipmentDialog.LoadWindow.BindObject")
  93.  
  94.         wndCostumeEquipmentSlot.SetOverInItemEvent(ui.__mem_func__(self.wndEquipment.OverInItem))
  95.         wndCostumeEquipmentSlot.SetOverOutItemEvent(ui.__mem_func__(self.wndEquipment.OverOutItem))
  96.         self.wndCostumeEquipmentSlot = wndCostumeEquipmentSlot
  97.  
  98.     def RefreshSlot(self):
  99.         equipmentDict = self.wndEquipment.itemDataDict
  100.         for i in [11, 12]:
  101.             if equipmentDict.has_key(i):
  102.                 self.wndCostumeEquipmentSlot.SetItemSlot(i, equipmentDict[i][0], equipmentDict[i][1])
  103.  
  104. class EquipmentDialog(ui.ScriptWindow):
  105.     wndCostumeEquipment = None
  106.  
  107.     def __init__(self):
  108.         #print "NEW EQUIPMENT DIALOG ----------------------------------------------------------------------------"
  109.         ui.ScriptWindow.__init__(self)
  110.         self.__LoadDialog()
  111.  
  112.         self.vid = None
  113.         self.eventClose = None
  114.         self.itemDataDict = {}
  115.         self.tooltipItem = None
  116.  
  117.     def __del__(self):
  118.         #print "---------------------------------------------------------------------------- DELETE EQUIPMENT DIALOG "
  119.         ui.ScriptWindow.__del__(self)
  120.  
  121.     def __LoadDialog(self):
  122.         try:
  123.             PythonScriptLoader = ui.PythonScriptLoader()
  124.             PythonScriptLoader.LoadScriptFile(self, "UIScript/EquipmentDialog.py")
  125.  
  126.             getObject = self.GetChild
  127.             self.board = getObject("Board")
  128.             self.slotWindow = getObject("EquipmentSlot")
  129.  
  130.             self.wndCostumeEquipment = CostumeEquipmentDialog(self)
  131.  
  132.         except:
  133.             import exception
  134.             exception.Abort("EquipmentDialog.LoadDialog.BindObject")
  135.  
  136.         self.board.SetCloseEvent(ui.__mem_func__(self.Close))
  137.         self.slotWindow.SetOverInItemEvent(ui.__mem_func__(self.OverInItem))
  138.         self.slotWindow.SetOverOutItemEvent(ui.__mem_func__(self.OverOutItem))
  139.  
  140.     def Open(self, vid):
  141.         self.vid = vid
  142.         self.itemDataDict = {}
  143.  
  144.         name = chr.GetNameByVID(vid)
  145.         self.board.SetTitleName(name)
  146.  
  147.         self.SetCenterPosition()
  148.         self.SetTop()
  149.         self.Show()
  150.  
  151.         if self.wndCostumeEquipment:
  152.             self.wndCostumeEquipment.Show()
  153.  
  154.     def Close(self):
  155.         self.itemDataDict = {}
  156.         self.tooltipItem = None
  157.         self.Hide()
  158.  
  159.         if self.eventClose:
  160.             self.eventClose(self.vid)
  161.  
  162.         if self.wndCostumeEquipment:
  163.             self.wndCostumeEquipment.Close()
  164.  
  165.     def Destroy(self):
  166.         self.eventClose = None
  167.  
  168.         self.Close()
  169.         self.ClearDictionary()
  170.  
  171.         self.board = None
  172.         self.slotWindow = None
  173.  
  174.         if self.wndCostumeEquipment:
  175.             self.wndCostumeEquipment.Destroy()
  176.             self.wndCostumeEquipment = None
  177.  
  178.     def SetEquipmentDialogItem(self, slotIndex, vnum, count):
  179.         if count <= 1:
  180.             count = 0
  181.  
  182.         self.slotWindow.SetItemSlot(slotIndex, vnum, count)
  183.  
  184.         emptySocketList = []
  185.         emptyAttrList = []
  186.         for i in xrange(player.METIN_SOCKET_MAX_NUM):
  187.             emptySocketList.append(0)
  188.         for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM):
  189.             emptyAttrList.append((0, 0))
  190.         self.itemDataDict[slotIndex] = (vnum, count, emptySocketList, emptyAttrList)
  191.  
  192.     def SetEquipmentDialogSocket(self, slotIndex, socketIndex, value):
  193.         if not slotIndex in self.itemDataDict:
  194.             return
  195.         if socketIndex < 0 or socketIndex > player.METIN_SOCKET_MAX_NUM:
  196.             return
  197.         self.itemDataDict[slotIndex][2][socketIndex] = value
  198.  
  199.     def SetEquipmentDialogAttr(self, slotIndex, attrIndex, type, value):
  200.         if not slotIndex in self.itemDataDict:
  201.             return
  202.         if attrIndex < 0 or attrIndex > player.ATTRIBUTE_SLOT_MAX_NUM:
  203.             return
  204.         self.itemDataDict[slotIndex][3][attrIndex] = (type, value)
  205.  
  206.     def SetItemToolTip(self, tooltipItem):
  207.         self.tooltipItem = tooltipItem
  208.  
  209.     def SetCloseEvent(self, event):
  210.         self.eventClose = event
  211.  
  212.     def OverInItem(self, slotIndex):
  213.  
  214.         if None == self.tooltipItem:
  215.             return
  216.  
  217.         if not slotIndex in self.itemDataDict:
  218.             return
  219.  
  220.         itemVnum = self.itemDataDict[slotIndex][0]
  221.         if 0 == itemVnum:
  222.             return
  223.  
  224.         self.tooltipItem.ClearToolTip()
  225.         metinSlot = self.itemDataDict[slotIndex][2]
  226.         attrSlot = self.itemDataDict[slotIndex][3]
  227.         self.tooltipItem.AddItemData(itemVnum, metinSlot, attrSlot)
  228.         self.tooltipItem.ShowToolTip()
  229.  
  230.     def OverOutItem(self):
  231.         if None != self.tooltipItem:
  232.             self.tooltipItem.HideToolTip()
  233.  
  234.     def OnPressEscapeKey(self):
  235.         self.Close()
  236.         return True
  237.  
  238.     def OnMoveWindow(self, x, y):
  239.         if self.wndCostumeEquipment:
  240.             self.wndCostumeEquipment.AdjustPositionAndSize()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement