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

glowSprite.py (5658B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\glowSprite.py
      2 import carbonui.const as uiconst
      3 import trinity
      4 from carbonui.primitives.container import Container
      5 from carbonui.primitives.sprite import Sprite
      6 from carbonui.uicore import uicore
      7 from eve.client.script.ui.control.eveIcon import Icon
      8 from eve.client.script.ui.control.themeColored import SpriteThemeColored
      9 GLOWAMOUNT_IDLE = 0.0
     10 GLOWAMOUNT_HOVER = 1.0
     11 GLOWAMOUNT_MOUSEDOWN = 1.5
     12 
     13 class GlowSprite(Container):
     14     default_name = 'GlowSprite'
     15     default_texturePath = ''
     16     default_state = uiconst.UI_NORMAL
     17     default_align = uiconst.TOPLEFT
     18     default_glowAmount = 0.0
     19     default_glowExpand = 0
     20     default_color = None
     21     default_rotation = 0.0
     22     default_iconOpacity = 0.9
     23     default_gradientStrength = 1.0
     24     default_ignoreColorBlindMode = True
     25     default_colorType = uiconst.COLORTYPE_UIHILIGHTGLOW
     26     default_iconClass = Sprite
     27     default_iconBlendMode = Sprite.default_blendMode
     28 
     29     def ApplyAttributes(self, attributes):
     30         super(GlowSprite, self).ApplyAttributes(attributes)
     31         self.texturePath = attributes.Get('texturePath', self.default_texturePath)
     32         self.rotation = attributes.Get('rotation', self.default_rotation)
     33         self.iconOpacity = attributes.Get('iconOpacity', self.default_iconOpacity)
     34         self.gradientStrength = attributes.get('gradientStrength', self.default_gradientStrength)
     35         self.color = attributes.get('color', self.default_color)
     36         self.glowColor = attributes.get('glowColor', self.default_color)
     37         self.ignoreColorBlindMode = attributes.get('ignoreColorBlindMode', self.default_ignoreColorBlindMode)
     38         self.iconClass = attributes.get('iconClass', self.default_iconClass)
     39         self.iconBlendMode = attributes.get('iconBlendMode', self.default_iconBlendMode)
     40         colorType = attributes.get('colorType', self.default_colorType)
     41         self._glowAmount = attributes.get('glowAmount', self.default_glowAmount)
     42         self.spriteEffect = None
     43         self.glowExpand = None
     44         self.icon = Sprite(bgParent=self, name='icon', state=uiconst.UI_DISABLED, align=uiconst.TOALL, color=self.color, texturePath=self.texturePath, rotation=self.rotation, ignoreColorBlindMode=self.ignoreColorBlindMode, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=self._glowAmount, blendMode=self.iconBlendMode)
     45         self.glowIcon = None
     46         self.bgGradient = None
     47 
     48     def _ConstructGlow(self):
     49         if not self.glowIcon:
     50             self.OnSizeUpdate()
     51             self.glowIcon = self.iconClass(name='glowIcon', bgParent=self, state=uiconst.UI_DISABLED, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, spriteEffect=self.spriteEffect, padding=-self.glowExpand, blendMode=trinity.TR2_SBM_ADDX2, opacity=0.0, texturePath=self.texturePath, rotation=self.rotation, color=self.glowColor)
     52             self.bgGradient = self.iconClass(name='bgGradient', bgParent=self, texturePath='res:/UI/Texture/shared/circularGradient.png', opacity=0.0, padding=-self.glowExpand, color=self.glowColor)
     53 
     54     def UpdateSpriteEffect(self, size):
     55         if size > 20:
     56             self.spriteEffect = trinity.TR2_SFX_GLOW
     57         else:
     58             self.spriteEffect = trinity.TR2_SFX_BLUR
     59 
     60     def OnSizeUpdate(self):
     61         w, h = self.GetAbsoluteSize()
     62         size = max(w, h)
     63         self.UpdateSpriteEffect(size)
     64         self.UpdateGlowExpand(size)
     65 
     66     def _OnResize(self, *args):
     67         self.OnSizeUpdate()
     68 
     69     def UpdateGlowExpand(self, size):
     70         g = size / 20
     71         g = max(1, min(g, 3))
     72         self.glowExpand = g
     73         if self.glowIcon:
     74             self.glowIcon.padding = (-g,
     75              -g,
     76              -g,
     77              -g)
     78             self.bgGradient.padding = (-g,
     79              -g,
     80              -g,
     81              -g)
     82 
     83     def SetTexturePath(self, texturePath):
     84         self.texturePath = texturePath
     85         self.icon.SetTexturePath(texturePath)
     86         if self.glowIcon:
     87             self.glowIcon.SetTexturePath(texturePath)
     88 
     89     def LoadTexture(self, texturePath):
     90         self.SetTexturePath(texturePath)
     91 
     92     def LoadIcon(self, iconNo, ignoreSize = False):
     93         texturePath, _ = Icon.ConvertIconNoToResPath(iconNo)
     94         self.SetTexturePath(texturePath)
     95 
     96     def LoadIconByTypeID(self, typeID, itemID, *args, **kw):
     97         icon = Icon(typeID=typeID, itemID=itemID)
     98         self.SetTexturePath(icon.texturePath)
     99 
    100     def SetRGBA(self, *color):
    101         self.color = color
    102         self.icon.SetRGBA(*color)
    103         if self.glowIcon and self.iconClass == SpriteThemeColored:
    104             self.glowIcon.SetFixedColor(color)
    105             self.bgGradient.SetFixedColor(color)
    106 
    107     def SetRGB(self, *args):
    108         self.SetRGBA(*args)
    109 
    110     def GetRGBA(self):
    111         return self.icon.GetRGBA()
    112 
    113     def OnMouseEnter(self, *args):
    114         self._AnimateGlow(GLOWAMOUNT_HOVER, uiconst.TIME_ENTRY)
    115 
    116     def OnMouseExit(self, *args):
    117         self._AnimateGlow(GLOWAMOUNT_IDLE, uiconst.TIME_EXIT)
    118 
    119     def OnMouseDown(self, *args):
    120         self._AnimateGlow(GLOWAMOUNT_HOVER, 0.1)
    121 
    122     def OnMouseUp(self, *args):
    123         self._AnimateGlow(1.0, 0.3)
    124 
    125     def _AnimateGlow(self, value, duration):
    126         uicore.animations.MorphScalar(self, 'glowAmount', self.glowAmount, value, duration=duration)
    127 
    128     @property
    129     def glowAmount(self):
    130         return self.icon.glowBrightness
    131 
    132     @glowAmount.setter
    133     def glowAmount(self, value):
    134         self.icon.glowBrightness = value
    135 
    136     def SetRotation(self, value):
    137         self.rotation = value
    138         self.icon.rotation = value
    139         if self.glowIcon:
    140             self.glowIcon.rotation = value