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

buttonCore.py (4847B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\vgs\buttonCore.py
      2 import math
      3 import trinity
      4 import uthread
      5 from carbon.client.script.environment.AudioUtil import PlaySound
      6 from carbonui import const as uiconst
      7 from carbonui.primitives.container import Container
      8 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      9 from carbonui.primitives.fill import Fill
     10 from carbonui.primitives.frame import Frame
     11 from carbonui.primitives.gradientSprite import GradientSprite
     12 from carbonui.primitives.sprite import Sprite
     13 from carbonui.uianimations import animations
     14 from eve.client.script.ui.control.eveLabel import EveHeaderSmall
     15 from eve.client.script.ui.util.uiComponents import Component, ButtonEffect
     16 
     17 @Component(ButtonEffect(audioOnEntry=uiconst.SOUND_BUTTON_HOVER, audioOnClick=uiconst.SOUND_BUTTON_CLICK))
     18 
     19 class ButtonCore(ContainerAutoSize):
     20     default_alignMode = uiconst.TOPLEFT
     21     default_color = (0.4, 0.4, 0.4, 1.0)
     22     default_contentSpacing = 3
     23     default_iconSize = (16, 16)
     24     default_iconColor = (1.0, 1.0, 1.0, 1.0)
     25     default_labelClass = EveHeaderSmall
     26     default_labelColor = (1.0, 1.0, 1.0, 1.0)
     27     default_labelShadow = False
     28     default_labelShadowColor = (0.0, 0.0, 0.0, 0.25)
     29     default_labelTop = 0
     30     default_padding = (4, 4, 4, 4)
     31     default_state = uiconst.UI_NORMAL
     32     default_text = None
     33     default_texturePath = None
     34 
     35     def ApplyAttributes(self, attributes):
     36         self.onClick = attributes.get('onClick', None)
     37         color = attributes.pop('color', self.default_color)
     38         contentSpacing = attributes.pop('contentSpacing', self.default_contentSpacing)
     39         iconSize = attributes.pop('iconSize', self.default_iconSize)
     40         iconColor = attributes.pop('iconColor', self.default_iconColor)
     41         labelClass = attributes.pop('labelClass', self.default_labelClass)
     42         labelColor = attributes.pop('labelColor', self.default_labelColor)
     43         labelShadow = attributes.pop('labelShadow', self.default_labelShadow)
     44         labelShadowColor = attributes.pop('labelShadowColor', self.default_labelShadowColor)
     45         labelTop = attributes.pop('labelTop', self.default_labelTop)
     46         padding = attributes.pop('padding', self.default_padding)
     47         attributes['padding'] = None
     48         text = attributes.pop('text', self.default_text)
     49         texturePath = attributes.pop('texturePath', self.default_texturePath)
     50         iconWidth, iconHeight = iconSize
     51         padLeft, padTop, padRight, padBottom = padding
     52         super(ButtonCore, self).ApplyAttributes(attributes)
     53         Fill(bgParent=self, align=uiconst.TOALL, padding=(1, 1, 1, 1), color=color)
     54         GradientSprite(bgParent=self, align=uiconst.TOALL, rgbData=((0.0, (0.9, 0.9, 0.9)), (0.5, (0.2, 0.2, 0.2)), (1.0, (0.9, 0.9, 0.9))), alphaData=((0.0, 0.3), (1.0, 0.3)), rotation=-math.pi / 4)
     55         Fill(bgParent=self, align=uiconst.TOALL, color=color)
     56         if texturePath:
     57             iconCont = Container(parent=self, align=uiconst.TOPLEFT, padding=(padLeft,
     58              padTop,
     59              contentSpacing if text else padRight,
     60              padBottom), height=iconHeight, width=iconWidth)
     61             Sprite(parent=iconCont, align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, texturePath=texturePath, height=iconHeight, width=iconWidth, color=iconColor)
     62         if text:
     63             if texturePath:
     64                 left = padLeft + iconWidth
     65                 labelPadding = (contentSpacing,
     66                  padTop,
     67                  padRight,
     68                  padBottom)
     69                 top = labelTop
     70             else:
     71                 left = 0
     72                 labelPadding = padding
     73                 top = 0
     74             labelCont = ContainerAutoSize(parent=self, align=uiconst.TOPLEFT, alignMode=uiconst.TOPLEFT, left=left, top=top)
     75             labelClass(parent=labelCont, align=uiconst.TOPLEFT, padding=labelPadding, text=text, color=labelColor)
     76             if labelShadow:
     77                 shadow = labelClass(parent=labelCont, align=uiconst.TOPLEFT, padding=labelPadding, text=text, color=labelShadowColor)
     78                 shadow.renderObject.spriteEffect = trinity.TR2_SFX_BLUR
     79                 Frame(parent=labelCont, align=uiconst.TOALL, texturePath='res:/UI/Texture/Vgs/radialShadow.png', cornerSize=8, color=labelShadowColor, opacity=labelShadowColor[3] * 0.5)
     80         self.SetSizeAutomatically()
     81 
     82     def OnClick(self, *args):
     83         if self.disabled:
     84             return
     85         PlaySound(uiconst.SOUND_BUTTON_CLICK)
     86         self.disabled = True
     87         uthread.new(self._OnClickThread)
     88 
     89     def _OnClickThread(self):
     90         try:
     91             if callable(self.onClick):
     92                 self.onClick()
     93         finally:
     94             self.disabled = False
     95 
     96     def AnimShow(self):
     97         self.Show()
     98         animations.FadeTo(self, duration=0.4)