NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

entry.py (6733B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\pointerTool\entry.py
      2 from carbonui.control.scrollentries import SE_BaseClassCore
      3 from carbonui.primitives.container import Container
      4 from carbonui.primitives.fill import Fill
      5 from carbonui.primitives.sprite import Sprite
      6 import carbonui.const as uiconst
      7 from carbonui.control.buttonIcon import ButtonIcon
      8 from eve.client.script.ui.control.eveLabel import EveLabelMedium
      9 from eve.client.script.ui.control.listgroup import ListGroup
     10 from eve.client.script.ui.shared.pointerTool.favorites import AddElementsToGroup, FindPointerObjectsForNodes
     11 from localization import GetByLabel
     12 from carbonui.uicore import uicore
     13 from utillib import KeyVal
     14 ICON_SIZE = 32
     15 
     16 class PointerWndEntry(SE_BaseClassCore):
     17     __guid__ = 'listentry.PointerWndEntry'
     18     isDragObject = True
     19 
     20     def Startup(self, *etc):
     21         self.labelleft = 32
     22         self.labelCont = Container(name='labelCont', parent=self, align=uiconst.TOALL, padLeft=40, padRight=35, state=uiconst.UI_DISABLED)
     23         self.label = EveLabelMedium(text='', parent=self.labelCont, state=uiconst.UI_DISABLED, align=uiconst.CENTERLEFT, autoFadeSides=35)
     24         self.iconCont = Container(name='iconCont', parent=self, pos=(0,
     25          0,
     26          ICON_SIZE,
     27          ICON_SIZE), align=uiconst.CENTERLEFT)
     28         self.icon = Sprite(parent=self.iconCont, pos=(0,
     29          0,
     30          ICON_SIZE,
     31          ICON_SIZE), align=uiconst.CENTER, state=uiconst.UI_DISABLED, opacity=0.75)
     32         self.playBtn = ButtonIcon(name='playBtn', parent=self, iconSize=20, align=uiconst.CENTERRIGHT, left=5, texturePath='res:/ui/texture/classes/HelpPointer/highlightElement.png', func=self.DoPoint)
     33 
     34     def Load(self, node):
     35         self.sr.node = node
     36         data = node
     37         text = data.label
     38         if data.useLongName and data.longName:
     39             text = data.longName
     40         self.label.text = text
     41         if data.texturePath:
     42             self.icon.SetTexturePath(data.texturePath)
     43             self.icon.LoadIcon(data.texturePath, ignoreSize=True)
     44             if data.iconSizes:
     45                 self.icon.SetSize(*data.iconSizes)
     46             else:
     47                 self.SetIconSize()
     48         elif data.iconData:
     49             maxIconDataSize = max(data.iconData.sizes)
     50             iconSize = min(maxIconDataSize, ICON_SIZE)
     51             self.icon.width = iconSize
     52             self.icon.height = iconSize
     53             self.icon.SetTexturePath(data.iconData)
     54         if node.Get('hint', None):
     55             self.hint = data.hint
     56         if node.selected:
     57             self.Select()
     58         else:
     59             self.Deselect()
     60         self.playBtn.hint = GetByLabel('UI/Help/PointerWndPointTo', elementName=data.label)
     61         sublevel = node.sublevel or 0
     62         indent = 16 * sublevel
     63         self.icon.left = indent
     64         self.labelCont.padLeft = 40 + indent
     65 
     66     def SetIconSize(self):
     67         try:
     68             textureWidth = self.icon.renderObject.texturePrimary.atlasTexture.width
     69             textureHeight = self.icon.renderObject.texturePrimary.atlasTexture.height
     70             newWidth = min(ICON_SIZE, max(16, textureWidth))
     71             newHeight = min(ICON_SIZE, max(16, textureHeight))
     72             widthRatio = newWidth / float(textureWidth)
     73             heightRatio = newHeight / float(textureHeight)
     74             if widthRatio != heightRatio:
     75                 smallerRatio = min(widthRatio, heightRatio)
     76                 newWidth = int(smallerRatio * textureWidth)
     77                 newHeight = int(smallerRatio * textureHeight)
     78             self.icon.width = newWidth
     79             self.icon.height = newHeight
     80         except Exception as e:
     81             pass
     82 
     83     def GetHeight(self, *args):
     84         node, width = args
     85         node.height = 32
     86         return node.height
     87 
     88     def GetDragData(self, *args):
     89         pointerObj = self.sr.node.pointerObject
     90         return [KeyVal(__guid__='listentry.PointerWndEntry', pointerObjects=[pointerObj])]
     91 
     92     def OnDblClick(self, *args):
     93         if self.sr.node.openElement:
     94             pointerObject = self.sr.node.pointerObject
     95             if pointerObject and pointerObject.cmdName:
     96                 uicore.cmd.GetCommandAndExecute(pointerObject.cmdName)
     97                 return
     98         self.DoPoint()
     99 
    100     def DoPoint(self, *args):
    101         sourceLocation = self.sr.node.sourceLocation
    102         sm.GetService('helpPointer').ActivateHelperPointer(self.sr.node.uiElementName, sourceLocation)
    103 
    104     def GetHint(self):
    105         node = self.sr.node
    106         return node.longName or node.label
    107 
    108     def GetMenu(self):
    109         if self.sr.get('node', None) and self.sr.node.get('OnGetMenu', None):
    110             return self.sr.node.OnGetMenu(self)
    111         return []
    112 
    113 
    114 class FavoritePointerWndEntry(PointerWndEntry):
    115 
    116     def Startup(self, *args):
    117         PointerWndEntry.Startup(self, args)
    118         self.posIndicatorCont = Container(name='posIndicator', parent=self, align=uiconst.TOTOP, state=uiconst.UI_DISABLED, height=2)
    119         self.posIndicator = Fill(parent=self.posIndicatorCont, color=(1.0, 1.0, 1.0, 0.5), state=uiconst.UI_DISABLED)
    120         self.posIndicator.Hide()
    121 
    122     def OnDropData(self, dragObj, nodes, *args):
    123         node = self.sr.node
    124         self.posIndicator.Hide()
    125         if not self.IsOfRightTypeForDragging(nodes):
    126             return
    127         nodeDragged = nodes[0]
    128         parentGroup = self.sr.node.parentGroup
    129         parentGroupID = parentGroup.groupID
    130         uiElementsInGroup = parentGroup.uiElementNames
    131         if node.uiElementName in uiElementsInGroup:
    132             idxInGroup = uiElementsInGroup.index(node.uiElementName)
    133         else:
    134             idxInGroup = None
    135         AddElementsToGroup(parentGroupID, [nodeDragged], idxInGroup)
    136 
    137     def OnDragEnter(self, dragObj, nodes, *args):
    138         if self.IsOfRightTypeForDragging(nodes):
    139             self.posIndicator.Show()
    140 
    141     def IsOfRightTypeForDragging(self, nodes):
    142         if len(nodes) != 1:
    143             return False
    144         return bool(FindPointerObjectsForNodes(nodes))
    145 
    146     def OnDragExit(self, *args):
    147         self.posIndicator.Hide()
    148 
    149 
    150 class FavoriteListGroup(ListGroup):
    151     isDragObject = True
    152 
    153     def GetDragData(self):
    154         node = self.sr.node
    155         groupKeyVal = node.groupKeyVal
    156         allPointers = sm.GetService('helpPointer').GetAllPointersByElementName()
    157         pointerObjects = []
    158         for uiElementName in groupKeyVal.uiElementNames:
    159             pointerObj = allPointers.get(uiElementName, None)
    160             if pointerObj:
    161                 pointerObjects.append(pointerObj)
    162 
    163         if pointerObjects:
    164             fakeNode = KeyVal(__guid__='listentry.PointerWndEntry', pointerObjects=pointerObjects)
    165             return [fakeNode]
    166         return []