panel.py (4921B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\systemMenu\feature_preview\panel.py 2 import localization 3 import threadutils 4 from carbonui import TextAlign, TextColor, uiconst 5 from carbonui.primitives.container import Container 6 from carbonui.primitives.containerAutoSize import ContainerAutoSize 7 from carbonui.primitives.sprite import Sprite 8 from eve.client.script.ui import eveColor 9 from eve.client.script.ui.control import eveLabel, eveScroll 10 from eve.client.script.ui.control.entries.generic import Generic 11 from eve.client.script.ui.control.entries.util import GetFromClass 12 from eve.client.script.ui.shared.systemMenu.feature_preview.card import FeaturePreviewCard 13 from eve.client.script.ui.shared.systemMenu.feature_preview.data import get_available_feature_previews 14 15 class FeaturePreviewsPanel(Container): 16 _scroll = None 17 18 def __init__(self, parent): 19 self._experiment_cards = [] 20 super(FeaturePreviewsPanel, self).__init__(parent=parent, align=uiconst.TOALL) 21 self._load() 22 23 @threadutils.threaded 24 def _load(self): 25 available_previews = get_available_feature_previews() 26 if not available_previews: 27 self._show_empty_state() 28 else: 29 self._show_feature_previews(available_previews) 30 31 def _show_empty_state(self): 32 wrap = ContainerAutoSize(parent=self, align=uiconst.CENTER, width=360) 33 eveLabel.EveCaptionLarge(parent=wrap, align=uiconst.TOTOP, text=localization.GetByLabel('UI/FeaturePreview/NoFeaturePreviewsTitle'), textAlign=TextAlign.CENTER) 34 eveLabel.EveLabelLarge(parent=wrap, align=uiconst.TOTOP, text=localization.GetByLabel('UI/FeaturePreview/NoFeaturePreviewsBody'), textAlign=TextAlign.CENTER, color=TextColor.SECONDARY) 35 36 def _show_feature_previews(self, feature_previews): 37 self._scroll = eveScroll.Scroll(parent=self, align=uiconst.TOLEFT, width=320, hasUnderlay=False) 38 self._scroll.OnSelectionChange = self._on_scroll_selection_change 39 experiment_entries = [] 40 for experiment in feature_previews: 41 experiment_entries.append(GetFromClass(ExperimentEntry, {'experiment': experiment})) 42 self._experiment_cards.append(FeaturePreviewCard(parent=self, align=uiconst.TOALL, experiment=experiment)) 43 44 self._scroll.LoadContent(contentList=experiment_entries) 45 self._scroll.SelectNode(self._scroll.GetNodes()[0]) 46 47 def _on_scroll_selection_change(self, nodes): 48 if not nodes: 49 return 50 node = nodes[0] 51 experiment_id = node.experiment.id 52 self._show_card(experiment_id) 53 54 def _show_card(self, experiment_id): 55 selected_card = None 56 for card in self._experiment_cards: 57 if card.experiment.id == experiment_id: 58 selected_card = card 59 elif card.display: 60 card.hide() 61 62 if selected_card: 63 selected_card.show() 64 65 def select_experiment(self, experiment_id): 66 for node in self._scroll.GetNodes(): 67 if node.experiment.id == experiment_id: 68 self._scroll.SelectNode(node) 69 return 70 71 72 class ExperimentEntry(Generic): 73 74 def __init__(self, **kwargs): 75 self._icon = None 76 self._label = None 77 self._trailing = None 78 self._experiment = None 79 super(ExperimentEntry, self).__init__(**kwargs) 80 81 def Startup(self, *args): 82 self._icon = Sprite(parent=ContainerAutoSize(parent=self, align=uiconst.TOLEFT, padding=(16, 8, 8, 8)), align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, width=18, height=18, texturePath='res:/UI/Texture/classes/insider/visibility_on_18.png') 83 self._trailing = ContainerAutoSize(parent=self, align=uiconst.TORIGHT) 84 label_clipper = Container(parent=self, align=uiconst.TOALL) 85 self._label = eveLabel.EveLabelLarge(parent=label_clipper, align=uiconst.CENTERLEFT, autoFadeSides=16) 86 87 def Load(self, node): 88 self.sr.node = node 89 self._experiment = node.experiment 90 self._label.text = self._experiment.title 91 self._update_icon() 92 if self._experiment.is_new: 93 eveLabel.EveLabelMedium(parent=ContainerAutoSize(parent=self._trailing, align=uiconst.CENTER, padding=(8, 0, 8, 0), bgColor=eveColor.CHERRY_RED[:3]), text=localization.GetByLabel('UI/FeaturePreview/NewTag'), padding=(8, 2, 8, 2), opacity=1.0) 94 self._experiment.on_toggle.connect(self._update_icon) 95 96 def GetHeight(self, node, width): 97 return 48 98 99 def _update_icon(self): 100 if self._experiment.is_enabled: 101 self._icon.texturePath = 'res:/UI/Texture/classes/insider/visibility_on_18.png' 102 self._icon.SetRGB(*eveColor.LEAFY_GREEN[:3]) 103 else: 104 self._icon.texturePath = 'res:/UI/Texture/classes/insider/visibility_off_18.png' 105 self._icon.SetRGB(0.5, 0.5, 0.5)