durationSelector.py (6047B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\structure\components\durationSelector.py 2 from carbonui import const as uiconst 3 from carbonui import TextColor, TextAlign 4 from eve.client.script.ui import eveColor 5 from carbonui.primitives.container import Container 6 from carbonui.primitives.containerAutoSize import ContainerAutoSize 7 from carbonui.primitives.flowcontainer import FlowContainer 8 from carbonui.primitives.frame import Frame 9 from carbonui.primitives.line import Line 10 from eve.client.script.ui.control.eveLabel import EveCaptionSmall, EveCaptionLarge, EveLabelMedium 11 from eve.client.script.ui.control.infoIcon import MoreInfoIcon 12 from eve.client.script.ui.cosmetics.structure import paintToolSelections, paintToolSignals 13 from localization import GetByLabel 14 from carbonui.uianimations import animations 15 from carbon.client.script.environment.AudioUtil import PlaySound 16 DURATION_CARD_WIDTH = 210 17 DURATION_CARD_HEIGHT = 87 18 19 class DurationSelector(ContainerAutoSize): 20 21 def __init__(self, **kw): 22 super(DurationSelector, self).__init__(**kw) 23 self._duration_cards = {} 24 self._construct_layout() 25 26 def Close(self): 27 super(DurationSelector, self).Close() 28 29 def set_durations(self, durations): 30 self._cards_cont.Flush() 31 self._duration_cards.clear() 32 for duration in durations: 33 self._duration_cards[duration] = DurationCard(parent=self._cards_cont, name='durationCard_%s' % duration, align=uiconst.NOALIGN, duration=duration) 34 35 if len(durations) > 0: 36 default_selection = durations[0] 37 paintToolSelections.set_selected_duration(default_selection) 38 39 def _construct_layout(self): 40 EveCaptionSmall(parent=self, name='topLabel', align=uiconst.TOTOP, text=GetByLabel('UI/Personalization/PaintTool/SelectDuration'), padBottom=16) 41 self._cards_cont = FlowContainer(name='cardsLibraryCont', parent=self, align=uiconst.TOTOP, contentSpacing=(28, 28), padBottom=8) 42 info_label_text = GetByLabel('UI/Personalization/PaintTool/DurationSelectionInfo') 43 info_label_width, info_label_height = EveLabelMedium.MeasureTextSize(info_label_text) 44 info_container = Container(name='info_container', parent=self, align=uiconst.TOTOP, height=info_label_height, padBottom=24) 45 info_icon = MoreInfoIcon(name='info_icon', parent=info_container, align=uiconst.CENTERLEFT) 46 info_icon.LoadTooltipPanel = self.LoadInfoTooltipPanel 47 EveLabelMedium(name='infoLabel', parent=info_container, align=uiconst.TOTOP, text=GetByLabel('UI/Personalization/PaintTool/DurationSelectionInfo'), padLeft=24) 48 Line(parent=self, align=uiconst.TOTOP, color=tuple(eveColor.WHITE[:3]) + (0.3,), weight=2) 49 50 def LoadInfoTooltipPanel(self, tooltipPanel, *args): 51 title_text = GetByLabel('UI/Personalization/PaintTool/DurationSelectionHintTitle') 52 body_text = GetByLabel('UI/Personalization/PaintTool/DurationSelectionHintBody') 53 wrap_width = 370 54 tooltipPanel.state = uiconst.UI_NORMAL 55 tooltipPanel.LoadGeneric1ColumnTemplate() 56 tooltipPanel.AddCaptionSmall(text=title_text, state=uiconst.UI_NORMAL, wrapWidth=wrap_width) 57 tooltipPanel.AddDivider() 58 tooltipPanel.AddLabelMedium(text=body_text, state=uiconst.UI_NORMAL, wrapWidth=wrap_width) 59 60 61 class DurationCard(Container): 62 default_width = DURATION_CARD_WIDTH 63 default_height = DURATION_CARD_HEIGHT 64 default_state = uiconst.UI_NORMAL 65 66 def __init__(self, duration, **kw): 67 super(DurationCard, self).__init__(**kw) 68 self._duration = duration 69 paintToolSignals.on_duration_selection_changed.connect(self._on_selected_duration_changed) 70 self._construct_layout() 71 self.set_selected(False) 72 73 def Close(self): 74 paintToolSignals.on_duration_selection_changed.disconnect(self._on_selected_duration_changed) 75 super(DurationCard, self).Close() 76 77 def OnClick(self, *args): 78 if paintToolSelections.SELECTED_DURATION != self._duration: 79 paintToolSelections.set_selected_duration(self._duration) 80 PlaySound(uiconst.SOUND_BUTTON_CLICK) 81 82 def OnMouseEnter(self, *args): 83 if paintToolSelections.SELECTED_DURATION != self._duration: 84 animations.MorphScalar(self._frame, 'glowBrightness', self._frame.glowBrightness, 1.0, duration=0.25) 85 PlaySound(uiconst.SOUND_BUTTON_HOVER) 86 87 def OnMouseExit(self, *args): 88 if paintToolSelections.SELECTED_DURATION != self._duration: 89 animations.MorphScalar(self._frame, 'glowBrightness', self._frame.glowBrightness, 0.0, duration=0.25) 90 91 def _construct_layout(self): 92 self._frame = Frame(bgParent=self, name='frame', outputMode=uiconst.OUTPUT_COLOR_AND_GLOW) 93 label_cont = ContainerAutoSize(parent=self, name='labelCont', align=uiconst.CENTER, width=DURATION_CARD_WIDTH) 94 self._duration_label = EveCaptionLarge(parent=label_cont, name='durationLabel', align=uiconst.TOTOP, textAlign=TextAlign.CENTER, text='%s' % (self._duration / 86400)) 95 self._bottom_label = EveCaptionSmall(parent=label_cont, name='bottomLabel', align=uiconst.TOTOP, textAlign=TextAlign.CENTER, text=GetByLabel('UI/Personalization/PaintTool/LicenseDuration')) 96 97 def set_selected(self, selected): 98 target_text_color = eveColor.LEAFY_GREEN if selected else TextColor.NORMAL 99 animations.SpColorMorphTo(self._duration_label, self._duration_label.GetRGBA(), target_text_color, 0.25) 100 animations.SpColorMorphTo(self._bottom_label, self._bottom_label.GetRGBA(), target_text_color, 0.25) 101 animations.SpColorMorphTo(self._frame, self._frame.GetRGBA(), target_text_color, 0.25) 102 target_brightness = 0.75 if selected else 0.0 103 animations.MorphScalar(self._frame, 'glowBrightness', self._frame.glowBrightness, target_brightness, duration=0.25) 104 105 def _on_selected_duration_changed(self): 106 self.set_selected(self._duration == paintToolSelections.SELECTED_DURATION)