treeViewEntries.py (9550B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\inventory\treeViewEntries.py 2 from carbon.common.script.util.format import FmtAmt 3 from carbonui.primitives.containerAutoSize import ContainerAutoSize 4 from carbonui.primitives.sprite import Sprite 5 from carbonui.uianimations import animations 6 from carbonui.control.buttonIcon import ButtonIcon 7 import eveicon 8 from eve.client.script.ui import eveColor 9 from eve.client.script.ui.control.eveLabel import EveLabelSmallBold 10 from eve.client.script.ui.control.themeColored import StretchSpriteHorizontalThemeColored 11 from eve.client.script.ui.control.treeViewEntry import TreeViewEntry, TreeViewEntryWithTag 12 from eve.common.script.sys import eveCfg 13 from inventorycommon.const import INVENTORY_ID_SHIP_CARGO, INVENTORY_ID_PLEX_VAULT, MAIN_PRIVATE_INVENTORY_IDS 14 import localization 15 import logging 16 import carbonui.const as uiconst 17 import uthread 18 from plex.client.api.repository import get_repository 19 from plex.client.api.signal import on_balance_changed 20 logger = logging.getLogger(__name__) 21 COLOR_SELECTED = (0.1, 1.0, 0.1, 1.0) 22 23 def GetTreeViewEntryClassByDataType(treeData): 24 treeEntryClass = TreeViewEntryInventory 25 if not treeData: 26 return treeEntryClass 27 className = getattr(treeData, 'clsName', None) 28 if not className: 29 return treeEntryClass 30 if className == INVENTORY_ID_SHIP_CARGO: 31 treeEntryClass = TreeViewEntryInventoryCargo 32 elif className in ('ShipMaintenanceBay', 'ShipFleetHangar') and treeData.invController.itemID == eveCfg.GetActiveShip(): 33 treeEntryClass = TreeViewEntryAccessConfig 34 elif className in ('StationCorpHangar', 'POSCorpHangar', 'StationContainer', 'StructureCorpHangar'): 35 treeEntryClass = TreeViewEntryAccessRestricted 36 elif className == INVENTORY_ID_PLEX_VAULT: 37 treeEntryClass = TreeViewEntryPlexVault 38 elif className in MAIN_PRIVATE_INVENTORY_IDS: 39 treeEntryClass = TreeViewEntryWithTag 40 return treeEntryClass 41 42 43 class TreeViewEntryInventory(TreeViewEntry): 44 default_name = 'TreeViewEntryInventory' 45 46 def GetTreeViewEntryClassByTreeData(self, treeData): 47 return GetTreeViewEntryClassByDataType(treeData) 48 49 50 class TreeViewEntryInventoryCargo(TreeViewEntryWithTag): 51 default_name = 'TreeViewEntryInventoryCargo' 52 53 def GetTreeViewEntryClassByTreeData(self, treeData): 54 return GetTreeViewEntryClassByDataType(treeData) 55 56 57 class TreeViewEntryAccessConfig(TreeViewEntry): 58 default_name = 'TreeViewEntryAccessConfig' 59 60 def ApplyAttributes(self, attributes): 61 self.iconCont = None 62 TreeViewEntry.ApplyAttributes(self, attributes) 63 self.iconCont = ContainerAutoSize(parent=self.topRightCont, align=uiconst.CENTERLEFT, height=16) 64 self.fleetAccessBtn = ButtonIcon(name='fleetAccessBtn', parent=self.iconCont, align=uiconst.TOLEFT, width=14, iconSize=14, texturePath='res:/UI/Texture/classes/Inventory/fleetAccess.png', func=self.OnFleetAccessBtn, colorSelected=COLOR_SELECTED) 65 self.corpAccessBtn = ButtonIcon(name='corpAccessBtn', parent=self.iconCont, align=uiconst.TOLEFT, width=14, padLeft=1, iconSize=12, texturePath='res:/UI/Texture/classes/Inventory/corpAccess.png', func=self.OnCorpAccessBtn, colorSelected=COLOR_SELECTED) 66 self.UpdateFleetIcon() 67 self.UpdateCorpIcon() 68 69 def OnFleetAccessBtn(self, *args): 70 if self.data.clsName == 'ShipMaintenanceBay': 71 sm.GetService('shipConfig').ToggleShipMaintenanceBayFleetAccess() 72 self.PlayButtonSound(sm.GetService('shipConfig').IsShipMaintenanceBayFleetAccessAllowed()) 73 elif self.data.clsName == 'ShipFleetHangar': 74 sm.GetService('shipConfig').ToggleFleetHangarFleetAccess() 75 self.PlayButtonSound(sm.GetService('shipConfig').IsFleetHangarFleetAccessAllowed()) 76 self.UpdateFleetIcon() 77 78 def UpdateFleetIcon(self): 79 if self.data.clsName == 'ShipMaintenanceBay': 80 isAllowed = sm.GetService('shipConfig').IsShipMaintenanceBayFleetAccessAllowed() 81 elif self.data.clsName == 'ShipFleetHangar': 82 isAllowed = sm.GetService('shipConfig').IsFleetHangarFleetAccessAllowed() 83 if isAllowed: 84 hint = localization.GetByLabel('UI/Inventory/DisableAccessToFleetMembers') 85 else: 86 hint = localization.GetByLabel('UI/Inventory/EnableAccessToFleetMembers') 87 self._UpdateButton(self.fleetAccessBtn, isAllowed, hint) 88 89 def OnCorpAccessBtn(self, *args): 90 if self.data.clsName == 'ShipMaintenanceBay': 91 sm.GetService('shipConfig').ToggleShipMaintenanceBayCorpAccess() 92 self.PlayButtonSound(sm.GetService('shipConfig').IsShipMaintenanceBayCorpAccessAllowed()) 93 elif self.data.clsName == 'ShipFleetHangar': 94 sm.GetService('shipConfig').ToggleFleetHangarCorpAccess() 95 self.PlayButtonSound(sm.GetService('shipConfig').IsFleetHangarCorpAccessAllowed()) 96 self.UpdateCorpIcon() 97 98 def UpdateCorpIcon(self): 99 if self.data.clsName == 'ShipMaintenanceBay': 100 isAllowed = sm.GetService('shipConfig').IsShipMaintenanceBayCorpAccessAllowed() 101 elif self.data.clsName == 'ShipFleetHangar': 102 isAllowed = sm.GetService('shipConfig').IsFleetHangarCorpAccessAllowed() 103 if isAllowed: 104 hint = localization.GetByLabel('UI/Inventory/DisableAccessToCorpMembers') 105 else: 106 hint = localization.GetByLabel('UI/Inventory/EnableAccessToCorpMembers') 107 self._UpdateButton(self.corpAccessBtn, isAllowed, hint) 108 109 def _UpdateButton(self, button, isAllowed, hint): 110 if isAllowed: 111 button.SetSelected() 112 else: 113 button.SetDeselected() 114 button.hint = hint 115 116 def UpdateLabel(self): 117 TreeViewEntry.UpdateLabel(self) 118 if self.iconCont: 119 self.iconCont.left = self.label.left + self.label.width + 3 120 121 def PlayButtonSound(self, buttonState): 122 if buttonState: 123 sm.GetService('audio').SendUIEvent('msg_DiodeClick_play') 124 else: 125 sm.GetService('audio').SendUIEvent('msg_DiodeDeselect_play') 126 127 128 class TreeViewEntryAccessRestricted(TreeViewEntry): 129 default_name = 'TreeViewEntryAccessRestricted' 130 ICONSIZE = 16 131 COLOR_RED = (0.867, 0.0, 0.0, 1.0) 132 COLOR_YELLOW = (0.984, 0.702, 0.22, 1.0) 133 134 def ApplyAttributes(self, attributes): 135 self.iconCont = None 136 TreeViewEntry.ApplyAttributes(self, attributes) 137 canTake = self.data.CheckCanTake() 138 canQuery = self.data.CheckCanQuery() 139 if not canQuery: 140 texturePath = eveicon.block_ban 141 hint = localization.GetByLabel('UI/Inventory/DropAccessOnly') 142 color = eveColor.DANGER_RED 143 else: 144 texturePath = eveicon.triangle 145 hint = localization.GetByLabel('UI/Inventory/ViewAccessOnly') 146 color = eveColor.WARNING_ORANGE 147 if not canTake or not canQuery: 148 self.iconCont = ContainerAutoSize(parent=self.topRightCont, align=uiconst.CENTERLEFT, height=self.ICONSIZE) 149 Sprite(name='restrictedIcon', parent=self.iconCont, align=uiconst.TOLEFT, texturePath=texturePath, width=self.ICONSIZE, color=color, hint=hint) 150 151 def UpdateLabel(self): 152 TreeViewEntry.UpdateLabel(self) 153 if self.iconCont: 154 self.iconCont.left = self.topRightCont.width + self.label.left + self.label.width + 3 155 156 157 class TreeViewEntryPlexVault(TreeViewEntryWithTag): 158 159 def ApplyAttributes(self, attributes): 160 self.balanceCont = None 161 super(TreeViewEntryPlexVault, self).ApplyAttributes(attributes) 162 self.Layout() 163 uthread.new(self.UpdateBalance, animate=False) 164 on_balance_changed.connect(self._on_plex_balance_changed) 165 166 def Close(self): 167 on_balance_changed.disconnect(self._on_plex_balance_changed) 168 super(TreeViewEntryPlexVault, self).Close() 169 170 def Layout(self): 171 self.balanceCont = ContainerAutoSize(name='PlexBalanceContainer', parent=self.topRightCont, align=uiconst.CENTERLEFT, state=uiconst.UI_HIDDEN, callback=self._UpdateBalanceContPosition) 172 StretchSpriteHorizontalThemeColored(name='PlexBalanceSprite', bgParent=self.balanceCont, colorType=uiconst.COLORTYPE_UIBASE, texturePath='res:/UI/Texture/Shared/counterFrame.png', leftEdgeSize=8, rightEdgeSize=8) 173 self.balanceLabel = EveLabelSmallBold(name='PlexBalanceLabel', parent=self.balanceCont, align=uiconst.TOPLEFT, padding=(6, 2, 6, 1)) 174 175 def GetBalance(self): 176 try: 177 return get_repository().get_balance() 178 except Exception: 179 logger.warning('Failed to retrieve the PLEX balance', exc_info=True) 180 return 0 181 182 def UpdateBalance(self, balance = None, animate = True, *args, **kwargs): 183 if balance is None: 184 balance = self.GetBalance() 185 self.balanceLabel.SetText(FmtAmt(balance, fmt='sn')) 186 if balance > 0: 187 self.balanceCont.state = uiconst.UI_PICKCHILDREN 188 if animate: 189 animations.BlinkIn(self.balanceCont) 190 else: 191 self.balanceCont.Hide() 192 193 def UpdateLabel(self): 194 super(TreeViewEntryPlexVault, self).UpdateLabel() 195 self._UpdateBalanceContPosition() 196 197 def _UpdateBalanceContPosition(self, *args): 198 if self.balanceCont: 199 self.balanceCont.left = self.topRightCont.width + self.label.left + self.label.width + 4 200 201 def _on_plex_balance_changed(self, balance, amount): 202 self.UpdateBalance(balance)