sidePanel.py (9339B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\mapView\sidePanel\sidePanel.py 2 import eveicon 3 import localization 4 from carbonui import Align, uiconst, TextColor 5 from carbonui.text.styles import TextHeader 6 from carbonui.control.buttonIcon import ButtonIcon 7 from carbonui.control.scrollContainer import ScrollContainer 8 from carbonui.primitives.container import Container 9 from carbonui.primitives.containerAutoSize import ContainerAutoSize 10 from carbonui.primitives.fill import Fill 11 from carbonui.primitives.sprite import Sprite 12 from carbonui.uianimations import animations 13 from eve.client.script.ui import eveThemeColor 14 from eve.client.script.ui.shared.mapView.controls.proximitySensor import ProximitySensor 15 from eve.client.script.ui.shared.mapView.mapViewSettings import SetMapViewSetting, GetMapViewSetting 16 CONTROL_CONT_HEIGHT = 24 17 CHILD_PADDING = (8, 8, 8, 8) 18 MARGIN_TOP = 80 19 MARGIN_BOTTOM = 160 20 PAD_LEFT = 16 21 PAD_RIGHT = 16 22 WIDTH_EXPANDED = 360 23 WIDTH_COLLAPSED = 32 24 INITIAL_HEIGHT = 750 25 26 class MapSidePanel(ContainerAutoSize): 27 __notifyevents__ = ['OnUIColorsChanged'] 28 default_align = Align.CENTERRIGHT 29 default_alignMode = Align.TOTOP 30 default_state = uiconst.UI_NORMAL 31 default_width = 360 32 default_bgColor = (1, 1, 1, 0.1) 33 34 def __init__(self, map_view_id, *args, **kwargs): 35 super(MapSidePanel, self).__init__(*args, **kwargs) 36 self._last_height = INITIAL_HEIGHT 37 self._mouse_over = False 38 self._mouse_in_proximity = False 39 self._animating = False 40 self._locked = GetMapViewSetting('side_panel_locked', map_view_id, True) 41 self._expanded = True 42 self.widget = None 43 self._window_height = 0 44 self._window_width = 0 45 self._window_state = None 46 self._map_view_id = map_view_id 47 self._construct_layout() 48 self._update_height() 49 self._register() 50 self.ToggleExpanded(self._locked, animate=False) 51 52 def _register(self): 53 sm.RegisterNotify(self) 54 self._proximity_sensor.on_mouse_enter.connect(self.on_mouse_enter_proximity) 55 self._proximity_sensor.on_mouse_exit.connect(self.on_mouse_exit_proximity) 56 57 def _construct_layout(self): 58 self._proximity_sensor = ProximitySensor(parent=self, align=Align.CENTERRIGHT, height=850, width=250) 59 self._construct_sideline(self) 60 self.main_cont = ContainerAutoSize(name='main_cont', parent=self, align=uiconst.TOTOP) 61 self._construct_header(self.main_cont) 62 self._construct_body(self.main_cont) 63 self._construct_footer(self.main_cont) 64 self._construct_bg(self.main_cont) 65 66 def _construct_header(self, parent): 67 self._header_cont = Container(name='header_cont', parent=parent, align=uiconst.TOTOP, height=18, padBottom=24, padTop=16, padLeft=PAD_LEFT, padRight=PAD_RIGHT) 68 header_icon_cont = Container(name='header_icon_cont', parent=self._header_cont, align=uiconst.TOLEFT, width=16) 69 header_label_cont = Container(name='header_label_cont', parent=self._header_cont, align=uiconst.TOALL, padLeft=8) 70 Sprite(name='header_icon', parent=header_icon_cont, align=uiconst.CENTER, texturePath=eveicon.info, width=16, height=16, color=TextColor.SECONDARY) 71 TextHeader(name='header_label', parent=header_label_cont, align=uiconst.CENTERLEFT, text=localization.GetByLabel('UI/Map/MapPallet/spHeader'), color=TextColor.SECONDARY) 72 73 def _construct_body(self, parent): 74 self._content_cont = ContainerAutoSize(name='content_cont', parent=parent, align=Align.TOTOP, padLeft=PAD_LEFT, padRight=PAD_RIGHT, padBottom=24) 75 self._widget_cont = Container(name='widget_cont', parent=self._content_cont, align=uiconst.TOTOP) 76 self._scroll_cont = ScrollContainer(name='scroll_cont', parent=self._widget_cont, align=uiconst.TOALL) 77 78 def _construct_footer(self, parent): 79 self._bottom_cont = Container(name='bottom_cont', parent=parent, align=uiconst.TOTOP, height=CONTROL_CONT_HEIGHT, padBottom=16, padLeft=PAD_LEFT, padRight=PAD_RIGHT) 80 Fill(name='separator', parent=self._bottom_cont, align=uiconst.TOTOP, height=1, color=TextColor.DISABLED) 81 self._lock_button = ButtonIcon(name='lock_button', parent=self._bottom_cont, align=uiconst.BOTTOMLEFT, pos=(0, 0, 16, 16), texturePath=eveicon.chevron_left if not self._locked else eveicon.chevron_right, func=self.on_lock_button_pressed) 82 83 def _construct_bg(self, parent): 84 self._bg = Fill(name='bg', bgParent=parent, color=(0, 0, 0, 0.9)) 85 86 def _construct_sideline(self, parent): 87 line_cont = Container(name='side_line_cont', parent=parent, align=Align.TOLEFT_NOPUSH, width=2) 88 self._line = Fill(name='side_line', parent=line_cont, align=uiconst.CENTERLEFT, color=eveThemeColor.THEME_FOCUS, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, height=64, width=2) 89 90 def _update_height(self, *args, **kwargs): 91 if self._animating: 92 return 93 if not self._expanded: 94 content_height = self._last_height 95 else: 96 _, content_height = self._scroll_cont.mainCont.GetAutoSize() 97 self._last_height = content_height 98 max_height = self._window_height - MARGIN_TOP - MARGIN_BOTTOM - CONTROL_CONT_HEIGHT 99 min_height = self.widget.MIN_HEIGHT if self.widget else 500 100 self._widget_cont.height = max(min_height, min(content_height, max_height)) 101 102 def ToggleExpanded(self, expanded, animate = True): 103 if expanded: 104 self.expand(animate=animate) 105 else: 106 self.collapse(animate=animate) 107 self._expanded = expanded 108 109 def expand(self, animate = True, *args, **kwargs): 110 if not animate: 111 self.width = WIDTH_EXPANDED 112 self._header_cont.opacity = 1.0 113 self._widget_cont.opacity = 1.0 114 self._bottom_cont.opacity = 1.0 115 self._update_height() 116 return 117 self._animating = True 118 animations.MorphScalar(self, 'width', self.width, WIDTH_EXPANDED, duration=0.2) 119 animations.FadeIn(self._header_cont, duration=0.2, timeOffset=0.2, callback=self._on_animation_completed) 120 animations.FadeIn(self._widget_cont, duration=0.2, timeOffset=0.2) 121 animations.FadeIn(self._bottom_cont, duration=0.2, timeOffset=0.2) 122 123 def collapse(self, animate = True, *args, **kwargs): 124 if not animate: 125 self.width = WIDTH_COLLAPSED 126 self._header_cont.opacity = 0.0 127 self._widget_cont.opacity = 0.0 128 self._bottom_cont.opacity = 0.0 129 return 130 self._animating = True 131 animations.MorphScalar(self, 'width', self.width, WIDTH_COLLAPSED, duration=0.2, timeOffset=0.2, callback=self._on_animation_completed) 132 animations.FadeOut(self._header_cont, duration=0.2) 133 animations.FadeOut(self._widget_cont, duration=0.2) 134 animations.FadeOut(self._bottom_cont, duration=0.2) 135 136 def _on_collapsed(self): 137 self.ToggleExpanded(not self._expanded) 138 139 def _on_animation_completed(self, *args, **kwargs): 140 self._animating = False 141 if self._expanded: 142 self._update_height() 143 144 def OnWindowResize(self, window_state, width, height): 145 self._window_width = width 146 self._window_height = height 147 self._window_state = window_state 148 self._update_height() 149 150 def OnFilterChanged(self, filter): 151 self._scroll_cont.Flush() 152 self.widget = None 153 if hasattr(filter, 'GetSidePanelWidget'): 154 self.widget = filter.GetSidePanelWidget(self._scroll_cont) 155 if self.widget: 156 self.widget.on_size_changed.connect(self._update_height) 157 self._update_height() 158 if self.widget: 159 self.Show() 160 else: 161 self.Hide() 162 163 def OnUIColorsChanged(self, *args): 164 self.widget.on_theme_colors_changed() 165 self._line.color = eveThemeColor.THEME_FOCUS 166 167 def OnMouseEnter(self, *args): 168 super(MapSidePanel, self).OnMouseEnter(*args) 169 self._mouse_over = True 170 self.update_collapsed_state() 171 172 def OnMouseExit(self, *args): 173 super(MapSidePanel, self).OnMouseExit(*args) 174 self._mouse_over = False 175 self.update_collapsed_state() 176 177 def on_mouse_enter_proximity(self): 178 self._mouse_in_proximity = True 179 self.update_collapsed_state() 180 181 def on_mouse_exit_proximity(self): 182 self._mouse_in_proximity = False 183 self.update_collapsed_state() 184 185 def update_collapsed_state(self): 186 if self._locked: 187 return 188 if self.is_mouse_over() and not self._expanded: 189 self.expand() 190 self._expanded = True 191 if not self.is_mouse_over() and self._expanded: 192 self.collapse() 193 self._expanded = False 194 195 def is_mouse_over(self): 196 return self._mouse_over or self._mouse_in_proximity 197 198 def on_lock_button_pressed(self): 199 self._locked = not self._locked 200 SetMapViewSetting('side_panel_locked', self._locked, self._map_view_id) 201 if self._locked: 202 self._lock_button.SetTexturePath(eveicon.chevron_right) 203 else: 204 self._lock_button.SetTexturePath(eveicon.chevron_left) 205 self.collapse() 206 self._expanded = False