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

radialMenuLayer.py (10146B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\radialMenu\radialMenuLayer.py
      2 import math
      3 from carbonui.primitives.transform import Transform
      4 import carbonui.const as uiconst
      5 import telemetry
      6 from eve.client.script.ui.control.themeColored import SpriteThemeColored
      7 from eve.client.script.ui.shared.radialMenu.radialMenuActions import ActionButtonParent, RangeActionButtonParent, SecondLevelButtonParent
      8 from eve.client.script.ui.util import uix
      9 from eve.client.script.ui.shared.radialMenu.radialMenuUtils import RangeRadialMenuAction, SecondLevelRadialMenuAction, SimpleRadialMenuAction, FindOptionsDegree
     10 from utillib import KeyVal
     11 from carbonui.uicore import uicore
     12 
     13 class RadialMenuLayer(Transform):
     14     default_align = uiconst.CENTER
     15     default_state = uiconst.UI_DISABLED
     16 
     17     def ApplyAttributes(self, attributes):
     18         Transform.ApplyAttributes(self, attributes)
     19         self.display = attributes.Get('display', True)
     20         self.isExpanded = False
     21         self.buttonDict = {}
     22         self.sizeInfo = attributes.sizeInfo
     23         self.buttonWidth = attributes.sizeInfo.buttonWidth
     24         self.actionDistance = attributes.sizeInfo.actionDistance
     25         self.actionButtonTopPadding = attributes.sizeInfo.buttonPaddingTop
     26         self.buttonBackgroundOpacity = attributes.Get('buttonBackgroundOpacity', 0.8)
     27         self.usePreciseRanges = attributes.Get('usePreciseRanges', True)
     28         self.menuType = attributes.menuType
     29 
     30     def AnimateFromCenter(self, curveSet, animationDuration, sizeRatio, opacityRatio, grow, skipBnts):
     31         for eachButtonCont in self.buttonDict.values():
     32             if eachButtonCont in skipBnts:
     33                 continue
     34             normalSize = eachButtonCont.actionDistance * 2
     35             if grow:
     36                 startSize = sizeRatio * normalSize
     37                 endSize = normalSize
     38                 startOpacity = opacityRatio
     39                 endOpacity = 1.0
     40             else:
     41                 startSize = eachButtonCont.height
     42                 endSize = sizeRatio * normalSize
     43                 startOpacity = eachButtonCont.opacity
     44                 endOpacity = opacityRatio
     45             eachButtonCont.actionButton.AnimateSize(sizeRatio=sizeRatio, duration=animationDuration, grow=grow)
     46             curveSet = uicore.animations.MorphScalar(eachButtonCont, 'height', startVal=startSize, endVal=endSize, duration=animationDuration, curveSet=curveSet)
     47             curveSet = uicore.animations.MorphScalar(eachButtonCont, 'width', startVal=startSize, endVal=endSize, duration=animationDuration, curveSet=curveSet)
     48             curveSet = uicore.animations.MorphScalar(eachButtonCont, 'opacity', startVal=startOpacity, endVal=endOpacity, duration=animationDuration, curveSet=curveSet)
     49 
     50         return curveSet
     51 
     52     @telemetry.ZONE_METHOD
     53     def FindMyButton(self, degree, stepSize):
     54         halfStepSize = stepSize / 2.0
     55         if not self.buttonDict:
     56             return None
     57         if degree > 360 - halfStepSize:
     58             degree = 0
     59         for eachButtonCont in self.buttonDict.itervalues():
     60             if eachButtonCont.degree - halfStepSize <= degree < eachButtonCont.degree + halfStepSize:
     61                 if eachButtonCont.actionButton.isDisabled:
     62                     return None
     63                 return eachButtonCont
     64 
     65     def HiliteOneButtonAndGetLabel(self, btnCont):
     66         label = None
     67         for eachButtonCont in self.buttonDict.itervalues():
     68             if btnCont and eachButtonCont == btnCont:
     69                 eachButtonCont.actionButton.ShowButtonHilite()
     70                 label = btnCont.actionButton.labelText
     71             else:
     72                 eachButtonCont.actionButton.HideButtonHilite()
     73 
     74         return label
     75 
     76     def Reset(self):
     77         self.Flush()
     78         self.buttonDict = {}
     79 
     80     def LoadButtons(self, itemID, stepSize, alternate, animate, doReset, optionsInfo, startingDegree, iconPathFunc):
     81         myWantedMenuOptions = optionsInfo.allWantedMenuOptions
     82         activeSingleOptionsDict = optionsInfo.activeSingleOptions
     83         inactiveSingleOptionsSet = optionsInfo.inactiveSingleOptions
     84         activeRangeOptions = optionsInfo.activeRangeOptions
     85         if doReset:
     86             self.Reset()
     87         for counter, menuOptions in enumerate(myWantedMenuOptions):
     88             degree = FindOptionsDegree(counter, stepSize, startingDegree=startingDegree, alternate=alternate)
     89             activeOption = menuOptions.activeOption
     90             iconTexturePath = iconPathFunc(activeOption, menuOptions)
     91             if isinstance(menuOptions, SimpleRadialMenuAction):
     92                 isEmpty = activeOption is None
     93                 actionCont = self.AddActionButton(counter=counter, degree=degree, itemID=itemID, degreeWidth=stepSize, isEmpty=isEmpty)
     94                 if activeOption in activeSingleOptionsDict:
     95                     actionCont.SetButtonInfo(menuOptions, activeSingleOptionsDict[activeOption], isEnabled=True, iconTexturePath=iconTexturePath)
     96                 elif activeOption is not None and activeOption in inactiveSingleOptionsSet:
     97                     actionCont.SetButtonInfo(menuOptions, None, isEnabled=False, iconTexturePath=iconTexturePath)
     98                 else:
     99                     actionCont.SetDisabledIcon(texturePath=iconTexturePath)
    100             if isinstance(menuOptions, RangeRadialMenuAction):
    101                 actionCont = self.AddRangeButton(counter=counter, degree=degree, itemID=itemID, degreeWidth=stepSize, rangeList=menuOptions.rangeList, defaultRange=menuOptions.defaultRange)
    102                 if activeOption in activeRangeOptions:
    103                     actionCont.SetButtonInfo(menuOptions, KeyVal(func=menuOptions.callback, funcArgs=menuOptions.funcArgs), isEnabled=True, iconTexturePath=iconTexturePath)
    104                 else:
    105                     actionCont.SetButtonInfo(menuOptions, KeyVal(func=None, funcArgs=None, texturePath=None), isEnabled=False, iconTexturePath=iconTexturePath)
    106             if isinstance(menuOptions, SecondLevelRadialMenuAction):
    107                 actionCont = self.AddSecondLevelButton(counter=counter, degree=degree, itemID=itemID, degreeWidth=stepSize, hasExtraOptions=menuOptions.hasExtraOptions, levelType=menuOptions.levelType, texturePath=menuOptions.texturePath)
    108                 if not menuOptions.hasExtraOptions:
    109                     actionCont.SetDisabledIcon(texturePath=iconTexturePath)
    110             iconOffset = getattr(menuOptions, 'iconOffset', None)
    111             if iconOffset is not None:
    112                 actionCont.SetIconOffset(iconOffset)
    113             if animate:
    114                 self.AnimateButtonsIn(startingDegree)
    115 
    116     def AnimateButtonsIn(self, startingDegree):
    117         curveSet = None
    118         for eachButton in self.buttonDict.itervalues():
    119             degreeToUse = eachButton.degree
    120             if eachButton.degree > 180 + startingDegree:
    121                 degreeToUse = degreeToUse - 360
    122             radians = math.radians(degreeToUse)
    123             startRad = math.radians(startingDegree)
    124             animationDuration = 0.25
    125             curveSet = uicore.animations.MorphScalar(eachButton, 'rotation', startVal=-startRad, endVal=-radians, duration=animationDuration, curveSet=curveSet)
    126 
    127     def AddActionButton(self, counter, degree, isEmpty = False, *args, **kw):
    128         actionCont = self.buttonDict.get(counter, None)
    129         if actionCont is None or actionCont.destroyed:
    130             actionCont = ActionButtonParent(parent=self, pos=(0,
    131              0,
    132              self.buttonWidth,
    133              self.actionDistance * 2), buttonBackgroundOpacity=self.buttonBackgroundOpacity, degree=degree, sizeInfo=self.sizeInfo, isEmpty=isEmpty, actionKeywords=kw, menuType=self.menuType)
    134             self.buttonDict[counter] = actionCont
    135         return actionCont
    136 
    137     def AddRangeButton(self, counter, degree, *args, **kw):
    138         actionCont = self.buttonDict.get(counter, None)
    139         if actionCont is None or actionCont.destroyed:
    140             actionCont = RangeActionButtonParent(parent=self, pos=(0,
    141              0,
    142              self.buttonWidth,
    143              self.actionDistance * 2), buttonBackgroundOpacity=self.buttonBackgroundOpacity, usePreciseRanges=self.usePreciseRanges, degree=degree, sizeInfo=self.sizeInfo, actionKeywords=kw)
    144             self.buttonDict[counter] = actionCont
    145         return actionCont
    146 
    147     def AddSecondLevelButton(self, counter, degree, *args, **kw):
    148         actionCont = self.buttonDict.get(counter, None)
    149         if actionCont is None or actionCont.destroyed:
    150             actionCont = SecondLevelButtonParent(parent=self, pos=(0,
    151              0,
    152              self.buttonWidth,
    153              self.actionDistance * 2), buttonBackgroundOpacity=self.buttonBackgroundOpacity, degree=degree, sizeInfo=self.sizeInfo, actionKeywords=kw)
    154             self.buttonDict[counter] = actionCont
    155         return actionCont
    156 
    157 
    158 class RadialMenuShadow(SpriteThemeColored):
    159     default_name = 'radialMenuShadow'
    160     default_state = uiconst.UI_DISABLED
    161     default_align = uiconst.CENTER
    162     default_colorType = uiconst.COLORTYPE_UIBASE
    163 
    164     def ApplyAttributes(self, attributes):
    165         SpriteThemeColored.ApplyAttributes(self, attributes)
    166         self.shadowSize = attributes.shadowSize
    167 
    168     def AnimateFromCenter(self, animationDuration, sizeRatio, opacityRatio, grow):
    169         if grow:
    170             shadowStartValue = sizeRatio * self.shadowSize
    171             shadowEndValue = self.shadowSize
    172             startOpacity = opacityRatio
    173             endOpacity = 1.3
    174         else:
    175             shadowStartValue = self.shadowSize
    176             shadowEndValue = sizeRatio * self.shadowSize
    177             startOpacity = self.opacity
    178             endOpacity = opacityRatio
    179         curveSet = None
    180         uicore.animations.MorphScalar(self, 'height', startVal=shadowStartValue, endVal=shadowEndValue, duration=animationDuration, curveSet=curveSet)
    181         uicore.animations.MorphScalar(self, 'width', startVal=shadowStartValue, endVal=shadowEndValue, duration=animationDuration, curveSet=curveSet)
    182         uicore.animations.MorphScalar(self, 'opacity', startVal=startOpacity, endVal=endOpacity, duration=animationDuration, curveSet=curveSet)