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

vgsUiPrimitives.py (17836B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\view\aurumstore\vgsUiPrimitives.py
      2 import blue
      3 import eveicon
      4 import trinity
      5 from carbon.common.script.sys.serviceConst import ROLE_PROGRAMMER
      6 from carbonui import const as uiconst
      7 from carbonui.control.combo import Combo
      8 from carbonui.fontconst import STYLE_HEADER, STYLE_DEFAULT
      9 from carbonui.primitives.container import Container
     10 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     11 from carbonui.primitives.fill import Fill
     12 from carbonui.primitives.gradientSprite import GradientSprite
     13 from carbonui.primitives.sprite import Sprite
     14 from carbonui.uianimations import animations
     15 from carbonui.uicore import uicore
     16 from carbonui.util.color import Color
     17 from eve.client.script.ui.control.eveLabel import Label, EveCaptionLarge
     18 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel
     19 from eve.client.script.ui.util.uiComponents import Component, ButtonEffect, RadioButtonEffect
     20 from eve.client.script.ui.view.aurumstore.vgsHelper import LoadImageToSprite
     21 from eve.client.script.ui.view.aurumstore.vgsUiConst import VGS_FONTSIZE_OFFER, VGS_WHITE_TEXT_COLOR
     22 from eve.client.script.ui.view.aurumstore.vgsUiConst import VGS_SPECIAL_PRICE_COLOR, VGS_AUR_TEXT_COLOR
     23 from eve.client.script.ui.view.aurumstore.vgsUiConst import CATEGORY_TEXT_COLOR, HEADER_BG_COLOR
     24 from eve.client.script.ui.view.aurumstore.vgsUiConst import TAG_COLOR, CATEGORY_COLOR
     25 from eve.client.script.ui.view.aurumstore.vgsUiConst import TAG_GLOW_COLOR
     26 from eve.client.script.ui.view.aurumstore.vgsUiConst import CATEGORY_GLOW_COLOR
     27 from eve.client.script.ui.view.aurumstore.vgsUiConst import SUBCATEGORY_TEXT_COLOR
     28 from eve.client.script.ui.view.aurumstore.vgsUiConst import BUY_AUR_BUTTON_COLOR, BUY_BUTTON_FONT_COLOR
     29 from eve.client.script.ui.view.aurumstore.vgsUiConst import VGS_FONTSIZE_SMALL, VGS_FONTSIZE_MEDIUM, VGS_FONTSIZE_LARGE
     30 from localization import GetByLabel
     31 from math import pi
     32 from uthread2 import StartTasklet
     33 TAG_TEXT_PADDING = 16
     34 DEFAULT_BUTTON_PADDING = 16
     35 AUR_COLOR_HEX = Color(*VGS_AUR_TEXT_COLOR).GetHex()
     36 SPECIAL_COLOR_HEX = Color(*VGS_SPECIAL_PRICE_COLOR).GetHex()
     37 
     38 class VgsLabelLarge(Label):
     39     default_name = 'VgsLabelLarge'
     40     default_fontsize = VGS_FONTSIZE_LARGE
     41     default_uppercase = True
     42     default_fontStyle = STYLE_HEADER
     43 
     44 
     45 class VgsLabelMedium(Label):
     46     default_name = 'VgsLabelMedium'
     47     default_fontsize = VGS_FONTSIZE_MEDIUM
     48     default_uppercase = True
     49     default_fontStyle = STYLE_HEADER
     50 
     51 
     52 class VgsLabelSmall(Label):
     53     default_name = 'VgsLabelSmall'
     54     default_fontsize = VGS_FONTSIZE_SMALL
     55 
     56 
     57 class VgsLabelSubCategories(Label):
     58     default_fontsize = VGS_FONTSIZE_MEDIUM
     59 
     60 
     61 class VgsLabelRibbon(Label):
     62     default_name = 'VgsLabelRibbon'
     63     default_fontsize = 14
     64     default_uppercase = True
     65     default_bold = True
     66     default_fontStyle = STYLE_DEFAULT
     67     default_blendMode = trinity.TR2_SBM_NONE
     68 
     69 
     70 class VgsLabelRibbonLarge(Label):
     71     default_name = 'VgsLabelRibbon'
     72     default_fontsize = 22
     73     default_uppercase = True
     74     default_bold = True
     75     default_fontStyle = STYLE_DEFAULT
     76     default_blendMode = trinity.TR2_SBM_NONE
     77 
     78 
     79 class VgsLabelAurSmall(Label):
     80     default_name = 'VgsLabelAurSmall'
     81     default_fontsize = VGS_FONTSIZE_SMALL
     82     default_uppercase = True
     83     default_bold = True
     84     default_color = VGS_AUR_TEXT_COLOR
     85     default_text = GetByLabel('UI/Wallet/WalletWindow/AUR')
     86 
     87 
     88 class VgsLabelAurLarge(VgsLabelAurSmall):
     89     default_name = 'VgsLabelAurLarge'
     90     default_fontsize = VGS_FONTSIZE_MEDIUM
     91 
     92 
     93 class AurAmountContainer(ContainerAutoSize):
     94     default_name = 'AurLabel'
     95     amountSize = VGS_FONTSIZE_OFFER
     96     aurSize = VGS_FONTSIZE_SMALL
     97     wordPadding = 8
     98     default_shouldUseUnits = True
     99 
    100     def ApplyAttributes(self, attributes):
    101         ContainerAutoSize.ApplyAttributes(self, attributes)
    102         self.shouldUseUnits = attributes.get('shouldUseUnits', self.default_shouldUseUnits)
    103         self.amountLabel = None
    104         self.baseAmountLabel = None
    105         if attributes.amountSize:
    106             self.amountSize = attributes.amountSize
    107         if attributes.aurSize:
    108             self.aurSize = attributes.aurSize
    109         amount = attributes.amount
    110         baseAmount = attributes.baseAmount
    111         self.amountLabel = self.AddAurSection(amount)
    112         if baseAmount is not None and amount != baseAmount:
    113             self.baseAmountLabel = self.AddAurSection(baseAmount, color=VGS_SPECIAL_PRICE_COLOR, strikeThrough=True)
    114 
    115     def AddAurSection(self, amount, color = None, strikeThrough = False):
    116         cont = Container(parent=self, align=uiconst.TOLEFT, padRight=self.wordPadding)
    117         if strikeThrough:
    118             Sprite(parent=cont, align=uiconst.TOALL, texturePath='res:/UI/Texture/Vgs/strikethrough.png', padding=(0, 0, 0, 0), color=color or VGS_WHITE_TEXT_COLOR, state=uiconst.UI_DISABLED)
    119         amountLabel = Label(parent=cont, align=uiconst.CENTER, fontsize=self.amountSize, color=color or VGS_WHITE_TEXT_COLOR)
    120         aurLabelColor = SPECIAL_COLOR_HEX if color else AUR_COLOR_HEX
    121         SetAmountForAurLabel(amountLabel, amount, self.aurSize, aurLabelColor, self.shouldUseUnits)
    122         return amountLabel
    123 
    124     def SetAmount(self, amount, baseAmount = None):
    125         SetAmountForAurLabel(self.amountLabel, amount, self.aurSize, AUR_COLOR_HEX, self.shouldUseUnits)
    126         if baseAmount and amount != baseAmount:
    127             SetAmountForAurLabel(self.baseAmountLabel, baseAmount, self.aurSize, SPECIAL_COLOR_HEX, self.shouldUseUnits)
    128 
    129 
    130 def _GetAurText(amount, aurSize, color, shouldUseUnits):
    131     if shouldUseUnits:
    132         return GetByLabel('UI/VirtualGoodsStore/OfferPriceLabel', amount=amount, size=aurSize, color=color)
    133     return GetByLabel('UI/VirtualGoodsStore/OfferPriceLabelNoUnit', amount=amount)
    134 
    135 
    136 def SetAmountForAurLabel(label, amount, aurSize, color, shouldUseUnits = True):
    137     label.SetText(text=_GetAurText(amount, aurSize, color, shouldUseUnits))
    138     label.parent.width = label.textwidth
    139 
    140 
    141 class AurLabelLarge(AurAmountContainer):
    142     default_name = 'AurLabelLarge'
    143     amountSize = VGS_FONTSIZE_LARGE
    144     aurSize = VGS_FONTSIZE_MEDIUM
    145     wordPadding = 12
    146 
    147 
    148 class AurLabelHeader(AurAmountContainer):
    149     default_name = 'AurLabelLarge'
    150     amountSize = VGS_FONTSIZE_LARGE
    151     aurSize = VGS_FONTSIZE_MEDIUM
    152     wordPadding = 0
    153 
    154 
    155 class GemAmountContainer(ContainerAutoSize):
    156     default_name = 'GemLabel'
    157     amountSize = VGS_FONTSIZE_OFFER
    158     gemSize = VGS_FONTSIZE_MEDIUM
    159     wordPadding = 8
    160     default_shouldUseUnits = True
    161 
    162     def ApplyAttributes(self, attributes):
    163         ContainerAutoSize.ApplyAttributes(self, attributes)
    164         self.shouldUseUnits = attributes.get('shouldUseUnits', self.default_shouldUseUnits)
    165         self.amountLabel = None
    166         self.baseAmountLabel = None
    167         if attributes.amountSize:
    168             self.amountSize = attributes.amountSize
    169         if attributes.gemSize:
    170             self.gemSize = attributes.gemSize
    171         amount = attributes.amount
    172         baseAmount = attributes.baseAmount
    173         self.amountLabel = self.AddGemSection(amount)
    174         if baseAmount is not None and amount != baseAmount:
    175             self.baseAmountLabel = self.AddGemSection(baseAmount, color=VGS_SPECIAL_PRICE_COLOR, strikeThrough=True)
    176 
    177     def AddGemSection(self, amount, color = None, strikeThrough = False):
    178         cont = Container(parent=self, align=uiconst.TOLEFT, padRight=self.wordPadding)
    179         if strikeThrough:
    180             Sprite(parent=cont, align=uiconst.TOALL, texturePath='res:/UI/Texture/Vgs/strikethrough.png', padding=(0, 0, 0, 0), color=color or VGS_WHITE_TEXT_COLOR, state=uiconst.UI_DISABLED)
    181         amountLabel = Label(parent=cont, align=uiconst.CENTER, fontsize=self.amountSize, color=color or VGS_WHITE_TEXT_COLOR)
    182         gemLabelColor = SPECIAL_COLOR_HEX if color else AUR_COLOR_HEX
    183         SetAmountGemLabel(amountLabel, amount, self.gemSize, gemLabelColor, self.shouldUseUnits)
    184         return amountLabel
    185 
    186     def SetAmount(self, amount, baseAmount = None):
    187         SetAmountGemLabel(self.amountLabel, amount, self.gemSize, AUR_COLOR_HEX, self.shouldUseUnits)
    188         if baseAmount and amount != baseAmount:
    189             SetAmountGemLabel(self.baseAmountLabel, baseAmount, self.gemSize, SPECIAL_COLOR_HEX, self.shouldUseUnits)
    190 
    191 
    192 def _GetGemText(amount, gemSize, color, shouldUseUnits):
    193     if shouldUseUnits:
    194         return GetByLabel('UI/VirtualGoodsStore/FormatAUR', amount=amount, size=gemSize, color=color)
    195     return GetByLabel('UI/VirtualGoodsStore/FormatAURNoUnit', amount=amount)
    196 
    197 
    198 def SetAmountGemLabel(label, amount, gemSize, color, shouldUseUnits = True):
    199     label.SetText(text=_GetGemText(amount, gemSize, color, shouldUseUnits))
    200     label.parent.width = label.textwidth
    201 
    202 
    203 class GemLabelHeader(GemAmountContainer):
    204     default_name = 'GemLabelLarge'
    205     amountSize = VGS_FONTSIZE_LARGE
    206     aurSize = VGS_FONTSIZE_MEDIUM
    207     wordPadding = 0
    208 
    209 
    210 @Component(ButtonEffect())
    211 
    212 class ExitButton(Container):
    213     default_name = 'exitButton'
    214     default_width = 16
    215     default_height = 16
    216     default_state = uiconst.UI_NORMAL
    217 
    218     def ApplyAttributes(self, attributes):
    219         Container.ApplyAttributes(self, attributes)
    220         self.onClick = attributes.onClick
    221         Sprite(parent=self, texturePath=eveicon.close, width=16, height=16, align=uiconst.CENTER, state=uiconst.UI_DISABLED, color=Color.GRAY7)
    222 
    223     def OnClick(self):
    224         self.onClick()
    225 
    226 
    227 @Component(ButtonEffect(opacityIdle=0.0, opacityHover=0.25, opacityMouseDown=0.5, bgElementFunc=lambda parent, _: parent.highlight))
    228 
    229 class LogoHomeButton(Container):
    230     default_name = 'LogoHomeButton'
    231     default_width = 280
    232     default_height = 100
    233     default_state = uiconst.UI_NORMAL
    234     logoTexturePath = 'res:/UI/Texture/Vgs/storeLogo.png'
    235     highlightTexturePath = 'res:/UI/Texture/Vgs/storeLogoGlow.png'
    236 
    237     def ApplyAttributes(self, attributes):
    238         Container.ApplyAttributes(self, attributes)
    239         logoTexturePath = attributes.logoTexturePath or self.logoTexturePath
    240         highlightTexturePath = attributes.highlightTexturePath or self.highlightTexturePath
    241         Sprite(name='Logo', bgParent=self, texturePath=logoTexturePath)
    242         self.highlight = Sprite(name='Highlight', bgParent=self, texturePath=highlightTexturePath)
    243         self.onClick = attributes.onClick
    244 
    245     def OnClick(self):
    246         self.onClick()
    247 
    248 
    249 @Component(ButtonEffect())
    250 
    251 class RedeemingQueueButton(Container):
    252     default_name = 'redeemingQueueButton'
    253     default_state = uiconst.UI_NORMAL
    254 
    255     def ApplyAttributes(self, attributes):
    256         Container.ApplyAttributes(self, attributes)
    257         self.label = EveCaptionLarge(parent=self, align=uiconst.CENTER, text=GetByLabel('UI/CharacterSelection/RedeemItems'))
    258         self.width = max(attributes.width, self.label.width + 2 * DEFAULT_BUTTON_PADDING)
    259         self.sprite = Sprite(parent=self, width=self.width, height=attributes.height, texturePath='res:\\UI\\Texture\\redeem_bar.png', bgColor=attributes.bgColor, state=uiconst.UI_DISABLED, align=uiconst.CENTER)
    260 
    261 
    262 @Component(ButtonEffect())
    263 
    264 class HeaderBuyPlexButton(Container):
    265     default_state = uiconst.UI_NORMAL
    266     default_padding = (4, 2, 4, 2)
    267     textPadding = (8, 4)
    268 
    269     def ApplyAttributes(self, attributes):
    270         Container.ApplyAttributes(self, attributes)
    271         Fill(bgParent=self, color=BUY_AUR_BUTTON_COLOR, opacity=1.0)
    272         label = VgsLabelMedium(parent=self, align=uiconst.CENTER, text=GetByLabel('UI/VirtualGoodsStore/BuyAurOnline'), color=BUY_BUTTON_FONT_COLOR)
    273         horizontalPadding, verticalPadding = self.textPadding
    274         width, _ = label.GetAbsoluteSize()
    275         self.width = width + 2 * horizontalPadding
    276         self.height = label.textheight + 2 * verticalPadding
    277         self.OnClick = attributes.onClick
    278 
    279 
    280 @Component(ButtonEffect())
    281 
    282 class HeaderBuyGemButton(Container):
    283     default_state = uiconst.UI_NORMAL
    284     default_padding = (4, 2, 4, 2)
    285     textPadding = (8, 4)
    286 
    287     def ApplyAttributes(self, attributes):
    288         Container.ApplyAttributes(self, attributes)
    289         Fill(bgParent=self, color=BUY_AUR_BUTTON_COLOR, opacity=1.0)
    290         label = VgsLabelMedium(parent=self, align=uiconst.CENTER, text=GetByLabel('UI/VirtualGoodsStore/BuyGemOnline'), color=BUY_BUTTON_FONT_COLOR)
    291         horizontalPadding, verticalPadding = self.textPadding
    292         self.width = 90 + 2 * horizontalPadding
    293         self.height = label.textheight + 2 * verticalPadding
    294         self.OnClick = attributes.onClick
    295 
    296 
    297 @Component(ButtonEffect())
    298 
    299 class DetailButton(Container):
    300     default_state = uiconst.UI_NORMAL
    301     default_height = 30
    302     textPadding = (8, 4)
    303 
    304     def ApplyAttributes(self, attributes):
    305         Container.ApplyAttributes(self, attributes)
    306         if attributes.textPadding:
    307             self.textPadding = attributes.textPadding
    308         self.color = Fill(bgParent=self, color=attributes.color, opacity=1.0)
    309         self.label = VgsLabelMedium(parent=self, align=uiconst.CENTER, text=attributes.label, color=BUY_BUTTON_FONT_COLOR)
    310         self.SetText(attributes.label)
    311         self.OnClick = attributes.onClick
    312 
    313     def SetText(self, text, animate = False):
    314         self.label.SetText(text)
    315         horizontalPadding, verticalPadding = self.textPadding
    316         if animate:
    317             animations.MorphScalar(self, 'width', startVal=self.width, endVal=self.label.textwidth + 2 * horizontalPadding)
    318             animations.MorphScalar(self, 'height', startVal=self.height, endVal=self.label.textheight + 2 * verticalPadding)
    319         else:
    320             self.width = self.label.textwidth + 2 * horizontalPadding
    321             self.height = self.label.textheight + 2 * verticalPadding
    322 
    323 
    324 @Component(RadioButtonEffect(bgElementFunc=lambda parent, _: parent.highlight, opacityHover=0.3, opacityMouseDown=0.9, audioOnEntry='store_menuhover', audioOnClick='store_click'))
    325 
    326 class CategoryButton(Container):
    327     default_state = uiconst.UI_NORMAL
    328 
    329     def ApplyAttributes(self, attributes):
    330         Container.ApplyAttributes(self, attributes)
    331         self.categoryId = attributes.categoryId
    332         self.highlight = Sprite(name='hoverGradient', bgParent=self, texturePath='res:/UI/Texture/Vgs/store-button-gradient.png', color=CATEGORY_GLOW_COLOR)
    333         Fill(name='BackgroundColor', bgParent=self, color=HEADER_BG_COLOR)
    334         self.label = VgsLabelMedium(parent=self, text=attributes.label, align=uiconst.CENTER, state=uiconst.UI_DISABLED, color=CATEGORY_TEXT_COLOR, top=-1)
    335         self.onClick = attributes.onClick
    336 
    337     def OnClick(self, *args):
    338         self.onClick(self.categoryId)
    339 
    340     def OnActiveStateChange(self):
    341         if self.isActive:
    342             self.label.SetTextColor(Color.WHITE)
    343         else:
    344             self.label.SetTextColor(CATEGORY_TEXT_COLOR)
    345 
    346     def GetMenu(self, *args):
    347         if session.role & ROLE_PROGRAMMER:
    348             return [('categoryId: %s' % self.categoryId, lambda : blue.pyos.SetClipboardData(str(self.categoryId)))]
    349 
    350 
    351 @Component(RadioButtonEffect(bgElementFunc=lambda parent, _: parent.highlight, opacityHover=0.3, opacityMouseDown=0.7, audioOnEntry='store_menuhover', audioOnClick='store_click'))
    352 
    353 class SubCategoryButton(Container):
    354     default_state = uiconst.UI_NORMAL
    355 
    356     def ApplyAttributes(self, attributes):
    357         Container.ApplyAttributes(self, attributes)
    358         self.categoryId = attributes.categoryId
    359         self.highlight = Sprite(name='hoverGradient', bgParent=self, texturePath='res:/UI/Texture/Vgs/store-button-gradient2.png', color=TAG_GLOW_COLOR)
    360         Fill(name='BackgroundColor', bgParent=self, color=TAG_COLOR)
    361         self.label = VgsLabelMedium(text=attributes.label, parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, color=SUBCATEGORY_TEXT_COLOR, top=-1)
    362         self.width = self.label.actualTextWidth + 2 * TAG_TEXT_PADDING
    363         self.onClick = attributes.onClick
    364 
    365     def OnClick(self, *args):
    366         self.onClick(self.categoryId)
    367 
    368     def OnActiveStateChange(self):
    369         if self.isActive:
    370             self.label.SetTextColor(Color.WHITE)
    371         else:
    372             self.label.SetTextColor(SUBCATEGORY_TEXT_COLOR)
    373 
    374     def GetMenu(self, *args):
    375         if session.role & ROLE_PROGRAMMER:
    376             return [('categoryId: %s' % self.categoryId, lambda : blue.pyos.SetClipboardData(str(self.categoryId)))]
    377 
    378 
    379 class VgsFilterCombo(Combo):
    380     default_adjustWidth = True
    381     default_name = 'VgsFilterCombo'
    382 
    383     def Prepare_Underlay_(self):
    384         self.sr.backgroundFrame = GradientSprite(bgParent=self, rotation=-pi / 2, rgbData=[(0, (1.0, 1.0, 1.0))], alphaData=[(0, 0.5), (0.3, 0.2), (0.6, 0.08)], opacity=0.0)
    385         Fill(bgParent=self, name='BackgroundColor', color=CATEGORY_COLOR)
    386 
    387     def Prepare_SelectedText_(self):
    388         super(VgsFilterCombo, self).Prepare_SelectedText_()
    389 
    390 
    391 class LazyUrlSprite(Container):
    392     default_name = 'LazyUrlSprite'
    393     default_clipChildren = False
    394 
    395     def ApplyAttributes(self, attributes):
    396         Container.ApplyAttributes(self, attributes)
    397         loadSize = attributes.loadSize or 100
    398         self.loadingWheel = LoadingWheel(parent=self, align=uiconst.CENTER, width=loadSize, height=loadSize, opacity=0.2)
    399         self.spriteBackgroundFill = Container(parent=self, align=uiconst.TOALL, bgColor=attributes.spriteBgFill or (0.0, 0.0, 0.0, 0.0), opacity=0.0)
    400         self.spriteContainer = Container(parent=self.spriteBackgroundFill, align=uiconst.TOALL)
    401         self.sprite = Sprite(bgParent=self.spriteContainer, align=uiconst.TOALL)
    402         self.SetImageFromUrl(attributes.imageUrl)
    403 
    404     def SetImageFromUrl(self, imageUrl):
    405         StartTasklet(self._SetImageFromUrl, imageUrl)
    406 
    407     def _SetImageFromUrl(self, imageUrl):
    408         LoadImageToSprite(self.sprite, imageUrl)
    409         uicore.animations.FadeIn(self.spriteBackgroundFill)
    410         uicore.animations.SpMaskIn(self.sprite, duration=1)
    411         self.loadingWheel.Close()