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

tidiIndicator.py (8738B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\tidiIndicator.py
      2 import math
      3 from collections import Iterable
      4 import blue
      5 import eveui
      6 import localization
      7 import mathext
      8 import uthread
      9 from carbon.common.script.util import logUtil as log
     10 from carbonui import uiconst
     11 from carbonui.primitives.container import Container
     12 from carbonui.primitives.sprite import Sprite
     13 from carbonui.primitives.transform import Transform
     14 labXfromRGB = (0.4124, 0.3576, 0.1805)
     15 labYfromRGB = (0.2126, 0.7152, 0.0722)
     16 labZfromRGB = (0.0193, 0.1192, 0.9505)
     17 labRfromXYZ = (3.2406, -1.5372, -0.4986)
     18 labGfromXYZ = (-0.9689, 1.8758, 0.0415)
     19 labBfromXYZ = (0.0557, -0.204, 1.057)
     20 
     21 def GammaCorrect(color):
     22     if color > 0.04045:
     23         return ((color + 0.055) / 1.055) ** 2.4
     24     else:
     25         return color / 12.92
     26 
     27 
     28 def UnGammaCorrect(color):
     29     if color > 0.0031308:
     30         return 1.055 * color ** (1 / 2.4) - 0.055
     31     else:
     32         return 12.92 * color
     33 
     34 
     35 def RGB2Lab(rgbColor):
     36     rgbColor = map(GammaCorrect, rgbColor)
     37     rgbColor = map(lambda x: x * 100, rgbColor)
     38     x = sum(map(lambda x: x[0] * x[1], zip(rgbColor, labXfromRGB)))
     39     y = sum(map(lambda x: x[0] * x[1], zip(rgbColor, labYfromRGB)))
     40     z = sum(map(lambda x: x[0] * x[1], zip(rgbColor, labZfromRGB)))
     41     x /= 95.047
     42     y /= 100
     43     z /= 108.883
     44 
     45     def Labify(x):
     46         if x > 0.008856:
     47             return x ** (1 / 3.0)
     48         else:
     49             return x * 7.787 + 16 / 116.0
     50 
     51     x, y, z = map(Labify, (x, y, z))
     52     L = y * 116.0 - 16.0
     53     a = 500.0 * (x - y)
     54     b = 200.0 * (y - z)
     55     return (L, a, b)
     56 
     57 
     58 def Lab2RGB(labColor):
     59     L, a, b = labColor
     60     y = (L + 16.0) / 116.0
     61     x = y + a * 0.002
     62     z = y - b * 0.005
     63     x, y, z = map(lambda x: x ** 3, (x, y, z))
     64 
     65     def what(x):
     66         if x > 0.008856:
     67             return x
     68         else:
     69             return (x - 16 / 166) / 7.787
     70 
     71     x, y, z = map(what, (x, y, z))
     72     x *= 95.047
     73     y *= 100
     74     z *= 108.883
     75     x, y, z = map(lambda x: x / 100, (x, y, z))
     76     r = sum(map(lambda x: x[0] * x[1], zip((x, y, z), labRfromXYZ)))
     77     g = sum(map(lambda x: x[0] * x[1], zip((x, y, z), labGfromXYZ)))
     78     b = sum(map(lambda x: x[0] * x[1], zip((x, y, z), labBfromXYZ)))
     79     return map(UnGammaCorrect, (r, g, b))
     80 
     81 
     82 rgbLerpValues = [(0, (1, 0, 0)),
     83  (0.25, (0.94, 0.35, 0.14)),
     84  (0.5, (1, 1, 0)),
     85  (0.9, (0, 1, 0)),
     86  (1, (1, 1, 1))]
     87 labLerpValues = map(lambda x: (x[0], RGB2Lab(x[1])), rgbLerpValues)
     88 
     89 def LerpHelper(lerpVals, value, errorValue):
     90     for i in xrange(len(lerpVals)):
     91         if value == lerpVals[i][0]:
     92             return lerpVals[i][1]
     93         if value > lerpVals[i][0] and value < lerpVals[i + 1][0]:
     94             lerpPct = (lerpVals[i][0] - value) / float(lerpVals[i][0] - lerpVals[i + 1][0])
     95             if isinstance(lerpVals[i][1], Iterable):
     96                 return map(lambda x: mathext.lerp(x[0], x[1], lerpPct), zip(lerpVals[i][1], lerpVals[i + 1][1]))
     97             else:
     98                 return mathext.lerp(lerpVals[i][1], lerpVals[i + 1][1], lerpPct)
     99 
    100     log.LogTraceback('TiDi LerpHelper ran off the edge')
    101     return errorValue
    102 
    103 
    104 class TiDiIndicator(Container):
    105 
    106     def ApplyAttributes(self, attributes):
    107         Container.ApplyAttributes(self, attributes)
    108         self.state = uiconst.UI_HIDDEN
    109         self.initialized = False
    110         size = 24
    111         self.ramps = Container(parent=self, name='ramps', pos=(0,
    112          0,
    113          size,
    114          size), align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED)
    115         leftRampCont = Container(parent=self.ramps, name='leftRampCont', pos=(0,
    116          0,
    117          size / 2,
    118          size), align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, clipChildren=True)
    119         self.leftRamp = Transform(parent=leftRampCont, name='leftRamp', pos=(0,
    120          0,
    121          size,
    122          size), align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED)
    123         Sprite(parent=self.leftRamp, name='rampSprite', pos=(0,
    124          0,
    125          size / 2,
    126          size), state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/TiDiIndicator/left.png', color=(0.0, 0.0, 0.0, 0.55))
    127         rightRampCont = Container(parent=self.ramps, name='rightRampCont', pos=(0,
    128          0,
    129          size / 2,
    130          size), align=uiconst.TOPRIGHT, state=uiconst.UI_DISABLED, clipChildren=True)
    131         self.rightRamp = Transform(parent=rightRampCont, name='rightRamp', pos=(-size / 2,
    132          0,
    133          size,
    134          size), align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED)
    135         Sprite(parent=self.rightRamp, name='rampSprite', pos=(size / 2,
    136          0,
    137          size / 2,
    138          size), state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/TiDiIndicator/right.png', color=(0.0, 0.0, 0.0, 0.55))
    139         self.coloredPie = Sprite(parent=self, name='tidiColoredPie', pos=(0,
    140          0,
    141          size,
    142          size), texturePath='res:/UI/Texture/classes/TiDiIndicator/circle.png', color=(0, 1, 0, 1), state=uiconst.UI_DISABLED)
    143         background = Sprite(parent=self, name='tidiBackground', pos=(0,
    144          0,
    145          size,
    146          size), texturePath='res:/UI/Texture/classes/TiDiIndicator/shadow.png', color=(0.2, 0.2, 0.2, 0.5), state=uiconst.UI_DISABLED)
    147         uthread.new(self.Animate)
    148 
    149     def StartupAnim(self):
    150         fadeLerps = ((0, 0), (750, 1), (1500, 1))
    151         spinLerps = ((0, 1),
    152          (250, 1),
    153          (600, 0),
    154          (950, 1),
    155          (1500, 1))
    156         startTime = blue.os.GetWallclockTime()
    157         elapsedTimeMS = 0
    158         while self and not self.destroyed and elapsedTimeMS < 1500:
    159             self.opacity = LerpHelper(fadeLerps, elapsedTimeMS, 0)
    160             spin = LerpHelper(spinLerps, elapsedTimeMS, 0)
    161             leftRamp = min(1.0, max(0.0, spin * 2))
    162             rightRamp = min(1.0, max(0.0, spin * 2 - 1.0))
    163             self.leftRamp.SetRotation(math.pi + math.pi * leftRamp)
    164             self.rightRamp.SetRotation(math.pi + math.pi * rightRamp)
    165             color = LerpHelper(labLerpValues, spin, (1, 1, 1))
    166             self.coloredPie.SetRGBA(*(Lab2RGB(color) + [0.65]))
    167             eveui.wait_for_next_frame()
    168             elapsedTimeMS = blue.os.TimeDiffInMs(startTime, blue.os.GetWallclockTime())
    169 
    170     def ShutdownAnim(self):
    171         self.leftRamp.SetRotation(0)
    172         self.rightRamp.SetRotation(0)
    173         fadeLerps = ((0, 1), (750, 0))
    174         startTime = blue.os.GetWallclockTime()
    175         elapsedTimeMS = 0
    176         while self and not self.destroyed and elapsedTimeMS < 750:
    177             self.opacity = LerpHelper(fadeLerps, elapsedTimeMS, 0)
    178             eveui.wait_for_next_frame()
    179             elapsedTimeMS = blue.os.TimeDiffInMs(startTime, blue.os.GetWallclockTime())
    180 
    181         self.state = uiconst.UI_HIDDEN
    182         self.opacity = 0
    183 
    184     def Animate(self):
    185         if not self or self.destroyed:
    186             return
    187         prevFactor = 1
    188         while self and not self.destroyed:
    189             curFactor = blue.os.desiredSimDilation
    190             if (not self.initialized or curFactor != prevFactor) and (curFactor < 0.98 or prevFactor < 0.98):
    191                 if not self.initialized:
    192                     prevFactor = curFactor
    193                 self.state = uiconst.UI_NORMAL
    194                 self.hint = localization.GetByLabel('UI/Neocom/TidiTooltip', tidiAmount=int(curFactor * 100))
    195                 if self.opacity < 1:
    196                     self.StartupAnim()
    197                     continue
    198 
    199                 def RotateAndColor(animFactor):
    200                     animFactor = min(max(animFactor, 0), 1)
    201                     leftRamp = min(1.0, max(0.0, animFactor * 2))
    202                     rightRamp = min(1.0, max(0.0, animFactor * 2 - 1.0))
    203                     self.leftRamp.SetRotation(math.pi + math.pi * leftRamp)
    204                     self.rightRamp.SetRotation(math.pi + math.pi * rightRamp)
    205                     color = LerpHelper(labLerpValues, animFactor, (0, 0, 0))
    206                     self.coloredPie.SetRGBA(*(Lab2RGB(color) + [0.65]))
    207 
    208                 startTime = blue.os.GetWallclockTime()
    209                 elapsedTimeMS = 0
    210                 animDurationMS = 500
    211                 while self and not self.destroyed and elapsedTimeMS < animDurationMS:
    212                     portionDone = elapsedTimeMS / float(animDurationMS)
    213                     animFactor = mathext.lerp(prevFactor, curFactor, portionDone)
    214                     RotateAndColor(animFactor)
    215                     eveui.wait_for_next_frame()
    216                     elapsedTimeMS = blue.os.TimeDiffInMs(startTime, blue.os.GetWallclockTime())
    217 
    218                 RotateAndColor(curFactor)
    219                 prevFactor = curFactor
    220                 if curFactor >= 0.98 and self:
    221                     self.ShutdownAnim()
    222             self.initialized = True
    223             eveui.wait_for_next_frame()