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

mapView.py (77941B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\mapView\mapView.py
      2 import itertools
      3 import logging
      4 import evecamera
      5 import evemath
      6 import uthread2
      7 from brennivin.itertoolsext import Bundle
      8 from carbonui.primitives.base import ScaleDpi
      9 from carbonui.uianimations import animations
     10 from carbonui.util import colorblind
     11 from carbonui.util.color import Color
     12 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel
     13 from eve.client.script.ui.shared.mapView import mapViewConst
     14 from eve.client.script.ui.shared.mapView.extraStarParticles import BaseExtraStarParticleController
     15 from eve.client.script.ui.shared.mapView.filters.mapFilterConst import PARTICLE_SPRITE_TEXTURE, PARTICLE_SPRITE_HEAT_TEXTURE, PARTICLE_ICON_ATLAS2, NEUTRAL_COLOR, MARKER_NONE
     16 from eve.client.script.ui.shared.mapView.layout.mapLayoutHandler import MapViewLayoutHandler
     17 from eve.client.script.ui.shared.mapView.mapViewBookmarkHandler import MapViewBookmarkHandler
     18 from eve.client.script.ui.shared.mapView.mapViewData import mapViewData
     19 from eve.client.script.ui.shared.mapView.mapViewLineOpacity import GetLineOpacityFinderClass
     20 from eve.client.script.ui.shared.mapView.mapViewNavigation import MapViewNavigation
     21 from eve.client.script.ui.shared.mapView.markers.mapMarkerEmanationLock import MarkerEmanationLock
     22 from eve.client.script.ui.shared.mapView.markers.mapMarkerMyHome import MarkerMyHome
     23 from eve.client.script.ui.shared.mapView.markers.mapMarkerMyLocation import MarkerMyLocation
     24 from eve.client.script.ui.shared.mapView.markers.mapMarkerSolarSystem import FilterInfo
     25 from eve.client.script.ui.shared.mapView.markers.mapMarkersHandler import MapViewMarkersHandler
     26 from eve.client.script.ui.shared.mapView.mapViewUtil import SolarSystemPosToMapPos, GetConstellationCorrdinates, GetRegionCorrdinates, GetLandmarkPos, CAMERA_DISTANCE_SCALING_FACTOR, BUBBLE_BASE_SIZE_MULTIPLIER, PARTICLE_SPRITE_TEXTURE, PARTICLE_SPRITE_DATA_TEXTURE, SpriteValues
     27 from eve.client.script.ui.shared.mapView.mapViewSceneContainer import MapViewSceneContainer
     28 from eve.client.script.ui.shared.mapView.mapViewSettings import GetMapViewSetting, IsAbstractModeActive, useFakeMapColorData
     29 from eve.client.script.ui.shared.mapView import mapViewUtil
     30 from eve.client.script.ui.shared.mapView.systemMapHandler import SystemMapHandler
     31 from eve.common.lib import appConst
     32 from eve.client.script.ui.shared.mapView.workforce import MapViewSovHubHandler
     33 from eve.common.script.sys.idCheckers import IsStation, IsKnownSpaceSystem, IsKnownSpaceRegion, IsKnownSpaceConstellation
     34 import blue
     35 import trinity
     36 import uthread
     37 from menu import MenuList
     38 from carbonui.primitives.container import Container
     39 from eve.client.script.ui.shared.mapView.mapViewConst import JUMPBRIDGE_COLOR, JUMPBRIDGE_COLOR_NO_ACCESS, JUMPBRIDGE_TYPE, MARKERID_MYHOME, MARKERID_MYPOS, MARKERID_SOLARSYSTEM_CELESTIAL, MARKERID_EMANATION_LOCK_GATE, UNIVERSE_SCALE, VIEWMODE_LAYOUT_CONSTELLATIONS, VIEWMODE_LAYOUT_REGIONS, VIEWMODE_LAYOUT_SETTINGS, VIEWMODE_LAYOUT_SHOW_ABSTRACT_SETTINGS, VIEWMODE_LINES_SETTINGS, VIEWMODE_LINES_SHOW_ALLIANCE_SETTINGS, VIEWMODE_LINES_SHOW_JUMP_BRIDGES_MY, VIEWMODE_LINES_SHOW_JUMP_BRIDGES_SETTINGS, VIEWMODE_MARKERS_SETTINGS, OPACITY_LINES_SELECTED, VIEWMODE_LAYOUT_SHOW_JUMP_RANGE_SETTINGS, LINE_COLOR, STAR_SIZE_UNIMPORTANT, VIEWMODE_LINES_SHOW_JUMP_BRIDGES_NONE
     40 import eve.client.script.ui.shared.maps.mapcommon as mapcommon
     41 from eve.common.script.sys.idCheckers import IsSolarSystem, IsConstellation, IsRegion
     42 import geo2
     43 import carbonui.const as uiconst
     44 from logmodule import LogException
     45 from carbonui.uicore import uicore
     46 from eveservices.menu import GetMenuService
     47 from eve.common.lib import appConst as const
     48 from stargate.client.gateLockController import GateLockController
     49 from stargate.client import get_gate_lock_messenger
     50 from stargate.client.gate_signals import on_lock_removed, on_lock_added
     51 from eve.common.script.util.systemExclusions import IsValidDestination
     52 ZOOM_DIST_REGION = 20000
     53 ZOOM_DIST_CONSTELLATION = 10000
     54 ZOOM_DIST_SYSTEM = 6000
     55 TIME_BENICE = 100
     56 log = logging.getLogger(__name__)
     57 LINE_EFFECT = 'res:/Graphics/Effect/Managed/Space/SpecialFX/Lines3DStarMapNew.fx'
     58 PARTICLE_EFFECT = 'res:/Graphics/Effect/Managed/Space/SpecialFX/Particles/StarmapNew.fx'
     59 DISTANCE_RANGE = 'distanceRange'
     60 SIZE_CONTROLS = 'SizeControls'
     61 ATLAS_CONFIG = 'AtlasConfiguration'
     62 HEX_TILE_SIZE = 60
     63 
     64 class MapView(Container):
     65     __notifyevents__ = ['OnUIScalingChange',
     66      'OnAutopilotUpdated',
     67      'OnDestinationSet',
     68      'OnHomeStationChanged',
     69      'OnBallparkSetState',
     70      'OnSessionChanged',
     71      'DoBallClear',
     72      'DoBallsAdded',
     73      'OnStructuresVisibilityUpdated']
     74     mapRoot = None
     75     curveSet = None
     76     systemMap = None
     77     markersHandler = None
     78     bookmarkHandler = None
     79     sovHubHandler = None
     80     layoutHandler = None
     81     markersAlwaysVisible = set()
     82     markersLoaded = False
     83     dirtyLineIDs = set()
     84     inFocus = False
     85     isFullScreen = False
     86     currentSolarsystem = None
     87     hilightID = None
     88     jumpRouteHighlightID = None
     89     mapViewID = None
     90     jumpDriveTransform = None
     91     waiting_for_layout_change = False
     92     showDebugInfo = False
     93     cameraID = evecamera.CAM_MAP
     94 
     95     def ApplyAttributes(self, attributes):
     96         self.activeFilter = None
     97         Container.ApplyAttributes(self, attributes)
     98         self.updating_filter_data = False
     99         self.isFullScreen = attributes.isFullScreen
    100         self.mapViewID = attributes.mapViewID or self.mapViewID
    101         interestID = attributes.interestID or self._GetDefaultInterestID()
    102         zoomToItem = attributes.get('zoomToItem', True)
    103         self.ConstructExtraParticleController()
    104         self.ResetVariables()
    105         self.mapSvc = sm.GetService('map')
    106         self.clientPathfinderService = sm.GetService('clientPathfinderService')
    107         self.mapGroupingMode = self.GetGroupingMode()
    108         self.layoutHandler = self.ConstructLayoutHandler()
    109         self.ConstructOverlayTools()
    110         self.ConstructMarkerLayers()
    111         self.ConstructMapNavigation()
    112         self.sceneContainer = MapViewSceneContainer(parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, cameraID=self.cameraID)
    113         self.UpdateInitCameraDistance()
    114         uicore.registry.SetFocus(self)
    115         self._BeforeConstructScene(attributes)
    116         self.constructSceneThread = uthread.new(self._ConstructScene_thread, interestID, zoomToItem)
    117         self._AfterConstructScene(attributes)
    118         on_lock_added.connect(self._on_emanation_lock_changed)
    119         on_lock_removed.connect(self._on_emanation_lock_changed)
    120 
    121     def ConstructExtraParticleController(self):
    122         self.extraStarParticleController = BaseExtraStarParticleController()
    123 
    124     def UpdateInitCameraDistance(self):
    125         pass
    126 
    127     def _BeforeConstructScene(self, attributes):
    128         pass
    129 
    130     def _AfterConstructScene(self, attributes):
    131         pass
    132 
    133     def RegisterListeners(self):
    134         sm.RegisterNotify(self)
    135 
    136     def UnregisterListeners(self):
    137         sm.UnregisterNotify(self)
    138 
    139     def _ConstructScene_thread(self, interestID, zoomToItem):
    140         self._ConstructScene(interestID, zoomToItem)
    141         self.RegisterListeners()
    142 
    143     def _ConstructScene(self, interestID, zoomToItem):
    144         self.waiting_for_layout_change = True
    145         self.sceneContainer.Hide()
    146         loadingWheel = LoadingWheel(parent=self, align=uiconst.CENTER)
    147         self._ConstructInfrastructure()
    148         self._ConstructAssetRequirements()
    149         self._ConstructAssets(interestID)
    150         self.InitCameraFocus(zoomToItem)
    151         self.constructSceneThread = None
    152         loadingWheel.Hide()
    153         self.sceneContainer.Show()
    154         if self.destroyed:
    155             return
    156         self.camera.on_transit_complete.connect(self.OnCameraTransitComplete)
    157 
    158     def _ConstructInfrastructure(self):
    159         self.sceneContainer.Startup()
    160         self.camera.SetUpdateCallback(self.OnCameraUpdate)
    161         self.ConstructStarDataTexture()
    162         self.ConstructMapScene()
    163         self.ConstructMapRoot()
    164         self.ConstructMarkersHandler()
    165         self.ConstructBookmarkHandler()
    166         self.ConstructSovHubHandler()
    167 
    168     def _ConstructAssetRequirements(self):
    169         if self.destroyed:
    170             return
    171         self.CreateStarParticles()
    172         self.CreateJumpLineSet()
    173         self.CreateWorkforceTransportLineSet()
    174         self.LoadJumpLines()
    175         self.LoadAllJumpBridges()
    176 
    177     def _ConstructAssets(self, interestID):
    178         if self.destroyed:
    179             return
    180         self.UpdateMapLayout()
    181         self.ReconstructEmanationLockMarker()
    182         self.ShowMyHomeStation()
    183         self._SetActiveItemID(interestID)
    184         self.CheckLoadAllMarkers()
    185         if self.destroyed:
    186             return
    187         self.ReconstructMyLocationMarker()
    188         self.LoadLineIndicators()
    189 
    190     def _GetDefaultInterestID(self):
    191         return session.solarsystemid2
    192 
    193     def InitCameraFocus(self, zoomToItem = True):
    194         self.FocusCameraOnActiveEntity(animate=False, zoomToItem=zoomToItem)
    195 
    196     def FocusCameraOnMultipleSystems(self, solarSystemIDs, animate):
    197         nodes = self.layoutHandler.GetNodesBySolarSystemIDs(solarSystemIDs)
    198         points = [ node.position for node in nodes ]
    199         centerPoint = evemath.get_center_point(points)
    200         distance = evemath.get_farthest_distance_from_point(centerPoint, points)
    201         self.camera.LookAtPoint(centerPoint, animate=animate, zoomDistance=2 * distance)
    202 
    203     def ConstructMarkerLayers(self):
    204         self.infoLayer = Container(parent=self, clipChildren=True, name='infoLayer')
    205 
    206     def ConstructMapNavigation(self):
    207         self.mapNavigation = MapViewNavigation(parent=self, align=uiconst.TOALL, state=uiconst.UI_NORMAL, mapView=self)
    208 
    209     def OnMouseWheel(self, *args):
    210         self.mapNavigation.OnMouseWheel(*args)
    211 
    212     def ConstructOverlayTools(self):
    213         pass
    214 
    215     def OnMapCompassClicked(self):
    216         self.camera.StopUpdateThreads()
    217         animations.MorphScalar(self.camera, 'yaw', self.camera.yaw, 0.0, duration=0.6)
    218 
    219     def OnSelectedInfoLocationClicked(self, locationID):
    220         self.SetActiveItemID(locationID, zoomToItem=True)
    221         self.UpdateLines()
    222 
    223     def Close(self, *args, **kwds):
    224         if self.destroyed:
    225             return
    226         try:
    227             self.UnregisterListeners()
    228             if self.constructSceneThread:
    229                 self.constructSceneThread.kill()
    230                 self.constructSceneThread = None
    231             sm.GetService('audio').SendUIEvent('map_stop_all')
    232             if self.currentSolarsystem:
    233                 self.currentSolarsystem.RemoveFromScene()
    234             self.currentSolarsystem = None
    235             if self.camera:
    236                 self.camera.OnDeactivated()
    237                 sm.GetService('sceneManager').UnregisterCamera(self.camera.cameraID)
    238             if self.markersHandler:
    239                 self.markersHandler.StopHandler()
    240             self.markersHandler = None
    241             if self.bookmarkHandler:
    242                 self.bookmarkHandler.StopHandler()
    243             self.bookmarkHandler = None
    244             if self.layoutHandler:
    245                 self.layoutHandler.StopHandler()
    246             self.layoutHandler = None
    247             self.mapNavigation = None
    248             self.ResetVariables()
    249             self.extraStarParticleController = None
    250         except:
    251             LogException()
    252 
    253         Container.Close(self, *args, **kwds)
    254 
    255     def UpdateDebugOutput(self):
    256         if self.destroyed:
    257             return
    258         mapViewUtil.UpdateDebugOutput(self.debugOutput, camera=self.camera, mapView=self)
    259 
    260     def SetFocusState(self, focusState):
    261         self.inFocus = focusState
    262 
    263     def ResetVariables(self):
    264         self.LogInfo('MapViewPanel Reset')
    265         self.destinationPath = [None]
    266         self.currentSolarsystem = None
    267         self.lineMode = None
    268         if self.mapRoot is not None:
    269             del self.mapRoot.children[:]
    270         self.mapRoot = None
    271         self.mapStars = None
    272         self.starParticles = None
    273         self.solarSystemJumpLineSet = None
    274         self.overlayContentFrame = None
    275         self.distanceRangeLines = None
    276         self.starColorByID = {}
    277         self.activeItemID = None
    278         self.activeLocalID = None
    279         self.activeSolarSystemID = None
    280         self.activeConstellationID = None
    281         self.activeRegionID = None
    282         self.isExpandingSolarSystem = False
    283         self.extraStarParticleController.ResetVariables()
    284 
    285     def OnDockModeChanged(self, isFullScreen):
    286         if self.destroyed:
    287             return
    288         self.isFullScreen = isFullScreen
    289         if isFullScreen:
    290             self.camera.EnableCenterOffset()
    291         else:
    292             self.camera.DisableCenterOffset()
    293 
    294     def OnMapViewSettingChanged(self, settingKey, settingValue, *args, **kwds):
    295         if settingKey == VIEWMODE_MARKERS_SETTINGS:
    296             if self.currentSolarsystem:
    297                 self.currentSolarsystem.LoadMarkers(showChanges=True)
    298             else:
    299                 self.LoadBookmarkMarkers()
    300                 self.LoadShowHubMarkers()
    301         elif settingKey == VIEWMODE_LAYOUT_SETTINGS:
    302             self.mapGroupingMode = settingValue
    303             self.UpdateMapLayout()
    304         elif settingKey == VIEWMODE_LAYOUT_SHOW_ABSTRACT_SETTINGS:
    305             self.AnimFadeOutInfoLayer()
    306             self.UpdateMapLayout()
    307             self.AnimFadeInInfoLayer()
    308         else:
    309             self.UpdateMapLayout()
    310 
    311     def UpdateAbstractMode(self):
    312         self.AnimFadeOutInfoLayer()
    313         if self.destroyed:
    314             return
    315         self.extraStarParticleController.ChangeDisplayState(False)
    316         self.UpdateRegionAndConstellationMarkerTransitionState(True)
    317         self.UpdateMapLayout(playSound=False)
    318         if self.destroyed:
    319             return
    320         self.AnimFadeInInfoLayer()
    321 
    322     def LookAtCurrentLocation(self, playSound = True):
    323         zoomToItem = self.camera.GetZoomDistance() > 50000
    324         self.SetActiveItemID(itemID=session.solarsystemid2, localID=(MARKERID_MYPOS, session.charid), zoomToItem=zoomToItem, playSound=playSound)
    325 
    326     def LookAtHomeStation(self, playSound = True):
    327         homeStationRow = sm.GetService('charactersheet').GetHomeStationRow()
    328         homeStationID = homeStationRow.stationID
    329         if not homeStationID or self.destroyed:
    330             return
    331         solarSystemID = homeStationRow.solarSystemID
    332         regionID = self.mapSvc.GetRegionForSolarSystem(solarSystemID)
    333         if not IsKnownSpaceRegion(regionID):
    334             return
    335         zoomToItem = self.camera.GetZoomDistance() > 50000
    336         self.SetActiveItemID(itemID=solarSystemID, localID=(MARKERID_MYHOME, session.charid), zoomToItem=zoomToItem, playSound=playSound)
    337 
    338     def UpdateMapLayout(self, playSound = True):
    339         if self.destroyed:
    340             return
    341         self.ReconstructMyLocationMarker()
    342         self.ReconstructEmanationLockMarker()
    343         self.RefreshActiveState(playSound=playSound)
    344         currentLineMode = self.GetLineMode()
    345         if currentLineMode != self.lineMode:
    346             self.UpdateLines(hint='OnMapViewSettingChanged')
    347 
    348     def UpdateCameraForAbstractView(self):
    349         pass
    350 
    351     def IsAbstractModeActive(self):
    352         return IsAbstractModeActive(self.mapViewID)
    353 
    354     def AreMarkersAbstractMode(self):
    355         return False
    356 
    357     def GetGroupingMode(self):
    358         return GetMapViewSetting(VIEWMODE_LAYOUT_SETTINGS, self.mapViewID)
    359 
    360     def SetGroupingMode(self, groupingMode):
    361         if self.mapGroupingMode == groupingMode:
    362             return
    363         self.mapGroupingMode = groupingMode
    364         self.LoadStarLayout(self.activeItemID)
    365 
    366     def ConstructLayoutHandler(self):
    367         return MapViewLayoutHandler(self)
    368 
    369     def ConstructMapScene(self):
    370         self.sceneContainer.Startup()
    371         self.mapScene = trinity.EveSpaceScene()
    372         self.mapScene.backgroundRenderingEnabled = True
    373         self.ConstructStarfield()
    374         self.sceneContainer.scene = self.mapScene
    375         self.sceneContainer.DisplaySpaceScene()
    376         return self.mapScene
    377 
    378     def ConstructStarfield(self):
    379         self.mapScene.starfield = trinity.Load('res:/dx9/scene/starfield/spritestars.red')
    380         self.mapScene.starfield.maxDist = 300
    381         self.mapScene.starfield.minDist = 300
    382 
    383     def ConstructMapRoot(self):
    384         self.mapRoot = trinity.EveRootTransform()
    385         self.mapRoot.name = 'mapRoot'
    386         self.mapRoot.display = False
    387         self.mapScene.objects.append(self.mapRoot)
    388 
    389     def ConstructMarkersHandler(self):
    390         self.markersHandler = MapViewMarkersHandler(self, self.sceneContainer.bracketCurveSet, self.infoLayer, eventHandler=self.mapNavigation, isAbstractMode=self.IsAbstractModeActive())
    391 
    392     def ConstructBookmarkHandler(self):
    393         self.bookmarkHandler = MapViewBookmarkHandler(self, loadUniverseBookmarks=True, solarSystemScaling=mapViewConst.SCALING_SOLARSYSTEMINWORLDMAP)
    394 
    395     def ConstructSovHubHandler(self):
    396         self.sovHubHandler = MapViewSovHubHandler(self)
    397 
    398     @apply
    399     def camera():
    400 
    401         def fget(self):
    402             if self.sceneContainer:
    403                 return self.sceneContainer.camera
    404 
    405         return property(**locals())
    406 
    407     @apply
    408     def scene():
    409 
    410         def fget(self):
    411             return self.sceneContainer.scene
    412 
    413         return property(**locals())
    414 
    415     def LogError(self, *args, **kwds):
    416         log.error('MAPVIEW ' + repr(args))
    417 
    418     def LogInfo(self, *args, **kwds):
    419         log.info('MAPVIEW ' + repr(args))
    420 
    421     def LogWarn(self, *args, **kwds):
    422         log.warning('MAPVIEW ' + repr(args))
    423 
    424     def OnUIScalingChange(self, *args):
    425         self.markersHandler.ReloadAll()
    426 
    427     def OnWindowResize(self, width, height):
    428         self.UpdateViewPort()
    429 
    430     def GetPickObjects(self, mouseX, mouseY, getMarkers = True):
    431         if not self.markersHandler:
    432             return
    433         x, y = ScaleDpi(mouseX), ScaleDpi(mouseY)
    434         vx, vy = self.sceneContainer.viewport.x, self.sceneContainer.viewport.y
    435         lastDistance = None
    436         picked = []
    437         for markerID, marker in self.markersHandler.projectBrackets.iteritems():
    438             if not marker.projectBracket.isInFront or not marker.positionPickable:
    439                 continue
    440             mx, my = marker.projectBracket.rawProjectedPosition
    441             if x - 7 < vx + mx < x + 8 and y - 7 < vy + my < y + 8:
    442                 distance = marker.projectBracket.cameraDistance
    443                 if distance < self.camera.farClip and (lastDistance is None or distance < lastDistance):
    444                     if getMarkers:
    445                         picked = [(markerID, marker)]
    446                     else:
    447                         picked = [markerID]
    448                     lastDistance = distance
    449 
    450         return picked
    451 
    452     def GetItemMenu(self, itemID):
    453         item = self.mapSvc.GetItem(itemID, retall=True)
    454         if not item:
    455             return MenuList()
    456         m = MenuList([None])
    457         m += GetMenuService().CelestialMenu(itemID, mapItem=item)
    458         return m.filter('UI/Commands/ShowLocationOnMap')
    459 
    460     def ShowMyHomeStation(self):
    461         if self.destroyed:
    462             return
    463         markerID = (MARKERID_MYHOME, session.charid)
    464         self.markersHandler.RemoveMarker(markerID)
    465         try:
    466             self.markersAlwaysVisible.remove(markerID)
    467         except:
    468             pass
    469 
    470         homeStationRow = sm.GetService('charactersheet').GetHomeStationRow()
    471         homeStationID = homeStationRow.stationID
    472         if not homeStationID or self.destroyed:
    473             return
    474         solarSystemID = homeStationRow.solarSystemID
    475         regionID = self.mapSvc.GetRegionForSolarSystem(solarSystemID)
    476         if not IsKnownSpaceRegion(regionID):
    477             return
    478         mapNode = self.layoutHandler.GetNodeBySolarSystemID(solarSystemID)
    479         solarSystemPosition = mapNode.position
    480         if IsStation(homeStationID):
    481             stationInfo = sm.GetService('ui').GetStationStaticInfo(homeStationID)
    482             pos = (stationInfo.x, stationInfo.y, stationInfo.z)
    483         else:
    484             stationInfo = Bundle(stationID=homeStationID, stationTypeID=homeStationRow.stationTypeID)
    485             pos = mapViewUtil.TryGetPosFromItemID(homeStationID, solarSystemID)
    486         localPosition = self.SolarSystemPosToMapPos(pos)
    487         self.markersHandler.AddSolarSystemBasedMarker(markerID, MarkerMyHome, stationInfo=stationInfo, solarSystemID=solarSystemID, mapPositionLocal=localPosition, mapPositionSolarSystem=solarSystemPosition)
    488         self.markersAlwaysVisible.add(markerID)
    489 
    490     def SolarSystemPosToMapPos(self, pos):
    491         return geo2.Vec3Scale(mapViewUtil.SolarSystemPosToMapPos(pos), mapViewConst.SCALING_SOLARSYSTEMINWORLDMAP)
    492 
    493     def RemoveMyLocation(self):
    494         markerID = (MARKERID_MYPOS, session.charid)
    495         self.markersHandler.RemoveMarker(markerID, fadeOut=False)
    496 
    497     def _on_emanation_lock_changed(self, lock_details):
    498         uthread.new(self.ReconstructEmanationLockMarker)
    499 
    500     def RemoveEmanationLockMarker(self):
    501         markerID = (MARKERID_EMANATION_LOCK_GATE, session.charid)
    502         self.markersHandler.RemoveMarker(markerID, fadeOut=False)
    503 
    504     def ReconstructEmanationLockMarker(self):
    505         if self.destroyed:
    506             return
    507         if self.mapRoot is None:
    508             return
    509         self.RemoveEmanationLockMarker()
    510         markerID = (MARKERID_EMANATION_LOCK_GATE, session.charid)
    511         self.markersAlwaysVisible.discard(markerID)
    512         gateLockController = GateLockController.get_instance(get_gate_lock_messenger(sm.GetService('publicGatewaySvc')))
    513         lockDetails = gateLockController.get_current_system_lock()
    514         if lockDetails is None or lockDetails.solar_system_id != session.solarsystemid2:
    515             return
    516         gateItemID = lockDetails.gate_id
    517         gateBall = sm.GetService('michelle').GetBall(gateItemID)
    518         if gateBall is None:
    519             return
    520         gateTypeID = gateBall.typeID
    521         pos = SolarSystemPosToMapPos((gateBall.x, gateBall.y, gateBall.z))
    522         pos = geo2.Vec3ScaleD(pos, mapViewConst.SCALING_SOLARSYSTEMINWORLDMAP)
    523         mapNode = self.layoutHandler.GetNodeBySolarSystemID(session.solarsystemid2)
    524         if mapNode is None:
    525             return
    526         solarSystemPos = mapNode.position
    527         marker = self.markersHandler.AddSolarSystemBasedMarker(markerID, MarkerEmanationLock, solarSystemID=session.solarsystemid2, mapPositionLocal=pos, mapPositionSolarSystem=solarSystemPos, distanceFadeAlphaNearFar=None)
    528         marker.SetLabelTextFromItem(gateItemID, gateTypeID)
    529         self.markersAlwaysVisible.add(markerID)
    530 
    531     def ReconstructMyLocationMarker(self):
    532         if self.destroyed:
    533             return
    534         if self.mapRoot is None:
    535             return
    536         self.RemoveMyLocation()
    537         markerID = (MARKERID_MYPOS, session.charid)
    538         try:
    539             self.markersAlwaysVisible.remove(markerID)
    540         except:
    541             pass
    542 
    543         markerObject = None
    544         if IsKnownSpaceRegion(session.regionid):
    545             mapNode = self.layoutHandler.GetNodeBySolarSystemID(session.solarsystemid2)
    546             if mapNode:
    547                 solarSystemPosition = mapNode.position
    548                 if session.stationid or session.structureid:
    549                     markerObject = self._ConstructMyLocationMarkerStation(markerID, solarSystemPosition)
    550                 else:
    551                     markerObject = self._ConstructMyLocationMarkerSpace(markerID, solarSystemPosition)
    552                 self.markersAlwaysVisible.add(markerID)
    553         self.ShowJumpDriveRange(markerObject)
    554 
    555     def _ConstructMyLocationMarkerSpace(self, markerID, solarSystemPosition):
    556         bp = sm.GetService('michelle').GetBallpark()
    557         if bp and bp.ego and bp.ego in bp.balls and False:
    558             ego = bp.balls[bp.ego]
    559             localPosition = self.SolarSystemPosToMapPos((ego.x, ego.y, ego.z))
    560         else:
    561             localPosition = (0.0, 0.0, 0.0)
    562         if self.currentSolarsystem:
    563             trackObjectID = session.shipid or session.stationid
    564             scale = mapViewConst.SCALING_SOLARSYSTEMINWORLDMAP
    565         else:
    566             trackObjectID = None
    567             scale = None
    568         markerObject = self.markersHandler.AddSolarSystemBasedMarker(markerID, MarkerMyLocation, trackObjectID=trackObjectID, trackObjectScale=scale, solarSystemID=session.solarsystemid2, mapPositionLocal=localPosition, mapPositionSolarSystem=solarSystemPosition)
    569         return markerObject
    570 
    571     def _ConstructMyLocationMarkerStation(self, markerID, solarSystemPosition):
    572         if session.stationid:
    573             stationInfo = sm.GetService('ui').GetStationStaticInfo(session.stationid)
    574             if self.destroyed:
    575                 return
    576             pos = (stationInfo.x, stationInfo.y, stationInfo.z)
    577         else:
    578             structure = self.mapSvc.GetMapDataForStructure(session.solarsystemid2, session.structureid)
    579             if not structure:
    580                 return
    581             pos = (structure.x, structure.y, structure.z)
    582         localPosition = self.SolarSystemPosToMapPos(pos)
    583         if self.destroyed:
    584             return
    585         return self.markersHandler.AddSolarSystemBasedMarker(markerID, MarkerMyLocation, solarSystemID=session.solarsystemid2, mapPositionLocal=localPosition, mapPositionSolarSystem=solarSystemPosition)
    586 
    587     def ShowJumpDriveRange(self, markerObject):
    588         self.RemoveJumpDriveRange()
    589         if not IsKnownSpaceRegion(session.regionid):
    590             return
    591         if markerObject is None:
    592             return
    593         if session.shipid is None:
    594             return
    595         driveRange = self.GetJumpDriveRange()
    596         self.UpdateJumpDriveRangeMarkers(driveRange)
    597         if self.IsAbstractModeActive():
    598             return
    599         if driveRange is None or driveRange == 0:
    600             return
    601         if not GetMapViewSetting(VIEWMODE_LAYOUT_SHOW_JUMP_RANGE_SETTINGS, self.mapViewID):
    602             return
    603         scale = 2.0 * driveRange * appConst.LIGHTYEAR * UNIVERSE_SCALE
    604         sphere = trinity.Load('res:/dx9/model/UI/JumpRangeBubble.red')
    605         scaling = (scale, scale, scale)
    606         sphere.scaling = scaling
    607         sphere.name = 'jumpDriveRange'
    608         self.mapRoot.children.append(sphere)
    609         markerObject.RegisterTrackingTransform(sphere)
    610         self.jumpDriveTransform = sphere
    611 
    612     def GetJumpDriveRange(self):
    613         dogmaLM = sm.GetService('clientDogmaIM').GetDogmaLocation()
    614         try:
    615             driveRange = dogmaLM.GetAttributeValue(session.shipid, const.attributeJumpDriveRange)
    616         except KeyError:
    617             log.warning('Unable to get driveRange for ship: %s' % session.shipid)
    618             return None
    619 
    620         return driveRange
    621 
    622     def UpdateJumpDriveRangeMarkers(self, driveRange):
    623         pass
    624 
    625     def RemoveJumpDriveRange(self):
    626         if self.jumpDriveTransform:
    627             if self.jumpDriveTransform in self.mapRoot.children:
    628                 self.mapRoot.children.remove(self.jumpDriveTransform)
    629 
    630     def LayoutChangeStarting(self, changedSolarSystems):
    631         pass
    632 
    633     def AnimFadeOutInfoLayer(self):
    634         uicore.animations.FadeTo(self.infoLayer, startVal=self.infoLayer.opacity, endVal=0.0, duration=0.1, sleep=True)
    635 
    636     def LayoutChanging(self, progress, changedSolarSystems):
    637         if self.currentSolarsystem and self.currentSolarsystem.solarsystemID in changedSolarSystems:
    638             mapNode = changedSolarSystems[self.currentSolarsystem.solarsystemID]
    639             newPosition = geo2.Vec3Lerp(mapNode.oldPosition, mapNode.position, progress)
    640             self.currentSolarsystem.SetPosition(newPosition)
    641 
    642     def LayoutChangeCompleted(self, changedSolarSystems):
    643         if self.destroyed:
    644             return
    645         self.starParticles.UpdateBoundingBox()
    646         self.mapStars.mesh.minBounds = self.starParticles.aabbMin
    647         self.mapStars.mesh.maxBounds = self.starParticles.aabbMax
    648         self.extraStarParticleController.UpdateBounds()
    649         self.markersHandler.UpdateMarkerPositions(changedSolarSystems)
    650         self.RefreshLines()
    651         self.waiting_for_layout_change = False
    652         self.mapRoot.display = True
    653         self.UpdateRegionAndConstellationMarkerTransitionState(False)
    654         self.UpdateRegionAndConstellationMarkerPositions()
    655         self.UpdateLandmarkPositions()
    656         self.markersHandler.ReloadAllAbstractBrackets(self.IsAbstractModeActive())
    657         self.UpdateCameraForAbstractView()
    658         self.extraStarParticleController.ChangeDisplayState(True)
    659 
    660     def LayoutAnimationStarted(self, changedSolarSystems):
    661         pass
    662 
    663     def AnimFadeInInfoLayer(self):
    664         uicore.animations.FadeTo(self.infoLayer, startVal=self.infoLayer.opacity, endVal=1.0, duration=0.3, timeOffset=0.7)
    665 
    666     def UpdateMarkersFilter(self):
    667         if self.destroyed:
    668             return
    669         self.SetMarkersFilter(self.layoutHandler.mapLayout.visibleMarkers)
    670 
    671     def SetMarkersFilter(self, showMarkers):
    672         if showMarkers:
    673             showMarkers += list(self.markersAlwaysVisible)
    674         self.markersHandler.SetDisplayStateOverrideFilter(showMarkers)
    675 
    676     def CreateStarParticles(self):
    677         self.mapStars = trinity.EveTransform()
    678         self.mapStars.name = 'mapStars'
    679         self.mapStars.sortValueMultiplier = 0.0
    680         self.starParticleTexture = trinity.TriTextureParameter()
    681         self.starParticleTexture.name = 'TexMap'
    682         self.starParticleTexture.resourcePath = PARTICLE_SPRITE_TEXTURE
    683         self.starParticleNumberAtlas = trinity.TriTextureParameter()
    684         self.starParticleNumberAtlas.name = 'IconAtlasTex'
    685         self.starParticleNumberAtlas.resourcePath = PARTICLE_ICON_ATLAS2
    686         distanceRangeStars = trinity.Tr2Vector4Parameter()
    687         distanceRangeStars.name = DISTANCE_RANGE
    688         distanceRangeStars.value = (0, 1, 0, 0)
    689         self.distanceRangeStars = distanceRangeStars
    690         sizeControls = trinity.Tr2Vector4Parameter()
    691         sizeControls.name = SIZE_CONTROLS
    692         sizeControls.x = BUBBLE_BASE_SIZE_MULTIPLIER
    693         atlasConfig = trinity.Tr2Vector4Parameter()
    694         atlasConfig.name = ATLAS_CONFIG
    695         atlasConfig.x = 3.0
    696         atlasConfig.y = 3.0
    697         self.starParticles = trinity.Tr2RuntimeInstanceData()
    698         self.starParticles.SetElementLayout([(trinity.PARTICLE_ELEMENT_TYPE.POSITION, 0, 3),
    699          (trinity.PARTICLE_ELEMENT_TYPE.POSITION, 1, 3),
    700          (trinity.PARTICLE_ELEMENT_TYPE.CUSTOM, 0, 1),
    701          (trinity.PARTICLE_ELEMENT_TYPE.CUSTOM, 1, 4),
    702          (trinity.PARTICLE_ELEMENT_TYPE.CUSTOM, 2, 1),
    703          (trinity.PARTICLE_ELEMENT_TYPE.CUSTOM, 3, 1)])
    704         mesh = trinity.Tr2InstancedMesh()
    705         mesh.geometryResPath = 'res:/Graphics/Generic/UnitPlane/UnitPlane.gr2'
    706         mesh.instanceGeometryResource = self.starParticles
    707         self.mapStars.mesh = mesh
    708         area = trinity.Tr2MeshArea()
    709         area.effect = trinity.Tr2Effect()
    710         area.effect.effectFilePath = PARTICLE_EFFECT
    711         area.effect.resources.append(self.starParticleTexture)
    712         area.effect.resources.append(self.starDataTexture)
    713         area.effect.resources.append(self.starParticleNumberAtlas)
    714         area.effect.parameters.append(distanceRangeStars)
    715         area.effect.parameters.append(sizeControls)
    716         area.effect.parameters.append(atlasConfig)
    717         mesh.transparentAreas.append(area)
    718         particleCounter = itertools.count()
    719         starParticleData = []
    720         initPos = (0.0, 0.0, 0.0)
    721         for systemID, system in self._GetKnownUniverseSolarSystems().iteritems():
    722             particleID = particleCounter.next()
    723             starParticleData.append((initPos,
    724              initPos,
    725              0.0,
    726              (0.0, 0.0, 0.0, 0.0),
    727              0.0,
    728              0.0))
    729             self.layoutHandler.CreateSolarSystemNode(particleID, systemID, initPos, system)
    730 
    731         vs = trinity.GetVariableStore()
    732         vs.RegisterVariable('StarmapMorphValue', 0.0)
    733         vs = trinity.GetVariableStore()
    734         vs.RegisterVariable('cameraDistanceScalingFactor', CAMERA_DISTANCE_SCALING_FACTOR)
    735         self.starParticles.SetData(starParticleData)
    736         self.layoutHandler.RegisterStarParticles(self.starParticles)
    737         self.mapRoot.children.append(self.mapStars)
    738         self.extraStarParticleController.CreateStarParticles(starParticleData)
    739         self.layoutHandler.RegisterExtraStarParticles(self.extraStarParticleController)
    740         if self.extraStarParticleController.extraMapStars:
    741             self.mapRoot.children.append(self.extraStarParticleController.extraMapStars)
    742 
    743     def _GetKnownUniverseSolarSystems(self):
    744         return mapViewData.GetKnownUniverseSolarSystems()
    745 
    746     def _GetKnownUniverseConstellations(self):
    747         return mapViewData.GetKnownUniverseConstellations()
    748 
    749     def _GetKnownUniverseRegions(self):
    750         return mapViewData.GetKnownUniverseRegions()
    751 
    752     def ConstructStarDataTexture(self):
    753         heattex = trinity.TriTextureParameter()
    754         heattex.name = 'HeatTexture'
    755         heattex.resourcePath = PARTICLE_SPRITE_HEAT_TEXTURE
    756         self.starDataTexture = heattex
    757         self.extraStarParticleController.ConstructStarDataTexture()
    758 
    759     def CreateJumpLineSet(self):
    760         self.solarSystemJumpLineSet = mapViewUtil.CreateLineSet()
    761         self.solarSystemJumpLineSet.lineEffect.effectFilePath = LINE_EFFECT
    762         self.solarSystemJumpLineSet.name = 'JumpLines'
    763         self.mapRoot.children.append(self.solarSystemJumpLineSet)
    764         if self.distanceRangeLines is None:
    765             distanceRangeLines = trinity.Tr2Vector4Parameter()
    766             distanceRangeLines.name = DISTANCE_RANGE
    767             distanceRangeLines.value = (0, 1, 0, 0)
    768             self.distanceRangeLines = distanceRangeLines
    769         self.solarSystemJumpLineSet.lineEffect.parameters.append(self.distanceRangeLines)
    770         self.layoutHandler.RegisterJumpLineSet(self.solarSystemJumpLineSet)
    771 
    772     def CreateWorkforceTransportLineSet(self):
    773         self.workforceTransportLineSet = mapViewUtil.CreateLineSet()
    774         self.workforceTransportLineSet.lineEffect.effectFilePath = LINE_EFFECT
    775         self.workforceTransportLineSet.name = 'WorkforceTransportLines'
    776         for tex2D in self.workforceTransportLineSet.lineEffect.resources:
    777             tex2D.resourcePath = 'res:/UI/Texture/classes/LineSet/lineSegment.dds'
    778 
    779         self.mapRoot.children.append(self.workforceTransportLineSet)
    780         self.workforceTransportLineSet.lineEffect.parameters.append(self.distanceRangeLines)
    781         self.layoutHandler.RegisterTransitLineSet(self.workforceTransportLineSet)
    782 
    783     def OnCameraUpdate(self):
    784         camera = self.camera
    785         if camera is None:
    786             return
    787         if not self.starParticles:
    788             return
    789         cameraDistance = self.camera.GetZoomDistanceForMap()
    790         self.UpdateAudioLoop(cameraDistance)
    791         aabbMin = self.starParticles.aabbMin
    792         aabbMax = self.starParticles.aabbMax
    793         bbSize = geo2.Vec3Add(geo2.Vec3Negate(aabbMin), aabbMax)
    794         maxLength = geo2.Vec3Length(bbSize)
    795         self.camera.nearClip = 0.1
    796         self.camera.farClip = cameraDistance + maxLength
    797         self._UpdateDistanceRangeValues(cameraDistance)
    798         if self.markersHandler:
    799             self.markersHandler.RegisterCameraTranslationFromParent(cameraDistance)
    800             self.markersHandler.RegisterCameraZoomValue(self.camera.GetZoomValue())
    801             self.markersHandler.RegisterCameraProjectionFov(self.camera.GetProjectionFovConst(self.camera.GetAspectRatio()))
    802         if self.currentSolarsystem:
    803             self.currentSolarsystem.RegisterCameraTranslationFromParent(cameraDistance)
    804         self._TryUpdateStarDataTexturePath()
    805         self.CheckToggleExpandSolarSystem()
    806 
    807     def _UpdateDistanceRangeValues(self, cameraDistance):
    808         fadeOutFar = max(100.0, cameraDistance * 4)
    809         self.distanceRangeStars.value = (cameraDistance,
    810          fadeOutFar,
    811          0,
    812          0)
    813         if self.distanceRangeLines:
    814             self.distanceRangeLines.value = (cameraDistance,
    815              fadeOutFar * 100,
    816              0,
    817              0)
    818 
    819     def OnCameraTransitComplete(self):
    820         if self.markersHandler:
    821             self.markersHandler.UpdateMarkers(forceUpdateGroupings=True)
    822 
    823     def UpdateAudioLoop(self, cameraDistance):
    824         if cameraDistance < mapViewConst.AUDIO_SOLARSYSTEM_DISTANCE:
    825             if self.inFocus:
    826                 self.ChangeAmbientAudioLoop('map_system_loop_play')
    827             else:
    828                 self.ChangeAmbientAudioLoop('map_system_loop_window_play')
    829         elif cameraDistance < mapViewConst.AUDIO_CONSTELLATION_DISTANCE:
    830             if self.inFocus:
    831                 self.ChangeAmbientAudioLoop('map_constellation_loop_play')
    832             else:
    833                 self.ChangeAmbientAudioLoop('map_constellation_loop_window_play')
    834         elif self.inFocus:
    835             self.ChangeAmbientAudioLoop('map_region_loop_play')
    836         else:
    837             self.ChangeAmbientAudioLoop('map_region_loop_window_play')
    838 
    839     def CheckToggleExpandSolarSystem(self):
    840         if self.camera.GetZoomDistance() < 5000 * mapViewConst.SCALING_SOLARSYSTEMINWORLDMAP:
    841             self.ExpandSelectedSolarSystem(self.activeSolarSystemID)
    842         else:
    843             self.CloseCurrentSolarSystemIfAny()
    844 
    845     def ChangeAmbientAudioLoop(self, audioPath):
    846         if getattr(self, 'ambientAudioPath', None) != audioPath:
    847             self.ambientAudioPath = audioPath
    848             sm.GetService('audio').SendUIEvent('map_stop_all')
    849             sm.GetService('audio').SendUIEvent(audioPath)
    850 
    851     def GetStarData(self):
    852         return getattr(self, 'starData', {})
    853 
    854     def GetDistance(self, fromVector, toVector):
    855         return geo2.Vec3Length(geo2.Vec3Subtract(fromVector, toVector))
    856 
    857     def GetExtraMouseOverInfoForItemID(self, itemID):
    858         return None
    859 
    860     def OnMarkerHovered(self, itemID = None):
    861         hilightID = itemID
    862         if self.hilightID != hilightID:
    863             self.hilightID = hilightID
    864             if hilightID:
    865                 self.markersHandler.HilightMarkers([hilightID])
    866             else:
    867                 self.markersHandler.HilightMarkers([])
    868             self.UpdateLines()
    869         elif not itemID and self.markersHandler and self.markersHandler.hilightMarkers:
    870             self.markersHandler.HilightMarkers([])
    871             self.UpdateLines()
    872 
    873     def SetCameraPointOfInterestSolarSystemPosition(self, solarSystemID, position):
    874         mapInfo = mapViewData.GetKnownSolarSystem(solarSystemID)
    875         if not mapInfo:
    876             return
    877         mapNode = self.layoutHandler.GetNodeBySolarSystemID(solarSystemID)
    878         self.camera.SetAtPosition(geo2.Vec3Add(mapNode.position, self.SolarSystemPosToMapPos(position)))
    879 
    880     def DoesZoomOnSelection(self):
    881         return True
    882 
    883     def SetSelectedMarker(self, markerObject, **kwds):
    884         if self.DoesZoomOnSelection():
    885             zoomToItem = self._GetZoomToItem(markerObject.markerID)
    886         else:
    887             zoomToItem = False
    888         if hasattr(markerObject, 'ShouldZoom') and markerObject.ShouldZoom():
    889             zoomToItem = True
    890         if mapViewUtil.IsDynamicMarkerType(markerObject.markerID):
    891             itemID = markerObject.markerID[1]
    892             self.SetActiveItemID(itemID=itemID, localID=markerObject.markerID, zoomToItem=zoomToItem, **kwds)
    893         else:
    894             self.SetActiveItemID(itemID=markerObject.markerID, zoomToItem=zoomToItem, **kwds)
    895 
    896     def _GetZoomToItem(self, itemID):
    897         if IsRegion(itemID):
    898             if self.camera.GetZoomDistance() > 2.0 * ZOOM_DIST_REGION:
    899                 return True
    900         elif IsConstellation(itemID):
    901             if self.camera.GetZoomDistance() > 1.5 * ZOOM_DIST_CONSTELLATION:
    902                 return True
    903         return False
    904 
    905     def RefreshActiveState(self, updateCamera = True, playSound = True):
    906         if self.activeItemID:
    907             self.SetActiveItemID(self.activeItemID, self.activeLocalID, updateCamera=updateCamera, playSound=playSound)
    908 
    909     def LoadStarLayout(self, itemID):
    910         isAbstract = self.IsAbstractModeActive()
    911         keywords = {'isAbstract': isAbstract}
    912         if self.mapGroupingMode == VIEWMODE_LAYOUT_REGIONS:
    913             if IsRegion(itemID):
    914                 keywords['expandedItems'] = [itemID]
    915             elif IsConstellation(itemID):
    916                 mapInfo = mapViewData.GetKnownConstellation(itemID)
    917                 keywords['expandedItems'] = [mapInfo.regionID]
    918             if IsSolarSystem(itemID) and IsKnownSpaceSystem(itemID):
    919                 mapInfo = mapViewData.GetKnownSolarSystem(itemID)
    920                 keywords['expandedItems'] = [mapInfo.regionID]
    921         elif self.mapGroupingMode == VIEWMODE_LAYOUT_CONSTELLATIONS:
    922             if IsConstellation(itemID):
    923                 keywords['expandedItems'] = [itemID]
    924             elif IsSolarSystem(itemID) and IsKnownSpaceSystem(itemID):
    925                 mapInfo = mapViewData.GetKnownSolarSystem(itemID)
    926                 keywords['expandedItems'] = [mapInfo.constellationID]
    927         self.layoutHandler.LoadLayout(self.mapGroupingMode, **keywords)
    928 
    929     def SetActiveItemID(self, itemID, localID = None, zoomToItem = False, animate = True, updateCamera = True, *args, **kwds):
    930         playSound = kwds.get('playSound', True)
    931         if self._SetActiveItemID(itemID, localID, playSound=playSound):
    932             if updateCamera:
    933                 self.FocusCameraOnActiveEntity(animate=animate, zoomToItem=zoomToItem)
    934             self.UpdateLines('SetActiveItemID')
    935 
    936     def ValidTarget(self, itemID):
    937         return IsValidDestination(itemID)
    938 
    939     def _SetActiveItemID(self, itemID, localID = None, playSound = True):
    940         if not self.ValidTarget(itemID):
    941             return False
    942         itemID, localID = self._CheckMangleIDs(itemID, localID)
    943         self.LoadStarLayout(itemID)
    944         if self.inFocus and playSound:
    945             self.PlaySelectionSound(itemID)
    946         previousActiveItemID = self.activeItemID
    947         self.activeItemID = itemID
    948         self.activeLocalID = localID
    949         self.UpdatePartilesForActiveItem(previousActiveItemID, self.activeItemID)
    950         if self.IsInKnownSpace(itemID):
    951             if IsConstellation(itemID) or IsRegion(itemID):
    952                 self.CloseCurrentSolarSystemIfAny()
    953             self._UpdateActiveSystemConstRegion(itemID)
    954             self._UpdateActiveMarkers(itemID)
    955         return True
    956 
    957     def UpdatePartilesForActiveItem(self, previousActiveItemID, currentActiveItemID):
    958         pass
    959 
    960     def IsInKnownSpace(self, itemID):
    961         return IsKnownSpaceSystem(itemID) or IsKnownSpaceConstellation(itemID) or IsKnownSpaceRegion(itemID)
    962 
    963     def _CheckMangleIDs(self, primaryItemID, localID):
    964         if localID == (MARKERID_MYPOS, session.charid):
    965             primaryItemID = session.solarsystemid2
    966             localID = localID
    967         elif IsStation(primaryItemID):
    968             stationData = cfg.stations.Get(primaryItemID)
    969             primaryItemID = stationData.solarSystemID
    970             localID = (MARKERID_SOLARSYSTEM_CELESTIAL, primaryItemID)
    971         return (primaryItemID, localID)
    972 
    973     def PlaySelectionSound(self, itemID):
    974         if IsSolarSystem(itemID):
    975             sm.GetService('audio').SendUIEvent('map_system_zoom_play')
    976         elif IsConstellation(itemID):
    977             sm.GetService('audio').SendUIEvent('map_constellation_zoom_play')
    978         elif IsRegion(itemID):
    979             sm.GetService('audio').SendUIEvent('map_region_zoom_play')
    980 
    981     def _GetCameraPointOfInterest(self, itemID):
    982         if IsSolarSystem(itemID):
    983             return self._GetCameraPointOfInterestSolarSystem(itemID)
    984         elif IsConstellation(itemID):
    985             return self._GetCameraPointOfInterestConstellation(itemID)
    986         elif IsRegion(itemID):
    987             return self._GetCameraPointOfInterestRegion(itemID)
    988         else:
    989             return (0.0, 0.0, 0.0)
    990 
    991     def _UpdateActiveMarkers(self, itemID):
    992         if IsSolarSystem(itemID):
    993             activeIDs, selectedIDs = self.GetActiveAndSelectedIdsSolarSystem(itemID)
    994         elif IsConstellation(itemID):
    995             activeIDs, selectedIDs = self.GetActiveAndSelectedIdsConstellation(itemID)
    996         elif IsRegion(itemID):
    997             activeIDs, selectedIDs = self.GetActiveAndSelectedIDsRegion(itemID)
    998         else:
    999             activeIDs = []
   1000             selectedIDs = []
   1001         activeIDs += self.GetAlwaysActiveSystemIDs()
   1002         self.markersHandler.UpdateMarkerState(activeIDs, selectedIDs)
   1003 
   1004     def GetActiveAndSelectedIdsSolarSystem(self, itemID):
   1005         solarSystemData = mapViewData.GetKnownSolarSystem(itemID)
   1006         constellationData = mapViewData.GetKnownConstellation(solarSystemData.constellationID)
   1007         regionData = mapViewData.GetKnownRegion(solarSystemData.regionID)
   1008         activeIDs = solarSystemData.neighbours + constellationData.solarSystemIDs + regionData.constellationIDs + [solarSystemData.regionID]
   1009         selectedIDs = [itemID, solarSystemData.constellationID]
   1010         return (activeIDs, selectedIDs)
   1011 
   1012     def GetActiveAndSelectedIdsConstellation(self, itemID):
   1013         constellationData = mapViewData.GetKnownConstellation(itemID)
   1014         regionData = mapViewData.GetKnownRegion(constellationData.regionID)
   1015         activeIDs = regionData.constellationIDs + constellationData.solarSystemIDs + [constellationData.regionID]
   1016         selectedIDs = [itemID]
   1017         return (activeIDs, selectedIDs)
   1018 
   1019     def GetActiveAndSelectedIDsRegion(self, itemID):
   1020         regionData = mapViewData.GetKnownRegion(itemID)
   1021         activeIDs = [itemID] + regionData.constellationIDs
   1022         selectedIDs = [itemID]
   1023         return (activeIDs, selectedIDs)
   1024 
   1025     def GetAlwaysActiveSystemIDs(self):
   1026         solarSystemIDs = sm.GetService('starmap').GetDestinationPath()
   1027         solarSystemIDs.append(session.solarsystemid2)
   1028         return solarSystemIDs
   1029 
   1030     def _UpdateActiveSystemConstRegion(self, itemID):
   1031         if IsSolarSystem(itemID):
   1032             self._UpdateActiveItemSolarSystem(itemID)
   1033         elif IsConstellation(itemID):
   1034             self._UpdateActiveItemConstellation(itemID)
   1035         elif IsRegion(itemID):
   1036             self._UpdateActiveItemRegion(itemID)
   1037         else:
   1038             self._UpdateActiveItemUniverse()
   1039 
   1040     def _UpdateActiveItemSolarSystem(self, itemID):
   1041         solarSystemData = mapViewData.GetKnownSolarSystem(itemID)
   1042         self.activeSolarSystemID = itemID
   1043         self.activeConstellationID = solarSystemData.constellationID
   1044         self.activeRegionID = solarSystemData.regionID
   1045 
   1046     def _GetCameraPointOfInterestSolarSystem(self, itemID):
   1047         try:
   1048             return self.layoutHandler.GetNodeBySolarSystemID(itemID).position
   1049         except AttributeError:
   1050             return None
   1051 
   1052     def _UpdateActiveItemConstellation(self, itemID):
   1053         mapData = mapViewData.GetKnownConstellation(itemID)
   1054         self.activeSolarSystemID = None
   1055         self.activeConstellationID = itemID
   1056         self.activeRegionID = mapData.regionID
   1057 
   1058     def _GetCameraPointOfInterestConstellation(self, itemID):
   1059         mapData = mapViewData.GetKnownConstellation(itemID)
   1060         positions = [ self.layoutHandler.GetNodeBySolarSystemID(solarSystemID).position for solarSystemID in mapData.solarSystemIDs ]
   1061         cameraPointOfInterest, radius = mapViewUtil.GetBoundingSphereRadiusCenter(positions)
   1062         return cameraPointOfInterest
   1063 
   1064     def _GetCameraPointOfInterestRegion(self, itemID):
   1065         mapData = mapViewData.GetKnownRegion(itemID)
   1066         positions = [ self.layoutHandler.GetNodeBySolarSystemID(solarSystemID).position for solarSystemID in mapData.solarSystemIDs ]
   1067         cameraPointOfInterest, radius = mapViewUtil.GetBoundingSphereRadiusCenter(positions)
   1068         return cameraPointOfInterest
   1069 
   1070     def _UpdateActiveItemRegion(self, itemID):
   1071         self.activeSolarSystemID = None
   1072         self.activeConstellationID = None
   1073         self.activeRegionID = itemID
   1074 
   1075     def _UpdateActiveItemUniverse(self):
   1076         self.activeSolarSystemID = None
   1077         self.activeConstellationID = None
   1078         self.activeRegionID = None
   1079 
   1080     def CheckLoadAllMarkers(self):
   1081         if not self.markersLoaded and not self.destroyed:
   1082             self.markersLoaded = True
   1083             self._LoadAllMarkers()
   1084             if self.destroyed:
   1085                 return
   1086             self.markersHandler.UpdateMarkers()
   1087 
   1088     def _LoadAllMarkers(self):
   1089         self.LoadRegionMarkers()
   1090         self.LoadConstellationMarkers()
   1091         self.LoadBookmarkMarkers()
   1092         self.LoadLandmarkMarkers()
   1093         self.LoadSolarSystemMarkers()
   1094         self.LoadShowHubMarkers()
   1095 
   1096     def FocusCameraOnActiveEntity(self, animate = True, zoomToItem = False):
   1097         markerObject = self.markersHandler.GetMarkerByID(self.activeLocalID)
   1098         if not markerObject:
   1099             markerObject = self.markersHandler.GetMarkerByID(self.activeItemID)
   1100         zoomDistance = self.GetZoomDistanceByLocationType(self.activeItemID) if zoomToItem else None
   1101         if markerObject:
   1102             self.camera.LookAtMarker(markerObject, animate=animate, zoomDistance=zoomDistance)
   1103         else:
   1104             cameraPointOfInterest = self._GetCameraPointOfInterest(self.activeItemID)
   1105             if cameraPointOfInterest:
   1106                 self.camera.LookAtPoint(cameraPointOfInterest, animate=animate, zoomDistance=zoomDistance)
   1107 
   1108     def GetZoomDistanceByLocationType(self, itemID):
   1109         if IsRegion(itemID):
   1110             zoomDistance = ZOOM_DIST_REGION
   1111         elif IsConstellation(itemID):
   1112             zoomDistance = ZOOM_DIST_CONSTELLATION
   1113         else:
   1114             zoomDistance = ZOOM_DIST_SYSTEM
   1115         return zoomDistance
   1116 
   1117     def CloseCurrentSolarSystemIfAny(self):
   1118         if not self.currentSolarsystem:
   1119             return
   1120         self.currentSolarsystem.Close()
   1121         self.currentSolarsystem = None
   1122         self.layoutHandler.SetExpandedSolarSystemID(None)
   1123         self.ReconstructMyLocationMarker()
   1124         self.ReconstructEmanationLockMarker()
   1125         self.LoadBookmarkMarkers()
   1126         self.LoadShowHubMarkers()
   1127 
   1128     def ExpandSelectedSolarSystem(self, solarSystemID):
   1129         if self.isExpandingSolarSystem:
   1130             return
   1131         self.isExpandingSolarSystem = True
   1132         uthread.new(self._ExpandSelectedSolarSystem, solarSystemID)
   1133 
   1134     def _ExpandSelectedSolarSystem(self, solarSystemID):
   1135         try:
   1136             if self.currentSolarsystem:
   1137                 resetSolarsystemID = self.currentSolarsystem.solarsystemID
   1138             else:
   1139                 resetSolarsystemID = None
   1140             if resetSolarsystemID == solarSystemID:
   1141                 return
   1142             self.layoutHandler.SetExpandedSolarSystemID(solarSystemID)
   1143             if not self.currentSolarsystem and solarSystemID is None:
   1144                 return
   1145             if self.currentSolarsystem:
   1146                 self.currentSolarsystem.Close()
   1147             mapNode = self.layoutHandler.GetNodeBySolarSystemID(solarSystemID)
   1148             if not mapNode:
   1149                 return
   1150             solarSystemPosition = mapNode.position
   1151             self.ConstructExpandedSolarsystem(solarSystemID, solarSystemPosition)
   1152         finally:
   1153             self.isExpandingSolarSystem = False
   1154 
   1155     def ConstructExpandedSolarsystem(self, solarSystemID, solarSystemPosition):
   1156         self.currentSolarsystem = SystemMapHandler(self, solarSystemID, scaling=mapViewConst.SCALING_SOLARSYSTEMINWORLDMAP, position=solarSystemPosition, loadBookmarks=True)
   1157         self.currentSolarsystem.LoadSolarSystemMap()
   1158         if self.destroyed:
   1159             return
   1160         if self.currentSolarsystem is None:
   1161             return
   1162         self.currentSolarsystem.LoadMarkers()
   1163         if self.destroyed:
   1164             return
   1165         cameraParentTravel = self.GetDistance(self.camera.atPosition, solarSystemPosition)
   1166         scaling = self.GetSolarSystemMapScaling()
   1167         if cameraParentTravel:
   1168             uicore.animations.MorphVector3(self.currentSolarsystem.systemMapTransform, 'scaling', (0.0, 0.0, 0.0), (scaling, scaling, scaling), duration=max(0.1, min(1500.0, cameraParentTravel) / 2000.0))
   1169         else:
   1170             self.currentSolarsystem.systemMapTransform.scaling = (scaling, scaling, scaling)
   1171         self.ReconstructMyLocationMarker()
   1172         self.ReconstructEmanationLockMarker()
   1173 
   1174     def GetSolarSystemMapScaling(self):
   1175         return mapViewUtil.ScaleSolarSystemValue(mapViewConst.SCALING_SOLARSYSTEMINWORLDMAP)
   1176 
   1177     def LoadBookmarkMarkers(self):
   1178         if not self.destroyed and self.bookmarkHandler:
   1179             self.bookmarkHandler.LoadBookmarkMarkers()
   1180 
   1181     def LoadLandmarkMarkers(self):
   1182         isAbstract = self.IsAbstractModeActive()
   1183         areMarkersAbstractMode = self.AreMarkersAbstractMode()
   1184         for landmarkID, landmark in self.mapSvc.GetLandmarks().iteritems():
   1185             if self.destroyed or not self.markersHandler:
   1186                 return
   1187             position = GetLandmarkPos(landmarkID, landmark, isAbstract)
   1188             pos = mapViewUtil.ScaledPosToMapPos(geo2.Vec3Scale(position, UNIVERSE_SCALE))
   1189             self.markersHandler.AddLandmarkMarker(-landmarkID, pos, landmarkData=landmark, isAbstract=areMarkersAbstractMode)
   1190 
   1191     def UpdateLandmarkPositions(self):
   1192         toUpdate = {}
   1193         isAbstract = self.IsAbstractModeActive()
   1194         for landmarkID, landmark in self.mapSvc.GetLandmarks().iteritems():
   1195             if self.destroyed or not self.markersHandler:
   1196                 return
   1197             position = GetLandmarkPos(landmarkID, landmark, isAbstract)
   1198             pos = mapViewUtil.ScaledPosToMapPos(geo2.Vec3Scale(position, UNIVERSE_SCALE))
   1199             toUpdate[-landmarkID] = pos
   1200 
   1201         self.markersHandler.UpdateLandmarkMarkerPositions(toUpdate)
   1202 
   1203     def LoadRegionMarkers(self):
   1204         self.LogInfo('LoadRegionMarkers')
   1205         isAbstract = self.IsAbstractModeActive()
   1206         for regionID, regionItem in self._GetKnownUniverseRegions().iteritems():
   1207             if not IsKnownSpaceRegion(regionID):
   1208                 continue
   1209             if not IsValidDestination(regionID):
   1210                 continue
   1211             if self.destroyed or not self.markersHandler:
   1212                 return
   1213             position = GetRegionCorrdinates(isAbstract, regionID, regionItem)
   1214             self.markersHandler.AddRegionMarker(regionID, position)
   1215             blue.pyos.BeNice(TIME_BENICE)
   1216 
   1217     def UpdateRegionAndConstellationMarkerPositions(self):
   1218         toUpdate = {}
   1219         isAbstract = self.IsAbstractModeActive()
   1220         for regionID, regionItem in self._GetKnownUniverseRegions().iteritems():
   1221             if not IsKnownSpaceRegion(regionID):
   1222                 continue
   1223             if self.destroyed or not self.markersHandler:
   1224                 return
   1225             position = GetRegionCorrdinates(isAbstract, regionID, regionItem)
   1226             toUpdate[regionID] = position
   1227 
   1228         self.markersHandler.UpdateRegionMarkerPositions(toUpdate)
   1229         toUpdate = {}
   1230         for constellationID in self._GetKnownUniverseConstellations().iterkeys():
   1231             if not IsKnownSpaceConstellation(constellationID):
   1232                 continue
   1233             if self.destroyed or not self.markersHandler:
   1234                 return
   1235             position = GetConstellationCorrdinates(isAbstract, constellationID)
   1236             toUpdate[constellationID] = position
   1237 
   1238         self.markersHandler.UpdateConstellationMarkerPositions(toUpdate)
   1239 
   1240     def UpdateRegionAndConstellationMarkerTransitionState(self, isTransitioning):
   1241         regions = self._GetKnownUniverseRegions().keys()
   1242         constellations = self._GetKnownUniverseConstellations().keys()
   1243         self.markersHandler.UpdateMarkerTransitionState(regions + constellations, isTransitioning)
   1244 
   1245     def LoadConstellationMarkers(self):
   1246         isAbstract = self.IsAbstractModeActive()
   1247         for constellationID in self._GetKnownUniverseConstellations().iterkeys():
   1248             if not IsKnownSpaceConstellation(constellationID):
   1249                 continue
   1250             if self.destroyed or not self.markersHandler:
   1251                 return
   1252             position = GetConstellationCorrdinates(isAbstract, constellationID)
   1253             self.markersHandler.AddConstellationMarker(constellationID, position, isAbstractMode=isAbstract)
   1254             blue.pyos.BeNice(TIME_BENICE)
   1255 
   1256     def LoadShowHubMarkers(self):
   1257         if not self.destroyed and self.sovHubHandler:
   1258             uthread.new(self.sovHubHandler.LoadShowHubMarkers)
   1259 
   1260     def LoadSolarSystemMarkers(self):
   1261         solarSystemIDs = self._GetAllSolarSystemIDs()
   1262         areMarkersAbstractMode = self.AreMarkersAbstractMode()
   1263         for solarSystemID in solarSystemIDs:
   1264             if not IsKnownSpaceSystem(solarSystemID):
   1265                 continue
   1266             if self.destroyed or not self.markersHandler:
   1267                 return
   1268             mapNode = self.layoutHandler.GetNodeBySolarSystemID(solarSystemID)
   1269             filterInfo = self.GetFilterInfoForSolarSystem(solarSystemID)
   1270             if mapNode:
   1271                 self.markersHandler.AddSolarSystemMarker(solarSystemID, mapNode.position, isAbstractMode=areMarkersAbstractMode, filterInfo=filterInfo)
   1272                 blue.pyos.BeNice(TIME_BENICE)
   1273 
   1274     def GetFilterInfoForSolarSystem(self, solarSystemID):
   1275         return FilterInfo(color=self.GetStarColor(solarSystemID), amount=0, texturePath=None, textureColor=None, amountFmtFunc=None)
   1276 
   1277     def _GetAllSolarSystemIDs(self):
   1278         solarSystemIDs = self._GetKnownUniverseSolarSystems()
   1279         if not self.activeSolarSystemID:
   1280             return solarSystemIDs
   1281         solarSystemData = mapViewData.GetKnownSolarSystem(self.activeSolarSystemID)
   1282         consteallationData = mapViewData.GetKnownConstellation(solarSystemData.constellationID)
   1283         activeSolarSystemIDs = consteallationData.solarSystemIDs + solarSystemData.neighbours
   1284         return sorted(solarSystemIDs, key=lambda ssid: ssid in activeSolarSystemIDs, reverse=True)
   1285 
   1286     def _GetSelectedSolarSystemIDs(self):
   1287         if not self.activeSolarSystemID:
   1288             return []
   1289         solarSystemData = mapViewData.GetKnownSolarSystem(self.activeSolarSystemID)
   1290         consteallationData = mapViewData.GetKnownConstellation(solarSystemData.constellationID)
   1291         activeSolarSystemIDs = consteallationData.solarSystemIDs + solarSystemData.neighbours
   1292         return activeSolarSystemIDs
   1293 
   1294     def GetLineIDForJumpBetweenSystems(self, fromSystemID, toSystemID):
   1295         mapNode = self.layoutHandler.GetNodeBySolarSystemID(fromSystemID)
   1296         if mapNode:
   1297             for lineData in mapNode.lineData:
   1298                 if lineData.fromSolarSystemID == toSystemID or lineData.toSolarSystemID == toSystemID:
   1299                     return lineData.lineID
   1300 
   1301     def LoadJumpLines(self):
   1302         self.allianceJumpLines = []
   1303         self.jumpLineInfoByLineID = {}
   1304         self.allJumpBridges = []
   1305         self.myJumpBridges = []
   1306         lineSet = self.solarSystemJumpLineSet
   1307         defaultColor = (0, 0, 0, 0)
   1308         defaultPos = (0, 0, 0)
   1309         for lineData in mapViewData.IterateJumps():
   1310             lineID = lineSet.AddStraightLine(defaultPos, defaultColor, defaultPos, defaultColor, mapViewConst.JUMPLINE_BASE_WIDTH)
   1311             lineData.lineID = lineID
   1312             self.jumpLineInfoByLineID[lineID] = lineData
   1313             fromNode = self.layoutHandler.GetNodeBySolarSystemID(lineData.fromSolarSystemID)
   1314             toNode = self.layoutHandler.GetNodeBySolarSystemID(lineData.toSolarSystemID)
   1315             if fromNode and toNode:
   1316                 fromNode.AddLineData(lineData)
   1317                 toNode.AddLineData(lineData)
   1318 
   1319     def LoadLineIndicators(self):
   1320         pass
   1321 
   1322     def LoadAllJumpBridges(self):
   1323         self.allJumpBridges = []
   1324         self.myJumpBridges = []
   1325         if useFakeMapColorData.get():
   1326             from evemap.map2d.fakeData.fakeDataUtil import GetJumpBridgeData
   1327             jumpBridgesGates, hasAccessTo, hasNoAccessTo = GetJumpBridgeData()
   1328         else:
   1329             jumpBridgesGates, hasAccessTo, hasNoAccessTo = sm.GetService('map').GetJumpBridgesWithMyAccess()
   1330         if self.destroyed:
   1331             return
   1332         defaultPos = (0, 0, 0)
   1333         newLineData = []
   1334         for structureA, structureB in jumpBridgesGates:
   1335             solarSystemA = structureA.solarSystemID
   1336             solarSystemB = structureB.solarSystemID
   1337             if not IsSolarSystem(solarSystemA) or not IsSolarSystem(solarSystemB):
   1338                 self.LogWarn("DrawAllianceJumpLines had entry that wasn't a solarsystem:", solarSystemA, solarSystemB)
   1339                 continue
   1340             hasAccessToA = structureA.structureID in hasAccessTo
   1341             hasAccessToB = structureB.structureID in hasAccessTo
   1342             colorA = JUMPBRIDGE_COLOR if hasAccessToA else JUMPBRIDGE_COLOR_NO_ACCESS
   1343             colorB = JUMPBRIDGE_COLOR if hasAccessToB else JUMPBRIDGE_COLOR_NO_ACCESS
   1344             lineID = self.solarSystemJumpLineSet.AddCurvedLineCrt(defaultPos, colorA, defaultPos, colorB, defaultPos, 3)
   1345             lineData = mapViewData.PrimeJumpData(solarSystemA, solarSystemB, JUMPBRIDGE_TYPE, colorA, colorB)
   1346             lineData.lineID = lineID
   1347             newLineData.append(lineData)
   1348             self.allJumpBridges.append(lineID)
   1349             if hasAccessToA or hasAccessToB:
   1350                 self.myJumpBridges.append(lineID)
   1351             self.jumpLineInfoByLineID[lineID] = lineData
   1352             fromNode = self.layoutHandler.GetNodeBySolarSystemID(solarSystemA)
   1353             fromNode.AddLineData(lineData)
   1354             toNode = self.layoutHandler.GetNodeBySolarSystemID(solarSystemB)
   1355             toNode.AddLineData(lineData)
   1356 
   1357         worldUp = geo2.Vector(0.0, -1.0, 0.0)
   1358         for eachLineData in newLineData:
   1359             self.layoutHandler.UpdateLinePosition(eachLineData, {}, worldUp)
   1360 
   1361         if self.solarSystemJumpLineSet:
   1362             self.solarSystemJumpLineSet.SubmitChanges()
   1363 
   1364     def RefreshLines(self):
   1365         self.dirtyLineIDs = set()
   1366         self._UpdateLines(hint='RefreshLines')
   1367 
   1368     def UpdateLines(self, hint = '', **kwds):
   1369         uthread.new(self._UpdateLines, hint)
   1370 
   1371     def _UpdateLines(self, hint = '', **kwds):
   1372         if self.destroyed:
   1373             return
   1374         self.LogInfo('MapView UpdateLines ' + hint)
   1375         lineMode = self.GetLineMode()
   1376         if lineMode != self.lineMode:
   1377             self.dirtyLineIDs = set()
   1378             self.lineMode = lineMode
   1379         self.UpdateLineColorData()
   1380         self.UpdateJumpLineColorData()
   1381         self.solarSystemJumpLineSet.SubmitChanges()
   1382 
   1383     def UpdateJumpLineColorData(self):
   1384         if self.jumpRouteHighlightID:
   1385             self.UpdateAutopilotJumpRoute(0.2)
   1386             self.UpdateHighlightJumpRoute()
   1387         else:
   1388             self.UpdateAutopilotJumpRoute()
   1389 
   1390     def _GetLineOpacityByLineID(self, lineOpacityFinder):
   1391         opacityByLineID = lineOpacityFinder.GetLineOpacityByLineID()
   1392         opacityByLineID.update(self._GetLineOpacityAllianceJumps())
   1393         opacityByLineID.update(self._GetLineOpacityJumpsBridges())
   1394         return opacityByLineID
   1395 
   1396     def _GetLineOpacityFinder(self):
   1397         opacityFinderClass = GetLineOpacityFinderClass(self.IsAbstractModeActive())
   1398         lineOpacityFinder = opacityFinderClass(self.layoutHandler, self.GetLineMode(), self.activeRegionID, self.activeConstellationID, self.mapGroupingMode, self.hilightID, self.GetSelectedItemID(), self.jumpLineInfoByLineID, self.camera.GetZoomValue(), self.GetBoldSystemsForOpacityModifcation())
   1399         return lineOpacityFinder
   1400 
   1401     def GetSelectedItemID(self):
   1402         return self.activeSolarSystemID or self.activeConstellationID or self.activeRegionID
   1403 
   1404     def _GetLineOpacityAllianceJumps(self):
   1405         showAllianceLines = GetMapViewSetting(VIEWMODE_LINES_SHOW_ALLIANCE_SETTINGS, self.mapViewID)
   1406         opacityByLineID = {}
   1407         for lineID in self.allianceJumpLines:
   1408             opacityByLineID[lineID] = OPACITY_LINES_SELECTED if showAllianceLines else 0.0
   1409 
   1410         return opacityByLineID
   1411 
   1412     def _GetLineOpacityJumpsBridges(self):
   1413         showJumpBridges = GetMapViewSetting(VIEWMODE_LINES_SHOW_JUMP_BRIDGES_SETTINGS, self.mapViewID)
   1414         if showJumpBridges == VIEWMODE_LINES_SHOW_JUMP_BRIDGES_NONE:
   1415             linesToShow = []
   1416         elif showJumpBridges == VIEWMODE_LINES_SHOW_JUMP_BRIDGES_MY:
   1417             linesToShow = self.myJumpBridges
   1418         else:
   1419             linesToShow = self.allJumpBridges
   1420         opacityByLineID = {}
   1421         for lineID in self.allJumpBridges:
   1422             opacityByLineID[lineID] = OPACITY_LINES_SELECTED if lineID in linesToShow else 0.0
   1423 
   1424         return opacityByLineID
   1425 
   1426     def GetLineMode(self):
   1427         return GetMapViewSetting(VIEWMODE_LINES_SETTINGS, self.mapViewID)
   1428 
   1429     def ChangeLineColor(self, lineSet, lineID, color, opacity = 1.0):
   1430         if len(color) == 2:
   1431             fromColor = self.ModulateAlpha(color[0], opacity)
   1432             toColor = self.ModulateAlpha(color[1], opacity)
   1433         else:
   1434             fromColor = toColor = self.ModulateAlpha(color, opacity)
   1435         fromColor = colorblind.CheckReplaceColor(fromColor)
   1436         toColor = colorblind.CheckReplaceColor(toColor)
   1437         lineSet.ChangeLineColor(lineID, fromColor, toColor)
   1438 
   1439     def ModulateAlpha(self, color, alphaModulate):
   1440         if len(color) == 3:
   1441             r, g, b = color
   1442             return (r,
   1443              g,
   1444              b,
   1445              alphaModulate)
   1446         r, g, b, a = color
   1447         return (r,
   1448          g,
   1449          b,
   1450          a * alphaModulate)
   1451 
   1452     def UpdateLineColorData(self):
   1453         lineOpacityFinder = self._GetLineOpacityFinder()
   1454         lineAlphaByLineID = self._GetLineOpacityByLineID(lineOpacityFinder)
   1455         newLineIDs = set(lineAlphaByLineID.keys())
   1456         updateLinesIDs = self.GetLineIDsToUpdate(newLineIDs)
   1457         opacityDefault = lineOpacityFinder.GetLineDefaultOpacity()
   1458         opacityRegionDefault = lineOpacityFinder.GetBaseOpacityForRegionalLines()
   1459         for lineID in updateLinesIDs:
   1460             self.UpdateLineColorAndWidth(lineID, lineAlphaByLineID, opacityDefault, opacityRegionDefault)
   1461 
   1462     def GetLineIDsToUpdate(self, newLineIDs):
   1463         if not self.dirtyLineIDs:
   1464             updateLinesIDs = self.jumpLineInfoByLineID.keys()
   1465         else:
   1466             updateLinesIDs = newLineIDs.union(self.dirtyLineIDs)
   1467         self.dirtyLineIDs = newLineIDs
   1468         return updateLinesIDs
   1469 
   1470     def UpdateLineColorAndWidth(self, lineID, lineAlphaByLineID, opacityDefault, opacityRegionDefault):
   1471         lineData = self.jumpLineInfoByLineID[lineID]
   1472         fromColor, toColor = self.GetLineColor(opacityDefault, opacityRegionDefault, lineAlphaByLineID, lineData, lineID)
   1473         lineSet = self.solarSystemJumpLineSet
   1474         lineSet.ChangeLineColor(lineID, fromColor, toColor)
   1475         lineSet.ChangeLineWidth(lineID, mapViewConst.JUMPLINE_BASE_WIDTH)
   1476         if lineData.jumpType == mapcommon.REGION_JUMP:
   1477             lineLength = self.layoutHandler.GetDistanceBetweenSolarSystems(lineData.fromSolarSystemID, lineData.toSolarSystemID)
   1478             if lineLength is not None:
   1479                 lineSet.ChangeLineAnimation(lineID, (0, 0, 0, 1), 0.0, lineLength / mapViewConst.REGION_LINE_TICKSIZE)
   1480                 lineSet.ChangeLineWidth(lineID, mapViewConst.JUMPLINE_BASE_WIDTH * 1.6)
   1481         elif lineData.jumpType == mapcommon.CONSTELLATION_JUMP:
   1482             lineLength = self.layoutHandler.GetDistanceBetweenSolarSystems(lineData.fromSolarSystemID, lineData.toSolarSystemID)
   1483             if lineLength is not None:
   1484                 ticksize = lineLength / mapViewConst.CONSTELLATION_LINE_TICKSIZE
   1485                 lineSet.ChangeLineAnimation(lineID, (0, 0, 0, 1), 0.0, ticksize)
   1486                 lineSet.ChangeLineWidth(lineID, mapViewConst.JUMPLINE_BASE_WIDTH * 1.3)
   1487         else:
   1488             lineSet.ChangeLineAnimation(lineID, (0, 0, 0, 0), 0.0, 1.0)
   1489 
   1490     def GetLineColor(self, baseLineAlphaModulate, baseRegionLineAlphaModulate, lineAlphaByLineID, lineData, lineID):
   1491         lineOpacity = lineAlphaByLineID.get(lineID, baseLineAlphaModulate)
   1492         if lineID in self.allianceJumpLines:
   1493             fromColor = toColor = JUMPBRIDGE_COLOR
   1494         else:
   1495             if lineID in self.allJumpBridges:
   1496                 lineData = self.jumpLineInfoByLineID[lineID]
   1497                 fromColor = lineData.colorFrom or JUMPBRIDGE_COLOR
   1498                 toColor = lineData.colorTo or JUMPBRIDGE_COLOR
   1499                 return (fromColor[:3] + (lineOpacity,), toColor[:3] + (lineOpacity,))
   1500             fromColor = LINE_COLOR
   1501             toColor = LINE_COLOR
   1502         if lineData.jumpType == mapcommon.REGION_JUMP:
   1503             fromColor = self._GetRegionJumpColor(fromColor)
   1504             toColor = self._GetRegionJumpColor(toColor)
   1505         fromColor = self.ModulateAlpha(fromColor, lineOpacity)
   1506         toColor = self.ModulateAlpha(toColor, lineOpacity)
   1507         return (fromColor, toColor)
   1508 
   1509     def _GetRegionJumpColor(self, color):
   1510         color = Color(*color)
   1511         if color.IsGrayscale():
   1512             color = color.SetBrightness(0.9)
   1513         else:
   1514             color = color.SetSaturation(0.7)
   1515         return color.GetRGBA()
   1516 
   1517     def GetSystemColorBasedOnSecRating(self, ssID, alpha = 2.0):
   1518         c = sm.GetService('map').GetModifiedSystemColor(ssID)
   1519         return (c[0],
   1520          c[1],
   1521          c[2],
   1522          alpha)
   1523 
   1524     def UpdateHighlightJumpRoute(self, lineAlpha = 3.0):
   1525         targetID = self.jumpRouteHighlightID
   1526         if targetID in [session.solarsystemid2, session.constellationid, session.regionid]:
   1527             return []
   1528         solarSystemIDs = sm.GetService('starmap').ShortestGeneralPath(targetID)
   1529         if not len(solarSystemIDs):
   1530             return
   1531         self._UpdatePathLineAppearance(solarSystemIDs=solarSystemIDs, lineAlpha=lineAlpha, animate=False)
   1532 
   1533     def UpdateAutopilotJumpRoute(self, lineAlpha = 2.0):
   1534         solarSystemIDs = sm.GetService('starmap').GetDestinationPath()
   1535         if solarSystemIDs and solarSystemIDs[0] != session.solarsystemid2:
   1536             solarSystemIDs = [session.solarsystemid2] + solarSystemIDs
   1537         self._UpdatePathLineAppearance(solarSystemIDs=solarSystemIDs, lineAlpha=lineAlpha, animate=True)
   1538 
   1539     def _UpdatePathLineAppearance(self, solarSystemIDs, lineAlpha, animate):
   1540         for i in xrange(len(solarSystemIDs) - 1):
   1541             fromID = solarSystemIDs[i]
   1542             toID = solarSystemIDs[i + 1]
   1543             lineID = self.GetLineIDForJumpBetweenSystems(fromID, toID)
   1544             if not lineID:
   1545                 continue
   1546             self.ApplyJumpLineColorAndWidth(lineAlpha, fromID, toID, lineID)
   1547             lineLength = self.layoutHandler.GetDistanceBetweenSolarSystems(fromID, toID)
   1548             if lineLength:
   1549                 if animate:
   1550                     animationSpeed, segmentScale = self.GetJumpRouteAnimationSpeedAndScale(fromID, lineID, lineLength)
   1551                 else:
   1552                     animationSpeed = segmentScale = 0
   1553                 self.solarSystemJumpLineSet.ChangeLineAnimation(lineID, (0, 0, 0, 0.75), animationSpeed, segmentScale)
   1554 
   1555     def GetJumpRouteAnimationSpeedAndScale(self, fromID, lineID, lineLength):
   1556         jumpLineInfo = self.jumpLineInfoByLineID[lineID]
   1557         animationDirection = -1 if fromID == jumpLineInfo.fromSolarSystemID else 1
   1558         segmentScale = lineLength / mapViewConst.AUTOPILOT_LINE_TICKSIZE
   1559         animationSpeed = mapViewConst.AUTOPILOT_LINE_ANIM_SPEED / segmentScale * animationDirection
   1560         return (animationSpeed, segmentScale)
   1561 
   1562     def ApplyJumpLineColorAndWidth(self, lineAlpha, fromID, toID, lineID):
   1563         jumpLineInfo = self.jumpLineInfoByLineID[lineID]
   1564         self.dirtyLineIDs.add(lineID)
   1565         if fromID == jumpLineInfo.fromSolarSystemID:
   1566             fromColor = self.GetSystemColorBasedOnSecRating(fromID, alpha=lineAlpha)
   1567             toColor = self.GetSystemColorBasedOnSecRating(toID, alpha=lineAlpha)
   1568         else:
   1569             fromColor = self.GetSystemColorBasedOnSecRating(toID, alpha=lineAlpha)
   1570             toColor = self.GetSystemColorBasedOnSecRating(fromID, alpha=lineAlpha)
   1571         fromColor = colorblind.CheckReplaceColor(fromColor)
   1572         toColor = colorblind.CheckReplaceColor(toColor)
   1573         self.solarSystemJumpLineSet.ChangeLineColor(lineID, fromColor, toColor)
   1574         self.solarSystemJumpLineSet.ChangeLineWidth(lineID, mapViewConst.AUTOPILOT_LINE_WIDTH)
   1575 
   1576     def ApplyStarColors(self):
   1577         self.starColorByID = {}
   1578         spriteValues = self._GetSpriteEffectPathAndStaticSize()
   1579         self.starDataTexture.resourcePath = spriteValues.spriteTexture
   1580         self.starParticleTexture.resourcePath = PARTICLE_SPRITE_TEXTURE
   1581         self._UpdateStarColor()
   1582         self._UpdateDataShapeAndSize()
   1583         self.markersHandler.UpdateMarkersWithFilters(self.activeFilter)
   1584         self.starParticles.UpdateData()
   1585         self.mapStars.display = 1
   1586         self.extraStarParticleController.UpdateStarParticleData()
   1587         if self.IsAbstractModeActive():
   1588             self.extraStarParticleController.ChangeDisplayState(True)
   1589 
   1590     def _UpdateStarColor(self):
   1591         boldSystemIDs = self.GetBoldSystemsForOpacityModifcation()
   1592         spriteValues = self._GetSpriteEffectPathAndStaticSize()
   1593         for particleID, mapNode in self.layoutHandler.GetNodesByParticleID().iteritems():
   1594             solarSystemID = mapNode.solarSystemID
   1595             originalStarColor = starColor = self.GetStarColor(solarSystemID)
   1596             self.starColorByID[solarSystemID] = originalStarColor
   1597             starColor = self._GetModifiedStarColor(solarSystemID, boldSystemIDs, spriteValues.spriteMode) or starColor
   1598             self.starParticles.SetItemElement(particleID, 3, starColor)
   1599             self.extraStarParticleController.SetItemElement(particleID, 3, originalStarColor)
   1600 
   1601     def _GetModifiedStarColor(self, solarSystemID, boldSystemIDs, spriteMode):
   1602         return None
   1603 
   1604     def _UpdateDataShapeAndSize(self):
   1605         spriteValues = self._GetSpriteEffectPathAndStaticSize()
   1606         boldSystemIDs = self.GetBoldSystemsForShape()
   1607         for particleID, mapNode in self.layoutHandler.GetNodesByParticleID().iteritems():
   1608             solarSystemID = mapNode.solarSystemID
   1609             self._UpdateDataShapeAndSizeForSolarSystem(particleID, solarSystemID, spriteValues, boldSystemIDs)
   1610 
   1611     def _UpdateDataShapeAndSizeForSolarSystem(self, particleID, solarSystemID, spriteValues, boldSystemIDs):
   1612         starSize = self.GetStarSize(solarSystemID)
   1613         bubbleSize = starSize if spriteValues.staticSize is None else spriteValues.staticSize
   1614         self.starParticles.SetItemElement(particleID, 2, float(bubbleSize))
   1615         self.extraStarParticleController.SetItemElement(particleID, 2, spriteValues.sizeFactor * float(starSize))
   1616         if spriteValues.spriteMode != self.starParticles.GetItemElement(particleID, 5):
   1617             updatedStarColor = self._GetModifiedStarColor(solarSystemID, boldSystemIDs, spriteValues.spriteMode)
   1618             if updatedStarColor:
   1619                 self.starParticles.SetItemElement(particleID, 3, updatedStarColor)
   1620         if spriteValues.spriteMode:
   1621             shape = self._GetDataTextureShape(boldSystemIDs, solarSystemID, spriteValues.markerSizeType)
   1622             self.starParticles.SetItemElement(particleID, 4, shape)
   1623         self.starParticles.SetItemElement(particleID, 5, spriteValues.spriteMode)
   1624 
   1625     def _GetDataTextureShape(self, boldSystemIDs, solarSystemID, markerSizeType):
   1626         return 0.0
   1627 
   1628     def GetStarParticleTexturePath(self):
   1629         return PARTICLE_SPRITE_TEXTURE
   1630 
   1631     def GetStarColor(self, solarSystemID):
   1632         return NEUTRAL_COLOR
   1633 
   1634     def GetStarSize(self, solarSystemID):
   1635         return STAR_SIZE_UNIMPORTANT
   1636 
   1637     def GetBoldSystemsForShape(self):
   1638         return set()
   1639 
   1640     def GetBoldSystemsForOpacityModifcation(self):
   1641         return set()
   1642 
   1643     def _TryUpdateStarDataTexturePath(self):
   1644         pass
   1645 
   1646     def _GetSpriteEffectPathAndStaticSize(self):
   1647         return SpriteValues(MARKER_NONE, PARTICLE_SPRITE_DATA_TEXTURE, None, 0.0, 1.0)
   1648 
   1649     def GetLegend(self, name):
   1650         return getattr(self, name + 'Legend', [])
   1651 
   1652     def OnAutopilotUpdated(self):
   1653         self.UpdateLines(hint='OnAutopilotUpdated')
   1654         self._UpdateActiveMarkers(self.GetSelectedItemID())
   1655 
   1656     def OnDestinationSet(self, *args, **kwds):
   1657         self.UpdateLines(hint='OnDestinationSet')
   1658         self._UpdateActiveMarkers(self.GetSelectedItemID())
   1659 
   1660     def OnHomeStationChanged(self, *args, **kwds):
   1661         self.ShowMyHomeStation()
   1662 
   1663     def OnBallparkSetState(self, *args):
   1664         if session.solarsystemid2:
   1665             if self.currentSolarsystem:
   1666                 self.currentSolarsystem.LoadMarkers()
   1667             self.layoutHandler.ClearCache()
   1668             self.RefreshActiveState(updateCamera=False)
   1669 
   1670     def OnStructuresVisibilityUpdated(self):
   1671         if session.solarsystemid2:
   1672             if self.currentSolarsystem:
   1673                 self.currentSolarsystem.LoadMarkers()
   1674 
   1675     def OnSessionChanged(self, isRemote, session, change):
   1676         if 'locationid' in change and not IsSolarSystem(change['locationid'][1]) or 'structureid' in change:
   1677             uthread2.call_after_wallclocktime_delay(self.UpdateMyLocation, 0.5)
   1678             uthread.new(self.ReconstructEmanationLockMarker)
   1679         if 'solarsystemid' in change:
   1680             lastSystem, newSystem = change['solarsystemid']
   1681             if self.activeItemID == lastSystem:
   1682                 self.SetActiveItemID(newSystem, zoomToItem=True)
   1683             uthread2.call_after_wallclocktime_delay(self.UpdateJumpRangeDisplay, 0.5)
   1684         if 'shipid' in change:
   1685             uthread2.call_after_wallclocktime_delay(self.UpdateMyLocation, 0.5)
   1686             uthread.new(self.ReconstructEmanationLockMarker)
   1687 
   1688     def UpdateMyLocation(self):
   1689         self.ReconstructMyLocationMarker()
   1690         self.UpdateJumpRangeDisplay()
   1691 
   1692     def UpdateJumpRangeDisplay(self):
   1693         if self.destroyed:
   1694             return
   1695         self.ApplyStarColors()
   1696         self.dirtyLineIDs.clear()
   1697         self.UpdateLineColorData()
   1698         self.solarSystemJumpLineSet.SubmitChanges()
   1699 
   1700     def DoBallClear(self, solitem):
   1701         self.RemoveMyLocation()
   1702 
   1703     def DoBallsAdded(self, balls_slimItems, *args, **kw):
   1704         for ball, slimItem in balls_slimItems:
   1705             if ball.id == session.shipid:
   1706                 uthread.new(self.ReconstructMyLocationMarker)
   1707                 uthread.new(self.ReconstructEmanationLockMarker)
   1708                 break
   1709 
   1710     def UpdateViewPort(self):
   1711         if self.sceneContainer:
   1712             self.sceneContainer.UpdateViewPort()