buttonIconHoverSprite.py (5302B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\buttonIconHoverSprite.py 2 import trinity 3 from carbon.client.script.environment.AudioUtil import PlaySound 4 from carbonui import uiconst 5 from carbonui.loggers.buttonLogger import log_button_clicked 6 from carbonui.primitives.container import Container 7 from carbonui.primitives.sprite import Sprite 8 from carbonui.uicore import uicore 9 from eve.client.script.ui.control.themeColored import SpriteThemeColored 10 11 class ButtonIconHoverSprite(Container): 12 __guid__ = 'uicontrols.ButtonIconHoverSprite' 13 default_func = None 14 default_args = None 15 default_width = 32 16 default_height = 32 17 default_align = uiconst.TOPLEFT 18 default_state = uiconst.UI_NORMAL 19 default_texturePath = None 20 default_hoverTexture = None 21 default_isActive = True 22 default_iconSize = 16 23 default_rotation = 0 24 default_noBgSize = 1 25 default_iconEnabledOpacity = 1.0 26 default_iconDisabledOpacity = 0.5 27 default_soundClick = uiconst.SOUND_BUTTON_CLICK 28 default_iconClass = SpriteThemeColored 29 default_useThemeColor = True 30 default_analyticID = '' 31 default_iconBlendMode = trinity.TR2_SBM_ADD 32 default_blendMode = trinity.TR2_SBM_BLEND 33 default_playClickSound = True 34 35 def ApplyAttributes(self, attributes): 36 super(ButtonIconHoverSprite, self).ApplyAttributes(attributes) 37 self.func = attributes.get('func', self.default_func) 38 self.args = attributes.get('args', self.default_args) 39 self.isActive = attributes.get('isActive', True) 40 self.texturePath = attributes.get('texturePath', self.default_texturePath) 41 self.baseTexture = self.texturePath 42 self.hoverTexture = attributes.get('hoverTexture', self.default_hoverTexture) 43 self.iconSize = attributes.get('iconSize', self.default_iconSize) 44 self.iconEnabledOpacity = attributes.get('iconEnabledOpacity', self.default_iconEnabledOpacity) 45 self.iconDisabledOpacity = attributes.get('iconDisabledOpacity', self.default_iconDisabledOpacity) 46 self.rotation = attributes.Get('rotation', self.default_rotation) 47 self.soundClick = attributes.Get('soundClick', self.default_soundClick) 48 self.playClickSound = attributes.Get('playClickSound', self.default_playClickSound) 49 self.iconBlendMode = attributes.Get('iconBlendMode', self.default_iconBlendMode) 50 self.blendMode = attributes.Get('blendMode', self.default_blendMode) 51 self.iconClass = attributes.Get('iconClass', self.default_iconClass) or self.default_iconClass 52 self.useThemeColor = attributes.Get('useThemeColor', self.default_useThemeColor) 53 self.analyticID = attributes.Get('analyticID', self.default_analyticID) 54 self.isSelected = False 55 self.enabled = True 56 self.ConstructIcon() 57 self.bgContainer = Container(name='bgCont', parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED) 58 enabled = attributes.get('enabled', True) 59 if not enabled: 60 self.Disable() 61 self._CheckUpdateTexturePath() 62 63 def SetIconSize(self, iconSize): 64 self.iconSize = iconSize 65 self.icon.width = self.icon.height = iconSize 66 67 def ConstructIcon(self): 68 self.icon = Sprite(name='icon', parent=self, align=uiconst.CENTER, width=self.iconSize, height=self.iconSize, texturePath=self.texturePath, state=uiconst.UI_DISABLED, rotation=self.rotation, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=0.0, blendMode=self.blendMode) 69 70 def SetTexturePath(self, texture_path): 71 self.texturePath = texture_path 72 self.icon.SetTexturePath(texturePath=texture_path) 73 74 def Disable(self, opacity = None): 75 self.enabled = 0 76 self._CheckUpdateTexturePath() 77 78 def Enable(self): 79 self.enabled = 1 80 self._CheckUpdateTexturePath() 81 82 def SetRotation(self, value): 83 self.icon.rotation = value 84 85 def _CheckUpdateTexturePath(self): 86 if (uicore.uilib.mouseOver == self or self.isSelected) and self.enabled: 87 texture_path = self.hoverTexture 88 else: 89 texture_path = self.baseTexture 90 self.SetTexturePath(texture_path) 91 92 def OnClick(self, *args): 93 if not self._IsClickable(): 94 return 95 if self.playClickSound: 96 PlaySound(self.soundClick) 97 log_button_clicked(self) 98 self._ExecuteFunction() 99 100 def _IsClickable(self): 101 return self.enabled 102 103 def _ExecuteFunction(self): 104 if not self.func: 105 return 106 if type(self.args) == tuple: 107 self.func(*self.args) 108 elif self.args: 109 self.func(self.args) 110 else: 111 self.func() 112 113 def OnMouseEnter(self, *args): 114 if not self.enabled: 115 return 116 self._CheckUpdateTexturePath() 117 PlaySound(uiconst.SOUND_BUTTON_HOVER) 118 119 def OnMouseExit(self, *args): 120 self._CheckUpdateTexturePath() 121 122 def OnMouseDown(self, *args): 123 if not self.enabled: 124 return 125 self._CheckUpdateTexturePath() 126 127 def OnMouseUp(self, *args): 128 if not self.enabled: 129 return 130 self._CheckUpdateTexturePath() 131 132 def OnEndDrag(self, *args): 133 self._CheckUpdateTexturePath()