moduleEffectTimer.py (5551B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\moduleEffectTimer.py 2 import carbonui.const as uiconst 3 import math 4 import trinity 5 from carbon.common.script.util.timerstuff import AutoTimer 6 from carbonui.primitives.container import Container 7 from carbonui.primitives.sprite import Sprite 8 from carbonui.uianimations import animations 9 10 class ModuleEffectTimer(Container): 11 default_blink = False 12 default_timeIncreases = True 13 default_timerColor = (0.5, 0.5, 0.5) 14 default_timerOpacity = 0.5 15 default_timerRightCounterTexturePath = None 16 default_timerLeftCounterTexturePath = None 17 default_timerCounterGaugeTexturePath = None 18 BLINK_MIN_DURATION = 2 19 BLINK_MAX_DURATION = 5 20 BLINK_LOOP_DURATION = 1.0 21 22 def ApplyAttributes(self, attributes): 23 Container.ApplyAttributes(self, attributes) 24 self.blink = attributes.get('blink', self.default_blink) 25 self.timeIncreases = attributes.get('timeIncreases', self.default_timeIncreases) 26 self.timerColor = attributes.get('timerColor', self.default_timerColor) 27 self.timerOpacity = attributes.get('timerOpacity', self.default_timerOpacity) 28 self.timerRightCounterTexturePath = attributes.get('timerRightCounterTexturePath', self.default_timerRightCounterTexturePath) 29 self.timerLeftCounterTexturePath = attributes.get('timerLeftCounterTexturePath', self.default_timerLeftCounterTexturePath) 30 self.timerCounterGaugeTexturePath = attributes.get('timerCounterGaugeTexturePath', self.default_timerCounterGaugeTexturePath) 31 32 def StartTimer(self, duration): 33 if self.destroyed: 34 return 35 leftTimer, rightTimer = self._GetTimers() 36 if leftTimer and rightTimer: 37 durationInSec = duration / 1000.0 38 curveSet = animations.CreateCurveSet(useRealTime=False) 39 if self.timeIncreases: 40 curvePoints = ([0, math.pi], [0.5, 0], [1, 0]) 41 else: 42 curvePoints = ([0, 0], [0.5, -math.pi], [1, -math.pi]) 43 animations.MorphScalar(rightTimer, 'rotationSecondary', duration=durationInSec, curveType=curvePoints, curveSet=curveSet) 44 if self.timeIncreases: 45 curvePoints = ([0, 0], [0.5, 0], [1, -math.pi]) 46 else: 47 curvePoints = ([0, math.pi], [0.5, math.pi], [1, 0]) 48 animations.MorphScalar(leftTimer, 'rotationSecondary', duration=durationInSec, curveType=curvePoints, curveSet=curveSet) 49 if self.blink: 50 blinkIn = max(self.BLINK_MIN_DURATION, durationInSec - self.BLINK_MAX_DURATION) 51 self.blinkTimer = AutoTimer(blinkIn * 1000, self._BlinkModule) 52 53 def RemoveTimer(self): 54 if self.destroyed: 55 return 56 for sideName in ('leftSide', 'rightSide'): 57 side = getattr(self, sideName, None) 58 if side: 59 side.Close() 60 setattr(self, sideName, None) 61 62 def SetTimerOpacity(self, timerOpacity): 63 self.timerOpacity = timerOpacity 64 right = getattr(self, 'rightSide', None) 65 left = getattr(self, 'leftSide', None) 66 timerRGB = self.timerColor + (self.timerOpacity,) 67 if right and not right.destroyed: 68 right.SetRGBA(*timerRGB) 69 if left and not left.destroyed: 70 left.SetRGBA(*timerRGB) 71 72 def _GetTimers(self): 73 right = getattr(self, 'rightSide', None) 74 left = getattr(self, 'leftSide', None) 75 if not right or right.destroyed: 76 timerName = 'rightSide' 77 rotation = 0 78 texturePath = self.timerRightCounterTexturePath 79 textureSecondaryPath = self.timerCounterGaugeTexturePath 80 color = self.timerColor + (self.timerOpacity,) 81 rightSide = self._CreateTimer(timerName, rotation, texturePath, textureSecondaryPath, color) 82 else: 83 rightSide = right 84 if not left or left.destroyed: 85 timerName = 'leftSide' 86 rotation = math.pi 87 texturePath = self.timerLeftCounterTexturePath 88 textureSecondaryPath = self.timerCounterGaugeTexturePath 89 color = self.timerColor + (self.timerOpacity,) 90 leftSide = self._CreateTimer(timerName, rotation, texturePath, textureSecondaryPath, color) 91 else: 92 leftSide = left 93 self.rightSide = rightSide 94 self.leftSide = leftSide 95 return (leftSide, rightSide) 96 97 def _CreateTimer(self, timerName = 'timer', rotation = 0, texturePath = None, textureSecondaryPath = None, color = None): 98 if not texturePath or not textureSecondaryPath: 99 return None 100 timer = Sprite(name=timerName, parent=self, align=uiconst.TOALL, texturePath=texturePath, textureSecondaryPath=textureSecondaryPath, blendMode=1, spriteEffect=trinity.TR2_SFX_MODULATE, state=uiconst.UI_DISABLED) 101 if color: 102 timer.SetRGBA(*color) 103 timer.baseRotation = rotation 104 timer.rotationSecondary = rotation 105 return timer 106 107 def _BlinkModule(self): 108 self.blinkTimer = None 109 if self.parent and not self.parent.destroyed: 110 numLoops = self.BLINK_MAX_DURATION / self.BLINK_LOOP_DURATION 111 animations.BlinkIn(self.parent, startVal=0.0, endVal=1.0, duration=self.BLINK_LOOP_DURATION, loops=numLoops) 112 113 def _AreTimerTexturePathsSet(self): 114 return self.timerRightCounterTexturePath and self.timerLeftCounterTexturePath and self.timerCounterGaugeTexturePath