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

shipTreeUISvc.py (11212B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\shipTree\shipTreeUISvc.py
      2 import evetypes
      3 import threadutils
      4 import uthread2
      5 from carbon.client.script.environment.AudioUtil import PlaySound
      6 from carbon.common.script.sys.service import Service
      7 from eve.client.script.ui.shared.shipTree.infoBubble import InfoBubbleShip, InfoBubbleShipGroup
      8 import blue
      9 import uthread
     10 from eve.client.script.ui.shared.shipTree import shipTreeConst
     11 from eve.client.script.ui.control.historyBuffer import HistoryBuffer
     12 from carbonui.uicore import uicore
     13 from eve.client.script.ui.shared.shipTree.shipTreeDockablePanel import ShipTreeDockablePanel
     14 from eve.client.script.ui.shared.shipTree.shipTreeShipGroup import ShipTreeShipGroup
     15 
     16 class ShipTreeUI(Service):
     17     __guid__ = 'svc.shipTreeUI'
     18     __servicename__ = 'Ship tree UI service'
     19     __displayname__ = 'Ship tree UI service'
     20     __notifyevents__ = ('OnSkillsChanged', 'OnSkillQueueRefreshed')
     21     __dependencies__ = []
     22 
     23     def Run(self, *args):
     24         self.forceCloseFanfareBubble = False
     25         self.selectedFaction = None
     26         self.infoBubble = None
     27         self.infoBubbleUIObj = None
     28         self.infoBubbleCloseThread = None
     29         self.fanfareBubble = None
     30         self.fanfareBubbleObj = None
     31         self.fanfareBubbleCloseThread = None
     32         self.fanfareBlinker = None
     33         self._isSelectingFaction = False
     34         self._isFanfareActive = False
     35         self.showInfoBubbleThread = None
     36 
     37     def Open(self, factionID = None):
     38         settings.char.ui.Set('shipTreeSelectedFaction', factionID)
     39         wnd = ShipTreeDockablePanel.GetIfOpen()
     40         if wnd and not wnd.destroyed and wnd.IsMinimized():
     41             wnd.Maximize()
     42         else:
     43             ShipTreeDockablePanel.Open()
     44         if factionID:
     45             self.SelectFaction(factionID)
     46 
     47     def OpenAndShowShip(self, typeID):
     48         factionID = evetypes.GetFactionID(typeID)
     49         shipGroupID = evetypes.GetShipGroupID(typeID)
     50         self._OpenAndPanToGroup(factionID, shipGroupID)
     51         sm.ScatterEvent('OnShipTreeShipFocused', typeID)
     52 
     53     def _OpenAndPanToGroup(self, factionID, shipGroupID = None):
     54         self.Open(factionID)
     55         animate = self._ShouldAnimatePanTo(factionID)
     56         if shipGroupID:
     57             self.PantoShipGroup(shipGroupID, animate)
     58 
     59     def _ShouldAnimatePanTo(self, factionID):
     60         if not ShipTreeDockablePanel.IsOpen():
     61             return False
     62         elif factionID != self.selectedFaction:
     63             return False
     64         else:
     65             return True
     66 
     67     def PantoShipGroup(self, shipGroupID, animate, duration = None):
     68         wnd = ShipTreeDockablePanel.GetIfOpen()
     69         if wnd:
     70             wnd.PanToShipGroup(shipGroupID, animate=animate, duration=duration)
     71 
     72     def OpenAndShowShipGroup(self, factionID, shipGroupID):
     73         self._OpenAndPanToGroup(factionID, shipGroupID)
     74         sm.ScatterEvent('OnShipTreeShipGroupFocused', factionID, shipGroupID)
     75 
     76     def OnShipTreeOpened(self):
     77         self.history = HistoryBuffer()
     78         sm.GetService('skills').GetSkills()
     79         self.SelectFaction(self.GetDefaultFactionID())
     80         sm.GetService('audio').SendUIEvent('isis_start')
     81 
     82     def GetDefaultFactionID(self):
     83         default = sm.GetService('facwar').GetFactionIDByRaceID(session.raceID)
     84         return settings.char.ui.Get('shipTreeSelectedFaction', default)
     85 
     86     def OnShipTreeClosed(self):
     87         self.factionTreesByFactionID = {}
     88         self.selectedFaction = None
     89         self._isFanfareActive = False
     90         self.CloseFanfareBubble()
     91         self.CloseInfoBubble()
     92         sm.GetService('audio').SendUIEvent('isis_end')
     93 
     94     def OnShipTreeMinimized(self):
     95         self._isFanfareActive = False
     96         self.CloseFanfareBubble()
     97         self.CloseInfoBubble()
     98 
     99     def GetEntityByID(self, factionID = None, shipGroupID = None, typeID = None):
    100         if typeID:
    101             return self.GetFactionTree(factionID).GetShipGroup(shipGroupID).GetShip(typeID)
    102         elif shipGroupID:
    103             return self.GetFactionTree(factionID).GetShipGroup(shipGroupID)
    104         else:
    105             return self.GetFactionTree(factionID)
    106 
    107     def GetFactionTree(self, factionID):
    108         return self.factionTreesByFactionID[factionID]
    109 
    110     def GetSelectedFaction(self):
    111         return self.selectedFaction or self.GetDefaultFactionID()
    112 
    113     def SelectFaction(self, factionID, appendHistory = True):
    114         if self.selectedFaction == factionID:
    115             return
    116         if self._isSelectingFaction:
    117             return
    118         self._isSelectingFaction = True
    119         self.CloseFanfareBubble()
    120         try:
    121             oldFactionID = self.selectedFaction
    122             self.selectedFaction = factionID
    123             sm.ScatterEvent('OnBeforeShipTreeFactionSelected', factionID)
    124             ShipTreeDockablePanel.GetIfOpen().SelectFaction(factionID, oldFactionID)
    125             settings.char.ui.Set('shipTreeSelectedFaction', factionID)
    126             sm.ScatterEvent('OnShipTreeFactionSelected', factionID)
    127             eventID = shipTreeConst.GetAudioEventIDForFaction(factionID)
    128             sm.GetService('audio').SendUIEvent(eventID)
    129             if appendHistory:
    130                 self.history.Append(factionID)
    131         finally:
    132             self._isSelectingFaction = False
    133 
    134     def IsGroupLocked(self, factionID, shipGroupID):
    135         group = self.GetEntityByID(factionID, shipGroupID)
    136         return group.data.IsLocked()
    137 
    138     def ShowInfoBubble(self, uiObj, factionID = None, node = None, typeID = None, expertSystems = []):
    139         isZooming = self.IsZooming()
    140         if isZooming:
    141             return
    142         if uiObj == self.infoBubbleUIObj:
    143             return
    144         if self.showInfoBubbleThread:
    145             self.showInfoBubbleThread.kill()
    146         if hasattr(node, 'factionID'):
    147             factionID = node.factionID
    148         self.showInfoBubbleThread = uthread.new(self._ShowInfoBubble, uiObj, factionID, node, typeID, expertSystems=expertSystems)
    149 
    150     def IsZooming(self):
    151         wnd = ShipTreeDockablePanel.GetIfOpen()
    152         return wnd and wnd.isZooming
    153 
    154     def _ShowInfoBubble(self, uiObj, factionID = None, node = None, typeID = None, expertSystems = []):
    155         self.CloseFanfareBubble()
    156         blue.synchro.SleepWallclock(150)
    157         mo = uicore.uilib.mouseOver
    158         if mo == self.infoBubble or mo.IsUnder(self.infoBubble):
    159             return
    160         if uicore.layer.menu.children:
    161             return
    162         if self.infoBubble:
    163             self.CloseInfoBubble()
    164         self.infoBubbleUIObj = uiObj
    165         if self.ShouldInfoBubbleClose():
    166             self.CloseInfoBubble()
    167             return
    168         if node:
    169             self.infoBubble = InfoBubbleShipGroup(factionID=factionID, node=node, parent=uicore.layer.infoBubble, parentObj=uiObj)
    170         else:
    171             self.infoBubble = InfoBubbleShip(factionID=factionID, typeID=typeID, parent=uicore.layer.infoBubble, parentObj=uiObj, expertSystems=expertSystems)
    172         self.infoBubbleCloseThread = uthread.new(self.InfoBubbleCloseThread)
    173         self.showInfoBubbleThread = None
    174 
    175     def InfoBubbleCloseThread(self, *args):
    176         while not self.ShouldInfoBubbleClose():
    177             blue.synchro.Sleep(500)
    178 
    179         self.CloseInfoBubble()
    180 
    181     def ShouldInfoBubbleClose(self):
    182         if self.IsZooming():
    183             return True
    184         mo = uicore.uilib.mouseOver
    185         if mo == self.infoBubbleUIObj or mo.IsUnder(self.infoBubbleUIObj):
    186             return False
    187         if mo == self.infoBubble or mo.IsUnder(self.infoBubble):
    188             return False
    189         if uicore.layer.menu.children:
    190             return False
    191         return True
    192 
    193     def CloseInfoBubble(self):
    194         if self.infoBubble:
    195             self.infoBubble.Close()
    196         self.infoBubble = None
    197         self.infoBubbleUIObj = None
    198         if self.infoBubbleCloseThread:
    199             self.infoBubbleCloseThread.kill()
    200             self.infoBubbleCloseThread = None
    201 
    202     @threadutils.threaded
    203     def ShowUnlockFanfare(self, factionID, shipGroupID):
    204         if self.fanfareBubble:
    205             self.CloseFanfareBubble()
    206         wnd = ShipTreeDockablePanel.GetIfOpen()
    207         if not wnd:
    208             return
    209         self.SelectFaction(factionID=factionID)
    210         self.PantoShipGroup(shipGroupID=shipGroupID, animate=True, duration=0.5)
    211         self.forceCloseFanfareBubble = False
    212         self._isFanfareActive = True
    213         uthread2.sleep(0.5)
    214         uiObj = wnd.GetShipGroup(shipGroupID)
    215         node = uiObj.node
    216         uiObj.FlashGroupIcon(0.9)
    217         uthread2.sleep(0.9)
    218         fanfareDelay = uiObj.PlayFanfare()
    219         uthread2.sleep(fanfareDelay)
    220         if self._isFanfareActive:
    221             self.OpenFanfareInfoBubble(uiObj, node, factionID)
    222         uthread2.sleep(1)
    223         self._isFanfareActive = False
    224 
    225     def OpenFanfareInfoBubble(self, uiObj, node, factionID):
    226         if self.fanfareBubble:
    227             self.CloseFanfareBubble()
    228         PlaySound('ship_goals_reveal_button_end_play')
    229         self.fanfareBubble = InfoBubbleShipGroup(factionID=factionID, node=node, parent=uicore.layer.infoBubble, parentObj=uiObj)
    230         self.fanfareBubbleCloseThread = uthread.new(self._FanfareBubbleCloseThread)
    231 
    232     def _FanfareBubbleCloseThread(self):
    233         while not self.ShouldFanfareInfoBubbleClose():
    234             blue.synchro.Sleep(500)
    235 
    236         self.CloseFanfareBubble()
    237 
    238     def ShouldFanfareInfoBubbleClose(self):
    239         if self._isFanfareActive:
    240             return False
    241         if self.IsZooming():
    242             return True
    243         return self.forceCloseFanfareBubble
    244 
    245     def CloseFanfareBubble(self):
    246         self.forceCloseFanfareBubble = False
    247         if self.fanfareBubble:
    248             self.fanfareBubble.Close()
    249         if self.fanfareBlinker:
    250             self.fanfareBlinker.dispose()
    251         self.fanfareBubble = None
    252         self.fanfareBlinker = None
    253         self.fanfareBubbleUIObj = None
    254         if self.fanfareBubbleCloseThread:
    255             self.fanfareBubbleCloseThread.kill()
    256             self.fanfareBubbleCloseThread = None
    257 
    258     def GetZoomLevel(self):
    259         wnd = ShipTreeDockablePanel.GetIfOpen()
    260         if wnd:
    261             return wnd.zoomLevel
    262 
    263     def PanTo(self, x, y, animate = True):
    264         wnd = ShipTreeDockablePanel.GetIfOpen()
    265         if wnd:
    266             wnd.PanToPropCoords(x, y, animate)
    267 
    268     def GoBack(self):
    269         factionID = self.history.GoBack()
    270         if factionID:
    271             self.SelectFaction(factionID, appendHistory=False)
    272 
    273     def GoForward(self):
    274         factionID = self.history.GoForward()
    275         if factionID:
    276             self.SelectFaction(factionID, appendHistory=False)
    277 
    278     def OnDrag(self):
    279         self.CloseInfoBubble()
    280         self.CloseFanfareBubble()
    281 
    282     def OnSkillsChanged(self, *args):
    283         sm.GetService('shipTree').FlushRecentlyChangedSkillsCache()
    284         self._UpdateActiveTreeSkills()
    285 
    286     def OnSkillQueueRefreshed(self):
    287         self._UpdateActiveTreeSkills()
    288 
    289     def _UpdateActiveTreeSkills(self):
    290         if sm.GetService('viewState').IsViewActive('shiptree'):
    291             wnd = ShipTreeDockablePanel.GetIfOpen()
    292             if wnd:
    293                 wnd.shipTreeCont.UpdateTreeSkills()
    294             sm.ScatterEvent('OnShipTreeSkillTrained')