InfoPanelBase.py (11704B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\infoPanels\InfoPanelBase.py 2 import math 3 import localization 4 import signals 5 import uthread2 6 from carbon.client.script.environment.AudioUtil import PlaySound 7 from carbonui import uiconst 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.control import eveLabel 14 from eve.client.script.ui.control import utilMenu 15 from carbonui.control.buttonIcon import ButtonIcon 16 from eve.client.script.ui.shared.infoPanels import infoPanelSettingsController 17 from eve.client.script.ui.shared.infoPanels.const import infoPanelConst 18 from eve.client.script.ui.shared.infoPanels.const import infoPanelUIConst 19 20 class InfoPanelBase(ContainerAutoSize): 21 default_iconTexturePath = 'res:/UI/texture/icons/77_32_30.png' 22 default_align = uiconst.TOTOP 23 default_isModeFixed = False 24 default_mode = infoPanelConst.MODE_NORMAL 25 label = '' 26 panelTypeID = None 27 hasSettings = True 28 isCollapsable = True 29 headerCls = eveLabel.EveCaptionSmall 30 MAINPADBOTTOM = 10 31 MAINPADTOP = 0 32 HEADER_FADE_WIDTH = 20 33 __notifyevents__ = ['ProcessUpdateInfoPanel'] 34 35 def __init__(self, **kwargs): 36 super(InfoPanelBase, self).__init__(**kwargs) 37 sm.RegisterNotify(self) 38 self.Update(None) 39 40 def ApplyAttributes(self, attributes): 41 super(InfoPanelBase, self).ApplyAttributes(attributes) 42 self.onModeTransitionToNormalSignal = signals.Signal(signalName='onModeTransitionToNormalSignal') 43 self.isInModeTransition = False 44 self.expandButton = None 45 self._mode = attributes.get('mode', self.default_mode) 46 self.isModeFixed = attributes.get('isModeFixed', self.default_isModeFixed) 47 self.__settingsID = attributes.get('settingsID', None) 48 self.ConstructLayout() 49 50 def ConstructLayout(self): 51 self.topCont = Container(name='topCont', parent=self, align=uiconst.TOTOP, height=28) 52 self.headerBtnCont = Container(name='headerBtnCont', parent=self.topCont, align=uiconst.TOLEFT, width=infoPanelUIConst.LEFTPAD) 53 self.headerCont = Container(name='headerCont', parent=self.topCont) 54 self.headerCompactCont = Container(name='headerCompactCont', parent=self.topCont, opacity=0.0) 55 self.headerButton = self.ConstructHeaderButton() 56 if not self.isModeFixed: 57 self.expandButton = ExpandButton(parent=self.headerBtnCont, align=uiconst.TOLEFT, width=self.topCont.height, expanded=self.mode == infoPanelConst.MODE_NORMAL, on_click=self.ToggleMode) 58 self.mainCont = ContainerAutoSize(name='mainCont', parent=self, align=uiconst.TOTOP, padLeft=infoPanelUIConst.LEFTPAD, padTop=self.MAINPADTOP, padBottom=self.MAINPADBOTTOM if self.mode == infoPanelConst.MODE_NORMAL else 0) 59 60 @property 61 def settingsID(self): 62 if not self.__settingsID: 63 self.__settingsID = sm.GetService('viewState').GetCurrentView().name 64 return self.__settingsID 65 66 @classmethod 67 def GetTexturePath(cls): 68 return cls.default_iconTexturePath 69 70 def ConstructHeaderButton(self): 71 return utilMenu.UtilMenu(name='headerButton', parent=self.headerBtnCont, align=uiconst.CENTERRIGHT, state=uiconst.UI_NORMAL if self.hasSettings else uiconst.UI_DISABLED, menuAlign=uiconst.TOPLEFT, pos=(0, 72 0, 73 self.topCont.height, 74 self.topCont.height), iconSize=18, texturePath=self.GetTexturePath(), GetUtilMenu=self.GetSettingsMenu) 75 76 def ConstructSimpleHeaderButton(self): 77 return ButtonIcon(name='headerButton', parent=self.headerBtnCont, align=uiconst.CENTERRIGHT, pos=(0, 78 0, 79 self.topCont.height, 80 self.topCont.height), iconSize=18, texturePath=self.GetTexturePath()) 81 82 @staticmethod 83 def IsAvailable(): 84 return True 85 86 @property 87 def mode(self): 88 if not self._mode: 89 self._mode = self.default_mode 90 return self._mode 91 92 @mode.setter 93 def mode(self, mode): 94 if mode == infoPanelConst.MODE_HIDDEN and not self.isCollapsable: 95 return 96 if self.mode is not None and mode == self.mode: 97 return 98 infoPanelSettingsController.save_mode_for_panel_in_setting(self.settingsID, self.panelTypeID, mode) 99 oldMode = self._mode 100 self._mode = mode 101 self.Update(oldMode) 102 103 def ProcessUpdateInfoPanel(self, panelTypeID): 104 if panelTypeID is None or panelTypeID == self.panelTypeID: 105 self.Update() 106 107 def Update(self, oldMode = None): 108 if not self.IsAvailable(): 109 self.Hide() 110 return 111 self.Show() 112 self.isInModeTransition = True 113 self.OnBeforeModeChanged(oldMode) 114 try: 115 if self.expandButton: 116 self.expandButton.expanded = self.mode == infoPanelConst.MODE_NORMAL 117 if self.mode == infoPanelConst.MODE_NORMAL: 118 if oldMode == infoPanelConst.MODE_COMPACT: 119 self.mainCont.opacity = 0.0 120 self.mainCont.height = 0 121 self.mainCont.padBottom = 0 122 self.EnableAutoSize() 123 self.mainCont.DisableAutoSize() 124 self.mainCont.Show() 125 self.ConstructNormal() 126 elif self.mode == infoPanelConst.MODE_COMPACT: 127 self.ConstructCompact() 128 elif self.mode == infoPanelConst.MODE_HIDDEN: 129 self.ConstructCollapsed() 130 else: 131 raise RuntimeError('Invalid infoPanel mode: %s' % self.mode) 132 self.ModeTransition(oldMode) 133 finally: 134 self.isInModeTransition = False 135 136 def ModeTransition(self, oldMode = None): 137 self.OnStartModeChanged(oldMode) 138 if self.mode == infoPanelConst.MODE_HIDDEN: 139 if oldMode: 140 self.AnimFadeOut() 141 self._SetCollapsedState() 142 elif self.mode == infoPanelConst.MODE_NORMAL: 143 self.Show() 144 if oldMode == infoPanelConst.MODE_HIDDEN: 145 self.AnimFadeIn() 146 elif oldMode == infoPanelConst.MODE_COMPACT: 147 self.AnimFadeInMainCont() 148 self._SetNormalState() 149 self.onModeTransitionToNormalSignal(self.panelTypeID) 150 elif self.mode == infoPanelConst.MODE_COMPACT: 151 self.Show() 152 if oldMode == infoPanelConst.MODE_HIDDEN: 153 self.AnimFadeIn() 154 elif oldMode == infoPanelConst.MODE_NORMAL: 155 self.AnimFadeOutMainCont() 156 self._SetCompactState() 157 self.OnEndModeChanged(oldMode) 158 159 def OnBeforeModeChanged(self, oldMode): 160 pass 161 162 def OnStartModeChanged(self, oldMode): 163 pass 164 165 def OnEndModeChanged(self, oldMode): 166 pass 167 168 def _SetNormalState(self): 169 self.mainCont.opacity = 1.0 170 self.mainCont.EnableAutoSize() 171 self.mainCont.Show() 172 173 def _SetCollapsedState(self): 174 self.Hide() 175 self.mainCont.Show() 176 self.mainCont.EnableAutoSize() 177 self.mainCont.opacity = 1.0 178 self.mainCont.padBottom = self.MAINPADBOTTOM 179 self.mainCont.left = 0 180 181 def _SetCompactState(self): 182 self.mainCont.Hide() 183 self.mainCont.DisableAutoSize() 184 185 def AnimFadeIn(self): 186 duration = 0.3 187 self.mainCont.Show() 188 _, height = self.mainCont.GetAutoSize() 189 height += self.MAINPADBOTTOM 190 height += self.topCont.height 191 self.left = 5 192 self.opacity = 0.0 193 animations.MorphScalar(self, 'height', 0, height, duration=duration) 194 uthread2.sleep(0.1) 195 animations.MorphScalar(self, 'left', 5, 0, duration=duration) 196 animations.MorphScalar(self, 'padBottom', 0, self.default_padBottom, duration=duration) 197 self._AnimFadeInSelf(duration) 198 199 def _AnimFadeInSelf(self, duration): 200 animations.FadeIn(self, duration=duration, sleep=True) 201 202 def AnimFadeOut(self): 203 duration = 0.3 204 animations.FadeOut(self, duration=duration) 205 uthread2.sleep(0.1) 206 animations.MorphScalar(self, 'left', 0, 5, duration=duration) 207 animations.MorphScalar(self, 'height', self.height, 0, duration=duration) 208 animations.MorphScalar(self, 'padBottom', self.padBottom, 0, duration=duration, sleep=True) 209 210 def AnimFadeInMainCont(self): 211 duration = 0.3 212 _, height = self.mainCont.GetAutoSize() 213 animations.MorphScalar(self.mainCont, 'height', 0, height, duration=duration) 214 animations.MorphScalar(self.mainCont, 'padBottom', 0, self.MAINPADBOTTOM, duration=duration) 215 uthread2.sleep(0.1) 216 animations.MorphScalar(self.mainCont, 'left', 5, 0, duration=duration) 217 animations.FadeTo(self.mainCont, 0.0, 1.0, duration=duration, sleep=True) 218 219 def AnimFadeOutMainCont(self): 220 duration = 0.3 221 self.mainCont.DisableAutoSize() 222 animations.MorphScalar(self.mainCont, 'left', 0, 5, duration=duration) 223 animations.FadeOut(self.mainCont, duration=duration) 224 uthread2.sleep(0.1) 225 animations.MorphScalar(self.mainCont, 'height', self.mainCont.height, 0, duration=duration) 226 animations.MorphScalar(self.mainCont, 'padBottom', self.mainCont.padBottom, 0, duration=duration, sleep=True) 227 228 def GetSettingsMenu(self, menuParent): 229 pass 230 231 def ToggleMode(self, *args): 232 if self.isInModeTransition: 233 return 234 if self.mode == infoPanelConst.MODE_NORMAL: 235 PlaySound(uiconst.SOUND_COLLAPSE) 236 self.mode = infoPanelConst.MODE_COMPACT 237 else: 238 PlaySound(uiconst.SOUND_EXPAND) 239 self.mode = infoPanelConst.MODE_NORMAL 240 241 @classmethod 242 def GetClassHint(cls): 243 if cls.mode != infoPanelConst.MODE_HIDDEN: 244 return localization.GetByLabel(cls.label) 245 246 def ConstructNormal(self): 247 pass 248 249 def ConstructCompact(self): 250 pass 251 252 def ConstructCollapsed(self): 253 pass 254 255 256 class ExpandButton(Container): 257 default_state = uiconst.UI_NORMAL 258 259 def __init__(self, expanded, on_click = None, **kwargs): 260 super(ExpandButton, self).__init__(**kwargs) 261 self._expanded = expanded 262 self._icon = None 263 self._fill = None 264 self.on_click = signals.Signal(signalName='on_click') 265 self.layout() 266 if on_click: 267 self.on_click.connect(on_click) 268 269 @property 270 def expanded(self): 271 return self._expanded 272 273 @expanded.setter 274 def expanded(self, expanded): 275 if expanded != self._expanded: 276 self._expanded = expanded 277 self.anim_update() 278 279 @property 280 def _icon_rotation(self): 281 if self._expanded: 282 return 0.0 283 return math.pi / 2.0 284 285 def layout(self): 286 self._fill = Fill(bgParent=self, color=(1.0, 1.0, 1.0), opacity=0.0) 287 self._icon = Sprite(parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Neocom/arrowDown.png', width=7, height=7, rotation=self._icon_rotation) 288 289 def anim_update(self): 290 animations.MorphScalar(self._icon, 'rotation', startVal=self._icon.rotation, endVal=self._icon_rotation, duration=0.3) 291 292 def OnClick(self, *args): 293 self.on_click() 294 295 def OnMouseEnter(self): 296 PlaySound(uiconst.SOUND_ENTRY_HOVER) 297 animations.FadeIn(self._fill, endVal=0.1, duration=0.1) 298 299 def OnMouseExit(self): 300 animations.FadeOut(self._fill, duration=0.3)