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

navigation.py (14680B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\station\navigation.py
      2 import os
      3 import videoplayer
      4 from carbon.common.script.util.format import FmtAmt
      5 from carbonui.primitives.container import Container
      6 from carbonui.util.color import Color
      7 from eve.client.script.ui.camera.capitalHangarCameraController import CapitalHangarCameraController
      8 from eve.client.script.ui.camera.debugCameraController import DebugCameraController
      9 from eve.client.script.ui.camera.modularHangarCameraController import ModularHangarCameraController
     10 from eve.client.script.ui.camera.modularHangarCapitalCameraController import ModularHangarCapitalCameraController
     11 from eve.client.script.ui.camera.cameraUtil import IsDynamicCameraMovementEnabled
     12 import blue
     13 from carbon.common.script.util import mathCommon
     14 from eve.client.script.ui.control import eveLabel
     15 from eve.client.script.ui.util import uix
     16 import evecamera
     17 import uthread
     18 import carbonui.const as uiconst
     19 from carbon.common.script.util.timerstuff import AutoTimer
     20 import localization
     21 from carbonui.control.layer import LayerCore
     22 from eve.client.script.ui.camera.hangarCameraController import HangarCameraController
     23 import inventorycommon.const as invconst
     24 from eve.common.script.sys import eveCfg
     25 from logmodule import LogException
     26 from carbonui.uicore import uicore
     27 from eveservices.menu import GetMenuService
     28 from menu import MenuList
     29 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     30 
     31 class HangarLayer(LayerCore):
     32     __notifyevents__ = ['OnActiveCameraChanged']
     33 
     34     def __init__(self, *args, **kwds):
     35         LayerCore.__init__(self, *args, **kwds)
     36         self.looking = 0
     37         self.scene = None
     38         self.cameraController = None
     39         self.maxZoom = 750.0
     40         self.minZoom = 150.0
     41         self.isMouseMoving = False
     42         self.mouseDownPick = None
     43         self.startYaw = None
     44         self.prevYaw = None
     45         self.prevDirection = None
     46         self.numSpins = 0
     47         self.spinThread = None
     48         self.prevSpinTime = None
     49         self.fadeLayer = Container(bgParent=self, bgColor=Color.BLACK, opacity=0.0)
     50         self.lastInputTimestamp = 0
     51         self._idleThread = None
     52         self.idleAnimationActive = False
     53 
     54     def Startup(self):
     55         pass
     56 
     57     def GetMenu(self):
     58         x, y = uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi(uicore.uilib.y)
     59         scene = sm.StartService('sceneManager').GetRegisteredScene('hangar')
     60         if scene:
     61             projection, view, viewport = uix.GetFullscreenProjectionViewAndViewport()
     62             pick = scene.PickObject(x, y, projection, view, viewport)
     63             if pick and pick.name == str(eveCfg.GetActiveShip()):
     64                 return self.GetShipMenu()
     65 
     66     def OnMouseEnter(self, *args):
     67         if sm.GetService('ui').IsUiVisible():
     68             uicore.layer.main.state = uiconst.UI_PICKCHILDREN
     69 
     70     def OnDropData(self, dragObj, nodes):
     71         sm.GetService('loading').StopCycle()
     72         station = sm.GetService('station')
     73         if len(nodes) == 1:
     74             node = nodes[0]
     75             if getattr(node, '__guid__', None) not in ('xtriui.InvItem', 'listentry.InvItem'):
     76                 return
     77             if session.shipid == node.item.itemID:
     78                 prompt_player_fsd_dialog('CantMoveActiveShip', {})
     79                 return
     80             if node.item.categoryID == const.categoryShip and node.item.singleton:
     81                 if not node.item.ownerID == session.charid:
     82                     prompt_player_fsd_dialog('CantDoThatWithSomeoneElsesStuff')
     83                     return
     84                 station.TryActivateShip(node.item)
     85 
     86     @staticmethod
     87     def GetShipMenu():
     88         if not eveCfg.GetActiveShip():
     89             return MenuList()
     90         hangarInv = sm.GetService('invCache').GetInventory(const.containerHangar)
     91         hangarItems = hangarInv.List(const.flagHangar)
     92         activeShip = eveCfg.GetActiveShip()
     93         for each in hangarItems:
     94             if each.itemID == activeShip:
     95                 return GetMenuService().InvItemMenu(each)
     96 
     97     def OnDblClick(self, *args):
     98         uicore.cmd.OpenCargoHoldOfActiveShip()
     99 
    100     def OnBillboardClicked(self):
    101         videoPath = videoplayer.playlistresource.get_currently_played_video('dynamic:/hangarvideos')
    102         if not videoPath:
    103             return
    104         fileName = os.path.basename(videoPath)
    105         try:
    106             if fileName.startswith('c_'):
    107                 corpID = self.GetContentID(fileName)
    108                 sm.GetService('info').ShowInfo(invconst.typeCorporation, corpID)
    109             elif fileName.startswith('s_'):
    110                 offerID = self.GetContentID(fileName)
    111                 sm.GetService('vgsService').ShowOffer(offerID)
    112             elif fileName.startswith('v_'):
    113                 dirName = os.path.dirname(videoPath)
    114                 videoPath = self.GetContentID(fileName)
    115                 uicore.cmd.OpenVideoPlayerWindow(videoPath=videoPath)
    116         except Exception as e:
    117             LogException('Failed to complete billboard click action video: %s' % videoPath)
    118 
    119     def GetContentID(self, fileName):
    120         return fileName.split('_')[1]
    121 
    122     def OnMouseDown(self, *args):
    123         self.mouseDownPick = self.GetAreaPick()
    124         cameraIsFixed = False
    125         if self.cameraController:
    126             self.cameraController.OnMouseDown(*args)
    127             cameraIsFixed = getattr(self.cameraController.GetCamera(), 'fixed', False)
    128         if sm.GetService('ui').IsUiVisible():
    129             uicore.layer.main.state = uiconst.UI_DISABLED
    130         if cameraIsFixed:
    131             self.cursor = uiconst.UICURSOR_DEFAULT
    132         else:
    133             self.cursor = uiconst.UICURSOR_DRAGGABLE
    134         self._UpdateLastActionTimeStamp()
    135         uicore.uilib.ClipCursor(0, 0, uicore.desktop.width, uicore.desktop.height)
    136         uicore.uilib.SetCapture(self)
    137 
    138     def GetAreaPick(self):
    139         if self.cameraController:
    140             pick = self.cameraController.GetPick()
    141             if pick:
    142                 areaID, _ = pick
    143                 return areaID
    144 
    145     def OnMouseUp(self, button, *args):
    146         sm.ScatterEvent('OnCameraDragEnd')
    147         self.isMouseMoving = False
    148         if self.cameraController:
    149             self.cameraController.OnMouseUp(button, *args)
    150         if sm.GetService('ui').IsUiVisible():
    151             uicore.layer.main.state = uiconst.UI_PICKCHILDREN
    152         self.cursor = None
    153         uicore.uilib.UnclipCursor()
    154         if uicore.uilib.GetCapture() == self:
    155             uicore.uilib.ReleaseCapture()
    156         areaID = self.GetAreaPick()
    157         if button == 0 and areaID == self.mouseDownPick == 'billboard':
    158             self.OnBillboardClicked()
    159         self._UpdateLastActionTimeStamp()
    160         self.mouseDownPick = None
    161 
    162     def OnMouseWheel(self, *args):
    163         if self.cameraController:
    164             self.cameraController.OnMouseWheel(*args)
    165         self._UpdateLastActionTimeStamp()
    166 
    167     def OnMouseMove(self, *args):
    168         if uicore.IsDragging():
    169             return
    170         if self.cameraController:
    171             self.cameraController.OnMouseMove(*args)
    172             if uicore.uilib.leftbtn and not uicore.uilib.rightbtn:
    173                 self._ActivateSpinThread()
    174 
    175     def GetShipSpins(self):
    176         return self.numSpins
    177 
    178     def OnOpenView(self, **kwargs):
    179         self._ActivateSpinThread()
    180         self.spinCounterLabel = eveLabel.EveLabelLargeBold(parent=self, align=uiconst.CENTERBOTTOM, top=14, hint=localization.GetByLabel('UI/Station/Hangar/ShipSpinCounter'), state=uiconst.UI_NORMAL, color=(1, 1, 1, 1))
    181         self.numSpins = 0
    182         self.spinCounterLabel.Hide()
    183         self.spinCounterLabel.startSpinCount = self.numSpins
    184         self.spinCounterLabel.displayTriggered = False
    185         self.spinCounterTimer = None
    186         self.InitCameraController()
    187         self.lastInputTimestamp = blue.os.GetSimTime()
    188         if self._idleThread is None and IsDynamicCameraMovementEnabled():
    189             self._idleThread = uthread.new(self._IdleThread)
    190 
    191     def InitCameraController(self):
    192         camera = sm.GetService('sceneManager').GetActivePrimaryCamera()
    193         if camera:
    194             self.UpdateCameraController(camera.cameraID)
    195 
    196     def OnActiveCameraChanged(self, cameraID):
    197         self.UpdateCameraController(cameraID)
    198         if self._idleThread is None and IsDynamicCameraMovementEnabled():
    199             self._idleThread = uthread.new(self._IdleThread)
    200 
    201     def UpdateCameraController(self, cameraID):
    202         if self.cameraController:
    203             self.cameraController.Deactivate()
    204         if cameraID == evecamera.CAM_HANGAR:
    205             self.cameraController = HangarCameraController()
    206         elif cameraID == evecamera.CAM_CAPITALHANGAR:
    207             self.cameraController = CapitalHangarCameraController()
    208         elif cameraID == evecamera.CAM_MODULARHANGAR:
    209             self.cameraController = ModularHangarCameraController()
    210         elif cameraID == evecamera.CAM_DEBUG:
    211             self.cameraController = DebugCameraController()
    212         elif cameraID == evecamera.CAM_MODULARHANGAR_CAPITAL:
    213             self.cameraController = ModularHangarCapitalCameraController()
    214         else:
    215             self.cameraController = None
    216         if self.cameraController:
    217             self.cameraController.Activate()
    218 
    219     def OnCloseView(self, *args):
    220         self.KillSpinThread()
    221         if self._idleThread is not None:
    222             self._idleThread.kill()
    223             self._idleThread = None
    224         if self.spinCounterLabel:
    225             self.spinCounterLabel.Close()
    226 
    227     def HideSpinCounter(self):
    228         if self.spinCounterTimer:
    229             self.spinCounterTimer = None
    230         uicore.animations.FadeOut(self.spinCounterLabel, duration=0.5, sleep=True)
    231         self.spinCounterLabel.displayTriggered = False
    232 
    233     def _CountRotations(self, curYaw):
    234         spinDirection = mathCommon.GetLesserAngleBetweenYaws(self.prevYaw, curYaw)
    235         if spinDirection == 0.0:
    236             return
    237         if self.prevDirection is None:
    238             self.prevDirection = spinDirection
    239         if self.prevDirection * spinDirection < 0.0:
    240             self.prevYaw = self.startYaw = curYaw
    241             self.prevDirection = spinDirection
    242         caughtSpin = False
    243         if self.prevYaw < curYaw:
    244             caughtSpin = self.prevYaw < self.startYaw < curYaw and spinDirection > 0.0
    245         elif self.prevYaw > curYaw:
    246             caughtSpin = self.prevYaw > self.startYaw > curYaw and spinDirection < 0.0
    247         if caughtSpin:
    248             self.numSpins += 1
    249             self.spinCounterLabel.text = FmtAmt(self.numSpins)
    250             self.spinCounterTimer = AutoTimer(30000, self.HideSpinCounter)
    251             if self.numSpins >= self.spinCounterLabel.startSpinCount + 10 and not self.spinCounterLabel.displayTriggered:
    252                 self.spinCounterLabel.Show()
    253                 uicore.animations.BlinkIn(self.spinCounterLabel, duration=0.5, endVal=0.6, loops=2)
    254                 self.spinCounterLabel.displayTriggered = True
    255             elif self.numSpins % 1000 == 0 and self.spinCounterLabel.displayTriggered:
    256                 uicore.animations.SpColorMorphTo(self.spinCounterLabel, startColor=(1.0, 1.0, 1.0, 0.6), endColor=(0.0, 1.0, 1.0, 1.0), duration=1.0, sleep=True)
    257                 uicore.animations.SpColorMorphTo(self.spinCounterLabel, startColor=(0.0, 1.0, 1.0, 1.0), endColor=(1.0, 1.0, 1.0, 0.6), duration=1.0)
    258             elif self.numSpins % 100 == 0 and self.spinCounterLabel.displayTriggered:
    259                 uicore.animations.SpColorMorphTo(self.spinCounterLabel, startColor=(1.0, 1.0, 1.0, 0.6), endColor=(1.0, 1.0, 1.0, 1.0), duration=0.75, sleep=True)
    260                 uicore.animations.SpColorMorphTo(self.spinCounterLabel, startColor=(1.0, 1.0, 1.0, 1.0), endColor=(1.0, 1.0, 1.0, 0.6), duration=0.75)
    261             if self.numSpins % 20 == 0 and self.spinCounterLabel.displayTriggered:
    262                 sm.ScatterEvent('OnSpinThresholdReached', self.numSpins)
    263             elif self.numSpins == 10 or self.numSpins == 42:
    264                 sm.ScatterEvent('OnSpinThresholdReached', self.numSpins)
    265         self.prevYaw = curYaw
    266 
    267     def _ActivateSpinThread(self):
    268         if self.spinThread is None:
    269             self.spinThread = uthread.new(self._PollCamera)
    270 
    271     def KillSpinThread(self):
    272         if self.spinThread:
    273             self.spinThread.kill()
    274             self.spinThread = None
    275 
    276     def _IsCameraSpinning(self, curYaw):
    277         now = blue.os.GetSimTime()
    278         if self.prevSpinTime is None:
    279             self.prevSpinTime = now
    280         if self.prevYaw is None:
    281             self.startYaw = self.prevYaw = curYaw
    282         notIdleFor1Sec = now < self.prevSpinTime + const.SEC
    283         cameraMoved = self.prevYaw != curYaw
    284         if cameraMoved:
    285             self.prevSpinTime = now
    286         return notIdleFor1Sec or cameraMoved
    287 
    288     def _PollCamera(self):
    289         cameraStillSpinning = True
    290         while cameraStillSpinning:
    291             blue.pyos.synchro.Yield()
    292             if self.cameraController is None or self.cameraController.GetCamera() is None:
    293                 break
    294             camera = self.cameraController.GetCamera()
    295             curYaw = camera.GetYaw()
    296             cameraStillSpinning = self._IsCameraSpinning(curYaw)
    297             if cameraStillSpinning:
    298                 self._CountRotations(curYaw)
    299 
    300         self.spinThread = None
    301 
    302     def _UpdateLastActionTimeStamp(self):
    303         self.lastInputTimestamp = blue.os.GetSimTime()
    304         self.idleAnimationActive = False
    305 
    306     def _IdleThread(self):
    307         idleTimer = 1000000000.0
    308         while self.cameraController is not None and self._idleThread is not None:
    309             if self.cameraController.GetCamera() is None:
    310                 break
    311             currentTime = blue.os.GetSimTime()
    312             if self.lastInputTimestamp + idleTimer < currentTime:
    313                 self.idleAnimationActive = True
    314                 camera = self.cameraController.GetCamera()
    315                 if hasattr(camera, 'StartIdleAnimation'):
    316                     camera.StartIdleAnimation()
    317                 while self.idleAnimationActive and self._idleThread is not None:
    318                     blue.pyos.synchro.Yield()
    319 
    320                 if hasattr(camera, 'StopIdleAnimations'):
    321                     camera.StopIdleAnimations()
    322                 if not IsDynamicCameraMovementEnabled():
    323                     break
    324             else:
    325                 blue.synchro.Sleep(1000)
    326 
    327         self._idleThread = None
    328 
    329     def FadeIn(self, duration = 0.5, sleep = False):
    330         sceneMan = sm.GetService('sceneManager')
    331         sceneMan.FadeIn(duration, sleep)
    332 
    333     def FadeOut(self, duration = 0.5, sleep = False):
    334         sceneMan = sm.GetService('sceneManager')
    335         sceneMan.FadeOut(duration, sleep)