simpleCurtain.py (5115B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\industry\simpleCurtain.py 2 from math import pi 3 import log 4 from carbonui.primitives.container import Container 5 from carbonui.primitives.gradientSprite import GradientSprite 6 from carbonui.primitives.sprite import Sprite 7 from eve.client.script.ui.control.eveLabel import EveCaptionSmall 8 import uthread 9 from carbonui import uiconst 10 from carbonui.uianimations import animations 11 12 class SimpleCurtain(Container): 13 14 def ApplyAttributes(self, attributes): 15 Container.ApplyAttributes(self, attributes) 16 self._statusIconColor = 0 17 self.topParent = Container(parent=self, align=uiconst.TOTOP_PROP, height=1.0) 18 self.barHeight = 24 19 self._CreateBar(attributes.curtainText) 20 self._SetTopContainer(attributes) 21 self._SetBottomContainer(attributes) 22 self.isUp = False 23 self.callback = attributes.callback 24 self.SetStatusIconOff() 25 26 def _SetBottomContainer(self, attributes): 27 self.bottomContainer = attributes.bottomContainer 28 self.bottomContainer.SetParent(self) 29 self.bottomContainer.align = uiconst.TOALL 30 self.bottomContainer.name += '_bottomContainer' 31 32 def _SetTopContainer(self, attributes): 33 self.topContainer = attributes.topContainer 34 self.topContainer.SetParent(self.topParent) 35 self.topContainer.name += '_topContainer' 36 self.topContainer.align = uiconst.TOALL 37 38 def _CreateBar(self, text): 39 self.bar = Container(parent=self.topParent, align=uiconst.TOBOTTOM, height=self.barHeight, state=uiconst.UI_NORMAL) 40 GradientSprite(bgParent=self.bar, rotation=-pi / 2, rgbData=[(0, (0.3, 0.3, 0.3))], alphaData=[(0, 0.5), (0.9, 0.15)]) 41 barLabelParent = Container(parent=self.bar, align=uiconst.CENTER, height=self.barHeight, width=300, state=uiconst.UI_DISABLED) 42 self.isUpIcons = [Sprite(parent=barLabelParent, align=uiconst.CENTERLEFT, pos=(-15, 0, 32, 32), name='statusIcon', state=uiconst.UI_NORMAL, texturePath='res:/UI/Texture/Icons/105_32_4.png', idx=0), Sprite(parent=barLabelParent, align=uiconst.CENTERRIGHT, pos=(-15, 0, 32, 32), name='statusIcon', state=uiconst.UI_NORMAL, texturePath='res:/UI/Texture/Icons/105_32_4.png', idx=0)] 43 self.barLabel = EveCaptionSmall(parent=barLabelParent, text=text, align=uiconst.CENTER) 44 w = self.barLabel.width 45 barLabelParent.left -= 25 46 barLabelParent.width = w + 50 47 self.bar.OnClick = self.ToggleBar 48 49 def ToggleBar(self, *args): 50 self.bar.state = uiconst.UI_DISABLED 51 try: 52 oldIsUp = self._IsUp() 53 self.isUp = not self.isUp 54 if oldIsUp: 55 self._MoveBarDown() 56 else: 57 self._MoveBarUp() 58 self.CallCallback() 59 finally: 60 self.bar.state = uiconst.UI_NORMAL 61 62 def _IsUp(self): 63 return self.isUp 64 65 def _MoveBarUp(self): 66 self.isUp = True 67 self._HideContainers() 68 self.topParent.align = uiconst.TOTOP 69 self.topParent.height = self._GetHeight() 70 animations.MorphScalar(self.topParent, 'height', endVal=24, duration=0.15, sleep=True) 71 self.SetStatusIconOn() 72 self._ShowContainers() 73 74 def _MoveBarDown(self): 75 self.isUp = False 76 self._HideContainers() 77 self.topParent.align = uiconst.TOTOP_PROP 78 currentHeight = self._GetHeight() 79 self.topParent.height = float(self.barHeight) / currentHeight 80 animations.MorphScalar(self.topParent, 'height', endVal=1, duration=0.15, sleep=True) 81 self.SetStatusIconOff() 82 self._ShowContainers() 83 84 def _ShowContainers(self): 85 self.topContainer.state = uiconst.UI_PICKCHILDREN 86 self.bottomContainer.state = uiconst.UI_PICKCHILDREN 87 uthread.parallel([(self._AnimateContainerOpacity, (self.topContainer, 1.0)), (self._AnimateContainerOpacity, (self.bottomContainer, 1.0))]) 88 89 def _HideContainers(self): 90 uthread.parallel([(self._AnimateContainerOpacity, (self.topContainer, 0.0)), (self._AnimateContainerOpacity, (self.bottomContainer, 0.0))]) 91 self.topContainer.state = uiconst.UI_DISABLED 92 self.bottomContainer.state = uiconst.UI_DISABLED 93 94 def _AnimateContainerOpacity(self, container, endOpacity): 95 animations.FadeIn(container, endVal=endOpacity, duration=0.1, sleep=True) 96 97 def _GetHeight(self): 98 _, currentHeight = self.GetAbsoluteSize() 99 return currentHeight 100 101 def _SetUpIconsTexturePath(self, texturePath): 102 for ic in self.isUpIcons: 103 ic.LoadTexture(texturePath) 104 105 def SetStatusIconOn(self): 106 self._SetUpIconsTexturePath('res:/UI/Texture/Icons/105_32_5.png') 107 108 def SetStatusIconOff(self): 109 self._SetUpIconsTexturePath('res:/UI/Texture/Icons/105_32_4.png') 110 111 def CallCallback(self): 112 try: 113 if self.callback is not None: 114 self.callback(self.isUp) 115 except Exception: 116 log.LogException('Failed to call callback when curtain was clicked')