editSections.py (22428B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\sov\sovHub\editSections.py 2 import carbonui 3 import carbonui.text.styles 4 import eveicon 5 import uthread2 6 from carbonui import const as uiconst 7 from carbonui.button.const import HEIGHT_NORMAL 8 from carbonui.button.group import ButtonGroup 9 from carbonui.control.button import Button 10 from carbonui.control.combo import Combo 11 from carbonui.control.singlelineedits.singleLineEditInteger import SingleLineEditInteger 12 from carbonui.primitives.container import Container 13 from carbonui.primitives.containerAutoSize import ContainerAutoSize 14 from carbonui.primitives.flowcontainer import FlowContainer 15 from carbonui.primitives.sprite import Sprite 16 from carbonui.uicore import uicore 17 from eve.client.script.ui import eveColor 18 from eve.client.script.ui.control.tooltips import TooltipPersistentPanel 19 from eve.client.script.ui.shared.bookmarks.bookmarkContainerWindow import DropCombo 20 from eve.client.script.ui.shared.messagebox import MessageBox 21 from eveexceptions import ExceptionEater 22 from localization import GetByLabel 23 from player_messaging.client.ui_message import prompt_player_fsd_dialog 24 from signals import Signal 25 from sovereignty.client.quasarCallWrapper import DATA_NOT_AVAILABLE 26 from sovereignty.workforce.client.data_types import WorkforceConfiguration, WorkforceImportConfiguration, WorkforceExportConfiguration 27 import sovereignty.workforce.workforceConst as workforceConst 28 29 class BaseSectionCont(ContainerAutoSize): 30 sectionTexturePath = eveicon.workforce 31 sectionNameLabelPath = '' 32 default_canEdit = True 33 34 def ApplyAttributes(self, attributes): 35 self.descLabel = None 36 self.editLabel = None 37 super(BaseSectionCont, self).ApplyAttributes(attributes) 38 self.canEdit = attributes.Get('canEdit', self.default_canEdit) 39 self.ConstructUI() 40 41 def ConstructUI(self): 42 self.header = carbonui.text.styles.TextDetail(parent=self, text=GetByLabel(self.sectionNameLabelPath), color=carbonui.TextColor.SECONDARY, align=carbonui.Align.TOTOP) 43 self.stateCont = ContainerAutoSize(name='stateCont', parent=self, align=carbonui.Align.TOTOP, alignMode=carbonui.Align.TOTOP) 44 self.stateSprite = Sprite(parent=self.stateCont, align=carbonui.Align.CENTERLEFT, pos=(0, 0, 16, 16), texturePath=self.sectionTexturePath, color=eveColor.TUNGSTEN_GREY) 45 self.labelCont = ContainerAutoSize(name='labelCont', parent=self.stateCont, align=carbonui.Align.TOTOP, alignMode=carbonui.Align.TOTOP, padLeft=20) 46 self.stateLabel = carbonui.text.styles.TextHeader(name='stateLabel', parent=self.labelCont, text=' ', align=carbonui.Align.TOTOP) 47 if self.canEdit: 48 self.editLabel = carbonui.text.styles.TextBody(parent=self.labelCont, text=GetByLabel('UI/Sovereignty/SovHub/HubWnd/SectionEdit'), color=eveColor.CRYO_BLUE, align=carbonui.Align.BOTTOMRIGHT, top=2, pickState=carbonui.PickState.ON) 49 self.stateLabel.padRight = self.editLabel.width 50 self.editLabel.OnClick = self.OnEditClicked 51 52 def LoadSection(self): 53 pass 54 55 def OnEditClicked(self, *args): 56 pass 57 58 def GetDesriptionText(self): 59 return '' 60 61 62 class TransitCont(BaseSectionCont): 63 default_name = 'transitCont' 64 sectionNameLabelPath = 'UI/Sovereignty/SovHub/HubWnd/SectionWorkforceTransport' 65 sectionTexturePath = eveicon.workforce 66 67 def ApplyAttributes(self, attributes): 68 self.workforceController = attributes.workforceController 69 self.section_loaded = Signal('section_loaded') 70 super(TransitCont, self).ApplyAttributes(attributes) 71 if hasattr(self.workforceController, 'on_workforce_changed'): 72 self.workforceController.on_workforce_changed.connect(self.OnWorkforceChanged) 73 74 def ConstructUI(self): 75 super(TransitCont, self).ConstructUI() 76 self.descLabel = carbonui.text.styles.TextBody(parent=self, text='', color=carbonui.TextColor.SECONDARY, align=carbonui.Align.TOTOP, pickState=carbonui.PickState.ON) 77 cont = ContainerAutoSize(parent=self, align=carbonui.Align.TOTOP) 78 self.systemFlowCont = FlowContainer(name='systemFlowCont', parent=cont, align=uiconst.TOTOP) 79 80 def LoadSection(self): 81 text, valid, texturePath = self.workforceController.GetWorkforceTextsAndTexturePath() 82 if text == DATA_NOT_AVAILABLE or not valid: 83 text = GetByLabel('UI/Sovereignty/HubPage/NotAvailable', color=eveColor.GUNMETAL_HEX) 84 if self.editLabel: 85 self.editLabel.Hide() 86 elif self.editLabel: 87 self.editLabel.Show() 88 self.stateSprite.SetTexturePath(texturePath) 89 self.stateLabel.text = text 90 descText = self.workforceController.GetWorkforceTransportDesc() 91 self.descLabel.text = descText 92 importedSystems = self.workforceController.GetWorkforceImportSystems() 93 self.systemFlowCont.Flush() 94 if importedSystems: 95 self._LoadImportedSystems(importedSystems) 96 uthread2.call_after_wallclocktime_delay(self.section_loaded, 0.05) 97 98 def _LoadImportedSystems(self, importedSystems): 99 for systemLink, amount in importedSystems: 100 cont = ContainerAutoSize(parent=self.systemFlowCont) 101 textLeft = 0 102 if not amount: 103 sprite = Sprite(parent=cont, align=carbonui.Align.CENTERLEFT, texturePath='res:/UI/Texture/classes/agency/iconExclamation.png', pos=(0, 0, 16, 16)) 104 if amount is None: 105 sprite.hint = GetByLabel('UI/Sovereignty/SovHub/HubWnd/SourceSystemNotConnected') 106 else: 107 sprite.hint = GetByLabel('UI/Sovereignty/SovHub/HubWnd/SourceSystemNotSendingWorkforce') 108 textLeft = 20 109 text = systemLink 110 else: 111 text = '%s (%s)' % (systemLink, amount) 112 carbonui.text.styles.TextBody(parent=cont, text=text, left=textLeft, pickState=carbonui.PickState.ON, align=carbonui.Align.CENTERLEFT, padRight=10) 113 114 def OnWorkforceChanged(self, *args): 115 self.KillTooltip() 116 self.LoadSection() 117 118 def OnEditClicked(self, *args): 119 uicore.uilib.tooltipHandler.LoadPersistentTooltip(owner=self.editLabel, customTooltipClass=EditSectionTooltip, loadArguments=(EditTransitCont, self.workforceController), parent=uicore.layer.utilmenu) 120 121 def KillTooltip(self): 122 existingTooltip = uicore.uilib.tooltipHandler.GetPersistentTooltipByOwner(self.editLabel) 123 if existingTooltip and not existingTooltip.destroyed: 124 existingTooltip.Close() 125 126 def Close(self): 127 with ExceptionEater('Closing TransitCont'): 128 self.section_loaded.clear() 129 super(TransitCont, self).Close() 130 131 132 class AclSectionCont(BaseSectionCont): 133 sectionTexturePath = 'res:/UI/Texture/WindowIcons/accessGroups.png' 134 sectionNameLabelPath = 'UI/Sovereignty/SovHub/HubWnd/SectionACL' 135 headerHintPath = 'UI/Sovereignty/SovHub/HubWnd/SectionACLDesc' 136 default_state = uiconst.UI_NORMAL 137 138 def ApplyAttributes(self, attributes): 139 self.editAclCont = None 140 self.aclCombo = None 141 self.controller = attributes.controller 142 super(AclSectionCont, self).ApplyAttributes(attributes) 143 if hasattr(self.controller, 'on_acl_changed'): 144 self.controller.on_acl_changed.connect(self.OnAclChanged) 145 if hasattr(self.controller, 'on_acl_setting_failed'): 146 self.controller.on_acl_setting_failed.connect(self.OnAclSettingFailed) 147 148 def ConstructUI(self): 149 super(AclSectionCont, self).ConstructUI() 150 self.header.pickState = carbonui.PickState.ON 151 self.header.hint = GetByLabel(self.headerHintPath) 152 if self.canEdit: 153 self.editAclCont = Container(name='editAclCont', parent=self.stateCont, height=HEIGHT_NORMAL, align=carbonui.Align.TOTOP) 154 bntCont = ContainerAutoSize(name='bntCont', parent=self.editAclCont, align=carbonui.Align.TORIGHT) 155 comboCont = Container(name='comboCont', parent=self.editAclCont) 156 btn = Button(name='applyBtn', parent=bntCont, align=uiconst.CENTER, label=GetByLabel('UI/Sovereignty/SovHub/HubWnd/SectionEditApply'), func=self.ApplyAcl) 157 self.aclCombo = DropCombo(parent=comboCont, name='aclCombo', align=carbonui.Align.TOALL, options=self.controller.accessGroupOptions, select=self.controller.fuelACL, dropped=self.OnDroppedGroup, emptyTooltip=GetByLabel('UI/OrbitalSkyhook/ConfigWnd/TakeAccessComboHint'), left=20, padRight=8) 158 self.editAclCont.display = False 159 160 def OnDroppedGroup(self, newGroupID): 161 for groupName, groupID in self.controller.accessGroupOptions: 162 if groupID == newGroupID: 163 self.aclCombo.SetValue(newGroupID) 164 return 165 166 self.controller.AddGroup(newGroupID) 167 self.aclCombo.entries = self.controller.accessGroupOptions 168 self.aclCombo.SetValue(newGroupID) 169 170 def ApplyAcl(self, *args): 171 newVal = self.aclCombo.GetValue() 172 self.controller.SetFuelACL(newVal) 173 self.editAclCont.display = False 174 self.labelCont.display = True 175 176 def LoadSection(self): 177 text = self.controller.GetAclName() 178 self.stateLabel.text = text 179 180 def GetContentClass(self): 181 return EditTransitCont 182 183 def OnAclChanged(self, *args): 184 self.LoadSection() 185 186 def OnAclSettingFailed(self): 187 self.editAclCont.display = False 188 self.labelCont.display = True 189 190 def OnEditClicked(self, *args): 191 self.editAclCont.display = True 192 self.labelCont.display = False 193 194 195 class EditSectionTooltip(TooltipPersistentPanel): 196 default_pointerDirection = carbonui.uiconst.POINT_LEFT_2 197 default_columns = 1 198 default_state = carbonui.uiconst.UI_NORMAL 199 default_margin = 16 200 isTopLevelWindow = True 201 202 def __init__(self, **kwargs): 203 super(EditSectionTooltip, self).__init__(**kwargs) 204 self.contentCont = None 205 self.pickState = uiconst.TR2_SPS_ON 206 uicore.registry.SetFocus(self) 207 uicore.uilib.RegisterForTriuiEvents(uiconst.UI_MOUSEDOWN, self._on_global_mouse_down) 208 209 def LoadTooltip(self, contentClass, workforceController, *args): 210 self.contentCont = contentClass(parent=self, workforceController=workforceController) 211 212 def _on_global_mouse_down(self, *args): 213 mouseOver = uicore.uilib.mouseOver 214 if mouseOver is self or mouseOver.IsUnder(self): 215 return True 216 if self.contentCont and self.contentCont.BelongsToWindow(mouseOver): 217 return True 218 messageBox = MessageBox.GetIfOpen() 219 if mouseOver.IsUnder(messageBox) and messageBox.isModal: 220 return True 221 self.Close() 222 return False 223 224 225 class EditTransitCont(ContainerAutoSize): 226 default_align = carbonui.Align.TOPLEFT 227 default_height = 150 228 default_width = 230 229 default_state = carbonui.uiconst.UI_NORMAL 230 231 def ApplyAttributes(self, attributes): 232 super(EditTransitCont, self).ApplyAttributes(attributes) 233 self.workforceController = attributes.workforceController 234 self.importCombos = [] 235 carbonui.text.styles.TextBody(parent=self, text=GetByLabel('UI/Sovereignty/SovHub/HubWnd/SectionWorkforceTransportSettings'), align=carbonui.Align.TOTOP) 236 modeCont, self.modeLabel, self.modeCombo = self.GetComboCont(self, 'modeCont', GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorceforceMode'), self.OnModeChanged) 237 options = self.workforceController.GetModeComboOptions() 238 self.modeCombo.LoadOptions(options) 239 self.ConstructExport() 240 self.ConstructImport() 241 self.AdjustComobWidths() 242 btnGroup = ButtonGroup(parent=self, align=carbonui.Align.TOTOP) 243 self.applyBtn = Button(name='applyBtn', align=uiconst.CENTER, label=GetByLabel('UI/Sovereignty/SovHub/HubWnd/SectionEditApply'), func=self.ApplySettings, enabled=False, top=6) 244 btnGroup.add_button(self.applyBtn) 245 self.LoadEditWnd() 246 247 def ConstructExport(self): 248 self.exportCont = ContainerAutoSize(name='exportCont', parent=self, align=carbonui.Align.TOTOP, top=4) 249 amountCont = ContainerAutoSize(name='amountCont', parent=self.exportCont, align=carbonui.Align.TOTOP, alignMode=carbonui.Align.CENTERLEFT) 250 self.amountLabel = carbonui.text.styles.TextBody(parent=amountCont, text=GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceTransitAmount'), align=carbonui.Align.CENTERLEFT) 251 self.amountEdit = SingleLineEditInteger(parent=amountCont, align=carbonui.Align.CENTERLEFT, setvalue=0, left=100, width=140, OnChange=self.OnExportAmountChanged) 252 receiverCont, self.receiverLabel, self.receiverCombo = self.GetComboCont(self.exportCont, 'receiverCont', GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceTransitReceiver'), self.OnSenderReceiverChanged) 253 254 def ConstructImport(self): 255 self.importCont = ContainerAutoSize(name='importCont', parent=self, align=carbonui.Align.TOTOP) 256 textS1 = GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceTransitSenderNum', senderNum=1) 257 s1Cont, self.s1Label, self.s1Combo = self.GetComboCont(self.importCont, 'sender1', textS1, callback=self.OnSenderChanged) 258 textS2 = GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceTransitSenderNum', senderNum=2) 259 s2Cont, self.s2Label, self.s2Combo = self.GetComboCont(self.importCont, 'sender2', textS2, callback=self.OnSenderChanged) 260 textS3 = GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceTransitSenderNum', senderNum=3) 261 s3Cont, self.s3Label, self.s3Combo = self.GetComboCont(self.importCont, 'sender3', textS3, callback=self.OnSenderChanged) 262 self.importCombos = [self.s1Combo, self.s2Combo, self.s3Combo] 263 264 def AdjustComobWidths(self): 265 allLabels = [self.modeLabel, 266 self.receiverLabel, 267 self.s1Label, 268 self.s2Label, 269 self.s3Label, 270 self.amountLabel, 271 self.receiverLabel] 272 allInput = [self.modeCombo, 273 self.receiverCombo, 274 self.s1Combo, 275 self.s2Combo, 276 self.s3Combo, 277 self.amountEdit, 278 self.receiverCombo] 279 maxLabelWidth = max(60, max([ x.textwidth for x in allLabels ]) + 28) 280 for inputElement in allInput: 281 inputElement.left = maxLabelWidth 282 283 def OnModeChanged(self, cb, key, value): 284 self.LoadEditWnd(value) 285 286 def OnSenderChanged(self, cb, key, value): 287 self.UpdateBtnState() 288 self.RefreshSenderOptions() 289 290 def OnSenderReceiverChanged(self, cb, key, value): 291 self.UpdateBtnState() 292 293 def OnExportAmountChanged(self, *args): 294 self.UpdateBtnState() 295 296 def GetComboCont(self, parent, configName, text, callback = None): 297 cont = ContainerAutoSize(name=configName, parent=parent, align=carbonui.Align.TOTOP, top=4) 298 label = carbonui.text.styles.TextBody(parent=cont, text=text, align=carbonui.Align.CENTERLEFT) 299 combo = Combo(parent=cont, name='%sCombo' % configName, options=[], left=100, align=carbonui.Align.CENTERLEFT, adjustWidth=False, callback=callback) 300 return (cont, label, combo) 301 302 def BelongsToWindow(self, elementToCheck): 303 for combo in [self.modeCombo, 304 self.s1Combo, 305 self.s2Combo, 306 self.s3Combo, 307 self.receiverCombo]: 308 optionMenu = getattr(combo, 'optionMenu', None) 309 if optionMenu: 310 if elementToCheck.IsUnder(combo.optionMenu): 311 return True 312 313 return False 314 315 def LoadEditWnd(self, mode = None): 316 if mode is None: 317 mode = self.workforceController.GetCurrentMode() 318 if mode == workforceConst.MODE_IMPORT: 319 self.RefreshSenderOptions() 320 elif mode == workforceConst.MODE_EXPORT: 321 systemOptions = self.workforceController.GetSystemOptions(False) 322 self.receiverCombo.LoadOptions(systemOptions) 323 self.ReloadWnd(mode) 324 325 def RefreshSenderOptions(self): 326 networkableHubs = self.workforceController.GetNetworkableHubs() 327 senderCombos = [self.s1Combo, self.s2Combo, self.s3Combo] 328 for eachCombo in senderCombos: 329 otherCombValues = filter(None, [ x.GetValue() for x in senderCombos if x != eachCombo ]) 330 options = self.workforceController.GetSystemOptionsFromNetworkableHubs(True, otherCombValues, networkableHubs) 331 eachCombo.LoadOptions(options, eachCombo.GetValue()) 332 333 def UpdateBtnState(self): 334 selectedMode = self.modeCombo.GetValue() 335 currentConfig = self.workforceController.workforceConfiguration 336 currentMode = currentConfig.get_mode() 337 if currentMode == selectedMode and selectedMode in (workforceConst.MODE_IDLE, workforceConst.MODE_TRANSIT): 338 self.applyBtn.enabled = False 339 return 340 if selectedMode == workforceConst.MODE_EXPORT: 341 exportedAmount = self.amountEdit.GetValue() 342 if not exportedAmount: 343 self.applyBtn.enabled = False 344 return 345 exportConfig = currentConfig.export_configuration 346 if exportConfig: 347 destination = self.receiverCombo.GetValue() 348 if exportedAmount == exportConfig.amount and destination == exportConfig.destination_system_id: 349 self.applyBtn.enabled = False 350 return 351 if selectedMode == workforceConst.MODE_IMPORT: 352 importConfig = currentConfig.import_configuration 353 if importConfig: 354 comboValues = [self.s1Combo.GetValue(), self.s2Combo.GetValue(), self.s3Combo.GetValue()] 355 sources = set(filter(None, comboValues)) 356 if sources == importConfig.source_system_ids: 357 self.applyBtn.enabled = False 358 return 359 self.applyBtn.enabled = True 360 361 def ReloadWnd(self, mode): 362 self.exportCont.Hide() 363 self.importCont.Hide() 364 self.modeCombo.SetValue(mode) 365 config = self.workforceController.workforceConfiguration 366 if mode == workforceConst.MODE_IDLE: 367 pass 368 elif mode == workforceConst.MODE_EXPORT: 369 self.exportCont.Show() 370 if config.export_configuration: 371 self.amountEdit.SetValue(config.export_configuration.amount) 372 destID = config.export_configuration.destination_system_id 373 self.receiverCombo.SetValue(destID) 374 elif mode == workforceConst.MODE_IMPORT: 375 self.importCont.Show() 376 if config.import_configuration: 377 sourceSystemIDs = filter(None, config.import_configuration.source_system_ids) 378 for combo, systemID in zip(self.importCombos, sourceSystemIDs): 379 combo.SetValue(systemID) 380 381 self.RefreshSenderOptions() 382 elif mode == workforceConst.MODE_TRANSIT: 383 pass 384 self.UpdateBtnState() 385 386 def ApplySettings(self, *args): 387 mode = self.modeCombo.GetValue() 388 if mode == workforceConst.MODE_IDLE: 389 newConfig = WorkforceConfiguration(self.workforceController.sovHubID, inactive=True) 390 elif mode == workforceConst.MODE_TRANSIT: 391 newConfig = WorkforceConfiguration(self.workforceController.sovHubID, transit=True) 392 elif mode == workforceConst.MODE_IMPORT: 393 importConfig = self._GetImportConfig() 394 newConfig = WorkforceConfiguration(self.workforceController.sovHubID, import_configuration=importConfig) 395 elif mode == workforceConst.MODE_EXPORT: 396 exportConfig = self._GetExportConfig() 397 newConfig = WorkforceConfiguration(self.workforceController.sovHubID, export_configuration=exportConfig) 398 else: 399 raise RuntimeError('Invalid mode = %s' % mode) 400 if self.ChangeIsConfirmed(self.workforceController.workforceConfiguration, newConfig): 401 self.workforceController.SetWorkforceConfiguration(newConfig) 402 403 def _GetImportConfig(self): 404 sourceIDs = set() 405 for combo in [self.s1Combo, self.s2Combo, self.s3Combo]: 406 val = combo.GetValue() 407 if val: 408 sourceIDs.add(val) 409 410 importConfig = WorkforceImportConfiguration(self.workforceController.sovHubID, sourceIDs) 411 return importConfig 412 413 def _GetExportConfig(self): 414 amount = self.amountEdit.GetValue() 415 systemID = self.receiverCombo.GetValue() 416 exportConfig = WorkforceExportConfiguration(self.workforceController.sovHubID, systemID, amount) 417 return exportConfig 418 419 def ChangeIsConfirmed(self, oldConfig, newConfig): 420 oldMode = oldConfig.get_mode() 421 newMode = newConfig.get_mode() 422 infoText = confirmText = '' 423 systemName = cfg.evelocations.Get(self.workforceController.solarSystemID).name 424 if oldMode == workforceConst.MODE_TRANSIT: 425 infoText = GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceChangeFromTransit', systemName=systemName) 426 if oldMode == workforceConst.MODE_IMPORT: 427 infoText = GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceChangeFromImport', systemName=systemName) 428 if oldMode == workforceConst.MODE_EXPORT: 429 infoText = GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceChangeFromExport', systemName=systemName) 430 if oldMode == workforceConst.MODE_IDLE: 431 infoText = GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceChangeFromInactive', systemName=systemName) 432 if newMode == workforceConst.MODE_TRANSIT: 433 confirmText = GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceChangeToTransit', systemName=systemName) 434 if newMode == workforceConst.MODE_IMPORT: 435 confirmText = GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceChangeToImport', systemName=systemName) 436 if newMode == workforceConst.MODE_EXPORT: 437 confirmText = GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceChangeToExport', systemName=systemName) 438 if newMode == workforceConst.MODE_IDLE: 439 confirmText = GetByLabel('UI/Sovereignty/SovHub/HubWnd/WorkforceChangeToInactive', systemName=systemName) 440 if prompt_player_fsd_dialog('ConfirmWorkforceChanged', {'infoText': infoText, 441 'confirmText': confirmText}, uiconst.YESNO) == uiconst.ID_YES: 442 return True 443 return False