leftSideButtonCargo.py (4847B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\shipHud\leftSideButtons\leftSideButtonCargo.py 2 import carbonui.const as uiconst 3 from carbonui.uicore import uicore 4 from carbonui.loggers.buttonLogger import log_button_clicked 5 from carbonui.util.sortUtil import SortListOfTuples 6 from eve.client.script.environment.invControllers import GetInvCtrlFromInvID, ShipCargo, GetNameForFlag 7 from eve.client.script.ui.inflight.shipHud.leftSideButton import LeftSideButton, BTN_SIZE, ICON_SIZE 8 from menu import MenuList 9 from eve.client.script.ui.shared.inventory.invWindow import Inventory 10 from eve.common.script.sys.eveCfg import GetActiveShip 11 from inventorycommon.const import INVENTORY_ID_SHIP_CARGO 12 from inventorycommon.holdTracker import HoldTracker 13 from inventorycommon.holdTrackerSettings import CargoTrackingSettings 14 import localization 15 from math import ceil 16 import eve.client.script.ui.shared.pointerTool.pointerToolConst as pConst 17 TRACKED_HOLD_COLOR = (0.27, 0.72, 1.0, 1.0) 18 19 class LeftSideButtonCargo(LeftSideButton): 20 default_name = 'inFlightCargoBtn' 21 uniqueUiName = pConst.UNIQUE_NAME_HUD_CARGO_BTN 22 default_texturePath = 'res:/UI/Texture/icons/44_32_10.png' 23 label = 'UI/Generic/Cargo' 24 cmdName = 'OpenCargoHoldOfActiveShip' 25 _tracker = None 26 27 def ApplyAttributes(self, attributes): 28 LeftSideButton.ApplyAttributes(self, attributes) 29 self.LoadTracker() 30 31 def LoadTracker(self): 32 self.adjustForTracker() 33 self._tracker = HoldTracker(cargoButton=self, trackingSettings=CargoTrackingSettings(), getControllerFromIDFunc=GetInvCtrlFromInvID) 34 35 def adjustForTracker(self): 36 self.busy.state = uiconst.UI_DISABLED 37 self.busyContainer.state = uiconst.UI_DISABLED 38 39 def BlinkWhite(self): 40 uicore.animations.FadeIn(self.blinkBG, callback=self.OnBlinkedIn, duration=1.0) 41 42 def OnBlinkedIn(self, *args): 43 uicore.animations.FadeOut(self.blinkBG, duration=0.25) 44 45 def OnClick(self, *args): 46 LeftSideButton.OnClick(self) 47 shipID = GetActiveShip() 48 if shipID is None: 49 return 50 Inventory.OpenOrShow((INVENTORY_ID_SHIP_CARGO, shipID), usePrimary=False, toggle=True) 51 52 def SetFillRatio(self, ratio): 53 reverseRatio = min(1.0, max(0.0, 1.0 - ratio)) 54 offset = ceil(ICON_SIZE * reverseRatio) + (BTN_SIZE - ICON_SIZE) / 2 55 self.busy.top = -offset 56 self.busyContainer.top = offset 57 self.busy.opacity = max(0.4, ratio) 58 self.busy.display = True 59 60 def OnDropData(self, dragObj, nodes): 61 ShipCargo().OnDropData(nodes) 62 63 def AddMoreToTooltipPanel(self, tooltipPanel): 64 if self._tracker: 65 holds = self._tracker.GetHoldsDictionary() 66 mainHold = self._tracker.mainHoldName 67 for cargoHold, percentageFull in holds.iteritems(): 68 percentage, locationFlag = percentageFull 69 localizedname = GetNameForFlag(locationFlag) 70 label, value = tooltipPanel.AddLabelValue(label=localizedname, value=percentage) 71 if cargoHold == mainHold: 72 label.bold = True 73 label.opacity = 1.0 74 label.color = TRACKED_HOLD_COLOR 75 value.bold = True 76 value.color = TRACKED_HOLD_COLOR 77 78 def GetMenu(self): 79 if self._tracker: 80 menu = MenuList() 81 submenu = MenuList() 82 holds = self._tracker.GetHoldsDictionary() 83 mainHold = self._tracker.mainHoldName 84 for cargoHold, percentageFull in holds.iteritems(): 85 percentage, locationFlag = percentageFull 86 holdName = GetNameForFlag(locationFlag) 87 holdText = holdName 88 if mainHold == cargoHold: 89 holdText = localization.GetByLabel('UI/Inflight/Submenus/HoldOrBayTracked', holdName=holdName) 90 submenu.append((holdText.lower(), (holdText, lambda x = cargoHold: self.SelectCargoHoldWithAnalytics(x)))) 91 92 submenu = SortListOfTuples(submenu) 93 menu.append([localization.GetByLabel('UI/Inflight/Submenus/TrackHoldBay'), submenu]) 94 return menu 95 96 def SetCargoHold(self, choiceHold): 97 if self._tracker: 98 self._tracker.SetMainCargoHold(choiceHold) 99 100 def _OnClose(self, *args, **kw): 101 if self._tracker: 102 self.busy.display = False 103 self._tracker.Destroy() 104 self._tracker = None 105 uicore.animations.StopAllAnimations(self.blinkBG) 106 LeftSideButton._OnClose(self, args, kw) 107 108 def SelectCargoHoldWithAnalytics(self, hold_name): 109 self.analyticID = 'ship_hud.hold_bay.select_hold.%s' % hold_name 110 log_button_clicked(self) 111 self.SetCargoHold(hold_name)