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

baseComponentCard.py (8350B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\ship\pages\cards\baseComponentCard.py
      2 from carbon.client.script.environment.AudioUtil import PlaySound
      3 from carbonui import Align, TextColor, uiconst
      4 from carbonui.text.styles import TextBody
      5 from carbonui.primitives.container import Container
      6 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      7 from carbonui.primitives.sprite import Sprite
      8 from carbonui.uianimations import animations
      9 from eve.client.script.ui import eveColor
     10 from eve.client.script.ui.cosmetics.ship.controls.rarityIndicator import RarityIndicator
     11 from eve.client.script.ui.cosmetics.ship.pages.cards import cardConst
     12 from signals import Signal
     13 
     14 class ComponentCard(Container):
     15     default_state = uiconst.UI_NORMAL
     16     default_width = cardConst.card_width
     17     default_height = cardConst.card_height
     18     ANIM_DURATION = 0.2
     19     GLOW_AMOUNT = 0.4
     20     RARITY_ICON_SIZE = 32
     21     USAGE_ICON_SIZE = 36
     22     CORNER_ICON_OFFSET = 12
     23 
     24     def __init__(self, *args, **kwargs):
     25         super(ComponentCard, self).__init__(*args, **kwargs)
     26         self._is_selected = False
     27         self.is_hovered = False
     28         self.on_click = Signal('on_click')
     29         self.construct_layout()
     30 
     31     def construct_layout(self):
     32         self.construct_label()
     33         self.construct_highlight()
     34         self.construct_top_line()
     35         self.construct_rarity_indicator()
     36         self.construct_usage_indicator()
     37         self.construct_icon()
     38         self.construct_background()
     39         self.update()
     40 
     41     def construct_background(self):
     42         self.background_sprite = Sprite(name='background_sprite', parent=self, align=Align.CENTERTOP, state=uiconst.UI_DISABLED, texturePath=self.get_background_texture(), color=eveColor.SMOKE_BLUE, opacity=0.2, width=self.default_width, height=self.default_height)
     43         self.hover_sprite = Sprite(name='hover_sprite', parent=self, align=Align.CENTERTOP, state=uiconst.UI_DISABLED, texturePath=self.get_background_texture(), color=eveColor.SMOKE_BLUE, opacity=0.0, width=self.default_width, height=self.default_height)
     44 
     45     def get_background_texture(self):
     46         return None
     47 
     48     def construct_icon(self):
     49         self.icon_container = ContainerAutoSize(name='icon_container', parent=self, align=Align.CENTER, top=-23)
     50 
     51     def construct_rarity_indicator(self):
     52         self.rarity_indicator = RarityIndicator(name='rarity_indicator', parent=self, align=Align.TOPLEFT, rarity=self.get_rarity(), opacity=0.5, top=self.CORNER_ICON_OFFSET, left=self.CORNER_ICON_OFFSET)
     53 
     54     def get_rarity(self):
     55         return None
     56 
     57     def construct_usage_indicator(self):
     58         pass
     59 
     60     def has_unlimited_uses(self):
     61         return False
     62 
     63     def get_uses_remaining(self):
     64         return None
     65 
     66     def construct_top_line(self):
     67         self.top_left_corner = Sprite(name='top_left_corner', parent=self, align=Align.TOPLEFT, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Cosmetics/Ship/cards/skin_design/top_corner.png', outputMode=uiconst.OutputMode.COLOR_AND_GLOW, glowBrightness=self.GLOW_AMOUNT, width=8, height=1)
     68         self.top_right_corner = Sprite(name='top_right_corner', parent=self, align=Align.TOPRIGHT, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Cosmetics/Ship/cards/skin_design/top_corner.png', outputMode=uiconst.OutputMode.COLOR_AND_GLOW, glowBrightness=self.GLOW_AMOUNT, width=8, height=1)
     69         self.top_line_container = Container(name='top_line_container', parent=self, align=Align.TOTOP_NOPUSH, opacity=0.5, width=self.default_width, height=1)
     70         self.top_line = Sprite(name='top_line', parent=self.top_line_container, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Cosmetics/Ship/cards/skin_design/top_line.png', outputMode=uiconst.OutputMode.COLOR_AND_GLOW, glowBrightness=self.GLOW_AMOUNT, color=eveColor.WHITE, width=self.default_width, height=1)
     71 
     72     def construct_highlight(self):
     73         self.highlight_container = Container(name='highlight_container', parent=self, align=Align.TOBOTTOM_NOPUSH, opacity=0.0, height=4, top=8)
     74         self.highlight_bottom = Sprite(name='highlight_bottom', parent=self.highlight_container, align=Align.CENTER, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Cosmetics/Ship/cards/skin_design/highlight_bottom.png', outputMode=uiconst.OutputMode.COLOR_AND_GLOW, glowBrightness=self.GLOW_AMOUNT, width=48, height=4)
     75 
     76     def construct_label(self):
     77         self.name_label_container = Container(name='name_label_container', parent=self, align=Align.TOBOTTOM, width=self.default_width, height=18, padLeft=10, padRight=10, top=10)
     78         self.name_label = TextBody(name='name_label', parent=self.name_label_container, align=Align.CENTERLEFT, text=self.get_component_name(), color=TextColor.SECONDARY, maxLines=1, autoFadeSides=16)
     79 
     80     def get_component_name(self):
     81         return ''
     82 
     83     def update(self):
     84         self.update_hover_sprite()
     85         self.update_top_line()
     86         self.update_highlight()
     87         self.update_rarity_indicator()
     88         self.update_label()
     89 
     90     def update_hover_sprite(self):
     91         target_opacity = 0.4 if self.is_selected or self.is_hovered else 0.0
     92         animations.FadeTo(self.hover_sprite, self.hover_sprite.opacity, target_opacity, self.ANIM_DURATION)
     93 
     94     def update_top_line(self):
     95         target_color = self.get_top_line_color()
     96         animations.SpColorMorphTo(self.top_line, self.top_line.GetRGBA(), target_color, self.ANIM_DURATION)
     97         animations.SpColorMorphTo(self.top_left_corner, self.top_left_corner.GetRGBA(), target_color, self.ANIM_DURATION)
     98         animations.SpColorMorphTo(self.top_right_corner, self.top_right_corner.GetRGBA(), target_color, self.ANIM_DURATION)
     99         animations.FadeTo(self.top_line_container, self.top_line_container.opacity, self.get_top_line_opacity(), self.ANIM_DURATION)
    100 
    101     def update_highlight(self):
    102         self.highlight_bottom.color = self.get_highlight_color()
    103         animations.FadeTo(self.highlight_container, self.highlight_container.opacity, self.get_highlight_opacity(), self.ANIM_DURATION)
    104 
    105     def get_top_line_color(self):
    106         if self.is_selected:
    107             return eveColor.CRYO_BLUE
    108         return eveColor.WHITE
    109 
    110     def get_top_line_opacity(self):
    111         if self.is_hovered or self.is_selected:
    112             return 1.0
    113         return 0.5
    114 
    115     def get_highlight_color(self):
    116         return eveColor.CRYO_BLUE
    117 
    118     def get_highlight_opacity(self):
    119         if self.is_selected:
    120             return 1.0
    121         return 0.0
    122 
    123     def update_rarity_indicator(self):
    124         target_opacity = 1.0 if self.is_hovered or self.is_selected else 0.5
    125         animations.FadeTo(self.rarity_indicator, self.rarity_indicator.opacity, target_opacity, self.ANIM_DURATION)
    126 
    127     def update_label(self):
    128         target_color = TextColor.HIGHLIGHT if self.is_selected or self.is_hovered else TextColor.SECONDARY
    129         animations.SpColorMorphTo(self.name_label, self.name_label.GetRGBA(), target_color, self.ANIM_DURATION)
    130 
    131     @property
    132     def is_selected(self):
    133         return self._is_selected
    134 
    135     @is_selected.setter
    136     def is_selected(self, value):
    137         if self._is_selected == value:
    138             return
    139         self._is_selected = value
    140         if value:
    141             self._on_selected()
    142         else:
    143             self._on_deselected()
    144         self.update()
    145 
    146     def _on_selected(self):
    147         pass
    148 
    149     def _on_deselected(self):
    150         pass
    151 
    152     def OnMouseEnter(self, *args):
    153         self.is_hovered = True
    154         PlaySound('nanocoating_button_hover_play')
    155         self.update()
    156 
    157     def OnMouseExit(self, *args):
    158         self.is_hovered = False
    159         self.update()
    160 
    161     def OnClick(self, *args):
    162         self.is_selected = not self.is_selected
    163         self.on_click(self)
    164 
    165 
    166 class BlankComponentCard(Container):
    167     default_width = cardConst.card_width
    168     default_height = cardConst.card_height
    169 
    170     def __init__(self, *args, **kwargs):
    171         super(BlankComponentCard, self).__init__(*args, **kwargs)
    172         self.construct_layout()
    173 
    174     def construct_layout(self):
    175         self.bg_sprite = Sprite(name='bg_sprite', parent=self, align=Align.CENTERTOP, texturePath=self.get_background_texture(), width=self.default_width, height=self.default_height)
    176 
    177     def get_background_texture(self):
    178         return None