invContainers.py (18731B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\inventory\invContainers.py 2 import threadutils 3 import uthread2 4 from carbonui import ButtonStyle, uiconst 5 from carbonui.primitives.frame import Frame 6 from carbonui.uicore import uicore 7 from eve.client.script.ui.crimewatch import crimewatchConst 8 from eve.client.script.ui.inflight.squadrons.fighterInvCont import FighterInvCont 9 from eve.client.script.ui.shared.container import _InvContBase, GetBasicSortOptions, GetSortMenuForOptionsOptions 10 from eve.client.script.ui.shared.redeem.redeemItem import RedeemItemSortData 11 import eve.client.script.environment.invControllers as invCtrl 12 import log 13 from eve.client.script.ui.shared.redeem.redeemUiConst import CREATION_DATE_SORT_KEY, EXPIRY_DATE_SORT_KEY 14 from eve.client.script.ui.shared.itemShip import ShipItemCard, ShipItemIcon 15 from eve.client.script.ui.structure.structureDeedInvCont import StructureDeedInvCont 16 from menu import MenuLabel 17 from inventorycommon.const import VIEWMODE_DETAILS, VIEWMODE_ICONS, VIEWMODE_LIST, VIEWMODE_CARDS 18 19 class _BaseCelestialContainer(_InvContBase): 20 __guid__ = 'invCont._BaseCelestialContainer' 21 __invControllerClass__ = None 22 23 def ApplyAttributes(self, attributes): 24 _InvContBase.ApplyAttributes(self, attributes) 25 if self.invController.IsLootable(): 26 self.CheckCanTakeItems = sm.GetService('crimewatchSvc').CheckCanTakeItems 27 self.restrictedFrame = Frame(parent=self, color=crimewatchConst.Colors.Yellow.GetRGBA(), state=uiconst.UI_HIDDEN) 28 self.restrictedButton = None 29 30 def RegisterSpecialActionButton(self, button): 31 if self.invController.IsLootable() and button.name == invCtrl.LOOT_ALL_BUTTON_NAME: 32 self.restrictedButton = button 33 self._start_loot_rights_update_loop() 34 35 @threadutils.threaded 36 def _start_loot_rights_update_loop(self): 37 while not self.destroyed: 38 self._update_loot_rights() 39 uthread2.sleep(0.25) 40 41 def _is_access_restricted(self): 42 return not self.CheckCanTakeItems(self.invController.itemID) 43 44 def _update_loot_rights(self): 45 if self.destroyed or self.restrictedButton.destroyed: 46 return 47 if self._is_access_restricted(): 48 self.restrictedFrame.Show() 49 self.restrictedButton.style = ButtonStyle.WARNING 50 else: 51 self.restrictedFrame.Hide() 52 self.restrictedButton.style = self.restrictedButton.default_style 53 54 def _EnforceLootableContainerRestrictions(self, *args): 55 if not self or self.destroyed: 56 return False 57 isAccessRestricted = False 58 if uicore.uilib.mouseOver in (self, self.restrictedButton) or uicore.uilib.mouseOver.IsUnder(self) or uicore.uilib.mouseOver.IsUnder(self.restrictedButton): 59 if not self.CheckCanTakeItems(self.invController.itemID): 60 isAccessRestricted = True 61 if isAccessRestricted: 62 self.restrictedFrame.Show() 63 self.restrictedButtonFill.Show() 64 else: 65 self.restrictedFrame.Hide() 66 self.restrictedButtonFill.Hide() 67 return True 68 69 70 class InventoryContainerWithItemTracking(_InvContBase): 71 __notifyevents__ = _InvContBase.__notifyevents__ + ['OnInventoryLocationSeen'] 72 73 def __init__(self, *args, **kwargs): 74 super(InventoryContainerWithItemTracking, self).__init__(*args, **kwargs) 75 76 def GetItemPanel(self, itemID): 77 for node in reversed(self.scroll.GetNodes()): 78 if node: 79 item = getattr(node, 'item', None) 80 panel = getattr(node, 'panel', None) 81 if item and panel: 82 if node.item.itemID == itemID: 83 return panel 84 85 def GetAllItemPanels(self): 86 panels = {} 87 for node in self.scroll.GetNodes(): 88 if node: 89 item = getattr(node, 'item', None) 90 panel = getattr(node, 'panel', None) 91 if item and panel: 92 itemID = node.item.itemID 93 panels[itemID] = panel 94 95 return panels 96 97 def OnInventoryLocationSeen(self, locationID): 98 if self.invController.GetInventoryLocationID() != locationID: 99 return 100 itemPanels = self.GetAllItemPanels() 101 for itemPanel in itemPanels.values(): 102 if itemPanel and itemPanel.IsTagged(): 103 itemPanel.HideTag() 104 105 106 class ShipCargo(InventoryContainerWithItemTracking): 107 __guid__ = 'invCont.ShipCargo' 108 __invControllerClass__ = invCtrl.ShipCargo 109 110 111 class POSRefinery(_BaseCelestialContainer): 112 __guid__ = 'invCont.POSRefinery' 113 __invControllerClass__ = invCtrl.POSRefinery 114 115 116 class POSCompression(_BaseCelestialContainer): 117 __guid__ = 'invCont.POSCompression' 118 __invControllerClass__ = invCtrl.POSCompression 119 120 121 class POSStructureCharges(_BaseCelestialContainer): 122 __guid__ = 'invCont.POSStructureCharges' 123 __invControllerClass__ = invCtrl.POSStructureCharges 124 125 126 class POSStructureChargeCrystal(POSStructureCharges): 127 __guid__ = 'invCont.POSStructureChargeCrystal' 128 __invControllerClass__ = invCtrl.POSStructureChargeCrystal 129 130 131 class POSStructureChargesStorage(_BaseCelestialContainer): 132 __guid__ = 'invCont.POSStructureChargesStorage' 133 __invControllerClass__ = invCtrl.POSStructureChargesStorage 134 135 136 class POSStrontiumBay(_BaseCelestialContainer): 137 __guid__ = 'invCont.POSStrontiumBay' 138 __invControllerClass__ = invCtrl.POSStrontiumBay 139 140 141 class POSFuelBay(_BaseCelestialContainer): 142 __guid__ = 'invCont.POSFuelBay' 143 __invControllerClass__ = invCtrl.POSFuelBay 144 145 146 class POSShipMaintenanceArray(_BaseCelestialContainer): 147 __guid__ = 'invCont.POSShipMaintenanceArray' 148 __invControllerClass__ = invCtrl.POSShipMaintenanceArray 149 150 151 class POSSilo(_BaseCelestialContainer): 152 __guid__ = 'invCont.POSSilo' 153 __invControllerClass__ = invCtrl.POSSilo 154 155 156 class POSMobileReactor(_BaseCelestialContainer): 157 __guid__ = 'invCont.POSMobileReactor' 158 __invControllerClass__ = invCtrl.POSMobileReactor 159 160 161 class POSPersonalHangar(_BaseCelestialContainer): 162 __guid__ = 'invCont.POSPersonalHangar' 163 __invControllerClass__ = invCtrl.POSPersonalHangar 164 165 166 class ItemWreck(_BaseCelestialContainer): 167 __guid__ = 'invCont.ItemWreck' 168 __invControllerClass__ = invCtrl.ItemWreck 169 170 171 class ItemFloatingCargo(_BaseCelestialContainer): 172 __guid__ = 'invCont.ItemFloatingCargo' 173 __invControllerClass__ = invCtrl.ItemFloatingCargo 174 175 176 class ItemSiphonPseudoSilo(_BaseCelestialContainer): 177 __guid__ = 'invCont.ItemSiphonPseudoSilo' 178 __invControllerClass__ = invCtrl.ItemSiphonPseudoSilo 179 180 181 class StationContainer(_BaseCelestialContainer): 182 __guid__ = 'invCont.StationContainer' 183 __invControllerClass__ = invCtrl.StationContainer 184 185 186 class AssetSafetyContainer(_BaseCelestialContainer): 187 __guid__ = 'invCont.AssetSafetyContainer' 188 __invControllerClass__ = invCtrl.AssetSafetyContainer 189 190 191 class ShipMaintenanceBay(_BaseCelestialContainer): 192 __guid__ = 'invCont.ShipMaintenanceBay' 193 __invControllerClass__ = invCtrl.ShipMaintenanceBay 194 195 196 class ShipDroneBay(_InvContBase): 197 __guid__ = 'invCont.ShipDroneBay' 198 __invControllerClass__ = invCtrl.ShipDroneBay 199 200 201 class ShipFighterBay(FighterInvCont): 202 __guid__ = 'invCont.ShipFighterBay' 203 __invControllerClass__ = invCtrl.ShipFighterBay 204 205 206 class ShipFrigateEscapeBay(_InvContBase): 207 __guid__ = 'invCont.ShipFrigateEscapeBay' 208 __invControllerClass__ = invCtrl.ShipFrigateEscapeBay 209 210 211 class ShipFuelBay(_InvContBase): 212 __guid__ = 'invCont.ShipFuelBay' 213 __invControllerClass__ = invCtrl.ShipFuelBay 214 215 216 class ShipGeneralMiningHold(_InvContBase): 217 __guid__ = 'invCont.ShipGeneralMiningHold' 218 __invControllerClass__ = invCtrl.ShipGeneralMiningHold 219 220 221 class ShipAsteroidHold(_InvContBase): 222 __guid__ = 'invCont.ShipAsteroidHold' 223 __invControllerClass__ = invCtrl.ShipAsteroidHold 224 225 226 class ShipIceHold(_InvContBase): 227 __guid__ = 'invCont.ShipIceHold' 228 __invControllerClass__ = invCtrl.ShipIceHold 229 230 231 class ShipGasHold(_InvContBase): 232 __guid__ = 'invCont.ShipGasHold' 233 __invControllerClass__ = invCtrl.ShipGasHold 234 235 236 class ShipMineralHold(_InvContBase): 237 __guid__ = 'invCont.ShipMineralHold' 238 __invControllerClass__ = invCtrl.ShipMineralHold 239 240 241 class ShipSalvageHold(_InvContBase): 242 __guid__ = 'invCont.ShipSalvageHold' 243 __invControllerClass__ = invCtrl.ShipSalvageHold 244 245 246 class ShipShipHold(_InvContBase): 247 __guid__ = 'invCont.ShipShipHold' 248 __invControllerClass__ = invCtrl.ShipShipHold 249 250 251 class ShipSmallShipHold(_InvContBase): 252 __guid__ = 'invCont.ShipSmallShipHold' 253 __invControllerClass__ = invCtrl.ShipSmallShipHold 254 255 256 class ShipMediumShipHold(_InvContBase): 257 __guid__ = 'invCont.ShipMediumShipHold' 258 __invControllerClass__ = invCtrl.ShipMediumShipHold 259 260 261 class ShipLargeShipHold(_InvContBase): 262 __guid__ = 'invCont.ShipLargeShipHold' 263 __invControllerClass__ = invCtrl.ShipLargeShipHold 264 265 266 class ShipIndustrialShipHold(_InvContBase): 267 __guid__ = 'invCont.ShipIndustrialShipHold' 268 __invControllerClass__ = invCtrl.ShipIndustrialShipHold 269 270 271 class ShipAmmoHold(_InvContBase): 272 __guid__ = 'invCont.ShipAmmoHold' 273 __invControllerClass__ = invCtrl.ShipAmmoHold 274 275 276 class ShipCommandCenterHold(_InvContBase): 277 __guid__ = 'invCont.ShipCommandCenterHold' 278 __invControllerClass__ = invCtrl.ShipCommandCenterHold 279 280 281 class ShipPlanetaryCommoditiesHold(_InvContBase): 282 __guid__ = 'invCont.ShipPlanetaryCommoditiesHold' 283 __invControllerClass__ = invCtrl.ShipPlanetaryCommoditiesHold 284 285 286 class ShipFleetHangar(_BaseCelestialContainer): 287 __guid__ = 'invCont.ShipFleetHangar' 288 __invControllerClass__ = invCtrl.ShipFleetHangar 289 290 291 class ShipQuafeHold(_InvContBase): 292 __guid__ = 'invCont.ShipQuafeHold' 293 __invControllerClass__ = invCtrl.ShipQuafeHold 294 295 296 class ShipCorpseHold(_InvContBase): 297 __guid__ = 'invCont.ShipCorpseHold' 298 __invControllerClass__ = invCtrl.ShipCorpseHold 299 300 301 class ShipBoosterHold(_InvContBase): 302 __guid__ = 'invCont.ShipBoosterHold' 303 __invControllerClass__ = invCtrl.ShipBoosterHold 304 305 306 class ShipSubsystemHold(_InvContBase): 307 __guid__ = 'invCont.ShipSubsystemHold' 308 __invControllerClass__ = invCtrl.ShipSubsystemHold 309 310 311 class ShipMobileDepotHold(_InvContBase): 312 __guid__ = 'invCont.ShipMobileDepotHold' 313 __invControllerClass__ = invCtrl.ShipMobileDepotHold 314 315 316 class ShipColonyResourcesHold(_InvContBase): 317 __guid__ = 'invCont.ShipColonyResourcesHold' 318 __invControllerClass__ = invCtrl.ShipColonyResourcesHold 319 320 321 class ShipExpeditionHold(_InvContBase): 322 __guid__ = 'invCont.ShipExpeditionHold' 323 __invControllerClass__ = invCtrl.ShipExpeditionHold 324 325 326 class StationCorpDeliveries(_InvContBase): 327 __guid__ = 'invCont.StationCorpDeliveries' 328 __invControllerClass__ = invCtrl.StationCorpDeliveries 329 330 331 class CapsuleerDeliveries(_InvContBase): 332 __guid__ = 'invCont.CapsuleerDeliveries' 333 __invControllerClass__ = invCtrl.CapsuleerDeliveries 334 335 336 class AssetSafetyDeliveries(_InvContBase): 337 __guid__ = 'invCont.AssetSafetyDeliveries' 338 __invControllerClass__ = invCtrl.AssetSafetyDeliveries 339 340 341 class StationItems(InventoryContainerWithItemTracking): 342 __guid__ = 'invCont.StationItems' 343 __invControllerClass__ = invCtrl.StationItems 344 __notifyevents__ = InventoryContainerWithItemTracking.__notifyevents__ + ['OnItemNameChange'] 345 346 def OnItemNameChange(self, *args): 347 self.Refresh() 348 349 350 class RedeemItems(_InvContBase): 351 __guid__ = 'invCont.RedeemItems' 352 __invControllerClass__ = invCtrl.RedeemItems 353 __notifyevents__ = _InvContBase.__notifyevents__ + ['OnItemNameChange'] 354 default_shouldShowHint = True 355 356 def ApplyAttributes(self, attributes): 357 super(RedeemItems, self).ApplyAttributes(attributes) 358 self.shouldShowHint = attributes.get('shouldShowHint', self.default_shouldShowHint) 359 if attributes.onSelectionChange: 360 self.scroll.OnSelectionChange = attributes.onSelectionChange 361 362 def OnItemNameChange(self, *args): 363 self.Refresh() 364 365 def AddItem(self, rec, index = None, fromWhere = None): 366 pass 367 368 def RemoveItem(self, item): 369 pass 370 371 def UpdateItem(self, rec, *etc): 372 pass 373 374 def SetItem(self, index, rec): 375 pass 376 377 def InitializeSortBy(self): 378 self.sortIconsBy, self.sortIconsDir = settings.char.ui.Get('containerSortIconsBy_%s' % self.name, (CREATION_DATE_SORT_KEY, 1)) 379 380 def GetSortData(self, sortby, direction): 381 sortData = [] 382 for rec in self.items: 383 if rec is None: 384 continue 385 sortKey = RedeemItemSortData(rec).GetSortKey(sortby, direction) 386 if not sortKey: 387 log.LogError('Unknown sortkey used in container sorting', sortby, direction) 388 continue 389 sortData.append((sortKey, rec)) 390 391 return sortData 392 393 def UpdateHint(self): 394 if not self.shouldShowHint: 395 return 396 super(RedeemItems, self).UpdateHint() 397 398 def GetContainerMenu(self): 399 return GetRedeemContainerMenu(self) 400 401 402 def GetRedeemContainerMenu(containerWindow): 403 m = [(MenuLabel('UI/Common/SelectAll'), containerWindow.SelectAll), (MenuLabel('UI/Inventory/InvertSelection'), containerWindow.InvertSelection)] 404 sortOptions = GetRedeemSortOptions() 405 m += [(MenuLabel('UI/Common/SortBy'), GetSortMenuForOptionsOptions(containerWindow, sortOptions))] 406 return m 407 408 409 def GetRedeemSortOptions(): 410 sortOptions = [None, 411 ('UI/RedeemWindow/TokenCreationDate', (CREATION_DATE_SORT_KEY, 1)), 412 ('UI/RedeemWindow/TokenCreationDateReversed', (CREATION_DATE_SORT_KEY, 0)), 413 None, 414 ('UI/RedeemWindow/TokenExpiryDate', (EXPIRY_DATE_SORT_KEY, 0)), 415 ('UI/RedeemWindow/TokenExpiryDateReversed', (EXPIRY_DATE_SORT_KEY, 1))] 416 sortOptions += GetBasicSortOptions() 417 return sortOptions 418 419 420 class StationShips(InventoryContainerWithItemTracking): 421 __guid__ = 'invCont.StationShips' 422 __invControllerClass__ = invCtrl.StationShips 423 __notifyevents__ = InventoryContainerWithItemTracking.__notifyevents__ + ['OnItemNameChange', 'ProcessActiveShipChanged'] 424 default_containerViewMode = VIEWMODE_CARDS 425 default_availableViewModes = (VIEWMODE_CARDS, 426 VIEWMODE_ICONS, 427 VIEWMODE_DETAILS, 428 VIEWMODE_LIST) 429 430 def ApplyAttributes(self, attributes): 431 super(StationShips, self).ApplyAttributes(attributes) 432 self.scroll.SetNodes_ = self.scroll.SetNodes 433 self.scroll.SetNodes = self._SetScrollNodes 434 435 def GetViewModeSettingKey(self): 436 return u'stationShipsViewMode_{}'.format(self.name) 437 438 def GetItemClass(self): 439 if self.viewMode == VIEWMODE_CARDS: 440 return ShipItemCard 441 return ShipItemIcon 442 443 def _SetScrollNodes(self, nodes): 444 self._SortActiveShip(nodes) 445 self.scroll.SetNodes_(nodes) 446 447 def SetSortedItems(self, sortedList): 448 self._SortActiveShip(sortedList) 449 super(StationShips, self).SetSortedItems(sortedList) 450 451 def _SortActiveShip(self, sortedList): 452 activeShip = None 453 for index, ship in enumerate(sortedList): 454 if ship.itemID == session.shipid: 455 if index != 0: 456 activeShip = ship 457 break 458 459 if activeShip: 460 sortedList.remove(activeShip) 461 sortedList.insert(0, activeShip) 462 463 def OnItemNameChange(self, *args): 464 self.Refresh() 465 466 def ProcessActiveShipChanged(self, shipID, oldShipID): 467 self.Refresh() 468 469 470 class StationCorpMember(_InvContBase): 471 __guid__ = 'invCont.StationCorpMember' 472 __invControllerClass__ = invCtrl.StationCorpMember 473 474 def ApplyAttributes(self, attributes): 475 _InvContBase.ApplyAttributes(self, attributes) 476 sm.GetService('invCache').InvalidateLocationCache((const.containerHangar, self.invController.ownerID)) 477 478 def _GetInvController(self, attributes): 479 return self.__invControllerClass__(itemID=attributes.itemID, ownerID=attributes.ownerID) 480 481 def Refresh(self): 482 sm.GetService('invCache').InvalidateLocationCache((const.containerHangar, self.invController.ownerID)) 483 _InvContBase.Refresh(self) 484 485 486 class StationCorpHangar(_InvContBase): 487 __guid__ = 'invCont.StationCorpHangar' 488 __invControllerClass__ = invCtrl.StationCorpHangar 489 490 def _GetInvController(self, attributes): 491 return self.__invControllerClass__(itemID=attributes.itemID, divisionID=attributes.divisionID) 492 493 494 class POSCorpHangar(_InvContBase): 495 __guid__ = 'invCont.POSCorpHangar' 496 __invControllerClass__ = invCtrl.POSCorpHangar 497 498 def _GetInvController(self, attributes): 499 return self.__invControllerClass__(itemID=attributes.itemID, divisionID=attributes.divisionID) 500 501 502 class SpaceComponentInventory(_BaseCelestialContainer): 503 __guid__ = 'invCont.SpaceComponentInventory' 504 __invControllerClass__ = invCtrl.SpaceComponentInventory 505 506 507 class Structure(_InvContBase): 508 __guid__ = 'invCont.Structure' 509 __invControllerClass__ = invCtrl.Structure 510 511 512 class StructureAmmoBay(_InvContBase): 513 __guid__ = 'invCont.StructureAmmoBay' 514 __invControllerClass__ = invCtrl.StructureAmmoBay 515 516 517 class StructureFuelBay(_InvContBase): 518 __guid__ = 'invCont.StructureFuelBay' 519 __invControllerClass__ = invCtrl.StructureFuelBay 520 521 522 class StructureFighterBay(FighterInvCont): 523 __guid__ = 'invCont.StructureFighterBay' 524 __invControllerClass__ = invCtrl.StructureFighterBay 525 526 527 class StructureItemHangar(InventoryContainerWithItemTracking): 528 __guid__ = 'invCont.StructureItemHangar' 529 __invControllerClass__ = invCtrl.StructureItemHangar 530 531 532 class StructureShipHangar(StationShips): 533 __guid__ = 'invCont.StructureShipHangar' 534 __invControllerClass__ = invCtrl.StructureShipHangar 535 536 537 class StructureDeliveriesHangar(_InvContBase): 538 __guid__ = 'invCont.StructureDeliveriesHangar' 539 __invControllerClass__ = invCtrl.StructureDeliveriesHangar 540 541 542 class StructureCorpHangar(_InvContBase): 543 __guid__ = 'invCont.StructureCorpHangar' 544 __invControllerClass__ = invCtrl.StructureCorpHangar 545 546 def _GetInvController(self, attributes): 547 return self.__invControllerClass__(itemID=attributes.itemID, divisionID=attributes.divisionID) 548 549 550 class StructureDeedBay(StructureDeedInvCont): 551 __guid__ = 'invCont.StructureDeedBay' 552 __invControllerClass__ = invCtrl.StructureDeedBay 553 554 555 class AssetSafetyCorpContainer(StructureCorpHangar): 556 __guid__ = 'invCont.AssetSafetyCorpContainer' 557 __invControllerClass__ = invCtrl.AssetSafetyCorpContainer 558 559 560 class StructureMoonMaterialBay(_InvContBase): 561 __guid__ = 'invCont.StructureMoonMaterialBay' 562 __invControllerClass__ = invCtrl.StructureMoonMaterialBay