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

mapViewLineOpacity.py (10509B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\mapView\mapViewLineOpacity.py
      2 from __future__ import print_function
      3 from collections import defaultdict
      4 from eve.client.script.ui.shared.mapView import mapViewConst
      5 from eve.client.script.ui.shared.mapView.mapViewConst import VIEWMODE_LINES_NONE, VIEWMODE_LINES_SELECTION_REGION, VIEWMODE_LINES_SELECTION_REGION_NEIGHBOURS, OPACITY_LINES_HOVERED, OPACITY_LINES_SELECTED, VIEWMODE_LINES_ALL, MAP2D_ZOOM_TUBE_BUBBLE
      6 from eve.client.script.ui.shared.mapView.mapViewData import mapViewData
      7 from eve.client.script.ui.shared.maps.mapcommon import REGION_JUMP
      8 from eve.common.script.sys.idCheckers import IsKnownSpaceRegion, IsSolarSystem, IsKnownSpaceSystem, IsConstellation, IsKnownSpaceConstellation, IsRegion
      9 
     10 def GetLineOpacityFinderClass(isAbstractView):
     11     if isAbstractView:
     12         return LineOpacityFinderAbstract
     13     return LineOpacityFinder3D
     14 
     15 
     16 class BaseLineOpacityFinder(object):
     17     selectedRegionMultiplier = 1.0
     18 
     19     def __init__(self, layoutHandler, lineMode, activeRegionID, activeConstellationID, groupingMode, hilightID, selectedID, jumpLineInfoByLineID, zoomValue, boldSystemIDs):
     20         self._layoutHandler = layoutHandler
     21         self._lineMode = lineMode
     22         self._activeRegionID = activeRegionID
     23         self._activeConstellationID = activeConstellationID
     24         self._groupingMode = groupingMode
     25         self._hilightID = hilightID
     26         self._selectedID = selectedID
     27         self._jumpLineInfoByLineID = jumpLineInfoByLineID
     28         self._zoomValue = zoomValue
     29         self._boldSystemIDs = boldSystemIDs
     30         self._opacityByLineID = defaultdict(int)
     31         self.mapSvc = sm.GetService('map')
     32 
     33     def GetLineOpacityByLineID(self):
     34         if self.ShowLines():
     35             self.UpdateLineOpacitySelectedRegionAndNeighbours()
     36             if self._hilightID:
     37                 self._UpdateLineOpacityByLineIDforItemID(self._hilightID, self.GetBaseOpacityForHoveredLines())
     38             self._UpdateLineOpacityByLineIDforItemID(self._selectedID, self.GetBaseOpacityForSelectedLines())
     39             self.UpdateLineOpacityForBoldSystems()
     40         return self._opacityByLineID
     41 
     42     def GetBaseOpacityForHoveredLines(self):
     43         return OPACITY_LINES_HOVERED
     44 
     45     def GetBaseOpacityForSelectedLines(self):
     46         return OPACITY_LINES_SELECTED
     47 
     48     def GetBaseOpacityForRegionalLines(self):
     49         return self.GetLineDefaultOpacity()
     50 
     51     def UpdateLineOpacitySelectedRegionAndNeighbours(self):
     52         pass
     53 
     54     def _UpdateLineOpacityByLineIDforItemID(self, itemID, baseOpacity):
     55         if IsSolarSystem(itemID) and IsKnownSpaceSystem(itemID):
     56             return self._UpdateLineOpacitySolarSystem(itemID, baseOpacity)
     57         if IsConstellation(itemID) and IsKnownSpaceConstellation(itemID):
     58             return self._UpdateLineOpacityConstellationSelected(itemID, baseOpacity)
     59         if IsRegion(itemID) and IsKnownSpaceRegion(itemID):
     60             return self._UpdateLineOpacityRegionSelected(itemID, baseOpacity)
     61 
     62     def _UpdateLineOpacitySolarSystem(self, solarSystemID, baseOpacity):
     63         pass
     64 
     65     def _UpdateLineOpacityConstellationSelected(self, hiliteID, baseOpacity):
     66         constellation = mapViewData.GetKnownConstellation(hiliteID)
     67         self._UpdateLineOpacityForSolarSystemIDs(baseOpacity, constellation.solarSystemIDs)
     68 
     69     def _UpdateLineOpacityRegionSelected(self, hiliteID, baseOpacity):
     70         hiliteItem = mapViewData.GetKnownRegion(hiliteID)
     71         opacity = baseOpacity * self.selectedRegionMultiplier
     72         self._UpdateLineOpacityForSolarSystemIDs(opacity, hiliteItem.solarSystemIDs)
     73 
     74     def _UpdateLineOpacityForSolarSystemIDs(self, opacity, solarSystemIDs):
     75         pass
     76 
     77     def UpdateLineOpacityForBoldSystems(self):
     78         pass
     79 
     80     def GetLineDataForSolarSystemID(self, solarSystemID):
     81         mapNode = self._layoutHandler.GetNodeBySolarSystemID(solarSystemID)
     82         if mapNode:
     83             return [ lineData for lineData in mapNode.lineData ]
     84         return []
     85 
     86     def GetLineDataForSolarSystemIDs(self, solarSystemIDs):
     87         result = []
     88         for solarSystemID in solarSystemIDs:
     89             lineData = self.GetLineDataForSolarSystemID(solarSystemID)
     90             result.extend(lineData)
     91 
     92         return result
     93 
     94     def IsGroupingConstellations(self):
     95         return self._groupingMode == mapViewConst.VIEWMODE_LAYOUT_CONSTELLATIONS
     96 
     97     def ShowLines(self):
     98         return True
     99 
    100     def CanUpdateSolarSystemLines(self):
    101         return False
    102 
    103     def GetLineDefaultOpacity(self):
    104         return 0.5
    105 
    106     def DebugLineOpacity(self, prefix = '-'):
    107         lineID = 0
    108         print('%s - %s - self._opacityByLineID = %s' % (prefix, lineID, self._opacityByLineID.get(lineID, -1)))
    109 
    110 
    111 class LineOpacityFinder3D(BaseLineOpacityFinder):
    112     selectedRegionMultiplier = 0.25
    113 
    114     def UpdateLineOpacitySelectedRegionAndNeighbours(self):
    115         if not self._activeRegionID:
    116             return
    117         if not IsKnownSpaceRegion(self._activeRegionID):
    118             return
    119         if self._lineMode != VIEWMODE_LINES_SELECTION_REGION:
    120             return
    121         if self.IsGroupingConstellations():
    122             regionsToShow = mapViewData.GetKnownUniverseRegions().keys()
    123         else:
    124             regionsToShow = [self._activeRegionID]
    125         show = self.GetNeighboringRegionsToShow()
    126         regionsToShow += show
    127         solarSystemIDs = self.mapSvc.ExpandItems(regionsToShow)
    128         opacity = self.GetBaseOpacityForSelectedLines() * self.selectedRegionMultiplier
    129         self._UpdateLineOpacityForSolarSystemIDs(opacity, solarSystemIDs)
    130 
    131     def _UpdateLineOpacitySolarSystem(self, solarSystemID, baseOpacity):
    132         if self._activeConstellationID:
    133             return self._UpdateLineOpacityConstellationSelected(self._activeConstellationID, baseOpacity)
    134 
    135     def ShowLines(self):
    136         return self._lineMode != VIEWMODE_LINES_NONE
    137 
    138     def CanUpdateSolarSystemLines(self):
    139         return bool(self._activeConstellationID)
    140 
    141     def GetNeighboringRegionsToShow(self):
    142         if self._lineMode == VIEWMODE_LINES_SELECTION_REGION_NEIGHBOURS:
    143             return mapViewData.GetKnownRegion(self._activeRegionID).neighbours
    144         return []
    145 
    146     def GetLineDefaultOpacity(self):
    147         opacityDefault = 0.0
    148         if self._lineMode == VIEWMODE_LINES_ALL:
    149             opacityDefault = 0.2
    150         return opacityDefault
    151 
    152     def _UpdateLineOpacityForSolarSystemIDs(self, opacity, solarSystemIDs):
    153         lineData = self.GetLineDataForSolarSystemIDs(solarSystemIDs)
    154         for line in lineData:
    155             self._opacityByLineID[line.lineID] += opacity
    156 
    157     def UpdateLineOpacityForBoldSystems(self):
    158         if not self._boldSystemIDs:
    159             return
    160         bolderLineData = self.GetLineDataForSolarSystemIDs(self._boldSystemIDs)
    161         for line in bolderLineData:
    162             self._opacityByLineID[line.lineID] += 1.0
    163 
    164 
    165 class LineOpacityFinderAbstract(BaseLineOpacityFinder):
    166     SELECTED_REGION_OPACITY_MULTIPLIER = 1.05
    167 
    168     def _UpdateLineOpacitySolarSystem(self, solarSystemID, baseOpacity):
    169         return self._UpdateLineOpacityForSolarSystemIDs(baseOpacity, [solarSystemID])
    170 
    171     def UpdateLineOpacitySelectedRegionAndNeighbours(self):
    172         if not self._activeRegionID:
    173             return
    174         if not IsKnownSpaceRegion(self._activeRegionID):
    175             return
    176         if self.IsGroupingConstellations():
    177             regionsToShow = mapViewData.GetKnownUniverseRegions().keys()
    178         else:
    179             regionsToShow = [self._activeRegionID]
    180         solarSystemIDs = self.mapSvc.ExpandItems(regionsToShow)
    181         solarSystemIDs += self.GetNeighboringSystemsToShow(self._activeRegionID)
    182         opacity = self.GetLineDefaultOpacity()
    183         self._UpdateLineOpacityForSolarSystemIDs(opacity, solarSystemIDs)
    184 
    185     def GetNeighboringSystemsToShow(self, regionID):
    186         solarSystemsInActivateRegion = self.mapSvc.ExpandItems([regionID])
    187         connectedSystems = set()
    188         for ssID in solarSystemsInActivateRegion:
    189             solarSystemInfo = mapViewData.GetKnownSolarSystem(ssID)
    190             connectedSystems.update(solarSystemInfo.neighbours)
    191 
    192         systemInOtherRegions = connectedSystems.difference(set(solarSystemsInActivateRegion))
    193         return list(systemInOtherRegions)
    194 
    195     def GetLineDefaultOpacity(self):
    196         if self._zoomValue < MAP2D_ZOOM_TUBE_BUBBLE:
    197             return 0.4
    198         else:
    199             return 0.3
    200 
    201     def GetBaseOpacityForRegionalLines(self):
    202         if self._zoomValue < MAP2D_ZOOM_TUBE_BUBBLE:
    203             return 0.3
    204         else:
    205             return 0.2
    206 
    207     def GetBaseOpacityForHoveredLines(self):
    208         return self.GetLineDefaultOpacity()
    209 
    210     def GetBaseOpacityForSelectedLines(self):
    211         return self.GetLineDefaultOpacity()
    212 
    213     def _UpdateLineOpacityForSolarSystemIDs(self, opacity, solarSystemIDs):
    214         lineData = self.GetLineDataForSolarSystemIDs(solarSystemIDs)
    215         regionOpacityDefault = self.GetBaseOpacityForRegionalLines()
    216         additionNormal = opacity * 0.5
    217         additionRegional = regionOpacityDefault * 0.5
    218         for line in lineData:
    219             lineID = line.lineID
    220             if line.jumpType == REGION_JUMP:
    221                 if lineID not in self._opacityByLineID:
    222                     self._opacityByLineID[lineID] = regionOpacityDefault
    223                 self._opacityByLineID[lineID] += additionRegional
    224             else:
    225                 if lineID not in self._opacityByLineID:
    226                     self._opacityByLineID[lineID] = opacity
    227                 self._opacityByLineID[lineID] += additionNormal
    228 
    229     def UpdateLineOpacityForBoldSystems(self):
    230         if not self._boldSystemIDs:
    231             return
    232         bolderLineData = self.GetLineDataForSolarSystemIDs(self._boldSystemIDs)
    233         defaultOpacity = self.GetLineDefaultOpacity()
    234         defaultRegionOpacity = self.GetBaseOpacityForRegionalLines()
    235         additionNormal = defaultOpacity * 0.5
    236         additionRegional = defaultRegionOpacity * 0.5
    237         for line in bolderLineData:
    238             lineID = line.lineID
    239             if line.jumpType == REGION_JUMP:
    240                 if lineID not in self._opacityByLineID:
    241                     self._opacityByLineID[lineID] = defaultRegionOpacity
    242                 self._opacityByLineID[lineID] += additionRegional
    243             else:
    244                 if lineID not in self._opacityByLineID:
    245                     self._opacityByLineID[lineID] = defaultOpacity
    246                 self._opacityByLineID[lineID] += additionNormal