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

dropBar.py (10341B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\structure\accessGroups\dropBar.py
      2 import math
      3 from carbonui import const as uiconst
      4 from carbonui.primitives.container import Container
      5 from carbonui.primitives.gridcontainer import GridContainer
      6 from carbonui.primitives.sprite import Sprite
      7 from eve.client.script.ui.control.eveLabel import EveLabelMedium
      8 from eve.client.script.ui.control.glowSprite import GlowSprite
      9 from eve.client.script.ui.control.themeColored import FillThemeColored
     10 from eve.client.script.ui.structure.accessGroups.ownerGroupUtils import GetOwnerIDsAndMembershipTypeFromNodes
     11 from localization import GetByLabel
     12 from ownergroups.ownergroupsUIUtil import ACCESS_SORT_ORDER, GetChangeRestrictions, GetMembershipTypeTextureAndLabelPaths, GetMembershipSortIdx, GetSetAsMembershipLabelPaths
     13 from carbonui.uicore import uicore
     14 FILL_IDLE_OPACITY = 0.5
     15 DRAGGING_OPACITY = 1.0
     16 HILITE_OPACITY = 0.6
     17 PADDING = 2
     18 MOUSE_EXIT = 0
     19 MOUSE_ENTER = 1
     20 MOUSE_DROP_ON = 2
     21 
     22 class DropCont(Container):
     23     default_height = 80
     24     __notifyevents__ = ['OnExternalDragInitiated', 'OnExternalDragEnded']
     25 
     26     def ApplyAttributes(self, attributes):
     27         Container.ApplyAttributes(self, attributes)
     28         controller = attributes.controller
     29         self.ConstructUI(controller)
     30         sm.RegisterNotify(self)
     31 
     32     def ConstructUI(self, controller):
     33         self.dropGridCont = DropBar(parent=self, align=uiconst.TOTOP, controller=controller, height=36, mouseCallback=self.DropContMouseCallback)
     34         arrowPos = (0,
     35          self.dropGridCont.top + self.dropGridCont.height - 2,
     36          7,
     37          7)
     38         self.arrow = Sprite(parent=self, align=uiconst.TOPLEFT, pos=arrowPos, texturePath='res:/UI/Texture/classes/Neocom/arrowDown.png', rotation=math.pi)
     39         arrowColor = sm.GetService('uiColor').GetUIColor(uiconst.COLORTYPE_UIHILIGHT)
     40         self.arrow.SetRGBA(arrowColor[0], arrowColor[1], arrowColor[2], HILITE_OPACITY)
     41         self.arrow.display = False
     42         self.dropTextCont = Container(name='dropOverlay', parent=self, align=uiconst.TOTOP, height=32, padding=(2, 6, 2, 1), state=uiconst.UI_DISABLED, clipChildren=True)
     43         dropText = GetByLabel('UI/Structures/AccessGroups/DropMembers')
     44         self.dropLabel = EveLabelMedium(name='dropLabel', parent=self.dropTextCont, text=dropText, align=uiconst.CENTER)
     45         self.colorFill = FillThemeColored(name='colorFill', bgParent=self.dropTextCont, colorType=uiconst.COLORTYPE_UIHILIGHT, opacity=0.0)
     46         self.bgFill = FillThemeColored(name='bgFill', bgParent=self.dropTextCont, colorType=uiconst.COLORTYPE_UIBASECONTRAST, opacity=FILL_IDLE_OPACITY)
     47 
     48     def DropContMouseCallback(self, mouseAction, membershipType, numNodes = 0):
     49         if mouseAction == MOUSE_DROP_ON:
     50             BlinkInAndOut(self.colorFill)
     51             self.dropLabel.text = GetByLabel('UI/Structures/AccessGroups/DropMembers')
     52             return
     53         if not uicore.IsDragging():
     54             return
     55         if mouseAction == MOUSE_ENTER:
     56             labelPath = GetSetAsMembershipLabelPaths(membershipType)
     57             self.MoveArrow(membershipType)
     58             FadeObject(self.colorFill, endValue=HILITE_OPACITY)
     59             FadeObject(self.arrow, endValue=HILITE_OPACITY)
     60             FadeObjectOut(self.bgFill)
     61         else:
     62             labelPath = 'UI/Structures/AccessGroups/DropMembers'
     63             self.arrow.display = False
     64             FadeObject(self.bgFill, endValue=DRAGGING_OPACITY)
     65             FadeObjectOut(self.colorFill)
     66         self.dropLabel.text = GetByLabel(labelPath, numMembers=numNodes)
     67 
     68     def MoveArrow(self, membershipType):
     69         w = self.dropGridCont.renderObject.displayWidth
     70         step = float(w) / len(ACCESS_SORT_ORDER)
     71         membershipIdx = GetMembershipSortIdx(membershipType)
     72         offset = (membershipIdx + 0.5) * step - self.arrow.width / 2.0
     73         uicore.animations.MorphScalar(self.arrow, 'left', startVal=self.arrow.left, endVal=offset, duration=0.2)
     74         self.arrow.display = True
     75 
     76     def OnExternalDragInitiated(self, dragSource, dragData):
     77         membershipTypesByMemberID = GetOwnerIDsAndMembershipTypeFromNodes(dragData)
     78         if membershipTypesByMemberID:
     79             self.dropGridCont.ExternalDragInitiated(dragSource, dragData, numNodes=len(membershipTypesByMemberID))
     80             FadeObject(self.bgFill, endValue=DRAGGING_OPACITY)
     81 
     82     def OnExternalDragEnded(self, *args):
     83         self.dropGridCont.ExternalDragEnded()
     84         FadeObject(self.bgFill, endValue=FILL_IDLE_OPACITY)
     85         FadeObjectOut(self.arrow)
     86         FadeObjectOut(self.colorFill)
     87 
     88 
     89 class DropBar(GridContainer):
     90     default_lines = 1
     91     default_height = 32
     92     default_name = 'dropGridCont'
     93     default_columns = len(ACCESS_SORT_ORDER)
     94 
     95     def ApplyAttributes(self, attributes):
     96         GridContainer.ApplyAttributes(self, attributes)
     97         self.parentMouseCallback = attributes.mouseCallback
     98         self.currentGroupID = attributes.currentGroupID
     99         self.controller = attributes.controller
    100         self.dropContainers = {}
    101         for membershipType in ACCESS_SORT_ORDER:
    102             texturePath, hintPath, textureSize = GetMembershipTypeTextureAndLabelPaths(membershipType)
    103             d = DropContainer(parent=self, texturePath=texturePath, textureSize=textureSize, membershipType=membershipType, controller=self.controller, currentGroupID=self.currentGroupID, hintPath=hintPath, dropCallback=self.AddGroupMembersWithMembershipType, mouseCallback=self.MouseCallback, padding=PADDING)
    104             self.dropContainers[membershipType] = d
    105 
    106         self.dropOverlay = Container(name='dropOverlay', parent=self, align=uiconst.TOBOTTOM, height=32, state=uiconst.UI_DISABLED, clipChildren=True)
    107 
    108     def SetCurrentGroupID(self, groupID, membershipType):
    109         self.currentGroupID = groupID
    110         accessRestrictions = GetChangeRestrictions(membershipType)
    111         for membershipType, cont in self.dropContainers.iteritems():
    112             cont.SetDisableStatus(membershipType in accessRestrictions)
    113 
    114     def AddGroupMembersWithMembershipType(self, memberIDs, membershipType):
    115         self.controller.SetGroupMembersWithSameRight(self.currentGroupID, memberIDs, membershipType)
    116 
    117     def ExternalDragInitiated(self, dragSource, dragData, numNodes):
    118         for eachCont in self.dropContainers.itervalues():
    119             eachCont.ExternalDragInitiated(dragSource, dragData, numNodes)
    120 
    121     def ExternalDragEnded(self, *args):
    122         for eachCont in self.dropContainers.itervalues():
    123             eachCont.ExternalDragEnded()
    124 
    125     def MouseCallback(self, mouseAction, membershipType, numNodes):
    126         self.parentMouseCallback(mouseAction, membershipType, numNodes)
    127 
    128 
    129 class DropContainer(Container):
    130     default_state = uiconst.UI_NORMAL
    131 
    132     def ApplyAttributes(self, attributes):
    133         Container.ApplyAttributes(self, attributes)
    134         self.mouseCallback = attributes.mouseCallback
    135         self.validDragNodes = 0
    136         self.colorFill = FillThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIHILIGHT, opacity=0.0)
    137         self.bgFill = FillThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIBASECONTRAST, opacity=FILL_IDLE_OPACITY)
    138         texturePath = attributes.texturePath
    139         textureWidth, textureHeight = attributes.textureSize
    140         self.membershipType = attributes.membershipType
    141         self.dropCallback = attributes.dropCallback
    142         self.isDisabled = False
    143         self.icon = GlowSprite(parent=self, align=uiconst.CENTER, pos=(0,
    144          0,
    145          textureWidth,
    146          textureHeight), texturePath=texturePath, state=uiconst.UI_DISABLED)
    147         self.hint = GetByLabel(attributes.hintPath)
    148 
    149     def ExternalDragInitiated(self, dragSource, dragData, numNodes):
    150         if self.isDisabled:
    151             return
    152         self.validDragNodes = numNodes
    153         self.FadeBgFill(endValue=DRAGGING_OPACITY)
    154 
    155     def ExternalDragEnded(self, *args):
    156         if self.isDisabled:
    157             return
    158         self.validDragNodes = 0
    159         self.FadeBgFill(endValue=FILL_IDLE_OPACITY)
    160 
    161     def FadeBgFill(self, endValue):
    162         FadeObject(self.bgFill, endValue=endValue)
    163         FadeObject(self.icon, endValue=endValue)
    164 
    165     def MouseOverCont(self):
    166         if self.isDisabled or not self.validDragNodes:
    167             return
    168         self.icon.OnMouseEnter()
    169         if uicore.IsDragging():
    170             FadeObject(self.colorFill, endValue=HILITE_OPACITY)
    171             FadeObjectOut(self.bgFill)
    172             self.mouseCallback(MOUSE_ENTER, self.membershipType, self.validDragNodes)
    173 
    174     def MouseExitCont(self):
    175         if self.isDisabled or not self.validDragNodes:
    176             return
    177         FadeObjectOut(self.colorFill)
    178         if uicore.IsDragging():
    179             bgEndValue = DRAGGING_OPACITY
    180         else:
    181             bgEndValue = FILL_IDLE_OPACITY
    182         self.icon.OnMouseExit()
    183         FadeObject(self.bgFill, endValue=bgEndValue)
    184         self.mouseCallback(MOUSE_EXIT, self.membershipType, 0)
    185 
    186     def OnMouseEnter(self, *args):
    187         self.MouseOverCont()
    188 
    189     def OnMouseExit(self, *args):
    190         self.MouseExitCont()
    191 
    192     def OnDragEnter(self, dragObj, nodes):
    193         self.MouseOverCont()
    194 
    195     def OnDragExit(self, *args):
    196         self.MouseExitCont()
    197 
    198     def OnDropData(self, dragSource, nodes):
    199         if self.isDisabled:
    200             return
    201         membershipTypesByMemberID = GetOwnerIDsAndMembershipTypeFromNodes(nodes)
    202         if not membershipTypesByMemberID:
    203             return
    204         memberIDs = membershipTypesByMemberID.keys()
    205         self.dropCallback(memberIDs, self.membershipType)
    206         BlinkInAndOut(object=self.colorFill)
    207         self.mouseCallback(MOUSE_DROP_ON, self.membershipType, 0)
    208 
    209     def SetDisableStatus(self, isDisabled):
    210         self.isDisabled = isDisabled
    211         if isDisabled:
    212             self.icon.opacity = 0.1
    213             self.bgFill.opacity = 0.05
    214         else:
    215             self.icon.opacity = FILL_IDLE_OPACITY
    216             self.bgFill.opacity = FILL_IDLE_OPACITY
    217 
    218 
    219 def BlinkInAndOut(object):
    220     uicore.animations.BlinkIn(object, startVal=0.0, endVal=0.5, loops=1, duration=0.25, curveType=uiconst.ANIM_BOUNCE)
    221 
    222 
    223 def FadeObjectOut(object):
    224     FadeObject(object, endValue=0.0)
    225 
    226 
    227 def FadeObject(object, endValue = 1.0):
    228     uicore.animations.FadeTo(object, startVal=object.opacity, endVal=endValue, duration=0.25)