workforceController.py (8931B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\sovereignty\workforce\client\workforceController.py 2 from __future__ import print_function 3 import eveicon 4 from evelink.client import location_link 5 from localization import GetByLabel 6 from signals import Signal 7 from sovereignty.client.quasarCallWrapper import DATA_NOT_AVAILABLE 8 from sovereignty.client.sovHub.hubUtil import GetTexturePathForWorkforceMode 9 from sovereignty.workforce import workforceConst 10 11 class WorkforceController(object): 12 13 def __init__(self, sovHubID, quasarCallWrapper, solarSystemID): 14 self._sovHubID = sovHubID 15 self._solarSystemID = solarSystemID 16 self.quasarCallWrapper = quasarCallWrapper 17 self._currentConfig = None 18 self._currentState = None 19 self.on_workforce_changed = Signal(signalName='on_workforce_changed') 20 21 @property 22 def sovHubID(self): 23 return self._sovHubID 24 25 @property 26 def solarSystemID(self): 27 return self._solarSystemID 28 29 def GetModeComboOptions(self): 30 options = workforceConst.LABELPATH_BY_MODE.copy() 31 options.pop(workforceConst.MODE_IDLE) 32 return [ (GetByLabel(labelPath), mode) for mode, labelPath in options.iteritems() ] 33 34 def GetWorkforceTextsAndTexturePath(self): 35 workforceConfig = self.workforceConfiguration 36 if workforceConfig == DATA_NOT_AVAILABLE: 37 return (DATA_NOT_AVAILABLE, False, eveicon.workforce) 38 workforceMode = workforceConfig.get_mode() 39 labelPath = workforceConst.LABELPATH_BY_MODE.get(workforceMode) 40 texturePath = GetTexturePathForWorkforceMode(workforceMode) 41 if labelPath: 42 return (GetByLabel(labelPath), True, texturePath) 43 return (GetByLabel('UI/Sovereignty/SovHub/UnknownWorkforceMode'), False, texturePath) 44 45 @property 46 def workforceConfiguration(self): 47 if self._currentConfig is None: 48 result = self.quasarCallWrapper.GetWorkforceConfiguration(self._sovHubID) 49 if result == DATA_NOT_AVAILABLE: 50 return DATA_NOT_AVAILABLE 51 self._currentConfig = result 52 return self._currentConfig 53 54 @property 55 def workforceState(self): 56 if self._currentState is None: 57 result = self.quasarCallWrapper.GetWorkforceState(self._sovHubID) 58 if result == DATA_NOT_AVAILABLE: 59 return DATA_NOT_AVAILABLE 60 self._currentState = result 61 return self._currentState 62 63 @workforceState.setter 64 def workforceState(self, value): 65 self._currentState = value 66 67 def UpdateWorkforceConfiguration(self, newConfig): 68 self._currentConfig = newConfig 69 self.on_workforce_changed() 70 71 def UpdateWorkforceState(self, newState): 72 self._currentState = newState 73 self.on_workforce_changed() 74 75 def SetWorkforceConfiguration(self, newConfig): 76 result = self.quasarCallWrapper.SaveWorkforceConfiguration(self._sovHubID, newConfig) 77 if result == DATA_NOT_AVAILABLE: 78 print('failed to set workforce') 79 return 80 self._currentConfig = newConfig 81 self._currentState = None 82 self.on_workforce_changed() 83 sm.ScatterEvent('OnSovHubMarkersChanged') 84 85 def GetWorkforceTransportDesc(self): 86 workforceConfiguration = self.workforceConfiguration 87 workforceState = self.workforceState 88 if workforceConfiguration == DATA_NOT_AVAILABLE or workforceState == DATA_NOT_AVAILABLE: 89 return '' 90 mode = workforceConfiguration.get_mode() 91 if mode == workforceConst.MODE_IDLE: 92 return GetByLabel('UI/Sovereignty/SovHub/Upgrades/WorkforceTransportInactive') 93 if mode == workforceConst.MODE_IMPORT: 94 importState = workforceState.import_state 95 amount = 0 96 for iSystemID, iAmount in importState.amount_by_source_system_id.iteritems(): 97 amount += iAmount 98 99 return GetByLabel('UI/Sovereignty/SovHub/Upgrades/WorkforceTransportImport', amount=amount, solarSystemNames='') 100 if mode == workforceConst.MODE_EXPORT: 101 exportConfig = workforceConfiguration.export_configuration 102 configDestID = exportConfig.destination_system_id 103 exportState = workforceState.export_state 104 stateAmount = exportState.amount 105 stateDestID = exportState.destination_system_id 106 if stateDestID: 107 systemName = location_link(stateDestID) 108 return GetByLabel('UI/Sovereignty/SovHub/Upgrades/WorkforceTransportExport', amount=stateAmount, solarSystemName=systemName) 109 elif configDestID: 110 systemName = location_link(configDestID) 111 configAmount = exportConfig.amount 112 return GetByLabel('UI/Sovereignty/SovHub/Upgrades/WorkforceTransportExportNoConnection', amount=configAmount, solarSystemName=systemName) 113 else: 114 return GetByLabel('UI/Sovereignty/SovHub/Upgrades/WorkforceTransportExportNotConfigured', amount=stateAmount) 115 if mode == workforceConst.MODE_TRANSIT: 116 return GetByLabel('UI/Sovereignty/SovHub/Upgrades/WorkforceTransportTransit') 117 118 def GetWorkforceImportSystems(self): 119 workforceConfiguration = self.workforceConfiguration 120 workforceState = self.workforceState 121 if workforceConfiguration == DATA_NOT_AVAILABLE or workforceState == DATA_NOT_AVAILABLE: 122 return [] 123 mode = workforceConfiguration.get_mode() 124 if mode == workforceConst.MODE_IMPORT: 125 importConfig = workforceConfiguration.import_configuration 126 importState = workforceState.import_state 127 source_system_ids = importConfig.source_system_ids.copy() 128 systemNameList = [] 129 for iSystemID, iAmount in importState.amount_by_source_system_id.iteritems(): 130 systemName = location_link(iSystemID) 131 source_system_ids.discard(iSystemID) 132 systemNameList.append((systemName, iAmount)) 133 134 for ssID in source_system_ids: 135 systemNameList.append((location_link(ssID), None)) 136 137 return systemNameList 138 return [] 139 140 def GetCurrentMode(self): 141 workforceConfiguration = self.workforceConfiguration 142 if workforceConfiguration == DATA_NOT_AVAILABLE: 143 return '' 144 return workforceConfiguration.get_mode() 145 146 def GetImportedWorkforceFromState(self): 147 workforceState = self.workforceState 148 if workforceState.get_mode() == workforceConst.MODE_IMPORT: 149 return sum(workforceState.import_state.amount_by_source_system_id.itervalues()) 150 return 0 151 152 def GetExportedWorkforceFromState(self): 153 workforceState = self.workforceState 154 if workforceState.get_mode() == workforceConst.MODE_EXPORT: 155 return workforceState.export_state.amount 156 return 0 157 158 def GetNetworkableHubs(self): 159 networkableHubs = self.quasarCallWrapper.GetNetworkableHubs(self.sovHubID) 160 return networkableHubs 161 162 def GetSystemOptions(self, inImportingMode, otherSelectedSystems = ()): 163 networkableHubs = self.GetNetworkableHubs() 164 return self.GetSystemOptionsFromNetworkableHubs(inImportingMode, otherSelectedSystems, networkableHubs) 165 166 def GetSystemOptionsFromNetworkableHubs(self, inImportingMode, otherSelectedSystems, networkableHubs): 167 otherSelectedSystems = otherSelectedSystems or () 168 if networkableHubs == DATA_NOT_AVAILABLE: 169 return [] 170 solarSystemIDs = [ x.system_id for x in networkableHubs ] 171 cfg.evelocations.Prime(solarSystemIDs) 172 options = [] 173 for hub in networkableHubs: 174 if self._FilterOutHub(hub, inImportingMode): 175 continue 176 if hub.system_id in otherSelectedSystems: 177 continue 178 text = cfg.evelocations.Get(hub.system_id).name 179 options.append((text, hub.system_id)) 180 181 options.insert(0, (GetByLabel('UI/Sovereignty/SovHub/HubWnd/SectionACLNotSet'), None)) 182 return options 183 184 def _FilterOutHub(self, networkedHub, inImportingMode): 185 inExportingMode = not inImportingMode 186 hubState = networkedHub.state 187 if hubState.inactive or hubState.transit_state: 188 return True 189 if inImportingMode and hubState.import_state: 190 return True 191 if inExportingMode and hubState.export_state: 192 return True 193 if inImportingMode and hubState.export_state.destination_system_id and hubState.export_state.destination_system_id != self.solarSystemID: 194 return True 195 if inExportingMode and len(hubState.import_state.amount_by_source_system_id) >= 3: 196 if self.solarSystemID not in hubState.import_state.amount_by_source_system_id: 197 return True 198 return False