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

loading.py (7662B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\loading.py
      2 from carbon.common.script.sys.service import Service
      3 from carbonui.primitives.fill import Fill
      4 from carbonui.util.color import Color
      5 from eve.client.script.ui.shared.progressWnd import ProgressWnd
      6 import blue
      7 import uthread
      8 import carbonui.const as uiconst
      9 import localization
     10 from carbonui.uicore import uicore
     11 
     12 class Loading(Service):
     13     __exportedcalls__ = {'CleanUp': [],
     14      'ProgressWnd': [],
     15      'Cycle': [],
     16      'StopCycle': [],
     17      'HideAllLoad': [],
     18      'FadeIn': [],
     19      'FadeOut': [],
     20      'GoBlack': [],
     21      'IsLoading': []}
     22     __notifyevents__ = ['OnNetClientReadProgress']
     23     __dependencies__ = []
     24     __guid__ = 'svc.loading'
     25     __servicename__ = 'loading'
     26     __displayname__ = 'Loading Service'
     27 
     28     def Run(self, memStream = None):
     29         self.LogInfo('Starting LoadingSvc')
     30         self.soundStarted = self.explicitSound = 0
     31         self.loadingwnd = None
     32         self.loading = 0
     33         self.que = []
     34         self.done = []
     35         self.premature = []
     36         self.currentid = None
     37         self.cycletext = None
     38         self.cycling = 0
     39         self.fill = None
     40         self.hideThread = None
     41         self.fadingToColor = 0
     42         self.fadingFromColor = 0
     43         self.faders = {}
     44 
     45     def Stop(self, memStream = None):
     46         self.CleanUp()
     47 
     48     def CleanUp(self):
     49         self.que = []
     50         self.StopSound()
     51         self.StopCycle()
     52         if self.loadingwnd is not None and not self.loadingwnd.destroyed:
     53             self.loadingwnd.Close()
     54             self.loadingwnd = None
     55         l_loading = uicore.layer.loading
     56         if l_loading:
     57             l_loading.Flush()
     58 
     59     def CountDownWindow(self, question, duration, confirmFunc, abortFunc, inModalLayer = False):
     60         startTime = blue.os.GetWallclockTime()
     61         if inModalLayer:
     62             par = uicore.layer.mloading
     63         else:
     64             par = uicore.layer.loading
     65         wnd = ProgressWnd(parent=par, idx=0)
     66         wnd._SetCaption(question)
     67         if confirmFunc and abortFunc:
     68             wnd.SetAbortConfirmFunc(abortFunc, confirmFunc)
     69         elif abortFunc:
     70             wnd.SetAbortFunc(abortFunc)
     71         wnd.sr.abortFunc = abortFunc
     72         wnd.sr.confirmFunc = confirmFunc
     73         uthread.new(wnd.CountDown, startTime, duration)
     74         return wnd
     75 
     76     def ProgressWnd(self, title = None, strng = '', portion = 1, total = 1, explicitSound = 0, abortFunc = None, useMorph = 1, **kw):
     77         if title is None:
     78             title = localization.GetByLabel('UI/Common/Loading')
     79         if not self.loadingwnd or self.loadingwnd.destroyed:
     80             self.loadingwnd = ProgressWnd(parent=uicore.layer.loading, idx=0)
     81         left = sm.GetService('window').GetCameraLeftOffset(self.loadingwnd.width, align=uiconst.CENTER, left=0)
     82         self.loadingwnd.left = left
     83         self.loadingwnd.top = 0
     84         self.CheckVisibility(portion, total)
     85         if portion >= total:
     86             if self.soundStarted:
     87                 self.StopSound()
     88         elif not self.soundStarted:
     89             self.soundStarted = 1
     90             self.explicitSound = explicitSound
     91         failed = self.loadingwnd.SetStatus(title, strng, max(0, portion), max(0, total), abortFunc, animate=useMorph)
     92         if failed:
     93             self.EndLoading()
     94 
     95     def CheckVisibility(self, portion, total):
     96         if portion is not None and total is not None:
     97             if portion >= total:
     98                 self.hideThread = uthread.new(self.DelayHide)
     99             else:
    100                 if self.hideThread:
    101                     self.hideThread.kill()
    102                     self.hideThread = None
    103                 uicore.layer.loading.state = uiconst.UI_NORMAL
    104 
    105     def DelayHide(self):
    106         blue.pyos.synchro.SleepWallclock(750)
    107         self.EndLoading()
    108 
    109     def EndLoading(self):
    110         if self.loadingwnd:
    111             self.loadingwnd.Close()
    112             self.loadingwnd = None
    113         uicore.layer.loading.state = uiconst.UI_HIDDEN
    114 
    115     def OnNetClientReadProgress(self, have, need):
    116         wnd = getattr(self, 'loadingwnd', None)
    117         if not wnd or wnd.destroyed:
    118             return
    119         wnd.SetReadProgress(int(have / 1024), int(need / 1024))
    120 
    121     def StopSound(self):
    122         if self.soundStarted:
    123             self.soundStarted = self.explicitSound = 0
    124 
    125     def LoadCycle(self, title = None, strng = ''):
    126         return _LoadingCtx(self, title, strng)
    127 
    128     def Cycle(self, title = None, strng = ''):
    129         if title is None:
    130             title = localization.GetByLabel('UI/Common/Loading')
    131         self.cycletext = (title, strng)
    132         uthread.new(self._Cycle)
    133 
    134     def _Cycle(self):
    135         if self.cycling:
    136             return
    137         blue.pyos.synchro.Yield()
    138         while self.cycletext:
    139             self.cycling = 1
    140             for i in xrange(100):
    141                 if self.cycletext:
    142                     self.ProgressWnd(self.cycletext[0], self.cycletext[1], portion=i, total=100, useMorph=0)
    143                 else:
    144                     self.EndLoading()
    145                     break
    146                 blue.pyos.BeNice()
    147 
    148         self.cycling = 0
    149 
    150     def StopCycle(self):
    151         self.cycletext = None
    152         l_loading = uicore.layer.loading
    153         if l_loading:
    154             self.EndLoading()
    155 
    156     def HideAllLoad(self):
    157         self.StopCycle()
    158 
    159     def GoBlack(self):
    160         self.ConstructFill()
    161         self.fill.opacity = 1.0
    162 
    163     def ConstructFill(self, color = Color.BLACK):
    164         if not self.fill:
    165             self.fill = Fill(parent=uicore.layer.loadingFill, state=uiconst.UI_NORMAL, padding=-2, opacity=0.0)
    166         color = (color[0],
    167          color[1],
    168          color[2],
    169          self.fill.opacity)
    170         self.fill.SetRGBA(*color)
    171         self.fill.Enable()
    172 
    173     def IsLoading(self):
    174         return uicore.layer.loading.state == uiconst.UI_NORMAL or self.fadingToColor or self.fadingFromColor or self.cycling
    175 
    176     def GetMaxFade(self):
    177         try:
    178             return max(self.faders.values())
    179         except ValueError:
    180             return 0
    181 
    182     def FadeIn(self, time = 1000.0, color = (0, 0, 0, 1.0), sleep = True, owner = None, *args):
    183         self.ConstructFill(color=color)
    184         sceneMan = sm.GetService('sceneManager')
    185         self.faders[owner] = color[3]
    186         maxFade = self.GetMaxFade()
    187         currentFade = self.fill.opacity
    188         sceneMan.FadeTo(time / 1000.0, color=color, fromValue=currentFade, toValue=maxFade)
    189         uicore.animations.FadeTo(self.fill, currentFade, maxFade, duration=time / 1000.0, sleep=sleep)
    190 
    191     def FadeOut(self, time = 1000.0, opacityStart = None, sleep = True, color = None, owner = None, *args):
    192         sceneMan = sm.GetService('sceneManager')
    193         if self.fill:
    194             if color:
    195                 self.fill.SetRGBA(*color)
    196             self.fill.Disable()
    197             if opacityStart is not None:
    198                 self.fill.opacity = opacityStart
    199             if owner in self.faders:
    200                 del self.faders[owner]
    201             toValue = self.GetMaxFade()
    202             currentFade = self.fill.opacity
    203             sceneMan.FadeTo(time / 1000.0, color=color, fromValue=currentFade, toValue=toValue)
    204             uicore.animations.FadeTo(self.fill, currentFade, toValue, duration=time / 1000.0, sleep=sleep)
    205 
    206 
    207 class _LoadingCtx(object):
    208 
    209     def __init__(self, lService, title, text):
    210         self.loadingService = lService
    211         self.title = title
    212         self.text = text
    213 
    214     def __enter__(self):
    215         self.loadingService.Cycle(self.title, self.text)
    216 
    217     def __exit__(self, exc_type, exc_val, exc_tb):
    218         self.loadingService.StopCycle()
    219         return False