workforce.py (8553B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\mapView\workforce.py 2 import geo2 3 from carbon.common.script.sys.serviceConst import ROLE_PROGRAMMER 4 from eve.client.script.ui.shared.mapView import mapViewConst 5 from eve.client.script.ui.shared.mapView.mapViewBookmarkHandler import IsMarkerGroupEnabled 6 from eve.client.script.ui.shared.mapView.mapViewConst import MARKERS_OPTION_SOV_HUBS, MARKERID_SOVHUBS, WORKFORCE_TRANSPORT_STATE_TYPE, WORKFORCE_TRANSPORT_CONFIG_TYPE 7 from eve.client.script.ui.shared.mapView.markers.mapMarkerSovHub import MarkerSovHub 8 from eve.common.script.sys.idCheckers import IsSolarSystem 9 from evemap.workforceUtil import GetStateAndConfigByHubID, GetOtherStateAndSystems, GetSystemsForConfigs 10 from sovereignty.workforce import workforceConst 11 from eve.client.script.ui.shared.mapView.mapViewData import mapViewData 12 import logging 13 logger = logging.getLogger(__name__) 14 IMPORT_STATE_COLOR = (191 / 255.0, 15 0, 16 207 / 255.0, 17 1.0) 18 EXPORT_STATE_COLOR = (0.0, 0.0, 1.0, 1.0) 19 IMPORT_CONFIG_COLOR = IMPORT_STATE_COLOR 20 EXPORT_CONFIG_COLOR = (0.0, 0.0, 1.0, 1.0) 21 22 class MapViewSovHubHandler(object): 23 __notifyevents__ = ['OnSovHubMarkersChanged'] 24 25 def __init__(self, mapView): 26 self.mapView = mapView 27 sm.RegisterNotify(self) 28 29 @property 30 def workforceTransportLineSet(self): 31 return self.mapView.workforceTransportLineSet 32 33 def OnSovHubMarkersChanged(self): 34 self.LoadShowHubMarkers() 35 36 def LoadShowHubMarkers(self): 37 if self.mapView.destroyed: 38 return 39 if not CanSeeSovHubs() or not session.allianceid: 40 return 41 isStationManager = session.corprole & const.corpRoleStationManager 42 if not isStationManager: 43 return 44 showSovHubMarkers = IsMarkerGroupEnabled(MARKERS_OPTION_SOV_HUBS, self.mapView.mapViewID) 45 markersHandler = self.mapView.markersHandler 46 if not showSovHubMarkers: 47 sovHubMarkers = markersHandler.GetMarkersByType(MARKERID_SOVHUBS) 48 sovHubMarkerIDs = set([ markerObject.markerID for markerObject in sovHubMarkers ]) 49 for removeMarkerID in sovHubMarkerIDs: 50 markersHandler.RemoveMarker(removeMarkerID) 51 52 self.workforceTransportLineSet.ClearLines() 53 self.workforceTransportLineSet.SubmitChanges() 54 return 55 svcSvc = sm.GetService('sov') 56 sovHubSvc = sm.GetService('sovHubSvc') 57 networkedHubByItemID = GetStateAndConfigByHubID(svcSvc, sovHubSvc) 58 for hubID, hubStateConfig in networkedHubByItemID.iteritems(): 59 ssID = hubStateConfig.solarSystemID 60 markerID = (MARKERID_SOVHUBS, ssID) 61 if self.mapView.destroyed: 62 return 63 mapNode = self.mapView.layoutHandler.GetNodeBySolarSystemID(ssID) 64 solarSystemPosition = mapNode.position 65 sovHubKwds = {'hubStateConfig': hubStateConfig} 66 marker = markersHandler.AddSolarSystemBasedMarker(markerID, markerClass=MarkerSovHub, solarSystemID=ssID, mapPositionSolarSystem=solarSystemPosition, mapPositionLocal=(0, 0, 0), idx=0, **sovHubKwds) 67 marker.SetMarkerKwds(sovHubKwds) 68 self.mapView.markersAlwaysVisible.add(markerID) 69 70 self.LoadTransportLines(networkedHubByItemID) 71 72 def LoadTransportLines(self, networkedHubByItemID): 73 newLineData = [] 74 self.workforceTransportLineSet.ClearLines() 75 newLineDataState, addedPairs = self._LoadStateTransportLines(networkedHubByItemID) 76 newLineData.extend(newLineDataState) 77 newLineDataConfig = self._LoadConfigTransportLines(networkedHubByItemID, addedPairs) 78 configLineIDs = [ lineData.lineID for lineData in newLineDataConfig ] 79 newLineData.extend(newLineDataConfig) 80 worldUp = geo2.Vector(0.0, -1.0, 0.0) 81 for eachLineData in newLineData: 82 self.mapView.layoutHandler.UpdateLinePosition(eachLineData, {}, worldUp) 83 84 if self.workforceTransportLineSet: 85 for lineID in configLineIDs: 86 self.workforceTransportLineSet.ChangeLineAnimation(lineID, (0, 0, 0, 1), 0.0, 100) 87 self.workforceTransportLineSet.ChangeLineWidth(lineID, mapViewConst.JUMPLINE_BASE_WIDTH * 1.3) 88 89 self.workforceTransportLineSet.SubmitChanges() 90 91 def _LoadStateTransportLines(self, networkedHubByItemID): 92 defaultPos = (0, 0, 0) 93 lineWidth = 3 94 newLineData = [] 95 addedStatePairs = {} 96 for hubID, hubInfo in networkedHubByItemID.iteritems(): 97 solarSystemA = hubInfo.solarSystemID 98 otherState, solarSystemBsState = GetOtherStateAndSystems(hubInfo) 99 if otherState is None: 100 continue 101 hubStateMode = hubInfo.hubState.get_mode() 102 for ssB in solarSystemBsState: 103 if not IsSolarSystem(solarSystemA) or not IsSolarSystem(ssB): 104 logger.warn("_LoadStateTransportLines had entry that wasn't a solarsystem: %s, %s" % (solarSystemA, ssB)) 105 continue 106 sortedInfo = sorted([(solarSystemA, hubStateMode), (ssB, otherState)], key=lambda x: x[0]) 107 pairKey = tuple([ x[0] for x in sortedInfo ]) 108 pairStates = [ x[1] for x in sortedInfo ] 109 existingPair = addedStatePairs.get(pairKey, None) 110 if existingPair and existingPair != pairStates: 111 logger.exception("states don't match :(") 112 continue 113 addedStatePairs[pairKey] = pairStates 114 if hubStateMode == workforceConst.MODE_IMPORT: 115 colorA = IMPORT_STATE_COLOR 116 colorB = EXPORT_STATE_COLOR 117 else: 118 colorA = EXPORT_STATE_COLOR 119 colorB = IMPORT_STATE_COLOR 120 lineID = self.workforceTransportLineSet.AddCurvedLineCrt(defaultPos, colorA, defaultPos, colorB, (1, 1, 1), lineWidth) 121 lineData = mapViewData.PrimeJumpData(solarSystemA, ssB, WORKFORCE_TRANSPORT_STATE_TYPE, colorA, colorB) 122 lineData.lineID = lineID 123 newLineData.append(lineData) 124 125 return (newLineData, addedStatePairs.keys()) 126 127 def _LoadConfigTransportLines(self, networkedHubByItemID, addedPairs): 128 existingLines = {} 129 defaultPos = (0, 0, 0) 130 lineWidth = 3 131 newLineData = [] 132 for hubID, hubInfo in networkedHubByItemID.iteritems(): 133 solarSystemA = hubInfo.solarSystemID 134 solarSystemBsConfig = GetSystemsForConfigs(hubInfo) 135 if solarSystemBsConfig is None: 136 continue 137 hubConfigMode = hubInfo.hubConfig.get_mode() 138 for ssB in solarSystemBsConfig: 139 if not IsSolarSystem(solarSystemA) or not IsSolarSystem(ssB): 140 logger.warn("_LoadConfigTransportLines had entry that wasn't a solarsystem: %s, %s" % (solarSystemA, ssB)) 141 continue 142 pairKey = tuple(sorted([solarSystemA, ssB])) 143 if pairKey in addedPairs: 144 continue 145 existingLineData = existingLines.get(pairKey, None) 146 if hubConfigMode == workforceConst.MODE_IMPORT: 147 colorA = IMPORT_CONFIG_COLOR 148 else: 149 colorA = EXPORT_CONFIG_COLOR 150 if existingLineData: 151 if solarSystemA == existingLineData.toSolarSystemID: 152 self.workforceTransportLineSet.ChangeLineColor(existingLineData.lineID, existingLineData.colorFrom, colorA) 153 else: 154 self.workforceTransportLineSet.ChangeLineColor(existingLineData.lineID, colorA, existingLineData.colorTo) 155 else: 156 colorB = (0.0, 0.0, 0.0, 1.0) 157 lineID = self.workforceTransportLineSet.AddCurvedLineCrt(defaultPos, colorA, defaultPos, colorB, defaultPos, lineWidth) 158 lineData = mapViewData.PrimeJumpData(solarSystemA, ssB, WORKFORCE_TRANSPORT_CONFIG_TYPE, colorA, colorB) 159 lineData.lineID = lineID 160 existingLines[pairKey] = lineData 161 newLineData.append(lineData) 162 163 return newLineData 164 165 166 def CanSeeSovHubs(): 167 if not session.allianceid: 168 return False 169 isStationManager = session.corprole & const.corpRoleStationManager 170 if not isStationManager: 171 return False 172 return True