NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

uianimations.py (32574B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\uianimations.py
      2 import math
      3 import blue
      4 import telemetry
      5 import trinity
      6 from carbon.common.lib.const import SEC
      7 from carbonui import uiconst
      8 from carbonui.util.color import Color
      9 OVERSHOT_TIME = 0.4
     10 
     11 class UIAnimations(object):
     12     CURVE_BLINK = 1
     13 
     14     def __init__(self):
     15         self.curveSetByObjectIDAttrName = {}
     16         self.curveByObjectIDAttrName = {}
     17 
     18     def CreateCurveSet(self, useRealTime = True):
     19         curveSet = trinity.TriCurveSet()
     20         curveSet.useRealTime = useRealTime
     21         trinity.device.curveSets.append(curveSet)
     22         return curveSet
     23 
     24     def Play(self, curve, obj, attrName, loops = 1, callback = None, sleep = False, curveSet = None):
     25         if loops is uiconst.ANIM_REPEAT or loops > 1:
     26             for each in curve.Find('trinity.Tr2CurveScalar'):
     27                 each.extrapolationAfter = trinity.Tr2CurveExtrapolation.CLAMP
     28                 each.extrapolationAfter = trinity.Tr2CurveExtrapolation.CYCLE
     29 
     30         curveSet = self._GetOrCreateCurveSet(curveSet, obj)
     31         curveSet.curves.append(curve)
     32         self.StopAnimation(obj, attrName)
     33         self.RegisterCurvesetForObject(obj, curveSet, attrName)
     34         self.RegisterCurveForObject(obj, curve, attrName)
     35         if hasattr(obj, '__iroot__'):
     36             binding = trinity.CreateBinding(curveSet, curve, 'currentValue', obj, attrName)
     37         else:
     38             try:
     39                 obj.isAnimated = True
     40             except AttributeError:
     41                 pass
     42 
     43             binding = trinity.CreatePythonBinding(curveSet, curve, 'currentValue', obj, attrName)
     44         binding.name = getattr(obj, 'name', str(id(obj))) + '_' + attrName
     45         if not curveSet.isPlaying:
     46             curveSet.Play()
     47         if loops == uiconst.ANIM_REPEAT:
     48             return curveSet
     49         duration = loops * curveSet.GetMaxCurveDuration()
     50         duration += self.GetMaxTimeOffset(curveSet)
     51         if callback:
     52             curveSet.StopAfterWithCallback(duration, callback)
     53         else:
     54             curveSet.StopAfter(duration)
     55         if sleep:
     56             blue.pyos.synchro.SleepWallclock(duration * 1000)
     57         return curveSet
     58 
     59     def _GetOrCreateCurveSet(self, curveSet, obj):
     60         if not curveSet:
     61             curveSet = self.CreateCurveSet(useRealTime=True)
     62             curveSet.name = getattr(obj, 'name', str(id(obj)))
     63         elif isinstance(curveSet, basestring):
     64             for cs in trinity.device.curveSets:
     65                 if cs.name == curveSet:
     66                     curveSet = cs
     67                     break
     68             else:
     69                 name = curveSet
     70                 curveSet = self.CreateCurveSet(useRealTime=True)
     71                 curveSet.name = name
     72 
     73         return curveSet
     74 
     75     def SyncPlayback(self, curveset):
     76         duration = 0.0
     77         for curve in curveset.curves[0].Find('trinity.Tr2CurveScalar'):
     78             duration = max(curve.keys[-1][0], duration)
     79 
     80         if duration == 0:
     81             return
     82         timeOffset = blue.os.GetWallclockTime() % (SEC * duration) / float(SEC)
     83         curveset.scaledTime += timeOffset
     84 
     85     def RegisterCurvesetForObject(self, obj, curveSet, attrName):
     86         key = self._GetKey(attrName, obj)
     87         self.curveSetByObjectIDAttrName[key] = blue.BluePythonWeakRef(curveSet)
     88         self.curveSetByObjectIDAttrName[key].callback = lambda : self.OnCurveSetWeakRefLost(key)
     89 
     90     def RegisterCurveForObject(self, obj, curve, attrName):
     91         key = self._GetKey(attrName, obj)
     92         self.curveByObjectIDAttrName[key] = blue.BluePythonWeakRef(curve)
     93         self.curveByObjectIDAttrName[key].callback = lambda : self.OnCurveWeakRefLost(key)
     94 
     95     def StopAnimation(self, obj, attrName):
     96         key = self._GetKey(attrName, obj)
     97         self._StopAndRemoveCurveSet(key)
     98 
     99     def _GetKey(self, attrName, obj):
    100         return (id(obj), attrName)
    101 
    102     def _StopAndRemoveCurveSet(self, key):
    103         curveSet = self.curveSetByObjectIDAttrName.pop(key, None)
    104         if curveSet:
    105             curveSet.callback = None
    106             curveSet = curveSet.object
    107         curve = self.curveByObjectIDAttrName.pop(key, None)
    108         if curve:
    109             curve.callback = None
    110             curve = curve.object
    111         if curve and curveSet:
    112             curveSet.curves.remove(curve)
    113         if curveSet and not curveSet.curves:
    114             curveSet.Stop()
    115 
    116     @telemetry.ZONE_METHOD
    117     def StopAllAnimations(self, obj):
    118         objID = id(obj)
    119         for key in self._GetToRemoveKeys(objID):
    120             self._StopAndRemoveCurveSet(key)
    121 
    122     def _GetToRemoveKeys(self, objID):
    123         toRemove = set()
    124         for key, curveSet in self.curveSetByObjectIDAttrName.iteritems():
    125             _objID, attrName = key
    126             if _objID == objID:
    127                 toRemove.add(key)
    128 
    129         for key, curveSet in self.curveByObjectIDAttrName.iteritems():
    130             _objID, attrName = key
    131             if _objID == objID:
    132                 toRemove.add(key)
    133 
    134         return toRemove
    135 
    136     def GetAnimationCurveSet(self, obj, attrName):
    137         key = self._GetKey(attrName, obj)
    138         wr = self.curveSetByObjectIDAttrName.get(key, None)
    139         if wr:
    140             return wr.object
    141 
    142     def IsAnimating(self, obj, attrName):
    143         return bool(self.curveSetByObjectIDAttrName.get(self._GetKey(attrName, obj), False))
    144 
    145     def OnCurveSetWeakRefLost(self, key):
    146         self._StopAndRemoveCurveSet(key)
    147 
    148     def OnCurveWeakRefLost(self, key):
    149         self._StopAndRemoveCurveSet(key)
    150 
    151     def GetMaxTimeOffset(self, curveSet):
    152         curves = curveSet.curves.Find('trinity.Tr2CurveScalar')
    153         if not curves:
    154             return 0.0
    155         return max([ getattr(curve, 'timeOffset', 0.0) for curve in curves ])
    156 
    157     def MorphScalar(self, obj, attrName, startVal = 0.0, endVal = 1.0, duration = 0.75, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, curveSet = None, timeOffset = 0.0):
    158         curve = self.GetScalar(startVal, endVal, duration, curveType, timeOffset=timeOffset)
    159         return self.Play(curve, obj, attrName, loops, callback, sleep, curveSet)
    160 
    161     def MorphVector2(self, obj, attrName, startVal = (0.0, 0.0), endVal = (1.0, 1.0), duration = 0.75, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0, curveSet = None):
    162         curve = self.GetVector2(startVal, endVal, duration, curveType, timeOffset=timeOffset)
    163         return self.Play(curve, obj, attrName, loops, callback, sleep, curveSet)
    164 
    165     def MorphVector3(self, obj, attrName, startVal = (0.0, 0.0, 0.0), endVal = (1.0, 1.0, 1.0), duration = 0.75, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0, curveSet = None):
    166         curve = self.GetVector3(startVal, endVal, duration, curveType, timeOffset=timeOffset)
    167         return self.Play(curve, obj, attrName, loops, callback, sleep, curveSet)
    168 
    169     def MorphQuaternion(self, obj, attrName, startVal = (0.0, 0.0), endVal = (1.0, 1.0), duration = 0.75, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0, curveSet = None):
    170         curve = self.GetQuaternion(startVal, endVal, duration, curveType, timeOffset=timeOffset)
    171         return self.Play(curve, obj, attrName, loops, callback, sleep, curveSet)
    172 
    173     def FadeTo(self, obj, startVal = 0.0, endVal = 1.0, duration = 0.75, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, curveSet = None, timeOffset = 0.0):
    174         if hasattr(obj, 'opacity'):
    175             curve = self.GetScalar(startVal, endVal, duration, curveType, timeOffset=timeOffset)
    176             attrName = 'opacity'
    177         else:
    178             c = obj.color
    179             if isinstance(c, tuple):
    180                 curve = self.GetColorCurve((c[0],
    181                  c[1],
    182                  c[2],
    183                  startVal), (c[0],
    184                  c[1],
    185                  c[2],
    186                  endVal), duration, curveType, timeOffset=timeOffset)
    187             else:
    188                 curve = self.GetColorCurve((c.r,
    189                  c.g,
    190                  c.b,
    191                  startVal), (c.r,
    192                  c.g,
    193                  c.b,
    194                  endVal), duration, curveType, timeOffset=timeOffset)
    195             attrName = 'color'
    196         return self.Play(curve, obj, attrName, loops, callback, sleep, curveSet=curveSet)
    197 
    198     def FadeIn(self, obj, endVal = 1.0, duration = uiconst.TIME_ENTRY, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, curveSet = None, timeOffset = 0.0):
    199         startVal = getattr(obj, 'opacity', 0.0)
    200         return self.FadeTo(obj, startVal, endVal, duration, loops, curveType, callback, sleep, curveSet=curveSet, timeOffset=timeOffset)
    201 
    202     def FadeOut(self, obj, duration = uiconst.TIME_EXIT, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, curveSet = None, timeOffset = 0.0):
    203         startVal = getattr(obj, 'opacity', 0.0)
    204         return self.FadeTo(obj, startVal, 0.0, duration, loops, curveType, callback, sleep, curveSet=curveSet, timeOffset=timeOffset)
    205 
    206     def BlinkIn(self, obj, startVal = 0.0, endVal = 1.0, duration = 0.1, loops = 3, curveType = uiconst.ANIM_LINEAR, callback = None, sleep = False, timeOffset = 0.0):
    207         return self.FadeTo(obj, startVal, endVal, duration, loops, curveType, callback, sleep, timeOffset=timeOffset)
    208 
    209     def BlinkOut(self, obj, startVal = 1.0, endVal = 0.0, duration = 0.1, loops = 3, curveType = uiconst.ANIM_LINEAR, callback = None, sleep = False, timeOffset = 0.0):
    210         return self.FadeTo(obj, startVal, endVal, duration, loops, curveType, callback, sleep, timeOffset=timeOffset)
    211 
    212     def MoveTo(self, obj, startPos = None, endPos = None, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0, curveSet = None):
    213         if not startPos:
    214             startPos = (obj.displayX, obj.displayY)
    215         if not endPos:
    216             endPos = (obj.displayX, obj.displayY)
    217         curve = self.GetScalar(startPos[0], endPos[0], duration, curveType, timeOffset=timeOffset)
    218         curveSet = self.Play(curve, obj, 'left', loops, callback, curveSet=curveSet)
    219         curve = self.GetScalar(startPos[1], endPos[1], duration, curveType, timeOffset=timeOffset)
    220         return self.Play(curve, obj, 'top', loops, callback, sleep, curveSet=curveSet)
    221 
    222     def MoveInFromLeft(self, obj, amount = 30, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, curveSet = None, timeOffset = 0.0):
    223         curve = self.GetScalar(obj.left - amount, obj.left, duration, curveType, timeOffset=timeOffset)
    224         return self.Play(curve, obj, 'left', loops, callback, sleep, curveSet=curveSet)
    225 
    226     def MoveInFromRight(self, obj, amount = 30, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, curveSet = None, timeOffset = 0.0):
    227         curve = self.GetScalar(obj.left + amount, obj.left, duration, curveType, timeOffset=timeOffset)
    228         return self.Play(curve, obj, 'left', loops, callback, sleep, curveSet=curveSet)
    229 
    230     def MoveInFromTop(self, obj, amount = 30, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    231         curve = self.GetScalar(obj.top - amount, obj.top, duration, curveType, timeOffset=timeOffset)
    232         return self.Play(curve, obj, 'top', loops, callback, sleep)
    233 
    234     def MoveInFromBottom(self, obj, amount = 30, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    235         curve = self.GetScalar(obj.top + amount, obj.top, duration, curveType, timeOffset=timeOffset)
    236         return self.Play(curve, obj, 'top', loops, callback, sleep)
    237 
    238     def MoveOutLeft(self, obj, amount = 30, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    239         curve = self.GetScalar(obj.left, obj.left - amount, duration, curveType, timeOffset=timeOffset)
    240         return self.Play(curve, obj, 'left', loops, callback, sleep)
    241 
    242     def MoveOutRight(self, obj, amount = 30, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    243         curve = self.GetScalar(obj.left, obj.left + amount, duration, curveType, timeOffset=timeOffset)
    244         return self.Play(curve, obj, 'left', loops, callback, sleep)
    245 
    246     def MoveOutTop(self, obj, amount = 30, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    247         curve = self.GetScalar(obj.top, obj.top - amount, duration, curveType, timeOffset=timeOffset)
    248         return self.Play(curve, obj, 'top', loops, callback, sleep)
    249 
    250     def MoveOutBottom(self, obj, amount = 30, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    251         curve = self.GetScalar(obj.top, obj.top + amount, duration, curveType, timeOffset=timeOffset)
    252         return self.Play(curve, obj, 'top', loops, callback, sleep)
    253 
    254     def Tr2DScaleTo(self, obj, startScale = (0.0, 0.0), endScale = (1.0, 1.0), duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0, curveSet = None):
    255         curve = self.GetVector2(startScale, endScale, duration, curveType, timeOffset=timeOffset)
    256         return self.Play(curve, obj, 'scale', loops, callback, sleep, curveSet=curveSet)
    257 
    258     def Tr2DScaleIn(self, obj, scaleCenter = (0.0, 0.0), duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0, curveSet = None):
    259         return self.Tr2DScaleTo(obj, (0.0, 0.0), (1.0, 1.0), duration, loops, curveType, callback, sleep, timeOffset, curveSet=curveSet)
    260 
    261     def Tr2DScaleOut(self, obj, startScale = (0.0, 0.0), endScale = (1.0, 1.0), duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0, curveSet = None):
    262         return self.Tr2DScaleTo(obj, obj.scale, (0.0, 0.0), duration, loops, curveType, callback, sleep, timeOffset, curveSet=curveSet)
    263 
    264     def Tr2DFlipIn(self, obj, startScale = (0.0, 0.0), endScale = (1.0, 1.0), duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    265         self.Tr2DScaleTo(obj, (1.0, 0.0), (1.0, 1.0), duration, loops, curveType, callback, timeOffset)
    266         curve = self.GetScalar(0.0, 1.0, duration, curveType, timeOffset=timeOffset)
    267         return self.Play(curve, obj, 'scalingRotation', loops, callback, sleep)
    268 
    269     def Tr2DFlipOut(self, obj, startScale = (1.0, 1.0), endScale = (0.0, 0.0), duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    270         self.Tr2DScaleTo(obj, startScale, endScale, duration, loops, curveType, callback, timeOffset)
    271         curve = self.GetScalar(1.0, 0.0, duration, curveType, timeOffset=timeOffset)
    272         return self.Play(curve, obj, 'scalingRotation', loops, callback, sleep)
    273 
    274     def Tr2DSquashOut(self, obj, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    275         obj.scalingRotation = 0.5
    276         obj.scalingCenter = (0.5, 0.5)
    277         curve = self.GetVector2((1.0, 1.0), (0.0, 1.0), duration, curveType=uiconst.ANIM_SMOOTH, timeOffset=timeOffset)
    278         return self.Play(curve, obj, 'scale', loops, callback, sleep)
    279 
    280     def Tr2DSquashIn(self, obj, startRotation = (0.0, 1.0), duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    281         obj.scalingRotation = 0.5
    282         curve = self.GetVector2(startRotation, (1.0, 1.0), duration, curveType, timeOffset=timeOffset)
    283         return self.Play(curve, obj, 'scale', loops, callback, sleep)
    284 
    285     def Tr2DRotateTo(self, obj, startAngle = 0.0, endAngle = 2 * math.pi, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0, curveSet = None):
    286         curve = self.GetScalar(startAngle, endAngle, duration, curveType, timeOffset=timeOffset)
    287         return self.Play(curve, obj, 'rotation', loops, callback, sleep, curveSet=curveSet)
    288 
    289     def SpColorMorphTo(self, obj, startColor = None, endColor = Color.BLUE, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0, attrName = 'color', curveSet = None):
    290         if startColor is None:
    291             startColor = obj.GetRGBA()
    292         excludeAlpha = len(endColor) == 3
    293         if excludeAlpha:
    294             startColor = startColor[:3]
    295             endColor = endColor[:3]
    296             curve = self.GetColorCurveNoAlpha(startColor, endColor, duration, curveType, timeOffset=timeOffset)
    297         else:
    298             curve = self.GetColorCurve(startColor, endColor, duration, curveType, timeOffset=timeOffset)
    299         return self.Play(curve, obj, attrName, loops, callback, sleep, curveSet=curveSet)
    300 
    301     def SpColorMorphToBlack(self, obj, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    302         return self.SpColorMorphTo(obj, obj.GetRGBA(), Color.BLACK, duration, loops, curveType, callback, sleep, timeOffset)
    303 
    304     def SpColorMorphToWhite(self, obj, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    305         return self.SpColorMorphTo(obj, obj.GetRGBA(), Color.WHITE, duration, loops, curveType, callback, sleep, timeOffset)
    306 
    307     def SpGlowFadeTo(self, obj, startColor = (0.8, 0.8, 1.0, 0.3), endColor = (0, 0, 0, 0), glowFactor = 0.8, glowExpand = 3.0, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, curveSet = None, timeOffset = 0.0):
    308         obj.glowFactor = glowFactor
    309         obj.glowExpand = glowExpand
    310         curve = self.GetColorCurve(startColor, endColor, duration, curveType, timeOffset=timeOffset)
    311         return self.Play(curve, obj, 'glowColor', loops, callback, sleep, curveSet=curveSet)
    312 
    313     def SpGlowFadeIn(self, obj, glowColor = (0.8, 0.8, 1.0, 0.3), glowFactor = 0.8, glowExpand = 3.0, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, curveSet = None, timeOffset = 0.0):
    314         return self.SpGlowFadeTo(obj, (0, 0, 0, 0), glowColor, glowFactor, glowExpand, duration, loops, curveType, callback, sleep, curveSet=curveSet, timeOffset=timeOffset)
    315 
    316     def SpGlowFadeOut(self, obj, glowColor = (0.8, 0.8, 1.0, 0.3), glowFactor = 0.8, glowExpand = 3.0, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, curveSet = None, timeOffset = 0.0):
    317         return self.SpGlowFadeTo(obj, glowColor, (0, 0, 0, 0), glowFactor, glowExpand, duration, loops, curveType, callback, sleep, curveSet=curveSet, timeOffset=timeOffset)
    318 
    319     def SpShadowMoveTo(self, obj, startPos = (0.0, 0.0), endPos = (10.0, 10.0), color = None, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    320         obj.shadowColor = color or (0.0, 0.0, 0.0, 0.5)
    321         curve = self.GetVector2(startPos, endPos, duration, curveType, timeOffset=timeOffset)
    322         return self.Play(curve, obj, 'shadowOffset', loops, callback, sleep)
    323 
    324     def SpShadowAppear(self, obj, offset = (10.0, 10.0), color = None, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    325         color = color or (0.0, 0.0, 0.0, 0.5)
    326         return self.SpShadowMoveTo(obj, (0.0, 0.0), offset, color, duration, loops, curveType, callback, sleep, timeOffset)
    327 
    328     def SpShadowDisappear(self, obj, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    329         return self.SpShadowMoveTo(obj, obj.shadowOffset, (0.0, 0.0), None, duration, loops, curveType, callback, sleep, timeOffset)
    330 
    331     def SpSecondaryTextureRotate(self, obj, startVal = 0.0, endVal = 2 * math.pi, duration = 2.0, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    332         curve = self.GetScalar(startVal, endVal, duration, curveType, timeOffset=timeOffset)
    333         return self.Play(curve, obj, 'rotationSecondary', loops, callback, sleep)
    334 
    335     def SpSecondaryTextureScale(self, obj, startVal = (1.0, 1.0), endVal = (0.0, 0.0), duration = 1.0, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    336         curve = self.GetVector2(startVal, endVal, duration, curveType, timeOffset=timeOffset)
    337         return self.Play(curve, obj, 'scaleSecondary', loops, callback, sleep)
    338 
    339     def SpTunnelTo(self, obj, startVal = (1.0, 1.0), endVal = (0.0, 0.0), texturePath = None, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    340         if not texturePath:
    341             texturePath = 'res:/UI/Texture/Classes/Animations/radialGradient.png'
    342         obj.SetSecondaryTexturePath(texturePath)
    343         obj.spriteEffect = trinity.TR2_SFX_MODULATE
    344         return self.SpSecondaryTextureScale(obj, startVal, endVal, duration=duration, loops=loops, curveType=curveType, callback=callback, sleep=sleep, timeOffset=timeOffset)
    345 
    346     def SpTunnelIn(self, obj, duration = 1.0, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    347         self.SpTunnelTo(obj, (3.0, 3.0), (0.0, 0.0), duration=duration, loops=loops, curveType=curveType, callback=callback, sleep=sleep, timeOffset=timeOffset)
    348 
    349     def SpTunnelOut(self, obj, duration = 1.0, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    350         self.SpTunnelTo(obj, (0.0, 0.0), (3.0, 3.0), duration=duration, loops=loops, curveType=curveType, callback=callback, sleep=sleep, timeOffset=timeOffset)
    351 
    352     def SpSecondaryTextureMove(self, obj, startVal = (-1.0, -1.0), endVal = (0, 0), duration = 1.0, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    353         curve = self.GetVector2(startVal, endVal, duration, curveType, timeOffset=timeOffset)
    354         return self.Play(curve, obj, 'translationSecondary', loops, callback, sleep)
    355 
    356     def SpMaskTo(self, obj, startVal = (-1.0, 0.0), endVal = (2.0, 0.0), texturePath = None, rotation = 0.0, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    357         if not texturePath:
    358             texturePath = 'res:/UI/Texture/Classes/Animations/maskToGradient.png'
    359         obj.SetSecondaryTexturePath(texturePath)
    360         obj.translationSecondary = startVal
    361         obj.spriteEffect = trinity.TR2_SFX_MODULATE
    362         obj.rotationSecondary = rotation
    363         return self.SpSecondaryTextureMove(obj, startVal, endVal, duration=duration, loops=loops, curveType=curveType, callback=callback, sleep=sleep, timeOffset=timeOffset)
    364 
    365     def SpMaskIn(self, obj, rotation = math.pi * 0.75, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0, texturePath = None):
    366         return self.SpMaskTo(obj, startVal=(-1.0, 0.0), endVal=(1.0, 0.0), rotation=rotation, duration=duration, loops=loops, curveType=curveType, callback=callback, sleep=sleep, timeOffset=timeOffset, texturePath=texturePath)
    367 
    368     def SpMaskOut(self, obj, rotation = -math.pi * 0.25, duration = 0.5, loops = 1, curveType = uiconst.ANIM_SMOOTH, callback = None, sleep = False, timeOffset = 0.0):
    369         return self.SpMaskTo(obj, startVal=(1.0, 0.0), endVal=(-1.0, 0.0), rotation=rotation, duration=duration, loops=loops, curveType=curveType, callback=callback, sleep=sleep, timeOffset=timeOffset)
    370 
    371     def SpSwoopBlink(self, obj, startVal = (-1.0, 0.0), endVal = (2.0, 0.0), texturePath = None, rotation = 0.75 * math.pi, duration = 0.5, loops = 1, curveType = uiconst.ANIM_LINEAR, callback = None, sleep = False, timeOffset = 0.0):
    372         if not texturePath:
    373             texturePath = 'res:/UI/Texture/Classes/Animations/swoopGradient.png'
    374         obj.SetSecondaryTexturePath(texturePath)
    375         obj.spriteEffect = trinity.TR2_SFX_MODULATE
    376         obj.rotationSecondary = rotation
    377         return self.SpSecondaryTextureMove(obj, startVal, endVal, duration=duration, loops=loops, curveType=curveType, callback=callback, sleep=sleep, timeOffset=timeOffset)
    378 
    379     def GetScalar(self, startValue, endValue, duration, curveType = uiconst.ANIM_SMOOTH, timeOffset = 0.0):
    380         if curveType is uiconst.ANIM_RANDOM:
    381             subCurve = trinity.Tr2CurveScalar()
    382             v = startValue + (endValue - startValue) / 2
    383             subCurve.AddKey(0, v, trinity.Tr2CurveInterpolation.LINEAR)
    384             subCurve.AddKey(25, endValue, trinity.Tr2CurveInterpolation.LINEAR)
    385             subCurve.AddKey(50, v, trinity.Tr2CurveInterpolation.LINEAR)
    386             subCurve.SetTimeOffset(timeOffset)
    387             curve = trinity.Tr2CurveScalarExpression()
    388             curve.expression = 'input1 + input2 * fractal(input(0), %s, 3.0, 4)' % duration
    389             curve.input1 = startValue
    390             curve.input2 = endValue
    391             curve.inputs.append(subCurve)
    392             return curve
    393         curve = trinity.Tr2CurveScalar()
    394         curve.SetTimeOffset(timeOffset)
    395         if curveType not in (uiconst.ANIM_LINEAR, uiconst.ANIM_RANDOM) and not isinstance(curveType, (list, tuple)):
    396             interpolation = trinity.Tr2CurveInterpolation.HERMITE
    397         else:
    398             interpolation = trinity.Tr2CurveInterpolation.LINEAR
    399         if isinstance(curveType, (list, tuple)):
    400             points = curveType
    401             for keyTime, keyValue in points:
    402                 key = keyTime * duration
    403                 curve.AddKey(key, keyValue, interpolation, 0, 0, trinity.Tr2CurveTangentType.FREE_SPLIT)
    404 
    405         else:
    406             curve.AddKey(0, startValue, interpolation, 0, 0, trinity.Tr2CurveTangentType.FREE_SPLIT)
    407             if curveType in uiconst.ANIM_OVERSHOT_TYPES:
    408                 amount = self.GetOvershotAmount(curveType)
    409                 keyTime = OVERSHOT_TIME * duration
    410                 keyVal = endValue + amount * (endValue - startValue)
    411                 curve.AddKey(keyTime, keyVal, interpolation, 0, 0, trinity.Tr2CurveTangentType.FREE_SPLIT)
    412             elif curveType is uiconst.ANIM_WAVE:
    413                 curve.AddKey(0.5 * duration, endValue, interpolation, 0, 0, trinity.Tr2CurveTangentType.FREE_SPLIT)
    414                 endValue = startValue
    415             elif curveType is uiconst.ANIM_BOUNCE:
    416                 curve.AddKey(0.5 * duration, endValue, interpolation, 0, 0, trinity.Tr2CurveTangentType.FREE_SPLIT)
    417                 endValue = startValue
    418             curve.AddKey(duration, endValue, interpolation, 0, 0, trinity.Tr2CurveTangentType.FREE_SPLIT)
    419         return curve
    420 
    421     def GetVector2(self, startValue, endValue, duration, curveType = uiconst.ANIM_SMOOTH, timeOffset = 0.0):
    422         curve = trinity.Tr2CurveVector2()
    423         curve.x.SetTimeOffset(timeOffset)
    424         curve.y.SetTimeOffset(timeOffset)
    425         return self._GetVector(curve, startValue, endValue, duration, curveType)
    426 
    427     def GetVector3(self, startValue, endValue, duration, curveType = uiconst.ANIM_SMOOTH, timeOffset = 0.0):
    428         curve = trinity.Tr2CurveVector3()
    429         curve.x.SetTimeOffset(timeOffset)
    430         curve.y.SetTimeOffset(timeOffset)
    431         curve.z.SetTimeOffset(timeOffset)
    432         if isinstance(curveType, (list, tuple)):
    433             numPoints = float(len(curveType))
    434             for i, point in enumerate(curveType):
    435                 curve.AddKey(i / numPoints * duration, point)
    436 
    437             return curve
    438         else:
    439             return self._GetVector(curve, startValue, endValue, duration, curveType)
    440 
    441     def _GetVector(self, curve, startValue, endValue, duration, curveType = uiconst.ANIM_SMOOTH):
    442         if curveType is not uiconst.ANIM_LINEAR:
    443             interpolation = trinity.Tr2CurveInterpolation.HERMITE
    444         else:
    445             interpolation = trinity.Tr2CurveInterpolation.LINEAR
    446         tail = ((0,) * len(startValue), (0,) * len(startValue), trinity.Tr2CurveTangentType.FREE_SPLIT)
    447         if isinstance(curveType, (list, tuple)):
    448             points = curveType
    449             for keyTime, keyValue in points:
    450                 key = keyTime * duration
    451                 curve.AddKey(key, keyValue, interpolation, *tail)
    452 
    453         else:
    454             curve.AddKey(0, startValue, interpolation, *tail)
    455             if curveType in uiconst.ANIM_OVERSHOT_TYPES:
    456                 amount = self.GetOvershotAmount(curveType)
    457                 keyTime = OVERSHOT_TIME * duration
    458                 overshotValue = []
    459                 for i, startV in enumerate(startValue):
    460                     endV = endValue[i]
    461                     keyVal = endV + amount * (endV - startV)
    462                     overshotValue.append(keyVal)
    463 
    464                 curve.AddKey(keyTime, tuple(overshotValue), interpolation, *tail)
    465             elif curveType is uiconst.ANIM_WAVE:
    466                 curve.AddKey((0.5 * duration), endValue, interpolation, *tail)
    467                 endValue = startValue
    468             curve.AddKey(duration, endValue, interpolation, *tail)
    469         return curve
    470 
    471     def GetOvershotAmount(self, curveType):
    472         return uiconst.ANIM_OVERSHOT_TYPES.index(curveType) * 0.2 + 0.1
    473 
    474     def GetQuaternion(self, startValue, endValue, duration, curveType = uiconst.ANIM_SMOOTH, timeOffset = 0.0):
    475         curve = trinity.Tr2CurveQuaternion()
    476         if isinstance(curveType, (list, tuple)):
    477             points = curveType
    478             for keyTime, keyValue in points:
    479                 key = keyTime * duration
    480                 curve.AddKey(key, keyValue)
    481 
    482         else:
    483             curve.AddKey(0, startValue)
    484             if curveType in uiconst.ANIM_OVERSHOT_TYPES:
    485                 amount = self.GetOvershotAmount(curveType)
    486                 keyTime = OVERSHOT_TIME * duration
    487                 keyValX = endValue[0] + amount * (endValue[0] - startValue[0])
    488                 keyValY = endValue[1] + amount * (endValue[1] - startValue[1])
    489                 curve.AddKey(keyTime, (keyValX, keyValY))
    490             elif curveType is uiconst.ANIM_WAVE:
    491                 curve.AddKey(0.5 * duration, endValue)
    492                 endValue = startValue
    493             curve.AddKey(duration, endValue)
    494         return curve
    495 
    496     def GetColorCurve(self, startValue, endValue, duration, curveType = uiconst.ANIM_LINEAR, timeOffset = 0.0):
    497         if len(startValue) == 3:
    498             startValue = startValue + (1,)
    499         if len(endValue) == 3:
    500             endValue = endValue + (1,)
    501         curve = trinity.Tr2CurveColor()
    502         curve.r.SetTimeOffset(timeOffset)
    503         curve.g.SetTimeOffset(timeOffset)
    504         curve.b.SetTimeOffset(timeOffset)
    505         curve.a.SetTimeOffset(timeOffset)
    506         if isinstance(curveType, (list, tuple)):
    507             points = curveType
    508             for keyTime, keyValue in points:
    509                 key = keyTime * duration
    510                 curve.AddKey(key, keyValue, trinity.Tr2CurveInterpolation.LINEAR)
    511 
    512             curve.AddKey(duration, (0, 0, 0, 1))
    513         else:
    514             curve.AddKey(0, startValue, trinity.Tr2CurveInterpolation.LINEAR)
    515         if curveType is uiconst.ANIM_WAVE:
    516             curve.AddKey(0.5 * duration, endValue, trinity.Tr2CurveInterpolation.LINEAR)
    517             curve.AddKey(duration, startValue, trinity.Tr2CurveInterpolation.LINEAR)
    518         else:
    519             curve.AddKey(duration, endValue, trinity.Tr2CurveInterpolation.LINEAR)
    520         return curve
    521 
    522     def GetColorCurveNoAlpha(self, startValue, endValue, duration, curveType = uiconst.ANIM_LINEAR, timeOffset = 0.0):
    523         curve = trinity.Tr2CurveVector3()
    524         curve.x.SetTimeOffset(timeOffset)
    525         curve.y.SetTimeOffset(timeOffset)
    526         curve.z.SetTimeOffset(timeOffset)
    527         if isinstance(curveType, (list, tuple)):
    528             points = curveType
    529             for keyTime, keyValue in points:
    530                 key = keyTime * duration
    531                 curve.AddKey(key, keyValue, trinity.Tr2CurveInterpolation.LINEAR)
    532 
    533             curve.AddKey(duration, (0, 0, 0))
    534         else:
    535             curve.AddKey(0, startValue, trinity.Tr2CurveInterpolation.LINEAR)
    536         if curveType is uiconst.ANIM_WAVE:
    537             curve.AddKey(0.5 * duration, endValue, trinity.Tr2CurveInterpolation.LINEAR)
    538             curve.AddKey(duration, startValue, trinity.Tr2CurveInterpolation.LINEAR)
    539         else:
    540             curve.AddKey(duration, endValue, trinity.Tr2CurveInterpolation.LINEAR)
    541         return curve
    542 
    543 
    544 animations = UIAnimations()