paintSlot.py (5169B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\structure\components\paintSlot.py 2 from carbon.client.script.environment.AudioUtil import PlaySound 3 from carbonui.primitives.vectorarc import VectorArc 4 from signals import Signal 5 from carbonui import const as uiconst 6 from carbonui.uianimations import animations 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.sprite import Sprite 9 from eve.client.script.ui import eveColor 10 import eve.client.script.ui.cosmetics.structure.paintToolSelections as paintToolSelections 11 from eve.client.script.ui.cosmetics.structure import const as paintToolConst 12 from localization import GetByLabel, GetByMessageID 13 from paints.data import dataLoader as paintsDataLoader 14 SLOT_SIZE = 64 15 SELECTED_INDICATOR_WIDTH = 4 16 SELECTED_INDICATOR_HEIGHT = 8 17 SELECTED_INDICATOR_PADDING = 4 18 SELECTED_COLOR = eveColor.CRYO_BLUE 19 HOVER_ON_EMPTY_COLOR = tuple(eveColor.WHITE[:3]) + (0.6,) 20 FILLED_COLOR = eveColor.LEAFY_GREEN 21 EMPTY_COLOR = tuple(eveColor.WHITE[:3]) + (0.1,) 22 23 class PaintSlot(Container): 24 default_state = uiconst.UI_NORMAL 25 on_paint_slot_clicked = Signal() 26 27 def __init__(self, slot_id, **kwargs): 28 super(PaintSlot, self).__init__(**kwargs) 29 self.hint = GetByLabel(paintToolConst.PAINT_SLOT_NAMES[slot_id]) 30 self.slot_id = slot_id 31 self._paint_id = None 32 self._hovered = False 33 self._selected = False 34 self._construct_layout() 35 self.update_selected_paint() 36 self.set_selected(False, animate=False) 37 38 def _construct_layout(self): 39 selected_indicator_cont = Container(parent=self, name='selectedIndicatorCont', align=uiconst.TORIGHT, width=SELECTED_INDICATOR_WIDTH, padLeft=SELECTED_INDICATOR_PADDING, padRight=SELECTED_INDICATOR_PADDING) 40 self._selected_indicator = Sprite(parent=selected_indicator_cont, align=uiconst.CENTER, width=SELECTED_INDICATOR_WIDTH, height=SELECTED_INDICATOR_HEIGHT, texturePath='res:/UI/Texture/classes/paintTool/paintSlots/selection_arrow.png') 41 btn_cont = Container(parent=self, name='btnCont') 42 self._circle = VectorArc(name='circle', parent=btn_cont, align=uiconst.CENTER, radius=0.5 * SLOT_SIZE, lineWidth=1, fill=False, glowBrightness=0, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW) 43 Sprite(name='iconSprite', parent=btn_cont, align=uiconst.CENTER, state=uiconst.UI_DISABLED, width=32, height=32, texturePath='res:/UI/Texture/classes/paintTool/paintSlots/%s.png' % self.slot_id) 44 self._color_sprite = Sprite(name='colorSprite', parent=btn_cont, align=uiconst.CENTER, state=uiconst.UI_DISABLED, width=56, height=56, texturePath='res:/UI/Texture/classes/paintTool/paintSlots/bg_white.png') 45 46 def OnClick(self, *args): 47 self.on_paint_slot_clicked(self.slot_id) 48 PlaySound(paintToolConst.PAINT_SLOT_CLICK_SOUND_EVENTS[self.slot_id]) 49 50 def OnMouseEnter(self, *args): 51 self._hovered = True 52 self._update_circle() 53 PlaySound('nanocoating_button_hover_play') 54 55 def OnMouseExit(self, *args): 56 self._hovered = False 57 self._update_circle() 58 59 def _update_icon(self): 60 if self._paint_id is not None: 61 target_color = paintsDataLoader.get_material_rgba(self._paint_id) 62 target_opacity = 0.5 63 else: 64 target_color = eveColor.BLACK 65 target_opacity = 0.2 66 animations.SpColorMorphTo(self._color_sprite, self._color_sprite.GetRGBA(), target_color, 0.25) 67 animations.FadeTo(self._color_sprite, self._color_sprite.opacity, target_opacity, 0.25) 68 69 def _update_circle(self): 70 target_brightness = 1.0 if self._hovered else 0.7 71 if self._selected: 72 target_color = SELECTED_COLOR 73 elif self._paint_id: 74 target_color = SELECTED_COLOR 75 elif self._hovered: 76 target_color = HOVER_ON_EMPTY_COLOR 77 else: 78 target_color = EMPTY_COLOR 79 animations.MorphScalar(self._circle, 'glowBrightness', self._circle.glowBrightness, target_brightness, duration=0.25) 80 animations.SpColorMorphTo(self._circle, self._circle.GetRGBA(), target_color, 0.25) 81 82 def _update_selected_indicator(self, animate = True): 83 target_opacity = 1.0 if self._selected else 0.0 84 if not animate: 85 self._selected_indicator.opacity = target_opacity 86 else: 87 animations.FadeTo(self._selected_indicator, self._selected_indicator.opacity, target_opacity, duration=0.25) 88 89 def _update_hint(self): 90 if self._paint_id is not None: 91 self.hint = GetByMessageID(paintsDataLoader.get_paint_brand_name_id(self._paint_id)) 92 else: 93 self.hint = GetByLabel(paintToolConst.PAINT_SLOT_NAMES[self.slot_id]) 94 95 def set_selected(self, selected, animate = True): 96 self._selected = selected 97 self._update_selected_indicator(animate=animate) 98 self._update_circle() 99 100 def update_selected_paint(self): 101 self._paint_id = paintToolSelections.SELECTED_PAINTWORK.get_slot(self.slot_id) 102 self._update_icon() 103 self._update_circle() 104 self._update_hint()