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

infoPanelSkyhookTheftTimerContainer.py (8892B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\infoPanels\skyhookTheftUI\infoPanelSkyhookTheftTimerContainer.py
      2 import localization
      3 import locks
      4 from carbonui import uiconst
      5 from carbonui.primitives.container import Container
      6 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      7 from carbonui.primitives.sprite import Sprite
      8 from carbonui.primitives.transform import Transform
      9 from carbonui.uianimations import animations
     10 from carbonui.util.color import Color
     11 from eve.client.script.ui import eveColor
     12 from dynamicresources.client.ui.ess_info_panel_ui_const import TRANSITION_LOCK
     13 from eve.client.script.ui.control.eveLabel import EveLabelLarge, EveCaptionLarge
     14 from eve.client.script.ui.control.gaugeCircular import GaugeCircular
     15 import eveicon
     16 from gametime import GetSimTime
     17 from localization.formatters import FormatTimeIntervalShort
     18 import uthread2
     19 import trinity
     20 import mathext
     21 import logging
     22 log = logging.getLogger(__name__)
     23 LINK_STARTED = 1
     24 LINK_FAILED = 2
     25 LINK_SUCCESS = 3
     26 
     27 class InfoPanelSkyhookTheftTimerContainer(ContainerAutoSize):
     28     default_name = 'skyhookLinkingCont'
     29     default_align = uiconst.TOTOP
     30     default_alignMode = uiconst.TOTOP
     31 
     32     def __init__(self, startTime = None, endTime = None, planetName = None, service = None, *args, **kwargs):
     33         super(InfoPanelSkyhookTheftTimerContainer, self).__init__(*args, **kwargs)
     34         self.completeLinkAtTime = endTime
     35         self.statedLinkAtTime = startTime
     36         self.planetName = planetName
     37         self._skyhookLinkingTimer = None
     38         self.skyhookSiloTheftProgressBar = None
     39         self.collapsedStateCont = None
     40         self.currentState = LINK_STARTED
     41         self.ConstructUncollapsedState(True)
     42 
     43     def ConstructUncollapsedState(self, animateChange):
     44         with locks.TempLock(TRANSITION_LOCK):
     45             gaugeStates = {'skyhookLinkingTimerStartValue': None}
     46             if self.skyhookSiloTheftProgressBar:
     47                 gaugeStates['skyhookLinkingTimerStartValue'] = self.skyhookSiloTheftProgressBar.value
     48             if self._skyhookLinkingTimer:
     49                 self._skyhookLinkingTimer.Kill()
     50                 self._skyhookLinkingTimer = None
     51             self.ConstructSkyhookLinkingState(gaugeStates, animateChange)
     52 
     53     def ConstructSkyhookLinkingState(self, gaugeStates, animate):
     54         self.skyhookLinkingTimerCont = Container(name='timerCont', parent=self, align=uiconst.TOTOP, alignMode=uiconst.TOPLEFT, height=46, state=uiconst.UI_DISABLED)
     55         startingOpacity = 0 if animate else 1
     56         self.skyhookSiloTheftProgressBar = GaugeCircular(parent=self.skyhookLinkingTimerCont, color=eveColor.FOCUS_BLUE, align=uiconst.TOLEFT, showMarker=True, lineWidth=2, radius=18, colorStart=eveColor.FOCUS_BLUE, colorEnd=eveColor.FOCUS_BLUE, colorBg=Color(*eveColor.WHITE).SetAlpha(0.2).GetRGBA(), opacity=startingOpacity)
     57         self.hourglassSymbolTransform = Transform(parent=self.skyhookLinkingTimerCont, align=uiconst.TOPLEFT, width=36, height=36)
     58         self.hourglassSymbolSprite = Sprite(parent=self.hourglassSymbolTransform, align=uiconst.CENTER, texturePath=eveicon.hourglass, color=eveColor.WHITE, width=16, height=16)
     59         self.hourglassSymbolSprite.scalingCenter = (0.5, 0.5)
     60         self.skyhookLinkingTimerTextCont = ContainerAutoSize(name='timerTextCont', parent=self.skyhookLinkingTimerCont, align=uiconst.TOLEFT, alignMode=uiconst.TOPLEFT, padLeft=15, opacity=startingOpacity)
     61         self.descriptionLabel = EveLabelLarge(parent=self.skyhookLinkingTimerTextCont, text=localization.GetByLabel('UI/OrbitalSkyhook/SkyhookInfoPanel/SkyhookTheftLootDrops', planetName=self.planetName), align=uiconst.TOPLEFT, top=-3)
     62         current = self.statedLinkAtTime
     63         maxVal = self.completeLinkAtTime
     64         countdown = max(0, maxVal - current)
     65         self.skyhookLinkingCountdownLabel = EveCaptionLarge(parent=self.skyhookLinkingTimerTextCont, text=FormatTimeIntervalShort(countdown, showFrom='hour', showTo='second'), align=uiconst.BOTTOMLEFT, bold=False, top=3, color=eveColor.FOCUS_BLUE)
     66         self.skyhookLinkingSuccessLabel = EveCaptionLarge(parent=self.skyhookLinkingTimerTextCont, text=localization.GetByLabel('UI/OrbitalSkyhook/SkyhookInfoPanel/SkyhookTheftSuccessful'), align=uiconst.BOTTOMLEFT, bold=False, top=3, color=eveColor.SUCCESS_GREEN, opacity=0)
     67         self.skyhookLinkingFailedLabel = EveCaptionLarge(parent=self.skyhookLinkingTimerTextCont, text=localization.GetByLabel('UI/OrbitalSkyhook/SkyhookInfoPanel/SkyhookTheftFailed'), align=uiconst.BOTTOMLEFT, bold=False, top=3, color=eveColor.DANGER_RED, opacity=0)
     68         if not animate and gaugeStates['skyhookLinkingTimerStartValue']:
     69             self.skyhookSiloTheftProgressBar.SetValue(gaugeStates['skyhookLinkingTimerStartValue'], animate=False)
     70 
     71         def animate_in():
     72             with locks.TempLock(TRANSITION_LOCK):
     73                 animations.FadeIn(self.skyhookSiloTheftProgressBar, duration=0.25)
     74                 animations.FadeIn(self.skyhookLinkingTimerTextCont, duration=0.25)
     75                 animations.MoveInFromRight(self.skyhookLinkingTimerTextCont, amount=10, duration=0.25, sleep=True)
     76 
     77         if animate:
     78             uthread2.StartTasklet(animate_in)
     79         self._skyhookLinkingTimer = uthread2.StartTasklet(self.UpdateLinkingTimer, self.skyhookLinkingCountdownLabel, self.skyhookSiloTheftProgressBar)
     80 
     81     def UpdateLinkingTimer(self, label, gauge, animate = True):
     82         while self._skyhookLinkingTimer:
     83             current = GetSimTime()
     84             timeLeft = long(max(0, self.completeLinkAtTime - current))
     85             proportion = 1.0 - float(current - self.statedLinkAtTime) / float(self.completeLinkAtTime - self.statedLinkAtTime)
     86             proportion = mathext.clamp(proportion, 0.0, 1.0)
     87             gauge.SetValue(proportion, animate=animate)
     88             if timeLeft > 0:
     89                 label.SetText(FormatTimeIntervalShort(timeLeft, showFrom='hour', showTo='second'))
     90                 uthread2.Sleep(1)
     91             else:
     92                 label.SetText(FormatTimeIntervalShort(0, showFrom='hour', showTo='second'))
     93                 self._skyhookLinkingTimer = None
     94 
     95     def LinkFailed(self):
     96         self.StopTimers()
     97         self.TransitionState(LINK_FAILED)
     98 
     99     def LinkSuccess(self):
    100         self.StopTimers()
    101         self.TransitionState(LINK_SUCCESS)
    102 
    103     def StopTimers(self):
    104         if self._skyhookLinkingTimer:
    105             self._skyhookLinkingTimer.Kill()
    106             self._skyhookLinkingTimer = None
    107 
    108     def TransitionState(self, newState = None):
    109         with locks.TempLock('TransitionState'):
    110             self.currentState = newState
    111             if self.currentState == LINK_SUCCESS:
    112                 descText = localization.GetByLabel('UI/OrbitalSkyhook/SkyhookInfoPanel/SkyhookTheftLootDropped', planetName=self.planetName)
    113                 self.AnimateState(descText, self.skyhookLinkingSuccessLabel)
    114             elif self.currentState == LINK_FAILED:
    115                 self.iconBlink = self.FlipFlop(self.hourglassSymbolSprite, startValue=1.0, endValue=0.0)
    116                 descText = localization.GetByLabel('UI/OrbitalSkyhook/SkyhookInfoPanel/SkyhookTheftLinkBroke', planetName=self.planetName)
    117                 self.AnimateState(descText, self.skyhookLinkingFailedLabel)
    118                 self.skyhookSiloTheftProgressBar.SetColorMarker(eveColor.DANGER_RED)
    119                 self.skyhookSiloTheftProgressBar.SetColor(eveColor.DANGER_RED, eveColor.DANGER_RED)
    120                 self.gaugeBlink = self.FlipFlop(self.skyhookSiloTheftProgressBar.gauge, startValue=1.0, endValue=0.0)
    121             animations.FadeOut(self.hourglassSymbolTransform, duration=0.25, timeOffset=2)
    122             animations.FadeOut(self.skyhookSiloTheftProgressBar, duration=0.25, timeOffset=2)
    123             animations.FadeOut(self.skyhookLinkingTimerTextCont, duration=0.25, timeOffset=2)
    124             animations.MoveOutRight(self.skyhookLinkingTimerTextCont, amount=10, duration=0.25, sleep=True, timeOffset=2)
    125         self.Close()
    126 
    127     def AnimateState(self, descText, label):
    128         self.descriptionLabel.text = descText
    129         animations.FadeOut(self.skyhookLinkingCountdownLabel, duration=0.25, timeOffset=0)
    130         animations.FadeIn(label, duration=0.25, timeOffset=0)
    131 
    132     def FlipFlop(self, sprite, duration = 1.0, startValue = 0.0, endValue = 1.0, loops = 5):
    133         curve = trinity.Tr2CurveScalar()
    134         curve.AddKey(0, startValue, trinity.Tr2CurveInterpolation.LINEAR)
    135         curve.AddKey(0.01 * duration, endValue, trinity.Tr2CurveInterpolation.LINEAR)
    136         curve.AddKey(0.5 * duration, endValue, trinity.Tr2CurveInterpolation.LINEAR)
    137         curve.AddKey(0.51 * duration, startValue, trinity.Tr2CurveInterpolation.LINEAR)
    138         curve.AddKey(duration, startValue, trinity.Tr2CurveInterpolation.LINEAR)
    139         return animations.Play(curve, sprite, 'opacity', loops, None, False)