inventory.py (5656B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\dockedUI\inventory.py 2 import logging 3 import localization 4 from carbon.common.script.sys.serviceManager import ServiceManager 5 from carbonui import uiconst 6 from carbonui.primitives.container import Container 7 from carbonui.control.tab import Tab 8 from carbonui.control.tabGroup import TabGroup 9 from inventorycommon.const import INVENTORY_ID_STATION_ITEMS, INVENTORY_ID_STATION_SHIPS, INVENTORY_ID_STRUCTURE_ITEMS, INVENTORY_ID_STRUCTURE_SHIPS 10 logger = logging.getLogger(__name__) 11 12 class InventoryPanel(Container): 13 _initialized = False 14 _items_panel = None 15 _ships_panel = None 16 _tabs = None 17 18 def __init__(self, station_controller, **kwargs): 19 self._station_controller = station_controller 20 super(InventoryPanel, self).__init__(**kwargs) 21 22 def on_drop_data(self, source, data): 23 if self._items_panel: 24 self._items_panel.OnDropData(source, data) 25 26 def _layout(self): 27 self._tabs = TabGroup(parent=self, align=uiconst.TOTOP, settingsID='lobbyInventoryPanel', UIIDPrefix='lobbyInventoryPanelTab') 28 self._ships_panel = ShipsPanel(parent=self, align=uiconst.TOALL, state=uiconst.UI_HIDDEN, station_controller=self._station_controller) 29 self._items_panel = ItemsPanel(parent=self, align=uiconst.TOALL, state=uiconst.UI_HIDDEN, station_controller=self._station_controller) 30 self._tabs.AddTab(label=localization.GetByLabel('UI/Station/Ships'), panel=self._ships_panel, tabClass=InventoryTab) 31 self._tabs.AddTab(label=localization.GetByLabel('UI/Station/Items'), panel=self._items_panel, tabClass=InventoryTab) 32 self._tabs.AutoSelect() 33 34 def _load(self): 35 if not self._initialized: 36 self._initialized = True 37 self._layout() 38 39 def LoadPanel(self): 40 self._load() 41 42 def OnDropData(self, dragSource, dragData): 43 self.on_drop_data(dragSource, dragData) 44 45 46 class InventoryTab(Tab): 47 __notifyevents__ = ('OnInventoryBadgingDestroyed', 'OnInventoryBadgingUpdated') 48 49 def __init__(self, **kwargs): 50 super(InventoryTab, self).__init__(**kwargs) 51 ServiceManager.Instance().RegisterNotify(self) 52 53 def _update_unseen_item_blink(self): 54 panel = self.GetPanel() 55 if panel is not None: 56 if panel.has_unseen_items(): 57 self.Blink(True) 58 else: 59 self.Blink(False) 60 61 def OnInventoryBadgingUpdated(self): 62 self._update_unseen_item_blink() 63 64 def OnInventoryBadgingDestroyed(self): 65 self._update_unseen_item_blink() 66 67 68 class InventorySubPanel(Container): 69 _container = None 70 _loaded = False 71 72 def __init__(self, station_controller, **kwargs): 73 self._controller = station_controller 74 super(InventorySubPanel, self).__init__(**kwargs) 75 76 def has_unseen_items(self): 77 inventory_id = self._get_inventory_id() 78 if inventory_id is not None: 79 neocom_service = ServiceManager.Instance().GetService('neocom') 80 return neocom_service.HasUnseenInventoryItemsInLocation(inventory_id) 81 else: 82 return False 83 84 def _get_inventory_id(self): 85 raise NotImplementedError() 86 87 def _get_inventory_container_class(self): 88 raise NotImplementedError() 89 90 def _get_inventory_controller_class(self): 91 return self._get_inventory_container_class().__invControllerClass__ 92 93 def _load(self): 94 if self._loaded: 95 return 96 self._loaded = True 97 try: 98 location_id = self._controller.GetItemID() 99 container_class = self._get_inventory_container_class() 100 self._container = container_class(parent=self, state=uiconst.UI_NORMAL, showControls=True, itemID=location_id) 101 except Exception: 102 logger.exception('Failed to load station inventory sub-panel') 103 104 def LoadPanel(self): 105 self._load() 106 107 def OnDropData(self, dragSource, dragData): 108 if self._container: 109 self._container.OnDropData(dragSource, dragData) 110 else: 111 controller_class = self._get_inventory_controller_class() 112 controller = controller_class(itemID=self._controller.GetItemID()) 113 controller.OnDropData(dragData) 114 115 def OnSelectedTabDeselected(self): 116 inventory_id = self._get_inventory_id() 117 if inventory_id is not None: 118 ServiceManager.Instance().ScatterEvent('OnStationServicesHangarDeselected', inventory_id) 119 120 121 class ShipsPanel(InventorySubPanel): 122 123 def __init__(self, station_controller, **kwargs): 124 super(ShipsPanel, self).__init__(name='StationServices_ShipContainer', station_controller=station_controller, **kwargs) 125 126 def _get_inventory_id(self): 127 if session.structureid: 128 return INVENTORY_ID_STRUCTURE_SHIPS 129 if session.stationid: 130 return INVENTORY_ID_STATION_SHIPS 131 132 def _get_inventory_container_class(self): 133 container_class = self._controller.GetShipInventoryClass() 134 return container_class 135 136 137 class ItemsPanel(InventorySubPanel): 138 139 def __init__(self, station_controller, **kwargs): 140 super(ItemsPanel, self).__init__(name='StationServices_ItemContainer', station_controller=station_controller, **kwargs) 141 142 def _get_inventory_id(self): 143 if session.structureid: 144 return INVENTORY_ID_STRUCTURE_ITEMS 145 if session.stationid: 146 return INVENTORY_ID_STATION_ITEMS 147 148 def _get_inventory_container_class(self): 149 container_class = self._controller.GetItemInventoryClass() 150 return container_class