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

offer.py (7303B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\vgs\offer.py
      2 from carbonui import const as uiconst
      3 from carbonui.primitives.container import Container
      4 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      5 from carbonui.primitives.gradientSprite import GradientSprite
      6 from carbonui.primitives.layoutGrid import LayoutGrid, LayoutGridRow
      7 from carbonui.primitives.sprite import Sprite
      8 from carbonui.primitives.transform import Transform
      9 from eve.client.script.ui.control.eveIcon import Icon
     10 from eve.client.script.ui.control.infoIcon import InfoIcon
     11 from vgs.client.currency import OFFER_CURRENCY_PLEX
     12 from eve.client.script.ui.shared.vgs.label import VgsLabelSmall, VgsHeaderLarge, VgsHeaderMedium, PlexPriceTag
     13 from eve.client.script.ui.view.aurumstore.shared.offerpricing import get_offer_price_and_base_price_in_currency
     14 from eve.client.script.ui.view.aurumstore.vgsUiPrimitives import LazyUrlSprite
     15 from eve.client.script.ui.util.uix import GetTechLevelIcon
     16 import evetypes
     17 from inventorycommon.const import categoryBlueprint
     18 import localization
     19 from utillib import KeyVal
     20 from eveservices.menu import GetMenuService
     21 
     22 class Ribbon(ContainerAutoSize):
     23     default_name = 'Ribbon'
     24     default_state = uiconst.UI_DISABLED
     25     default_align = uiconst.TOPLEFT
     26     default_left = 8
     27     FONT_CLASS = VgsHeaderMedium
     28     FONT_BOLD = True
     29     PADDING = (10, 2, 10, 2)
     30 
     31     def ApplyAttributes(self, attributes):
     32         super(Ribbon, self).ApplyAttributes(attributes)
     33         Sprite(bgParent=self, texturePath=attributes.label.url)
     34         self.FONT_CLASS(parent=self, align=uiconst.TOPLEFT, text=attributes.label.description, bold=self.FONT_BOLD, uppercase=True, padding=self.PADDING)
     35 
     36 
     37 class Offer(Container):
     38     default_clipChildren = True
     39     default_showDescription = True
     40     default_showPrice = False
     41     default_showImage = True
     42     BACKGROUND_COLOR = (0.349, 0.439, 0.529, 1.0)
     43     RADIAL_SHADOW = (0.196, 0.208, 0.224)
     44     TEXT_BOX_COLOR = (0.133, 0.141, 0.149, 0.5)
     45     PADDING_BIG = 10
     46     TITLE_FONT_CLASS = VgsHeaderLarge
     47     DESCRIPTION_FONT_CLASS = VgsLabelSmall
     48     RIBBON_TYPE = Ribbon
     49     RIBBON_ALIGN = uiconst.TOPLEFT
     50 
     51     def ApplyAttributes(self, attributes):
     52         super(Offer, self).ApplyAttributes(attributes)
     53         self.offer = attributes.offer
     54         self.description = attributes.get('showDescription', self.default_showDescription)
     55         self.price = attributes.get('showPrice', self.default_showPrice)
     56         self.image = attributes.get('showImage', self.default_showImage)
     57         self.onClick = attributes.get('onClick', None)
     58         self.Layout()
     59 
     60     def Layout(self):
     61         self.imageLayer = Transform(parent=self, align=uiconst.CENTER, scalingCenter=(0.5, 0.5), bgColor=self.BACKGROUND_COLOR)
     62         GradientSprite(align=uiconst.TOALL, bgParent=self.imageLayer, rgbData=((1.0, self.RADIAL_SHADOW),), alphaData=((0.0, 0.0), (1.0, 1.0)), radial=True, idx=0)
     63         if self.image:
     64             self.lazySprite = LazyUrlSprite(parent=self.imageLayer, align=uiconst.TOALL, imageUrl=self.offer.imageUrl, state=uiconst.UI_DISABLED)
     65         descriptionBox = ContainerAutoSize(parent=self, align=uiconst.TOBOTTOM, bgColor=self.TEXT_BOX_COLOR, clipChildren=True, idx=0)
     66         if self.price:
     67             offer_price, base_price = get_offer_price_and_base_price_in_currency(self.offer, OFFER_CURRENCY_PLEX)
     68             PlexPriceTag(parent=descriptionBox, align=uiconst.TOBOTTOM, amount=offer_price, baseAmount=base_price, padding=(self.PADDING_BIG,
     69              0,
     70              self.PADDING_BIG,
     71              10))
     72         if self.description:
     73             self.DESCRIPTION_FONT_CLASS(parent=descriptionBox, align=uiconst.TOBOTTOM, text=self.offer.description, padding=(self.PADDING_BIG,
     74              0,
     75              self.PADDING_BIG,
     76              10))
     77         self.TITLE_FONT_CLASS(parent=descriptionBox, align=uiconst.TOBOTTOM, text=self.offer.name, padding=(self.PADDING_BIG,
     78          2,
     79          self.PADDING_BIG + 32,
     80          2))
     81         if self.offer.label is not None:
     82             self.RIBBON_TYPE(parent=self, align=self.RIBBON_ALIGN, label=self.offer.label, idx=0)
     83 
     84     def OnClick(self, *args):
     85         if callable(self.onClick):
     86             self.onClick()
     87 
     88     def UpdateAlignment(self, budgetLeft = 0, budgetTop = 0, budgetWidth = 0, budgetHeight = 0, updateChildrenOnly = False):
     89         size = max(self.displayWidth, self.displayHeight)
     90         self.imageLayer.width = size
     91         self.imageLayer.height = size
     92         return super(Offer, self).UpdateAlignment(budgetLeft, budgetTop, budgetWidth, budgetHeight, updateChildrenOnly=updateChildrenOnly)
     93 
     94 
     95 class OfferProductList(LayoutGrid):
     96     default_name = 'OfferProductList'
     97     default_columns = 2
     98     default_cellSpacing = (0, 8)
     99 
    100     def ApplyAttributes(self, attributes):
    101         super(OfferProductList, self).ApplyAttributes(attributes)
    102         self.iconSize = attributes.get('iconSize', None)
    103         products = attributes.get('products', [])
    104         for product in products:
    105             self.AddProduct(product)
    106 
    107     def AddProduct(self, product):
    108         self.AddRow(rowClass=OfferProductRow, typeID=product.typeId, quantity=product.quantity, name=product.name, imageUrl=product.imageUrl, iconSize=self.iconSize)
    109 
    110 
    111 class OfferProductRow(LayoutGridRow):
    112     default_columns = 2
    113     default_iconSize = 64
    114     default_state = uiconst.UI_NORMAL
    115 
    116     def ApplyAttributes(self, attributes):
    117         super(OfferProductRow, self).ApplyAttributes(attributes)
    118         self.typeID = attributes.typeID
    119         self.quantity = attributes.get('quantity', 1)
    120         self.name = attributes.name
    121         self.imageUrl = attributes.get('imageUrl')
    122         self.iconSize = attributes.get('iconSize', None) or self.default_iconSize
    123         self.Layout()
    124 
    125     def Layout(self):
    126         self.AddCell(cellObject=self._PrepareProductIcon())
    127         self.AddCell(cellObject=self._PrepareProductLabel())
    128 
    129     def _PrepareProductIcon(self):
    130         icon = Container(name='productIcon', align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, width=self.iconSize, height=self.iconSize)
    131         techIcon = GetTechLevelIcon(typeID=self.typeID)
    132         if techIcon:
    133             techIcon.SetParent(icon)
    134         Icon(parent=icon, align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, size=self.iconSize, typeID=self.typeID, isCopy=True)
    135         return icon
    136 
    137     def _PrepareProductLabel(self):
    138         labelCont = LayoutGrid(align=uiconst.CENTERLEFT, columns=2)
    139         VgsLabelSmall(parent=labelCont, padding=(8, 0, 4, 0), text=localization.GetByLabel('UI/VirtualGoodsStore/ItemNameAndQuantity', itemName=self.name, quantity=self.quantity))
    140         InfoIcon(parent=labelCont, align=uiconst.CENTERLEFT, typeID=self.typeID, abstractinfo=self._GetAbstractInfo())
    141         return labelCont
    142 
    143     def GetMenu(self):
    144         abstractInfo = self._GetAbstractInfo()
    145         return GetMenuService().GetMenuFromItemIDTypeID(None, self.typeID, includeMarketDetails=True, abstractInfo=abstractInfo)
    146 
    147     def _GetAbstractInfo(self):
    148         if evetypes.GetCategoryID(self.typeID) != categoryBlueprint:
    149             return None
    150         bpSvc = sm.GetService('blueprintSvc')
    151         bpData = bpSvc.GetBlueprintTypeCopy(self.typeID, original=False)
    152         return KeyVal(bpData=bpData)