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

mapViewUtil.py (16977B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\mapView\mapViewUtil.py
      2 import math
      3 import sys
      4 from math import sin, cos
      5 import geo2
      6 import trinity
      7 from caching import Memoize
      8 from carbonui.util.dpi import ReverseScaleDpi
      9 from eve.client.script.ui.inflight.scannerFiles.scannerUtil import IsSolarSystemMapFullscreen, IsDirectionalScanPanelEmbedded, SetDirectionalScanEmbeddedPanelClosed, SetProbeScanEmbeddedPanelClosed, SetDirectionalScanEmbeddedPanelOpen, SetProbeScanEmbeddedPanelOpen
     10 from eve.client.script.ui.shared.mapView import mapViewConst
     11 from eve.client.script.ui.shared.mapView.mapViewConst import MARKER_TYPES, UNIVERSE_SCALE, SOLARSYSTEM_SCALE
     12 from eve.client.script.ui.shared.mapView.settings import classic_map_enabled_setting
     13 from carbonui.uicore import uicore
     14 from eve.common.script.sys import idCheckers
     15 from eve.common.script.sys.idCheckers import IsTriglavianSystem, IsZarzakh, IsJoveSystem, IsSolarSystem, IsConstellation, IsRegion
     16 from evemap.map2d.coordinateOverrideController import get_coordinate_overrider_controller, landmark_overriden_coordinates
     17 
     18 def GetBoundingSphereRadiusCenter(vectors):
     19     minX = sys.maxint
     20     minY = sys.maxint
     21     minZ = sys.maxint
     22     maxX = -sys.maxint
     23     maxY = -sys.maxint
     24     maxZ = -sys.maxint
     25     for x, y, z in vectors:
     26         minX = min(minX, x)
     27         minY = min(minY, y)
     28         minZ = min(minZ, z)
     29         maxX = max(maxX, x)
     30         maxY = max(maxY, y)
     31         maxZ = max(maxZ, z)
     32 
     33     maxBound = (maxX, maxY, maxZ)
     34     minBound = (minX, minY, minZ)
     35     center = geo2.Vec3Scale(geo2.Vec3Add(minBound, maxBound), 0.5)
     36     offset = geo2.Vec3Scale(geo2.Vec3Subtract(minBound, maxBound), 0.5)
     37     return (center, geo2.Vec3Length(offset))
     38 
     39 
     40 def GetTranslationFromParentWithRadius(radius, camera):
     41     camangle = camera.fov * 0.5
     42     translationFromParent = max(mapViewConst.MIN_CAMERA_DISTANCE, min(mapViewConst.MAX_CAMERA_DISTANCE, radius / sin(camangle) * cos(camangle)))
     43     return translationFromParent
     44 
     45 
     46 def SolarSystemPosToMapPos(position):
     47     if not position:
     48         return
     49     x, y, z = position
     50     return (ScaleSolarSystemValue(x), ScaleSolarSystemValue(y), ScaleSolarSystemValue(z))
     51 
     52 
     53 def MapPosToSolarSystemPos(position):
     54     if not position:
     55         return
     56     x, y, z = position
     57     return (x / SOLARSYSTEM_SCALE, y / SOLARSYSTEM_SCALE, z / SOLARSYSTEM_SCALE)
     58 
     59 
     60 def WorldPosToMapPos(position):
     61     x, y, z = position
     62     return (x * -UNIVERSE_SCALE, y * -UNIVERSE_SCALE, z * UNIVERSE_SCALE)
     63 
     64 
     65 def ScaledPosToMapPos(pos):
     66     x, y, z = pos
     67     return (-x, -y, z)
     68 
     69 
     70 def ScaleSolarSystemValue(value):
     71     return value * SOLARSYSTEM_SCALE
     72 
     73 
     74 def IsDynamicMarkerType(itemID):
     75     try:
     76         if itemID[0] in MARKER_TYPES:
     77             return True
     78     except:
     79         return False
     80 
     81 
     82 def IsLandmark(itemID):
     83     return itemID and itemID < 0
     84 
     85 
     86 def IsDirectionalScannerOpen():
     87     if IsDirectionalScanPanelEmbedded():
     88         from eve.client.script.ui.shared.mapView.solarSystemViewPanel import SolarSystemViewPanel
     89         w = SolarSystemViewPanel.GetIfOpen()
     90         return w and w.IsDirectionalScannerOpen()
     91     else:
     92         from eve.client.script.ui.inflight.scannerFiles.directionalScannerWindow import DirectionalScanner
     93         return DirectionalScanner.IsOpen()
     94 
     95 
     96 def ToggleSolarSystemMap(openProbeScanPanel = False, openDirectionalScanPanel = False):
     97     if IsSolarSystemMapFullscreen():
     98         _ToggleSolarSystemMapFullscreen(openDirectionalScanPanel, openProbeScanPanel)
     99     else:
    100         _ToggleSolarSystemMapWindowed(openDirectionalScanPanel, openProbeScanPanel)
    101 
    102 
    103 def _ToggleSolarSystemMapFullscreen(openDirectionalScanPanel, openProbeScanPanel):
    104     from eve.client.script.ui.shared.mapView.solarSystemViewPanel import SolarSystemViewPanel
    105     w = SolarSystemViewPanel.GetIfOpen()
    106     if not w:
    107         if openDirectionalScanPanel:
    108             SetDirectionalScanEmbeddedPanelOpen()
    109         if openProbeScanPanel:
    110             SetProbeScanEmbeddedPanelOpen()
    111         SolarSystemViewPanel.Open()
    112     elif not openDirectionalScanPanel and not openProbeScanPanel:
    113         w.Close()
    114     else:
    115         if openDirectionalScanPanel:
    116             w.ToggleDirectionalScanner()
    117         if openProbeScanPanel:
    118             w.ToggleProbeScanner()
    119 
    120 
    121 def _ToggleSolarSystemMapWindowed(openDirectionalScanPanel, openProbeScanPanel):
    122     from eve.client.script.ui.shared.mapView.solarSystemViewPanel import SolarSystemViewPanel
    123     w = SolarSystemViewPanel.GetIfOpen()
    124     if w:
    125         if w.mapView and session.solarsystemid2 and (openProbeScanPanel or openDirectionalScanPanel):
    126             if openDirectionalScanPanel:
    127                 w.ToggleDirectionalScanner()
    128             if openProbeScanPanel:
    129                 w.ToggleProbeScanner()
    130         elif w.IsMinimized():
    131             w.Maximize()
    132         else:
    133             SolarSystemViewPanel.CloseIfOpen()
    134     else:
    135         if openDirectionalScanPanel:
    136             SetDirectionalScanEmbeddedPanelOpen()
    137         if openProbeScanPanel:
    138             SetProbeScanEmbeddedPanelOpen()
    139         if openDirectionalScanPanel and not openProbeScanPanel:
    140             SetProbeScanEmbeddedPanelClosed()
    141         elif openProbeScanPanel and not openDirectionalScanPanel:
    142             SetDirectionalScanEmbeddedPanelClosed()
    143         elif not openProbeScanPanel and not openDirectionalScanPanel:
    144             SetProbeScanEmbeddedPanelClosed()
    145             SetDirectionalScanEmbeddedPanelClosed()
    146         SolarSystemViewPanel.Open()
    147 
    148 
    149 def OpenSolarSystemMap(openProbeScanPanel = False, openDirectionalScanPanel = False):
    150     if session.solarsystemid2:
    151         from eve.client.script.ui.shared.mapView.solarSystemViewPanel import SolarSystemViewPanel
    152         panel = SolarSystemViewPanel.GetIfOpen()
    153         if panel:
    154             if openProbeScanPanel:
    155                 panel.OpenProbeScanner()
    156             if openDirectionalScanPanel:
    157                 panel.ToggleDirectionalScanner()
    158             panel.Maximize()
    159         else:
    160             SolarSystemViewPanel.Open(isDirectionalScanPanelOpen=openDirectionalScanPanel, isProbeScanPanelOpen=openProbeScanPanel)
    161 
    162 
    163 def ToggleMap(*args, **kwds):
    164     if not classic_map_enabled_setting.is_enabled():
    165         from eve.client.script.ui.shared.mapView.mapViewPanel import MapViewPanel
    166         if not MapViewPanel.CloseIfOpen():
    167             return OpenMap(*args, **kwds)
    168     else:
    169         viewSvc = sm.GetService('viewState')
    170         if viewSvc.IsViewActive('starmap', 'systemmap'):
    171             viewSvc.CloseSecondaryView()
    172         else:
    173             viewSvc.ActivateView('starmap', **kwds)
    174 
    175 
    176 def OpenMap(interestID = None, hightlightedSolarSystems = None, starColorMode = None, zoomToItem = True, updateFocus = True, **kwds):
    177     if not classic_map_enabled_setting.is_enabled():
    178         from eve.client.script.ui.shared.mapView.mapViewPanel import MapViewPanel
    179         mapPanel = MapViewPanel.GetIfOpen()
    180         if mapPanel:
    181             if interestID:
    182                 mapPanel.SetActiveItemID(interestID, zoomToItem=zoomToItem)
    183             if starColorMode:
    184                 mapPanel.SetMapFilter(starColorMode, updateFocus)
    185             if mapPanel.IsMinimized():
    186                 mapPanel.Maximize()
    187         else:
    188             if hightlightedSolarSystems:
    189                 interestID = hightlightedSolarSystems.keys()
    190             MapViewPanel.Open(parent=uicore.layer.main, interestID=interestID, starColorMode=starColorMode, zoomToItem=zoomToItem)
    191     else:
    192         sm.GetService('viewState').ActivateView('starmap', interestID=interestID, hightlightedSolarSystems=hightlightedSolarSystems, starColorMode=starColorMode)
    193 
    194 
    195 def SelectMapFilter(mapFilter, updateFocus = True):
    196     from eve.client.script.ui.shared.mapView.mapViewPanel import MapViewPanel
    197     mapPanel = MapViewPanel.GetIfOpen()
    198     if mapPanel:
    199         mapPanel.SetMapFilter(mapFilter, updateFocus)
    200 
    201 
    202 def UpdateDebugOutput(debugOutput, camera = None, mapView = None, **kwds):
    203     debugText = ''
    204     if mapView:
    205         debugText += '<br>MapViewID %s' % mapView.mapViewID
    206     if camera:
    207         debugText += '<br>field of view %s' % camera.fov
    208         debugText += '<br>min/max distance %s/%s' % (camera.maxZoom, camera.minZoom)
    209         debugText += '<br>front/back clip %s/%s' % (camera.nearClip, camera.farClip)
    210         debugText += '<br>translationFromParent %s' % camera.GetZoomDistance()
    211         debugText += '<br>viewAngle %.3f, %.3f, %.3f' % camera.GetViewVector()
    212     debugOutput.text = debugText
    213 
    214 
    215 def CreateLineSet(pickEnabled = False, texturePath = None, overlayTexturePath = None):
    216     lineSet = trinity.EveCurveLineSet()
    217     tex2D = trinity.TriTextureParameter()
    218     tex2D.name = 'TexMap'
    219     tex2D.resourcePath = texturePath or 'res:/UI/Texture/classes/LineSet/lineSegment.dds'
    220     lineSet.lineEffect.resources.append(tex2D)
    221     overlayTex2D = trinity.TriTextureParameter()
    222     overlayTex2D.name = 'OverlayTexMap'
    223     overlayTex2D.resourcePath = overlayTexturePath or 'res:/UI/Texture/classes/MapView/lineSegmentConstellation.dds'
    224     lineSet.lineEffect.resources.append(overlayTex2D)
    225     if not pickEnabled:
    226         lineSet.pickEffect = None
    227     return lineSet
    228 
    229 
    230 def CreatePlanarLineSet(pickEnabled = False, texturePath = None):
    231     lineSet = trinity.EveCurveLineSet()
    232     lineSet.lineEffect = trinity.Tr2Effect()
    233     lineSet.lineEffect.effectFilePath = 'res:/Graphics/Effect/Managed/Space/SpecialFX/Lines/Lines3DPlanar.fx'
    234     tex2D = trinity.TriTextureParameter()
    235     tex2D.name = 'TexMap'
    236     tex2D.resourcePath = texturePath or 'res:/dx9/texture/ui/linePlanarBase.dds'
    237     lineSet.lineEffect.resources.append(tex2D)
    238     if pickEnabled:
    239         lineSet.pickEffect.effectFilePath = 'res:/Graphics/Effect/Managed/Space/SpecialFX/Lines/Lines3DPlanarPicking.fx'
    240     else:
    241         lineSet.pickEffect = None
    242     return lineSet
    243 
    244 
    245 PARTICLE_EFFECT = 'res:/Graphics/Effect/Managed/Space/SpecialFX/Particles/StarmapNew.fx'
    246 PARTICLE_SPRITE_TEXTURE = 'res:/Texture/Particle/mapStarNew5.dds'
    247 PARTICLE_SPRITE_HEAT_TEXTURE = 'res:/Texture/Particle/mapStarNewHeat.dds'
    248 PARTICLE_SPRITE_DATA_TEXTURE = 'res:/Texture/Particle/mapStatData_Circle.dds'
    249 PARTICLE_SPRITE_TUBE_TEXTURE = 'res:/Texture/Particle/disk.dds'
    250 PARTICLE_SPRITE_DATA_TEXTURE_TEST = 'res:/Texture/Particle/circleScalingOpacity25.dds'
    251 TUBE_BUBBLE_SIZE = 200
    252 SIZE_FACTOR_VALUE = 5000
    253 PREVIEW_PICKER_SIZE = 1400
    254 TUBE_BUBBLE_CONTENT_BIG = 93 / 128.0 * TUBE_BUBBLE_SIZE
    255 TUBE_BUBBLE_CONTENT_MEDIUM = 68 / 128.0 * TUBE_BUBBLE_SIZE
    256 EXTRA_BUBBLE_BIG_SIZE_FACTOR = 7.6
    257 EXTRA_BUBBLE_MEDIUM_SIZE_FACTOR = 4.5
    258 BUBBLE_BASE_SIZE_MULTIPLIER = 1.0
    259 CAMERA_DISTANCE_SCALING_FACTOR = 1.0 / SIZE_FACTOR_VALUE
    260 DISTANCE_RANGE = 'distanceRange'
    261 JUMP_RANGE_INSIDE = 1
    262 JUMP_RANGE_OUTSIDE = 2
    263 JUMP_RANGE_OFF = 3
    264 JUMP_RANGE_INSIDE_EXCLUDED = 4
    265 
    266 def DrawCircle(lineSet, centerPosition, radius, arcSegments = 4, startColor = (0.3, 0.3, 0.3, 0.5), endColor = (0.3, 0.3, 0.3, 0.5), **kwds):
    267     lineIDs = set()
    268     arcAngle = math.pi * 2 / float(arcSegments)
    269     stepSize = 1.0 / float(arcSegments)
    270     for i in xrange(arcSegments):
    271         step = i / float(arcSegments)
    272         startAngle = math.pi * 2 * step
    273         color1 = geo2.Vec4Lerp(startColor, endColor, step)
    274         color2 = geo2.Vec4Lerp(startColor, endColor, step + stepSize)
    275         lineID = DrawCircularArc(lineSet, centerPosition, radius, angle=arcAngle, startAngle=startAngle, startColor=color1, endColor=color2, **kwds)
    276         lineIDs.add(lineID)
    277 
    278     return lineIDs
    279 
    280 
    281 def DrawCircularArc(lineSet, centerPosition, radius, angle, startAngle = 0.0, lineWidth = 1.0, startColor = (0.3, 0.3, 0.3, 0.5), endColor = (0.3, 0.3, 0.3, 0.5)):
    282     cos = math.cos(startAngle)
    283     sin = math.sin(startAngle)
    284     p1 = geo2.Vec3Add(centerPosition, (-radius * cos, 0.0, -radius * sin))
    285     cos = math.cos(startAngle + angle)
    286     sin = math.sin(startAngle + angle)
    287     p2 = geo2.Vec3Add(centerPosition, (-radius * cos, 0.0, -radius * sin))
    288     lineID = lineSet.AddSpheredLineCrt(p1, startColor, p2, endColor, centerPosition, lineWidth)
    289     lineSet.ChangeLineSegmentation(lineID, int(math.degrees(angle)))
    290     return lineID
    291 
    292 
    293 def TryGetPosFromItemID(locationID, solarsystemID):
    294     locationInfo = cfg.evelocations.GetIfExists(locationID)
    295     if locationInfo and locationInfo.solarSystemID == solarsystemID and (locationInfo.x, locationInfo.y, locationInfo.z) != (0, 0, 0):
    296         return (locationInfo.x, locationInfo.y, locationInfo.z)
    297     return (0, 0, 0)
    298 
    299 
    300 def GetPosForConstellationMarker(constellationData):
    301     return GetPosForConstellationMarkerForSolarSystems(constellationData.solarSystemIDs)
    302 
    303 
    304 def GetPosForConstellationMarkerForSolarSystems(solarSystemIDs):
    305     xPosForSystems = []
    306     zPosForSystems = []
    307     coordOverrider = get_coordinate_overrider_controller()
    308     for solarSystemID in solarSystemIDs:
    309         if not idCheckers.IsKnownSpaceSystem(solarSystemID):
    310             continue
    311         x, y, z = GetPosForSolarSystemID(coordOverrider, solarSystemID)
    312         xPosForSystems.append(x)
    313         zPosForSystems.append(z)
    314 
    315     if not xPosForSystems:
    316         return (0, 0, 0)
    317     avgX = sum(xPosForSystems) / len(xPosForSystems)
    318     avgZ = sum(zPosForSystems) / len(zPosForSystems)
    319     return (avgX, 0, avgZ)
    320 
    321 
    322 def GetPosForSolarSystemID(coordOverrider, solarSystemID):
    323     solarSystemData = cfg.mapSystemCache[solarSystemID]
    324     overriddenCoords = coordOverrider.GetOverridenCoordinates(solarSystemID)
    325     if overriddenCoords:
    326         x = overriddenCoords[0]
    327         z = overriddenCoords[1]
    328         y = solarSystemData.center.y
    329     else:
    330         x = solarSystemData.center.x
    331         y = solarSystemData.center.y
    332         z = solarSystemData.center.z
    333     return (x, y, z)
    334 
    335 
    336 def GetSolarSystemCoordinates(isAbstract, solarSystemID, solarSystemItem):
    337     if isAbstract:
    338         coordOverrider = get_coordinate_overrider_controller()
    339         newPos = coordOverrider.GetOverridenCoordinates(solarSystemID)
    340         if newPos:
    341             return WorldPosToMapPos((newPos[0], 0, newPos[1]))
    342     originalPosition = solarSystemItem.mapPosition
    343     return originalPosition
    344 
    345 
    346 @Memoize
    347 def GetConstellationCorrdinates(isAbstract, constellationID):
    348     from eve.client.script.ui.shared.mapView.mapViewData import mapViewData
    349     constellationItem = mapViewData.GetKnownConstellation(constellationID)
    350     if isAbstract:
    351         newPos = GetPosForConstellationMarker(constellationItem)
    352         if newPos:
    353             mapPos = WorldPosToMapPos(newPos)
    354             return mapPos
    355     return constellationItem.mapPosition
    356 
    357 
    358 def GetRegionCorrdinates(isAbstract, regionID, regionItem):
    359     if isAbstract:
    360         coordOverrider = get_coordinate_overrider_controller()
    361         newPos = coordOverrider.GetOverridenCoordinatesForRegion(regionID)
    362         if newPos:
    363             mapPos = WorldPosToMapPos((newPos[0], 0, newPos[1]))
    364             return mapPos
    365     return regionItem.mapPosition
    366 
    367 
    368 def GetSizeForUIElement(sizeValue, viewportHeight, cameraProjectionFovConst):
    369     sizePerPixel = float(sizeValue) / SIZE_FACTOR_VALUE
    370     size = sizePerPixel * viewportHeight
    371     size = size / cameraProjectionFovConst
    372     size = ReverseScaleDpi(size)
    373     return size
    374 
    375 
    376 def GetLandmarkPos(landmarkID, landmark, isAbstract):
    377     overriddenPos = landmark_overriden_coordinates.get(landmarkID, None)
    378     if overriddenPos:
    379         return (overriddenPos[0], 0, overriddenPos[1])
    380     if isAbstract:
    381         position2d = getattr(landmark, 'position2d', landmark.position)
    382         if position2d:
    383             return (position2d[0], 0, position2d[1])
    384     return landmark.position
    385 
    386 
    387 class SpriteValues(object):
    388 
    389     def __init__(self, markerSizeType, spriteTexture, staticSize, spriteMode, sizeFactor):
    390         self._markerSizeType = markerSizeType
    391         self._spriteTexture = spriteTexture
    392         self._staticSize = staticSize
    393         self._spriteMode = spriteMode
    394         self._sizeFactor = sizeFactor
    395 
    396     @property
    397     def markerSizeType(self):
    398         return self._markerSizeType
    399 
    400     @property
    401     def spriteTexture(self):
    402         return self._spriteTexture
    403 
    404     @property
    405     def staticSize(self):
    406         return self._staticSize
    407 
    408     @property
    409     def spriteMode(self):
    410         return self._spriteMode
    411 
    412     @property
    413     def sizeFactor(self):
    414         return self._sizeFactor
    415 
    416     def __eq__(self, other):
    417         if not isinstance(other, type(self)):
    418             return False
    419         return self.markerSizeType == other.markerSizeType and self._spriteTexture == other._spriteTexture and self._staticSize == other._staticSize and self._spriteMode == other._spriteMode and self._sizeFactor == other._sizeFactor
    420 
    421     def __repr__(self):
    422         return '<SpriteValues %s>, %s' % (self.__dict__, id(self))
    423 
    424 
    425 def IsValidJumpTarget(solarSystemID):
    426     isHighSec = sm.GetService('securitySvc').is_effective_high_sec_system(solarSystemID)
    427     if isHighSec:
    428         return False
    429     if IsTriglavianSystem(solarSystemID):
    430         return False
    431     if IsZarzakh(solarSystemID):
    432         return False
    433     if IsJoveSystem(solarSystemID):
    434         return False
    435     return True