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

newRedeemPanel.py (11484B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\redeem\newRedeemPanel.py
      2 from math import pi
      3 import homestation.client
      4 from carbon.client.script.environment.AudioUtil import PlaySound
      5 from carbonui import uiconst
      6 from carbonui.control.scroll import MAIN_CONTAINER_PADDING
      7 from carbonui.primitives.container import Container
      8 from carbonui.primitives.fill import Fill
      9 from carbonui.primitives.gradientSprite import GradientSprite
     10 from carbonui.primitives.line import Line
     11 from carbonui.primitives.sprite import Sprite
     12 from carbonui.primitives.transform import Transform
     13 from carbonui.uicore import uicore
     14 from eve.client.script.ui.control.eveLabel import EveCaptionMedium
     15 from eve.client.script.ui.shared.redeem.redeemItem import GetRedeemItemHeightWithoutDescription
     16 from eve.client.script.ui.shared.redeem.redeemItemsContainer import RedeemItemsContainer, ControlContainer, Controller
     17 from eve.client.script.ui.shared.redeem.redeemUiConst import REDEEM_BUTTON_BACKGROUND_COLOR, REDEEM_BUTTON_BORDER_COLOR, REDEEM_BUTTON_FILL_COLOR, REDEEM_PANEL_BACKGROUND_COLOR, TEXT_COLOR
     18 from localization import GetByLabel
     19 
     20 def GetOneRowHeightWithoutDescription():
     21     return GetRedeemItemHeightWithoutDescription() + MAIN_CONTAINER_PADDING * 2
     22 
     23 
     24 REDEEM_BUTTON_HEIGHT = 35
     25 REDEEM_ITEMS_PADDING_TOP = 4
     26 REDEEM_ITEMS_PADDING_BOTTOM = 2
     27 REDEEM_ITEMS_HEIGHT = GetOneRowHeightWithoutDescription() + REDEEM_ITEMS_PADDING_TOP + REDEEM_ITEMS_PADDING_BOTTOM
     28 DEFAULT_ANIMATION_DURATION = 0.2
     29 
     30 class RedeemPanelNew(Container):
     31     isDropLocation = False
     32 
     33     def ApplyAttributes(self, attributes):
     34         super(RedeemPanelNew, self).ApplyAttributes(attributes)
     35         self._ReadAttributes(attributes)
     36         self.isCollapsed = True
     37         self.display = False
     38         self._ConstructRedeemButton()
     39         self._ConstructRedeemItems()
     40         self._ConstructCenterSection()
     41         self.UpdateSizes()
     42         self.UpdateVisibility()
     43 
     44     def _ReadAttributes(self, attributes):
     45         self.redeemData = attributes.redeemData
     46         self.buttonOnClick = attributes.get('buttonClick', self.ChangeCollapsedState)
     47         self.onVisibilityChanged = attributes.get('onVisibilityChanged', None)
     48         self.onCollapsibilityChanged = attributes.get('onCollapsibilityChanged', None)
     49         self.animationDuration = attributes.get('animationDuration', DEFAULT_ANIMATION_DURATION)
     50         self.instructionText = attributes.get('instructionText', None)
     51         self.textColor = attributes.get('textColor', TEXT_COLOR)
     52         self.buttonBorderColor = attributes.get('redeemButtonBorderColor', REDEEM_BUTTON_BORDER_COLOR)
     53         self.buttonBackgroundColor = attributes.get('redeemButtonBackgroundColor', REDEEM_BUTTON_BACKGROUND_COLOR)
     54         self.buttonFillColor = attributes.get('redeemButtonFillColor', REDEEM_BUTTON_FILL_COLOR)
     55         self.panelBackgroundColor = attributes.get('redeemPanelBackgroundColor', REDEEM_PANEL_BACKGROUND_COLOR)
     56         self.controller = Controller(redeem_data=self.redeemData, redeem_service=sm.GetService('redeem'), home_station_service=homestation.Service.instance())
     57 
     58     def _ConstructRedeemButton(self):
     59         self.redeemButton = RedeemButton(name='RedeemPanel_Button', parent=self, align=uiconst.TOTOP, state=uiconst.UI_NORMAL, height=REDEEM_BUTTON_HEIGHT, OnClick=self.buttonOnClick, borderColor=self.buttonBorderColor, backgroundColor=self.buttonBackgroundColor, fillColor=self.buttonFillColor, textColor=self.textColor, animationDuration=self.animationDuration, controller=self.controller)
     60 
     61     def _ConstructRedeemItems(self):
     62         self.redeemContainer = RedeemItemsContainer(name='RedeemPanel_ItemsContainer', parent=self, align=uiconst.TOTOP, state=uiconst.UI_NORMAL, height=REDEEM_ITEMS_HEIGHT, redeemData=self.redeemData, controller=self.controller, areItemsDraggable=True, showHeaderCount=False, showDeliveryInfo=False, showFooter=False, onContentUpdateCallback=self.OnContentUpdated, sidePadding=8, topPadding=REDEEM_ITEMS_PADDING_TOP, bottomPadding=REDEEM_ITEMS_PADDING_BOTTOM)
     63 
     64     def _ConstructCenterSection(self):
     65         Fill(name='RedeemPanel_CenterSection', bgParent=self, color=self.panelBackgroundColor, opacity=0.8)
     66 
     67     def IsCollapsed(self):
     68         return self.isCollapsed
     69 
     70     def OnContentUpdated(self):
     71         if self.destroyed:
     72             return
     73         self.UpdateVisibility()
     74         self.UpdateSizes()
     75 
     76     def UpdateVisibility(self):
     77         areTokensAvailable = self.redeemContainer.HasTokens()
     78         isRedeemContainerVisible = self.redeemContainer.IsVisible()
     79         if isRedeemContainerVisible and not areTokensAvailable:
     80             self.HidePanel()
     81             return True
     82         if not isRedeemContainerVisible and areTokensAvailable:
     83             self.ShowPanel()
     84             return True
     85         return False
     86 
     87     def UpdateSizes(self):
     88         self.height = self.GetCollapsedHeight() if self.IsCollapsed() else self.GetExpandedHeight()
     89 
     90     def GetExpandedHeight(self):
     91         return self.redeemButton.height + self.redeemContainer.height
     92 
     93     def GetCollapsedHeight(self):
     94         return self.redeemButton.height
     95 
     96     def ChangeCollapsedState(self):
     97         if self.isCollapsed:
     98             self.ExpandPanel()
     99         else:
    100             self.CollapsePanel()
    101         if self.onCollapsibilityChanged:
    102             self.onCollapsibilityChanged()
    103 
    104     def ShowPanel(self, animate = True):
    105         if self.IsHidden() and animate:
    106             self.CollapsePanel(animate=False)
    107             self.top = -self.height
    108             self.Show()
    109             startTop = self.top
    110             endTop = 0
    111             uicore.animations.MorphScalar(self, 'top', startTop, endTop, self.animationDuration)
    112         else:
    113             self.top = 0
    114             self.Show()
    115 
    116     def HidePanel(self, animate = True):
    117         if not self.IsHidden() and animate:
    118             timeOffset = 0.0
    119             if not self.isCollapsed:
    120                 self._Collapse(animate)
    121                 timeOffset = self.animationDuration
    122             startTop = self.top
    123             endTop = -self.GetCollapsedHeight()
    124             animation = uicore.animations.MorphScalar
    125             animation(self, 'top', startTop, endTop, self.animationDuration, timeOffset=timeOffset, callback=self.Hide)
    126         else:
    127             self.top = -self.height
    128             self.Hide()
    129 
    130     def ExpandPanel(self, animate = True):
    131         self.redeemButton.Expand(animate)
    132         startHeight = self.height
    133         endHeight = self.GetExpandedHeight()
    134         if animate:
    135             uicore.animations.MorphScalar(self, 'height', startHeight, endHeight, self.animationDuration)
    136         else:
    137             self.height = endHeight
    138         self.isCollapsed = False
    139 
    140     def CollapsePanel(self, animate = True):
    141         self.redeemButton.Collapse(animate)
    142         self._Collapse(animate)
    143         self.isCollapsed = True
    144 
    145     def _Collapse(self, animate):
    146         startHeight = self.height
    147         endHeight = self.GetCollapsedHeight()
    148         if animate:
    149             uicore.animations.MorphScalar(self, 'height', startHeight, endHeight, self.animationDuration)
    150         else:
    151             self.height = endHeight
    152 
    153     def Hide(self):
    154         wasHidden = self.IsHidden()
    155         super(RedeemPanelNew, self).Hide()
    156         if not wasHidden and self.onVisibilityChanged:
    157             self.onVisibilityChanged()
    158 
    159     def Show(self):
    160         wasHidden = self.IsHidden()
    161         super(RedeemPanelNew, self).Show()
    162         if wasHidden and self.onVisibilityChanged:
    163             self.onVisibilityChanged()
    164 
    165     def FadeOut(self):
    166         if self.IsHidden():
    167             return
    168         startVal = self.opacity
    169         endVal = 0.0
    170         uicore.animations.MorphScalar(self, 'opacity', startVal, endVal, duration=self.animationDuration)
    171 
    172 
    173 class RedeemButton(Transform):
    174     default_name = 'RedeemButton'
    175 
    176     def ApplyAttributes(self, attributes):
    177         Transform.ApplyAttributes(self, attributes)
    178         borderColor = attributes.get('borderColor', REDEEM_BUTTON_BORDER_COLOR)
    179         backgroundColor = attributes.get('backgroundColor', REDEEM_BUTTON_BACKGROUND_COLOR)
    180         fillColor = attributes.get('fillColor', REDEEM_BUTTON_FILL_COLOR)
    181         textColor = attributes.get('textColor', TEXT_COLOR)
    182         self.animationDuration = attributes.get('animationDuration', DEFAULT_ANIMATION_DURATION)
    183         controller = attributes.controller
    184         Line(parent=self, color=borderColor, align=uiconst.TOTOP, weight=1)
    185         Fill(bgParent=self, color=backgroundColor)
    186         borderFillColor = fillColor[:3]
    187         self.borderFill = GradientSprite(bgParent=self, rgbData=[(0, borderFillColor), (0.5, borderFillColor), (1.0, borderFillColor)], alphaData=[(0.3, 0.1), (0.5, 0.4), (0.7, 0.1)], idx=0, state=uiconst.UI_DISABLED)
    188         self.onClick = attributes.get('OnClick', None)
    189         self.captionCont = Container(parent=self, name='captionCont', align=uiconst.CENTERTOP)
    190         self.expanderIcon = Sprite(parent=self.captionCont, texturePath='res:/UI/Texture/Icons/105_32_5.png', align=uiconst.CENTERRIGHT, pos=(0, 0, 32, 32), state=uiconst.UI_DISABLED, color=textColor)
    191         self.availableLabel = EveCaptionMedium(parent=self.captionCont, align=uiconst.CENTERLEFT, text=GetByLabel('UI/RedeemWindow/RedeemableItems'), state=uiconst.UI_DISABLED, color=textColor, bold=False)
    192         self.availableLabel.letterspace = 1
    193         self.captionCont.width = self.availableLabel.textwidth + 10 + self.expanderIcon.width
    194         self.captionCont.height = max(self.availableLabel.textheight + 10, self.expanderIcon.height)
    195         self.height = self.captionCont.height
    196         leftPadding = 20
    197         availableSpace = (uicore.desktop.width - self.captionCont.width - leftPadding) / 2
    198         self.controlCont = ControlContainer(parent=self, align=uiconst.CENTERRIGHT, controller=controller, left=leftPadding, availableSpace=availableSpace)
    199         push = sm.GetService('window').GetCameraLeftOffset(self.captionCont.width, align=uiconst.CENTERTOP, left=0)
    200         self.captionCont.left = push
    201 
    202     def Expand(self, animate = True):
    203         PlaySound(uiconst.SOUND_EXPAND)
    204         self.Animate(0, animate)
    205         self.ShowOrHideControls(1, animate)
    206 
    207     def Collapse(self, animate = True):
    208         PlaySound(uiconst.SOUND_COLLAPSE)
    209         self.Animate(pi, animate)
    210         self.ShowOrHideControls(0, animate)
    211 
    212     def Animate(self, endVal, animate):
    213         if animate:
    214             startVal = self.expanderIcon.rotation
    215             uicore.animations.MorphScalar(self.expanderIcon, 'rotation', startVal, endVal, self.animationDuration)
    216             uicore.animations.FadeOut(self.controlCont, duration=self.animationDuration)
    217         else:
    218             self.expanderIcon.rotation = endVal
    219             uicore.animations.FadeIn(self.controlCont, duration=self.animationDuration)
    220 
    221     def ShowOrHideControls(self, display, animate):
    222         if animate:
    223             if display:
    224                 self.controlCont.Show()
    225                 uicore.animations.FadeIn(self.controlCont, duration=self.animationDuration, callback=self.controlCont.Show)
    226             else:
    227                 uicore.animations.FadeOut(self.controlCont, duration=self.animationDuration, callback=self.controlCont.Hide)
    228         else:
    229             self.controlCont.display = False
    230 
    231     def DefaultOnClick(self):
    232         pass
    233 
    234     def OnClick(self, *args):
    235         if self.onClick:
    236             self.onClick()
    237 
    238     def OnMouseEnter(self, *args):
    239         PlaySound(uiconst.SOUND_BUTTON_HOVER)