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

rewardToggleButtonGroupButton.py (10707B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\loginRewards\rewardToggleButtonGroupButton.py
      2 import uthread2
      3 from carbon.client.script.environment.AudioUtil import PlaySound
      4 from carbonui import uiconst
      5 from carbonui.primitives.container import Container
      6 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      7 from carbonui.primitives.frame import Frame
      8 from carbonui.primitives.layoutGrid import LayoutGrid
      9 from carbonui.primitives.sprite import Sprite
     10 from carbonui.primitives.stretchspritehorizontal import StretchSpriteHorizontal
     11 from carbonui.primitives.stretchspritevertical import StretchSpriteVertical
     12 from carbonui.uicore import uicore
     13 from eve.client.script.ui.control.eveLabel import EveLabelMedium, CaptionLabel, EveLabelLarge, EveLabelLargeBold
     14 from eve.client.script.ui.shared.loginRewards.rewardUiConst import BLUE_TEXT_COLOR, GREEN_CHECKMARK
     15 from localization import GetByLabel
     16 import blue
     17 DESELECTED_TAB_OFFSET = 6
     18 OPACITY_LABEL_IDLE = 0.8
     19 OPACITY_LABEL_HOVER = 1.0
     20 OPACITY_LABEL_MOUSEDOWN = 1.2
     21 
     22 class ToggleButtonGroupButtonHeader(Container):
     23     OPACITY_SELECTED = 1.0
     24     OPACITY_HOVER = 0.125
     25     TEXT_TOPMARGIN = 4
     26     default_bgColor = (0, 0, 0, 1)
     27     default_padRight = 1
     28     default_align = uiconst.TOLEFT_PROP
     29     default_state = uiconst.UI_NORMAL
     30     default_iconSize = 32
     31     default_colorSelected = None
     32     default_iconOpacity = 1.0
     33     default_clipChildren = True
     34 
     35     def ApplyAttributes(self, attributes):
     36         Container.ApplyAttributes(self, attributes)
     37         self.controller = attributes.controller
     38         self.btnID = attributes.Get('btnID', None)
     39         self.btnIdx = attributes.Get('btnIdx', 0)
     40         self.totalBtnNum = attributes.Get('totalBtnNum') or 0
     41         self.panel = attributes.Get('panel', None)
     42         self.textureInfo = attributes.textureInfo
     43         label = attributes.Get('label', None)
     44         self.hint = attributes.Get('hint', None)
     45         btnWidth = attributes.Get('btnWidth', None)
     46         self.isSelected = False
     47         self.isDisabled = attributes.Get('isDisabled', False)
     48         self.labelClipperGrid = LayoutGrid(parent=self, align=uiconst.CENTER, columns=1, name='labelClipperGrid', cellSpacing=(0, 4))
     49         text = '<center>%s</center>' % label if btnWidth else label
     50         self.label = CaptionLabel(name='captionLabel', align=uiconst.CENTER, parent=self.labelClipperGrid, text=text, letterspace=-1, fontsize=34, width=btnWidth)
     51         self.labelShadow = CaptionLabel(name='captionLabel', align=uiconst.CENTER, parent=self.label.parent, text=text, letterspace=-1, fontsize=34, pos=(1,
     52          1,
     53          btnWidth,
     54          0), color=(0, 0, 0, 1))
     55         self.AddExtras(attributes)
     56         self.btnDeco = Container(name='btnDeco', parent=self, align=uiconst.TOALL, clipChildren=True)
     57         self.ConstructSelectedBG()
     58         opacity = getattr(self.textureInfo, 'textureOpacity', 1.0)
     59         self.bgSprite = Sprite(name='bgSprite', parent=self.btnDeco, opacity=opacity, align=getattr(self.textureInfo, 'textureAlign', uiconst.CENTERTOP), state=uiconst.UI_DISABLED, texturePath=self.textureInfo.texturePath, pos=(0,
     60          0,
     61          self.textureInfo.textureWidth,
     62          self.textureInfo.textureHeight))
     63         uthread2.start_tasklet(self._AdjustBgResolution, self.textureInfo.textureWidth, self.textureInfo.textureHeight)
     64 
     65     def OnButtonAdded(self):
     66         pass
     67 
     68     def _AdjustBgResolution(self, w, h):
     69         try:
     70             for x in xrange(3):
     71                 textureWidth = self.bgSprite.renderObject.texturePrimary.atlasTexture.width
     72                 textureHeight = self.bgSprite.renderObject.texturePrimary.atlasTexture.height
     73                 if textureWidth and textureHeight:
     74                     if w != textureWidth:
     75                         self.textureInfo.textureWidth = textureWidth
     76                         self.bgSprite.width = self.textureInfo.textureWidth
     77                     if h != textureHeight:
     78                         self.textureInfo.textureHeight = textureHeight
     79                         self.bgSprite.height = self.textureInfo.textureHeight
     80                     break
     81                 blue.synchro.Sleep(100)
     82 
     83         except Exception as e:
     84             pass
     85 
     86     def AddExtras(self, attributes):
     87         pass
     88 
     89     def ConstructSelectedBG(self):
     90         self.selectedBG = Container(name='selectedBG', parent=self.btnDeco)
     91         self.headerFrame = Frame(parent=self.selectedBG, opacity=1.0, frameConst=('res:/UI/Texture/classes/LoginCampaign/imageTab_selectedStroke.png', 4, 0))
     92         self.headerFrame.fullOpacity = self.headerFrame.opacity
     93         self.selectedBar = StretchSpriteHorizontal(name='selectedBar', parent=self.selectedBG, align=uiconst.CENTERTOP, texturePath='res:/UI/Texture/classes/LoginCampaign/windowselection_bar.png', top=1, height=6, width=120, rightEdgeSize=7, leftEdgeSize=7, opacity=0.5)
     94         self.shadowBarLeft = StretchSpriteVertical(name='shadowBarLeft', parent=self.selectedBG, align=uiconst.TOLEFT_NOPUSH, texturePath='res:/UI/Texture/classes/LoginCampaign/imageTab_gradient.png', width=-3, left=3, rightEdgeSize=7, leftEdgeSize=7, opacity=1.0, color=(0, 0, 0, 1))
     95         self.shadowBarRight = StretchSpriteVertical(name='shadowBarRight', parent=self.selectedBG, align=uiconst.TORIGHT_NOPUSH, texturePath='res:/UI/Texture/classes/LoginCampaign/imageTab_gradient.png', width=3, rightEdgeSize=7, leftEdgeSize=7, opacity=1.0, color=(0, 0, 0, 1))
     96         self.selectedBar.fullOpacity = self.selectedBar.opacity
     97         self.unselectedLine = Frame(parent=self.selectedBG, opacity=1.0, frameConst=('res:/UI/Texture/classes/LoginCampaign/imageTab_unselectedStroke.png', 4, 0))
     98 
     99     def SetDisabled(self):
    100         self.isDisabled = True
    101         if self.label:
    102             self.label.opacity = 0.1
    103             self.labelShadow.opacity = 0.1
    104 
    105     def SetEnabled(self):
    106         self.isDisabled = False
    107 
    108     def _ShouldSkipMouseFeedback(self):
    109         return self.isSelected or self.isDisabled or self.totalBtnNum == 1
    110 
    111     def OnMouseEnter(self, *args):
    112         PlaySound(uiconst.SOUND_BUTTON_HOVER)
    113         if self._ShouldSkipMouseFeedback():
    114             return
    115         uicore.animations.FadeTo(self.headerFrame, self.headerFrame.opacity, self.headerFrame.fullOpacity - 0.1, duration=uiconst.TIME_ENTRY)
    116         uicore.animations.FadeTo(self.label, self.label.opacity, OPACITY_LABEL_HOVER, duration=uiconst.TIME_ENTRY)
    117 
    118     def OnMouseExit(self, *args):
    119         if self._ShouldSkipMouseFeedback():
    120             return
    121         uicore.animations.FadeTo(self.headerFrame, self.headerFrame.opacity, 0.0, duration=uiconst.TIME_EXIT)
    122         uicore.animations.FadeTo(self.label, self.label.opacity, OPACITY_LABEL_IDLE, duration=uiconst.TIME_EXIT)
    123 
    124     def OnMouseDown(self, *args):
    125         if self._ShouldSkipMouseFeedback():
    126             return
    127         uicore.animations.FadeTo(self.headerFrame, self.headerFrame.opacity, self.headerFrame.fullOpacity + 0.2, duration=0.1)
    128 
    129     def OnMouseUp(self, *args):
    130         if self._ShouldSkipMouseFeedback():
    131             return
    132 
    133     def SetSelected(self, animate = True):
    134         self.isSelected = True
    135         self.headerFrame.StopAnimations()
    136         self.selectedBar.StopAnimations()
    137         self.headerFrame.opacity = self.headerFrame.fullOpacity
    138         self.selectedBar.opacity = self.selectedBar.fullOpacity
    139         self.unselectedLine.opacity = 0.0
    140         if self.label:
    141             self.label.opacity = OPACITY_LABEL_HOVER
    142         self.btnDeco.padTop = 0
    143 
    144     def SetDeselected(self, animate = True):
    145         self.isSelected = False
    146         if self.label:
    147             self.label.opacity = 1.0
    148         if self.isDisabled:
    149             return
    150         self.unselectedLine.opacity = 1.0
    151         self.headerFrame.opacity = 0.0
    152         self.selectedBar.opacity = 0.0
    153 
    154     def ChangePositionBasedTextures(self, selectedBtnIdx):
    155         self.shadowBarLeft.display = False
    156         self.shadowBarRight.display = False
    157         if selectedBtnIdx == self.btnIdx - 1:
    158             self.shadowBarLeft.display = True
    159         elif selectedBtnIdx == self.btnIdx + 1:
    160             self.shadowBarRight.display = True
    161 
    162     def IsSelected(self):
    163         return self.isSelected
    164 
    165     def OnClick(self, *args):
    166         if not self.isDisabled and not self.IsSelected():
    167             self.controller.Select(self, playSound=True)
    168 
    169     def HideOrShowBg(self, displayValue):
    170         self.bgSprite.display = displayValue
    171 
    172 
    173 class RewardToggleButtonGroupButtonHeader(ToggleButtonGroupButtonHeader):
    174 
    175     def AddExtras(self, attributes):
    176         topText = attributes.Get('topText', None)
    177         text = attributes.Get('subLabel', None)
    178         btnWidth = attributes.Get('btnWidth', None)
    179         if text:
    180             row = self.labelClipperGrid.AddRow()
    181             extraInfo = ContainerAutoSize(parent=row, align=uiconst.CENTER, top=2, maxWidth=btnWidth)
    182             w, h = EveLabelMedium.MeasureTextSize(text=text)
    183             labelWidth = None
    184             if btnWidth and w > btnWidth:
    185                 labelWidth = btnWidth
    186                 text = '<center>%s</center>' % text
    187             EveLabelLarge(parent=extraInfo, align=uiconst.CENTER, text=text, width=labelWidth)
    188             Sprite(name='headerGradient', bgParent=extraInfo, texturePath='res:/UI/Texture/classes/LoginCampaign/header_textGradient.png', opacity=0.5, padding=(-40, -6, -40, -6), color=(0, 0, 0, 1))
    189             self.labelClipperGrid.top = 10
    190         if topText:
    191             topCont = ContainerAutoSize(parent=self, align=uiconst.CENTERTOP, top=20, maxWidth=btnWidth)
    192             w, h = EveLabelMedium.MeasureTextSize(text=topText)
    193             labelWidth = None
    194             if btnWidth and w > btnWidth:
    195                 labelWidth = btnWidth
    196                 topText = '<center>%s</center>' % topText
    197             EveLabelLargeBold(parent=topCont, align=uiconst.CENTER, text=topText, width=labelWidth)
    198 
    199     def ConstructSelectedBG(self):
    200         ToggleButtonGroupButtonHeader.ConstructSelectedBG(self)
    201 
    202     def UpdateUnseenCont(self, hasUnseenRewards):
    203         if hasUnseenRewards and not self.isSelected:
    204             self.selectedBar.color = GREEN_CHECKMARK
    205         else:
    206             self.selectedBar.color = (1.0, 1.0, 1.0, 1.0)
    207 
    208     def OnMouseEnter(self, *args):
    209         if self._ShouldSkipMouseFeedback():
    210             return
    211         ToggleButtonGroupButtonHeader.OnMouseEnter(self, *args)
    212 
    213     def OnMouseExit(self, *args):
    214         if self._ShouldSkipMouseFeedback():
    215             return
    216         ToggleButtonGroupButtonHeader.OnMouseExit(self, *args)
    217 
    218     def OnMouseDown(self, *args):
    219         if self._ShouldSkipMouseFeedback():
    220             return
    221         ToggleButtonGroupButtonHeader.OnMouseDown(self, *args)