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

upgradeButton.py (6921B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\cloneGrade\upgradeButton.py
      2 from carbon.client.script.environment.AudioUtil import PlaySound
      3 from carbonui import const as uiconst
      4 from carbonui.primitives.container import Container
      5 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      6 from carbonui.text.styles import TextBody
      7 from carbonui.primitives.sprite import Sprite
      8 from carbonui.primitives.stretchspritehorizontal import StretchSpriteHorizontal
      9 from carbonui.uianimations import animations
     10 from carbonui.util.color import Color
     11 from clonegrade.const import COLOR_OMEGA_ORANGE
     12 from eve.client.script.ui.control.eveLabel import Label
     13 from carbonui.loggers.buttonLogger import log_button_clicked
     14 import signals
     15 COLOR_IDLE = (1.0, 1.0, 1.0, 0.0)
     16 
     17 class UpgradeButton(Container):
     18     default_state = uiconst.UI_NORMAL
     19     default_color = COLOR_OMEGA_ORANGE
     20     default_fontSize = 18
     21     default_upperCase = True
     22     default_stretchTexturePath = 'res:/UI/Texture/Classes/CloneGrade/omegaBG.png'
     23     default_hiliteTexturePath = 'res:/UI/Texture/Classes/CloneGrade/omegaHilite.png'
     24     default_textureEdgeSize = 18
     25     default_hoverSound = 'upgrade_menu_button_hover_play'
     26     default_clickSound = 'upgrade_future_play'
     27     default_onMouseEnterCallback = None
     28     default_onMouseExitCallback = None
     29     default_glowBrightness = 0
     30 
     31     def ApplyAttributes(self, attributes):
     32         Container.ApplyAttributes(self, attributes)
     33         self.text = attributes.text
     34         self.labelColor = attributes.get('labelColor', self.default_color)
     35         self.fillColor = attributes.get('fillColor', self.default_color)
     36         self.onMouseEnterCallback = attributes.get('onMouseEnterCallback', self.default_onMouseEnterCallback)
     37         self.onMouseExitCallback = attributes.get('onMouseExitCallback', self.default_onMouseExitCallback)
     38         self.onClick = attributes.onClick
     39         self.fontSize = attributes.get('fontSize', self.default_fontSize)
     40         self.upperCase = attributes.get('upperCase', self.default_upperCase)
     41         self.stretchTexturePath = attributes.get('stretchTexturePath', self.default_stretchTexturePath)
     42         self.stretchTextureColor = attributes.Get('stretchTextureColor', Color.WHITE)
     43         self.textureEdgeSize = attributes.get('textureEdgeSize', self.default_textureEdgeSize)
     44         self.hiliteTexturePath = attributes.get('hiliteTexturePath', self.default_hiliteTexturePath)
     45         self.hoverSound = attributes.get('hoverSound', self.default_hoverSound)
     46         self.clickSound = attributes.get('clickSound', self.default_clickSound)
     47         self.glowBrightness = attributes.get('glowBrightness', self.default_glowBrightness)
     48         self.analyticID = attributes.analyticID
     49         self._layout()
     50 
     51     def _layout(self):
     52         self._construct_content()
     53         self.hilite = StretchSpriteHorizontal(parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath=self.hiliteTexturePath, rightEdgeSize=self.textureEdgeSize, leftEdgeSize=self.textureEdgeSize, opacity=0.0, glowBrightness=self.glowBrightness)
     54         self.bg = StretchSpriteHorizontal(parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath=self.stretchTexturePath, color=self.stretchTextureColor, rightEdgeSize=self.textureEdgeSize, leftEdgeSize=self.textureEdgeSize, opacity=0.85, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=self.glowBrightness)
     55 
     56     def _construct_content(self):
     57         self.label = Label(parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, text=self.text, fontsize=self.fontSize, uppercase=self.upperCase, bold=True, color=self.labelColor)
     58 
     59     def OnMouseEnter(self, *args):
     60         if self.hoverSound is not None:
     61             PlaySound(self.hoverSound)
     62         animations.SpColorMorphTo(self.hilite, (1.0, 1.0, 1.0, 0.5), self.fillColor, duration=0.3)
     63         animations.SpColorMorphTo(self.label, self.label.GetRGBA(), Color.BLACK, duration=0.3)
     64         if self.onMouseEnterCallback:
     65             self.onMouseEnterCallback()
     66 
     67     def OnMouseExit(self, *args):
     68         duration = 0.15
     69         animations.SpColorMorphTo(self.hilite, self.hilite.GetRGBA(), COLOR_IDLE, duration=duration)
     70         animations.SpColorMorphTo(self.label, self.label.GetRGBA(), self.labelColor, duration=duration)
     71         if self.onMouseExitCallback:
     72             self.onMouseExitCallback()
     73 
     74     def OnClick(self, *args):
     75         if self.clickSound is not None:
     76             PlaySound(self.clickSound)
     77         log_button_clicked(self)
     78         self.onClick()
     79         animations.SpColorMorphTo(self.label, self.label.GetRGBA(), self.labelColor, duration=0.3)
     80         animations.SpColorMorphTo(self.hilite, (1.0, 1.0, 1.0, 1.0), COLOR_IDLE, duration=0.3)
     81 
     82 
     83 class UpgradeIconButton(UpgradeButton):
     84 
     85     def ApplyAttributes(self, attributes):
     86         self._iconTexturePath = attributes.icon or 'res:/UI/Texture/classes/CloneGrade/omega_16.png'
     87         self._iconSize = attributes.iconSize or (16, 17)
     88         self._animate = attributes.animate
     89         self.on_mouse_enter = signals.Signal('on_mose_enter_button')
     90         self.on_mouse_exit = signals.Signal('on_mouse_exit_button')
     91         UpgradeButton.ApplyAttributes(self, attributes)
     92 
     93     def start_pulse_glow(self):
     94         if self._animate:
     95             self._pulse_glow()
     96 
     97     def stop_pulse_glow(self):
     98         if self._animate:
     99             animations.StopAnimation(self.bg, 'glowBrightness')
    100             self.bg.glowBrightness = 0
    101 
    102     def _layout(self):
    103         super(UpgradeIconButton, self)._layout()
    104         self.bg.opacity = 1
    105         if self._animate:
    106             self._pulse_glow()
    107 
    108     def _construct_content(self):
    109         container = ContainerAutoSize(parent=self, align=uiconst.CENTER)
    110         self.icon = Sprite(parent=container, align=uiconst.CENTERLEFT, texturePath=self._iconTexturePath, width=self._iconSize[0], height=self._iconSize[1], left=12, color=self.labelColor)
    111         self.icon.OnClick = self.OnClick
    112         self.label = TextBody(parent=container, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, left=self.icon.width + 16, padRight=12, text=self.text, color=self.labelColor)
    113         self.width = container.GetAbsoluteSize()[0]
    114 
    115     def _pulse_glow(self):
    116         animations.MorphScalar(self.bg, 'glowBrightness', duration=3, startVal=self.bg.glowBrightness, endVal=1.2, loops=uiconst.ANIM_REPEAT, curveType=uiconst.ANIM_BOUNCE)
    117 
    118     def OnMouseEnter(self, *args):
    119         super(UpgradeIconButton, self).OnMouseEnter(*args)
    120         self.on_mouse_enter()
    121         animations.SpColorMorphTo(self.icon, self.icon.GetRGBA(), Color.BLACK, duration=0.3)
    122 
    123     def OnMouseExit(self, *args):
    124         super(UpgradeIconButton, self).OnMouseExit(*args)
    125         self.on_mouse_exit()
    126         animations.SpColorMorphTo(self.icon, self.icon.GetRGBA(), self.labelColor, duration=0.15)
    127         if self._animate:
    128             self._pulse_glow()