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

componentListingCard.py (8437B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\ship\pages\cards\componentListingCard.py
      2 import eveformat
      3 import eveicon
      4 from carbonui import Align, PickState, SpriteEffect, uiconst
      5 from carbonui.text.styles import TextBody
      6 from carbonui.text.custom import TextCustom
      7 from carbonui.primitives.container import Container
      8 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      9 from carbonui.primitives.frame import Frame
     10 from carbonui.primitives.sprite import Sprite
     11 from carbonui.uianimations import animations
     12 from carbon.common.script.util.format import FmtAmt
     13 from cosmetics.common.ships.skins.live_data.component_license_type import ComponentLicenseType
     14 from cosmetics.common.ships.skins.static_data.component_category import ComponentCategory
     15 from cosmetics.common.ships.skins.util import Currency
     16 from eve.client.script.ui import eveColor
     17 from eve.client.script.ui.cosmetics.ship.controls.numRunsIndicator import NumRunsIndicator
     18 from eve.client.script.ui.cosmetics.ship.pages.cards.baseComponentCard import ComponentCard
     19 from eve.client.script.ui.cosmetics.ship.pages.store import storeSignals
     20 from eveservices.menu import GetMenuService
     21 from localization import GetByLabel
     22 _TAG_HEIGHT = 26
     23 
     24 class ComponentListingCard(ComponentCard):
     25 
     26     def __init__(self, listing, *args, **kwargs):
     27         self.listing = listing
     28         self.name = str(self.listing.identifier)
     29         super(ComponentListingCard, self).__init__(*args, **kwargs)
     30 
     31     def construct_layout(self):
     32         self.construct_cost_container()
     33         self.construct_tag()
     34         super(ComponentListingCard, self).construct_layout()
     35 
     36     def construct_cost_container(self):
     37         self.cost_cont = ContainerAutoSize(name='const_cont', parent=self, align=Align.CENTERBOTTOM, opacity=0.5, top=58, pickState=PickState.OFF)
     38         self.cost_icon = Sprite(parent=self.cost_cont, align=Align.CENTERLEFT, pos=(0, 0, 16, 16))
     39         self.cost_label = TextBody(parent=self.cost_cont, align=Align.CENTERLEFT, left=20)
     40 
     41     def construct_tag(self):
     42         self._tag = ComponentListingCardTag(name='discount_tag', parent=self, align=Align.CENTERTOP, top=-0.4 * _TAG_HEIGHT, listing=self.listing)
     43 
     44     def get_background_texture(self):
     45         if self.listing.component_license.get_component_data().category == ComponentCategory.PATTERN:
     46             return 'res:/UI/Texture/classes/Cosmetics/Ship/cards/components/pattern_background.png'
     47         else:
     48             return 'res:/UI/Texture/classes/Cosmetics/Ship/cards/components/material_background.png'
     49 
     50     def get_rarity(self):
     51         return self.listing.component_license.get_component_data().rarity
     52 
     53     def has_unlimited_uses(self):
     54         return self.listing.component_license.license_type is ComponentLicenseType.UNLIMITED
     55 
     56     def get_uses_remaining(self):
     57         return self.listing.component_license.remaining_license_uses
     58 
     59     def get_component_name(self):
     60         return self.listing.component_license.name
     61 
     62     def get_top_line_color(self):
     63         if self.listing.is_limited_offer() or self.listing.has_discount():
     64             return eveColor.WHITE
     65         return super(ComponentListingCard, self).get_top_line_color()
     66 
     67     def get_highlight_color(self):
     68         if self.listing.is_limited_offer() or self.listing.has_discount():
     69             return eveColor.WHITE
     70         return super(ComponentListingCard, self).get_highlight_color()
     71 
     72     def get_highlight_opacity(self):
     73         if self.listing.is_limited_offer() or self.listing.has_discount():
     74             return 1.0
     75         return super(ComponentListingCard, self).get_highlight_opacity()
     76 
     77     def construct_icon(self):
     78         super(ComponentListingCard, self).construct_icon()
     79         if self.listing.component_license.get_component_data().category == ComponentCategory.PATTERN:
     80             self.icon = Sprite(name='icon', parent=self.icon_container, align=Align.CENTER, state=uiconst.UI_DISABLED, texturePath=self.listing.component_license.get_component_data().icon_file_path, textureSecondaryPath='res:/UI/Texture/classes/Cosmetics/Ship/cards/components/pattern_icon_mask.png', spriteEffect=SpriteEffect.MODULATE, glow=False, width=80, height=80)
     81         else:
     82             self.icon = Sprite(name='icon', parent=self.icon_container, align=Align.CENTER, state=uiconst.UI_DISABLED, texturePath=self.listing.component_license.get_component_data().icon_file_path, textureSecondaryPath='res:/UI/Texture/classes/Cosmetics/Ship/pages/studio/nanocoating_mask.png', spriteEffect=SpriteEffect.MODULATE, glow=False, width=64, height=64)
     83             Sprite(name='icon_ring', parent=self, align=Align.CENTERTOP, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Cosmetics/Ship/cards/components/material_ring.png', width=90, height=90, top=49)
     84 
     85     def construct_usage_indicator(self):
     86         self.usage_container = NumRunsIndicator(name='usage_container', parent=self, align=Align.TOPRIGHT, opacity=0.5, width=self.USAGE_ICON_SIZE, height=self.USAGE_ICON_SIZE, top=self.CORNER_ICON_OFFSET, left=self.CORNER_ICON_OFFSET, num_runs=self.get_uses_remaining(), licence_type=self.listing.component_license.license_type)
     87 
     88     def update(self):
     89         super(ComponentListingCard, self).update()
     90         self.update_usage_indicator()
     91         self.update_tag()
     92         self.update_cost()
     93 
     94     def update_usage_indicator(self):
     95         target_opacity = 1.0 if self.is_hovered or self.is_selected else 0.5
     96         animations.FadeTo(self.usage_container, self.usage_container.opacity, target_opacity, self.ANIM_DURATION)
     97 
     98     def update_tag(self):
     99         self._tag.display = True
    100         if self.listing.has_discount():
    101             self._tag.label_text = GetByLabel('UI/Personalization/ShipSkins/SKINR/Store/DiscountPercent', percentage=FmtAmt(self.listing.discount_percent))
    102         elif self.listing.is_limited_offer():
    103             self._tag.label_text = GetByLabel('UI/Personalization/ShipSkins/SKINR/Store/LimitedOfferTag')
    104         else:
    105             self._tag.display = False
    106 
    107     def update_cost(self):
    108         self.cost_label.text = eveformat.number(self.listing.price)
    109         if self.listing.currency == Currency.PLEX:
    110             self.cost_icon.texturePath = eveicon.plex
    111             self.cost_icon.color = eveColor.PLEX_YELLOW
    112         else:
    113             self.cost_icon.texturePath = eveicon.isk
    114             self.cost_icon.color = eveColor.WHITE
    115         target_opacity = 1.0 if self.is_hovered or self.is_selected else 0.5
    116         animations.FadeTo(self.cost_cont, self.cost_cont.opacity, target_opacity, self.ANIM_DURATION)
    117 
    118     def _on_selected(self):
    119         storeSignals.on_component_listing_selected(self.listing)
    120 
    121     def OnClick(self, *args):
    122         if self.is_selected:
    123             return
    124         super(ComponentListingCard, self).OnClick(*args)
    125 
    126     def GetMenu(self):
    127         return GetMenuService().GetMenuFromItemIDTypeID(itemID=None, typeID=self.listing.component_item_type_id, includeMarketDetails=True)
    128 
    129     def GetHint(self):
    130         if self.listing.is_limited_offer():
    131             return GetByLabel('UI/Personalization/ShipSkins/SKINR/Store/LimitedOffer', valid_until=self.listing.valid_until_seconds)
    132 
    133 
    134 class ComponentListingCardTag(Container):
    135     default_height = _TAG_HEIGHT
    136     label_padding = 8
    137     text_color = eveColor.OMEGA_TAG_TEXT_GREEN
    138 
    139     def __init__(self, listing, *args, **kwargs):
    140         super(ComponentListingCardTag, self).__init__(*args, **kwargs)
    141         self.listing = listing
    142         self._label_text = ''
    143         self.construct_layout()
    144         self.update()
    145 
    146     def construct_layout(self):
    147         Frame(bgParent=self, color=eveColor.COPPER_OXIDE_GREEN, frameConst=uiconst.FRAME_FILLED_CORNER4)
    148         self.construct_label()
    149 
    150     def construct_label(self):
    151         self._label = TextCustom(name='label', parent=self, align=Align.TOPLEFT, color=self.text_color, fontSize=14, bold=True, padding=(self.label_padding,
    152          3,
    153          self.label_padding,
    154          0))
    155 
    156     def update(self):
    157         self._label.text = self.label_text
    158         self.width = self.component_width
    159 
    160     @property
    161     def label_text(self):
    162         return self._label_text
    163 
    164     @label_text.setter
    165     def label_text(self, value):
    166         self._label_text = value
    167         self.update()
    168 
    169     @property
    170     def component_width(self):
    171         w, _ = TextCustom.MeasureTextSize(self.label_text, fontSize=14, bold=True)
    172         return w + self.label_padding * 2