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

uisvc.py (13642B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\uisvc.py
      2 import math
      3 import sys
      4 import weakref
      5 import blue
      6 import log
      7 import carbonui.const as uiconst
      8 import uthread
      9 from carbon.common.script.sys.service import Service
     10 from carbon.common.script.util import mathUtil
     11 from carbonui.uianimations import animations
     12 from carbonui.uicore import uicore
     13 from eve.client.script.ui.shared.ctrltab import CtrlTabWindow
     14 from eve.common.script.sys.idCheckers import IsStation
     15 UI_LAYER_NAMES = ('abovemain', 'bracket', 'charsel', 'intro', 'login', 'main', 'shipui', 'tactical', 'target', 'space_ui')
     16 
     17 class UI(Service):
     18     __update_on_reload__ = 0
     19     __guid__ = 'svc.ui'
     20     __dependencies__ = ['settings']
     21     __notifyevents__ = []
     22 
     23     def Run(self, *etc):
     24         Service.Run(self, *etc)
     25         self.stationsdata = None
     26         self.blinksA = {}
     27         self.blinksRGB = {}
     28         self.blink_running = False
     29         self.knownNonStations = set()
     30         self.stationNames = {}
     31         self.hiddenLayers = weakref.WeakSet()
     32         self._hidden = False
     33         self._suppressed = False
     34         self._can_be_toggled = True
     35         self.cursorSurfaces = {}
     36         uicore.event.RegisterForTriuiEvents([uiconst.UI_KEYUP], self.CheckKeyUp)
     37 
     38     def Stop(self, memStream = None):
     39         self.LogInfo('Stopping UI Service')
     40         self.blink_running = False
     41         self.cursorSurfaces.clear()
     42 
     43     def StopBlink(self, sprite):
     44         if not getattr(self, 'blink_running', False):
     45             return
     46         if not hasattr(self, 'remPending'):
     47             self.remPending = []
     48         self.remPending.append(id(sprite))
     49 
     50     def BlinkSpriteA(self, sprite, a, time = 1000.0, maxCount = 10, passColor = 1, minA = 0.0, timeFunc = blue.os.GetWallclockTime):
     51         if not hasattr(self, 'blinksA'):
     52             self.blinksA = {}
     53         key = id(sprite)
     54         self.blinksA[key] = (sprite,
     55          a,
     56          minA,
     57          time,
     58          maxCount,
     59          passColor,
     60          timeFunc)
     61         if key in getattr(self, 'remPending', []):
     62             self.remPending.remove(key)
     63         if not getattr(self, 'blink_running', False):
     64             self.blink_running = True
     65             uthread.new(self._BlinkThread)
     66 
     67     def BlinkSpriteRGB(self, sprite, r, g, b, time = 1000.0, maxCount = 10, passColor = 1, timeFunc = blue.os.GetWallclockTime):
     68         if not hasattr(self, 'blinksRGB'):
     69             self.blinksRGB = {}
     70         key = id(sprite)
     71         self.blinksRGB[key] = (sprite,
     72          r,
     73          g,
     74          b,
     75          time,
     76          maxCount,
     77          passColor,
     78          timeFunc)
     79         if key in getattr(self, 'remPending', []):
     80             self.remPending.remove(key)
     81         if not getattr(self, 'blink_running', False):
     82             self.blink_running = True
     83             uthread.new(self._BlinkThread)
     84 
     85     def _BlinkThread(self):
     86         startTimes = {}
     87         countsA = {}
     88         countsRGB = {}
     89         if not hasattr(self, 'blinksA'):
     90             self.blinksA = {}
     91         if not hasattr(self, 'blinksRGB'):
     92             self.blinksRGB = {}
     93         try:
     94             while 1:
     95                 if not self:
     96                     return
     97                 diffTimes = {}
     98                 rem = []
     99                 for key, each in self.blinksA.iteritems():
    100                     sprite, a, minA, time, maxCount, passColor, timeFunc = each
    101                     if not sprite or sprite.destroyed:
    102                         rem.append(key)
    103                         continue
    104                     if passColor and getattr(sprite, 'tripass', None):
    105                         color = sprite.tripass.textureStage0.customColor
    106                     else:
    107                         color = sprite.color
    108                     if key in getattr(self, 'remPending', []):
    109                         rem.append(key)
    110                         color.a = minA or a
    111                         continue
    112                     now = timeFunc()
    113                     try:
    114                         diff = blue.os.TimeDiffInMs(now, startTimes[timeFunc])
    115                     except KeyError:
    116                         startTimes[timeFunc] = now
    117                         diff = 0
    118 
    119                     pos = diff % time
    120                     if pos < time / 2.0:
    121                         ndt = min(pos / (time / 2.0), 1.0)
    122                         color.a = mathUtil.Lerp(a, minA, ndt)
    123                     else:
    124                         ndt = min((pos - time / 2.0) / (time / 2.0), 1.0)
    125                         color.a = mathUtil.Lerp(minA, a, ndt)
    126                     if key not in countsA:
    127                         countsA[key] = timeFunc()
    128                     if maxCount and blue.os.TimeDiffInMs(countsA[key], timeFunc()) / time > maxCount:
    129                         rem.append(key)
    130                         color.a = minA or a
    131                         if key in countsA:
    132                             del countsA[key]
    133 
    134                 for each in rem:
    135                     if each in self.blinksA:
    136                         del self.blinksA[each]
    137 
    138                 rem = []
    139                 for key, each in self.blinksRGB.iteritems():
    140                     sprite, r, g, b, time, maxCount, passColor, timeFunc = each
    141                     if not sprite or sprite.destroyed:
    142                         rem.append(key)
    143                         continue
    144                     if passColor and getattr(sprite, 'tripass', None):
    145                         color = sprite.tripass.textureStage0.customColor
    146                     else:
    147                         color = sprite.color
    148                     if key in getattr(self, 'remPending', []):
    149                         rem.append(key)
    150                         color.r = r
    151                         color.g = g
    152                         color.b = b
    153                         continue
    154                     now = timeFunc()
    155                     try:
    156                         diff = blue.os.TimeDiffInMs(now, startTimes[timeFunc])
    157                     except KeyError:
    158                         startTimes[timeFunc] = now
    159                         diff = 0
    160 
    161                     pos = diff % time
    162                     if pos < time / 2.0:
    163                         ndt = min(pos / (time / 2.0), 1.0)
    164                         color.r = mathUtil.Lerp(r, 0.0, ndt)
    165                         color.g = mathUtil.Lerp(g, 0.0, ndt)
    166                         color.b = mathUtil.Lerp(b, 0.0, ndt)
    167                     else:
    168                         ndt = min((pos - time / 2.0) / (time / 2.0), 1.0)
    169                         color.r = mathUtil.Lerp(0.0, r, ndt)
    170                         color.g = mathUtil.Lerp(0.0, g, ndt)
    171                         color.b = mathUtil.Lerp(0.0, b, ndt)
    172                     if key not in countsRGB:
    173                         countsRGB[key] = timeFunc()
    174                     if maxCount and blue.os.TimeDiffInMs(countsRGB[key], timeFunc()) / time > maxCount:
    175                         rem.append(key)
    176                         color.r = r
    177                         color.g = g
    178                         color.b = b
    179                         if key in countsRGB:
    180                             del countsRGB[key]
    181 
    182                 for each in rem:
    183                     if each in self.blinksRGB:
    184                         del self.blinksRGB[each]
    185 
    186                 self.remPending = []
    187                 if not len(self.blinksA) and not len(self.blinksRGB) or not self.blink_running:
    188                     self.blinksA = {}
    189                     self.blinksRGB = {}
    190                     self.blink_running = False
    191                     break
    192                 blue.pyos.synchro.Yield()
    193 
    194         except Exception:
    195             self.blink_running = False
    196             log.LogException()
    197             sys.exc_clear()
    198 
    199     def Rotate(self, uitransform, time = 1.0, fromRot = 360.0, toRot = 0.0, timeFunc = blue.os.GetWallclockTime):
    200         uthread.new(self._Rotate, uitransform, time, fromRot, toRot, timeFunc)
    201 
    202     def _Rotate(self, uitransform, time, fromRot, toRot, timeFunc):
    203         time *= 1000
    204         i = 0
    205         while not uitransform.destroyed:
    206             start, ndt = timeFunc(), 0.0
    207             while ndt != 1.0:
    208                 ndt = max(ndt, min(blue.os.TimeDiffInMs(start, timeFunc()) / time, 1.0))
    209                 deg = mathUtil.Lerp(fromRot, toRot, ndt)
    210                 rad = math.radians(deg)
    211                 uitransform.SetRotation(rad)
    212                 blue.pyos.synchro.Yield()
    213 
    214     def Browse(self, msgkey, dict):
    215         if msgkey == 'BrowseHtml':
    216             blue.os.ShellExecute(dict['url'])
    217         elif msgkey == 'BrowseIGB':
    218             uicore.cmd.GetCommandAndExecute('OpenBrowser', **dict)
    219 
    220     def ForceCursorUpdate(self):
    221         if uicore.uilib:
    222             uicore.UpdateCursor(uicore.uilib.mouseOver, 1)
    223 
    224     def IsNotificationCenterAvailable(self):
    225         notificationUi = sm.GetServiceIfRunning('notificationUIService')
    226         return notificationUi and notificationUi.IsAvailable()
    227 
    228     def CheckKeyUp(self, wnd, msgID, vkey_flag):
    229         ctrl = uicore.uilib.Key(uiconst.VK_CONTROL)
    230         alt = uicore.uilib.Key(uiconst.VK_MENU)
    231         vkey, flag = vkey_flag
    232         if hasattr(wnd, 'KeyUp') and not wnd.destroyed:
    233             if wnd.KeyUp(vkey, flag):
    234                 return 1
    235         if vkey == uiconst.VK_CONTROL:
    236             return self.CheckCtrlUp(wnd, msgID, vkey)
    237         return 1
    238 
    239     def CheckCtrlUp(self, wnd, msgID, ckey):
    240         wnd = CtrlTabWindow.GetIfOpen()
    241         if wnd:
    242             wnd.ChooseHilited()
    243         return 1
    244 
    245     def GetStation(self, stationid):
    246         if self.stationsdata is None:
    247             data = sm.RemoteSvc('map').GetStationInfo()
    248             self.stationsdata = data.Index('stationID')
    249         return self.stationsdata.get(stationid, None)
    250 
    251     def GetStationStaticInfo(self, stationID):
    252         if stationID in cfg.oldStations:
    253             return cfg.oldStations.Get(stationID)
    254         try:
    255             if IsStation(stationID) and stationID not in self.knownNonStations:
    256                 return cfg.stations.Get(stationID)
    257         except RuntimeError:
    258             self.knownNonStations.add(stationID)
    259 
    260     def GetStationName(self, stationID):
    261         try:
    262             return self.stationNames[stationID]
    263         except KeyError:
    264             stationName = cfg.evelocations.Get(stationID).locationName
    265             self.stationNames[stationID] = stationName
    266             return stationName
    267 
    268     def GetStationSolarSystem(self, stationID):
    269         stationInfo = self.GetStationStaticInfo(stationID)
    270         return stationInfo.solarSystemID
    271 
    272     def GetStationOwner(self, stationID):
    273         stationInfo = self.GetStationStaticInfo(stationID)
    274         return stationInfo.ownerID
    275 
    276     def IsUiVisible(self):
    277         return not self._hidden and not self._suppressed
    278 
    279     def IsUIHidden(self):
    280         return self._hidden
    281 
    282     def IsUISuppressed(self):
    283         return self._suppressed
    284 
    285     def GetHiddenLayers(self):
    286         return self.hiddenLayers
    287 
    288     def SetUiToggleState(self, can_be_toggled):
    289         self._can_be_toggled = can_be_toggled
    290 
    291     def HideUi(self, duration = None, except_layers = None):
    292         if self._hidden:
    293             return
    294         if except_layers is None:
    295             except_layers = []
    296         layers = filter(None, map(uicore.layer.Get, UI_LAYER_NAMES))
    297         for layer in layers:
    298             if layer in except_layers:
    299                 continue
    300             if duration:
    301                 animations.FadeOut(layer, duration=duration, callback=layer.Hide)
    302             else:
    303                 layer.state = uiconst.UI_HIDDEN
    304             self.hiddenLayers.add(layer)
    305 
    306         self._hidden = True
    307         if not self._suppressed:
    308             sm.ScatterEvent('OnHideUI')
    309 
    310     def ShowUi(self, duration = None, except_layers = None):
    311         if self._suppressed:
    312             self.hiddenLayers.clear()
    313             self._hidden = False
    314             return
    315         if not self._hidden:
    316             return
    317         if except_layers is None:
    318             except_layers = []
    319         for layer in self.hiddenLayers:
    320             if layer in except_layers:
    321                 continue
    322             layer.state = uiconst.UI_PICKCHILDREN
    323             if duration:
    324                 animations.FadeIn(layer, duration=duration)
    325             else:
    326                 layer.opacity = 1.0
    327 
    328         self.hiddenLayers.clear()
    329         self._hidden = False
    330         if not self._suppressed:
    331             sm.ScatterEvent('OnShowUI')
    332 
    333     def ToggleUiVisible(self):
    334         if not self._can_be_toggled:
    335             return
    336         if self._hidden:
    337             self.ShowUi()
    338         else:
    339             self.HideUi()
    340 
    341     def SuppressUI(self, duration = None):
    342         if self._suppressed:
    343             return
    344         layers = filter(None, map(uicore.layer.Get, UI_LAYER_NAMES))
    345         for layer in layers:
    346             if layer in self.hiddenLayers:
    347                 continue
    348             if duration:
    349                 animations.FadeOut(layer, duration=duration, callback=layer.Hide)
    350             else:
    351                 layer.state = uiconst.UI_HIDDEN
    352 
    353         self._suppressed = True
    354         if not self._hidden:
    355             sm.ScatterEvent('OnHideUI')
    356 
    357     def UnsuppressUI(self, duration = None):
    358         if not self._suppressed:
    359             return
    360         layers = filter(None, map(uicore.layer.Get, UI_LAYER_NAMES))
    361         for layer in layers:
    362             if self.hiddenLayers and layer in self.hiddenLayers:
    363                 continue
    364             layer.state = uiconst.UI_PICKCHILDREN
    365             if duration:
    366                 animations.FadeIn(layer, duration=duration)
    367             else:
    368                 layer.opacity = 1.0
    369 
    370         self._suppressed = False
    371         if not self._hidden:
    372             sm.ScatterEvent('OnShowUI')