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

planetNavigation.py (13585B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\planet\planetNavigation.py
      2 import math
      3 import carbonui.const as uiconst
      4 import blue
      5 from carbon.common.script.sys.serviceConst import ROLE_GML
      6 from carbonui.control.layer import LayerCore
      7 from eve.client.script.ui.camera.planetCameraController import PlanetCameraController
      8 from eve.client.script.ui.shared.planet import planetConst, planetCommon
      9 import uthread
     10 import log
     11 import geo2
     12 from carbonui.uicore import uicore
     13 from eve.client.script.ui.shared.planet.templateSavingUtil import ConfirmExportWnd
     14 from inventorycommon.const import groupExtractionControlUnitPins, groupSpaceportPins
     15 from menu import MenuLabel
     16 TYPE_PLANET = 1
     17 TYPE_LINK = 2
     18 TYPE_PIN = 3
     19 TYPE_OTHERPLAYERSPIN = 4
     20 TYPE_EXTRACTIONHEAD = 6
     21 TYPE_TILE = 7
     22 TYPE_DEPLETIONPIN = 8
     23 
     24 class PlanetLayer(LayerCore):
     25 
     26     def OnCloseView(self, *args):
     27         self.cameraController.camera.SetCallback(None)
     28         ConfirmExportWnd.CloseIfOpen()
     29 
     30     def ApplyAttributes(self, attributes):
     31         LayerCore.ApplyAttributes(self, attributes)
     32         self.align = uiconst.TOALL
     33         self.orbitOnMouseMove = False
     34         self.planetWasRotated = False
     35         self.isTabStop = True
     36         self.pickLast = None
     37         self.mouseDownID = None
     38 
     39     def Startup(self):
     40         self.eventManager = sm.GetService('planetUI').eventManager
     41         self.myPinManager = sm.GetService('planetUI').myPinManager
     42         self.otherPinManager = sm.GetService('planetUI').otherPinManager
     43         self.cameraController = PlanetCameraController()
     44         self.cameraController.camera.SetCallback(self.OnCameraUpdated)
     45         uthread.new(self.InitCamera)
     46 
     47     def InitCamera(self):
     48         return self.OrbitToPointOfInterest(initStartPos=True)
     49 
     50     def OnCameraUpdated(self):
     51         self.UpdateSunDirection()
     52         sm.GetService('planetUI').OnPlanetZoomChanged(self.cameraController.camera.GetZoomLinear())
     53         if uicore.uilib.mouseOver == self:
     54             uicore.UpdateCursor(self)
     55 
     56     def UpdateSunDirection(self):
     57         camera = self.cameraController.camera
     58         rightMat = geo2.MatrixRotationAxis(camera.GetXAxis(), math.radians(-225))
     59         upMat = geo2.MatrixRotationAxis(camera.upDirection, math.radians(-45))
     60         scene = self.GetScene()
     61         scene.sunDirection = geo2.Vec3Normalize(geo2.Vec3TransformNormal(geo2.Vec3TransformNormal(camera.GetLookAtDirection(), rightMat), upMat))
     62 
     63     def OnSetFocus(self, *args):
     64         pass
     65 
     66     def OnKillFocus(self, *args):
     67         self.eventManager.OnPlanetNavFocusLost()
     68 
     69     def OnMouseMove(self, *args):
     70         if self.orbitOnMouseMove:
     71             self.cameraController.OnMouseMove()
     72             self.planetWasRotated = True
     73         typeID, ID, isTemplatePin = self.GetPick()
     74         if not self.orbitOnMouseMove and isTemplatePin:
     75             return self.eventManager.MoveTemplate()
     76         if not self.pickLast:
     77             self.pickLast = typeID
     78             self.areaIDLast = ID
     79             return
     80         if not typeID:
     81             return
     82         if (typeID, ID) == (self.pickLast, self.areaIDLast):
     83             self._ScatterMouseMoveEvent(typeID, ID)
     84             return
     85         if self.pickLast:
     86             self._ScatterMouseExitEvent(self.pickLast, self.areaIDLast)
     87         self._ScatterMouseEnterEvent(typeID, ID)
     88         self.pickLast = typeID
     89         self.areaIDLast = ID
     90 
     91     def OnMouseExit(self, *args):
     92         if self.pickLast:
     93             self._ScatterMouseExitEvent(self.pickLast, self.areaIDLast)
     94             self.pickLast = self.areaIDLast = None
     95 
     96     def OnMouseEnter(self, *args):
     97         if sm.GetService('ui').IsUiVisible():
     98             uicore.layer.main.state = uiconst.UI_PICKCHILDREN
     99 
    100     def _ScatterMouseMoveEvent(self, typeID, ID):
    101         state = self.eventManager.state
    102         if typeID != TYPE_PIN or state in (planetConst.STATE_BUILDPIN, planetConst.STATE_SURVEY):
    103             surfacePoint = planetCommon.GetPickIntersectionPoint()
    104             if surfacePoint:
    105                 self.eventManager.OnPlanetSurfaceMouseMoved(surfacePoint)
    106 
    107     def _ScatterMouseEnterEvent(self, typeID, ID):
    108         if typeID == TYPE_PIN:
    109             self.eventManager.OnPlanetPinMouseEnter(ID)
    110         elif typeID == TYPE_OTHERPLAYERSPIN:
    111             self.eventManager.OnPlanetOtherPinMouseEnter(ID)
    112         elif typeID == TYPE_LINK:
    113             self.eventManager.OnPlanetLinkMouseEnter(ID)
    114         elif typeID == TYPE_EXTRACTIONHEAD:
    115             self.eventManager.OnExtractionHeadMouseEnter(*ID)
    116 
    117     def _ScatterMouseExitEvent(self, typeID, ID):
    118         if typeID == TYPE_PIN:
    119             self.eventManager.OnPlanetPinMouseExit(ID)
    120         elif typeID == TYPE_OTHERPLAYERSPIN:
    121             self.eventManager.OnPlanetOtherPinMouseExit(ID)
    122         elif typeID == TYPE_LINK:
    123             self.eventManager.OnPlanetLinkMouseExit(ID)
    124         elif typeID == TYPE_EXTRACTIONHEAD:
    125             self.eventManager.OnExtractionHeadMouseExit(*ID)
    126 
    127     def OnClick(self, *args):
    128         typeID, ID, isTemplatePin = self.GetPick()
    129         if self.planetWasRotated or self.eventManager.state == planetConst.STATE_BUILDPIN:
    130             self.eventManager.OnPlanetNavClicked(self.planetWasRotated)
    131         elif isTemplatePin:
    132             self.eventManager.OnPlanetNavClicked(self.planetWasRotated)
    133         elif ID == self.mouseDownID:
    134             if typeID == TYPE_PIN:
    135                 self.eventManager.OnPlanetPinClicked(ID)
    136             elif typeID == TYPE_LINK:
    137                 self.eventManager.OnPlanetLinkClicked(ID)
    138             elif typeID == TYPE_OTHERPLAYERSPIN:
    139                 self.eventManager.OnOtherCharactersCommandPinClicked(ID)
    140             elif typeID == TYPE_DEPLETIONPIN:
    141                 self.eventManager.OnDepletionPinClicked(ID)
    142             elif typeID == TYPE_EXTRACTIONHEAD:
    143                 self.eventManager.OnExtractionHeadClicked(*ID)
    144             else:
    145                 self.eventManager.OnPlanetNavClicked(self.planetWasRotated)
    146         self.planetWasRotated = False
    147         self.mouseDownID = None
    148         self.cameraAuto = False
    149 
    150     def OnMouseDown(self, *args):
    151         if not uicore.uilib.leftbtn:
    152             return
    153         typeID, self.mouseDownID, isTemplatePin = self.GetPick()
    154         if typeID == TYPE_EXTRACTIONHEAD:
    155             self.eventManager.OnExtractionHeadMouseDown(*self.mouseDownID)
    156         elif typeID not in (TYPE_PIN, TYPE_LINK):
    157             self.orbitOnMouseMove = True
    158 
    159     def OnMouseUp(self, btnNum):
    160         self.eventManager.OnPlanetNavMouseUp()
    161         if btnNum == 0:
    162             self.orbitOnMouseMove = False
    163         elif btnNum == 1:
    164             self.rightMbtnUsedForCameraControl = False
    165 
    166     def OnDblClick(self, *args):
    167         surfacePoint = planetCommon.GetPickIntersectionPoint()
    168         typeID, ID, isTemplatePin = self.GetPick()
    169         if typeID == TYPE_PIN:
    170             self.eventManager.OnPlanetPinDblClicked(ID)
    171         elif typeID == TYPE_LINK:
    172             self.eventManager.OnPlanetLinkDblClicked(ID)
    173         elif typeID == TYPE_OTHERPLAYERSPIN:
    174             pass
    175         elif surfacePoint is not None:
    176             self.OrbitToCommandCenter()
    177 
    178     def OrbitToCommandCenter(self, initStartPos = False):
    179         pin = sm.GetService('planetUI').myPinManager.GetCommandCenterPin()
    180         if pin:
    181             self.cameraController.camera.OrbitToSurfacePoint(pin.surfacePoint, newZoom=0.15, initStartPos=initStartPos)
    182         else:
    183             self.cameraController.camera.SetZoomLinear(0.9)
    184 
    185     def OrbitToPointOfInterest(self, initStartPos = False):
    186         planetUISvc = sm.GetService('planetUI')
    187         pinsByTypeID = planetUISvc.myPinManager.GetPinsByGroupTypeIDs()
    188         extractionControlUnitPins = pinsByTypeID.get(groupExtractionControlUnitPins, [])
    189         spaceportPins = pinsByTypeID.get(groupSpaceportPins, [])
    190         if len(extractionControlUnitPins) > 0:
    191             pin = extractionControlUnitPins[0]
    192             self.cameraController.camera.OrbitToSurfacePoint(pin.surfacePoint, newZoom=0.15, initStartPos=initStartPos)
    193         elif len(spaceportPins) > 0:
    194             pin = spaceportPins[0]
    195             self.cameraController.camera.OrbitToSurfacePoint(pin.surfacePoint, newZoom=0.15, initStartPos=initStartPos)
    196         else:
    197             self.OrbitToCommandCenter(initStartPos=initStartPos)
    198 
    199     def OnMouseWheel(self, *args):
    200         self.cameraController.OnMouseWheel(*args)
    201 
    202     def ZoomBy(self, amount):
    203         self.cameraController.ZoomBy(amount)
    204 
    205     def DebugMenu(self):
    206         menu = []
    207         planetUISvc = sm.GetService('planetUI')
    208         planetID = sm.GetService('planetUI').planetID
    209         surfacePoint = planetCommon.GetPickIntersectionPoint()
    210         menuItems = [('ID: %d' % planetID, blue.pyos.SetClipboardData, [str(planetID)]),
    211          None,
    212          ('Verify Simulation', planetUISvc.VerifySimulation, []),
    213          ('Draw cartesian axis', planetUISvc.curveLineDrawer.DrawCartesianAxis, [])]
    214         if surfacePoint is not None:
    215             menuItems.append(('Get Local Resource Report', planetUISvc.GetLocalDistributionReport, [surfacePoint]))
    216             menuItems.append(('Add depletion point', planetUISvc.AddDepletionPoint, [surfacePoint]))
    217             menuItems.append(('Theta: {0} Phi: {1}'.format(surfacePoint.theta, surfacePoint.phi), blue.pyos.SetClipboardData, ['']))
    218         menu.extend(menuItems)
    219         return menu
    220 
    221     def GetMenu(self):
    222         typeID, ID, isTemplatePin = self.GetPick()
    223         if self.eventManager.OnPlanetNavRightClicked():
    224             return
    225         if typeID == TYPE_PIN:
    226             return self.myPinManager.GetPinMenu(ID)
    227         if typeID == TYPE_OTHERPLAYERSPIN:
    228             return self.otherPinManager.GetPinMenuOther(ID)
    229         if typeID == TYPE_LINK:
    230             m = self.myPinManager.GetLinkMenu(ID)
    231             if m:
    232                 return m
    233         if getattr(self, 'rightMbtnUsedForCameraControl', None):
    234             self.rightMbtnUsedForCameraControl = False
    235             return
    236         m = []
    237         if session.role & ROLE_GML == ROLE_GML:
    238             m.append(['GM/Debug Menu...', self.DebugMenu()])
    239             m.append(None)
    240         if sm.GetService('planetUI').otherPinManager is not None:
    241             showOtherPins = settings.user.ui.Get('planetShowOtherCharactersPins', True)
    242             if showOtherPins:
    243                 showOtherPinsTxt = MenuLabel('UI/PI/Common/HideOtherNetworks')
    244             else:
    245                 showOtherPinsTxt = MenuLabel('UI/PI/Common/ShowOtherNetworks')
    246             m.append((showOtherPinsTxt, sm.GetService('planetUI').otherPinManager.ShowOrHideOtherCharactersPins, [not showOtherPins]))
    247         m.append((MenuLabel('UI/PI/Common/ExitPlanetMode'), sm.GetService('viewState').CloseSecondaryView, ('planet',)))
    248         return m
    249 
    250     def GetPick(self):
    251         scene = self.GetScene()
    252         x, y = uicore.uilib.x, uicore.uilib.y
    253         pickType = TYPE_PLANET
    254         id = None
    255         isTemplatePin = False
    256         if scene:
    257             areaID, pick = self.cameraController.GetPick(x, y, scene)
    258             if pick:
    259                 if pick.__bluetype__ == 'trinity.EveSpherePin' and pick.name:
    260                     try:
    261                         pickType, id, isTemplatePin = self.GetPinTypeAndIDFromPickName(pick.name)
    262                     except Exception:
    263                         log.LogException('A pin with no ID was picked... this should not be possible:')
    264                         return (None, None, False)
    265 
    266                 elif pick == sm.GetService('planetUI').curveLineDrawer.GetLineSet('links'):
    267                     pickType = TYPE_LINK
    268                     id = areaID
    269             else:
    270                 pickType = TYPE_PLANET
    271                 id = None
    272         else:
    273             pickType = None
    274         return (pickType, id, isTemplatePin)
    275 
    276     def GetScene(self):
    277         return sm.GetService('sceneManager').GetRegisteredScene('planet')
    278 
    279     def GetPinTypeAndIDFromPickName(self, pickName):
    280         ids = pickName.split(',')
    281         pinType = int(ids[0])
    282         isTemplatePin = False
    283         if pickName.endswith('temp'):
    284             isTemplatePin = True
    285         if pinType == planetCommon.PINTYPE_NORMAL:
    286             pickID = int(ids[1])
    287             pickType = TYPE_PIN
    288         elif pinType == planetCommon.PINTYPE_NORMALEDIT:
    289             pickID = (int(ids[1]), int(ids[2]))
    290             pickType = TYPE_PIN
    291         elif pinType == planetCommon.PINTYPE_EXTRACTIONHEAD:
    292             pickID = (int(ids[1]), int(ids[2]))
    293             pickType = TYPE_EXTRACTIONHEAD
    294         elif pinType == planetCommon.PINTYPE_OTHERS:
    295             pickID = int(ids[1])
    296             pickType = TYPE_OTHERPLAYERSPIN
    297         elif pinType == planetCommon.PINTYPE_DEPLETION:
    298             pickID = int(ids[1])
    299             pickType = TYPE_DEPLETIONPIN
    300         else:
    301             return (None, None, False)
    302         return (pickType, pickID, isTemplatePin)
    303 
    304     def GetCursor(self):
    305         state = self.eventManager.state
    306         if state in (planetConst.STATE_CREATELINKSTART, planetConst.STATE_CREATELINKEND):
    307             return uiconst.UICURSOR_PLANET_CREATE_LINK
    308         elif state == planetConst.STATE_BUILDPIN:
    309             return uiconst.UICURSOR_PLANET_PLACE_PIN
    310         elif state == planetConst.STATE_DECOMMISSION:
    311             return uiconst.UICURSOR_PLANET_DECOMMISSION
    312         elif state == planetConst.STATE_CREATEROUTE:
    313             return uiconst.UICURSOR_PLANET_CREATE_ROUTE
    314         elif state == planetConst.STATE_SURVEY and uicore.uilib.Key(uiconst.VK_CONTROL):
    315             return uiconst.UICURSOR_PLANET_PLACE_PIN
    316         else:
    317             return uiconst.UICURSOR_DRAGGABLE