assetSafetyDeliverWindow.py (9203B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\assets\assetSafetyDeliverWindow.py 2 from carbon.common.script.util.linkUtil import GetShowInfoLink 3 from carbonui import const as uiconst 4 from carbonui.control.scrollContainer import ScrollContainer 5 from carbonui.primitives.containerAutoSize import ContainerAutoSize 6 from carbonui.primitives.line import Line 7 from carbonui.uicore import uicore 8 from carbonui.util.color import Color 9 from carbonui.util.sortUtil import SortListOfTuples 10 from carbonui.control.button import Button 11 from eve.client.script.ui.control.eveLabel import EveLabelLargeBold, EveLabelMedium, EveLabelMediumBold 12 from carbonui.control.window import Window 13 import evetypes 14 from localization import GetByLabel 15 from localization.formatters import FormatTimeIntervalShortWritten 16 import uthread 17 import blue 18 from carbonui.uicore import uicore 19 from player_messaging.client.ui_message import prompt_player_fsd_dialog 20 MAX_STATIONCONT_HEIGHT = 500 21 22 class AssetSafetyDeliverWindow(Window): 23 __guid__ = 'form.AssetSafetyDeliverWindow' 24 default_width = 600 25 default_height = 100 26 default_windowID = 'AssetSafetyDeliverWindow' 27 default_clipChildren = True 28 default_isLightBackgroundConfigurable = False 29 LINE_COLOR = (1, 1, 1, 0.2) 30 BLUE_COLOR = (0.0, 0.54, 0.8, 1.0) 31 GREEN_COLOR = (0.0, 1.0, 0.0, 0.8) 32 GRAY_COLOR = Color.GRAY5 33 PADDING = 15 34 35 def ApplyAttributes(self, attributes): 36 Window.ApplyAttributes(self, attributes) 37 self.solarSystemID = attributes.solarSystemID 38 self.assetWrapID = attributes.assetWrapID 39 self.nearestNPCStationInfo = attributes.nearestNPCStationInfo 40 self.autoDeliveryTimestamp = attributes.autoDeliveryTimestamp 41 self.manualDeliveryTimestamp = attributes.manualDeliveryTimestamp 42 self.Layout() 43 uthread.new(self.ReloadContent) 44 45 def Layout(self): 46 self.MakeUnMinimizable() 47 self.HideHeader() 48 self.MakeUnResizeable() 49 self.container = ContainerAutoSize(parent=self.GetMainArea(), align=uiconst.TOTOP, alignMode=uiconst.TOTOP, state=uiconst.UI_PICKCHILDREN, padding=(self.PADDING, 50 self.PADDING, 51 self.PADDING, 52 self.PADDING), callback=self.OnContainerResized) 53 text = GetByLabel('UI/Inventory/AssetSafety/DeliverToStation') 54 header = EveLabelLargeBold(parent=self.container, align=uiconst.TOTOP, text=text) 55 self.explanationLabel = EveLabelMedium(parent=self.container, align=uiconst.TOTOP, text='', color=self.GRAY_COLOR, padding=(0, 0, 0, 15), state=uiconst.UI_NORMAL) 56 Line(parent=self.container, align=uiconst.TOTOP, color=self.LINE_COLOR) 57 self.sameSolarSystemParent = ScrollContainer(parent=self.container, align=uiconst.TOTOP) 58 self.sameSolarSystem = ContainerAutoSize(parent=self.sameSolarSystemParent, align=uiconst.TOTOP, alignMode=uiconst.TOTOP) 59 self.nearestStationLabel = EveLabelMedium(parent=self.container, align=uiconst.TOTOP, text='', color=self.GRAY_COLOR, padding=(0, 0, 0, 0)) 60 self.closeButton = Button(parent=self.container, label=GetByLabel('UI/Generic/Cancel'), func=self.Close, align=uiconst.TOTOP, fontsize=13, padding=(220, 10, 220, 0)) 61 uicore.animations.FadeTo(self.container, startVal=0.0, endVal=1.0, duration=0.5) 62 63 def SetText(self, systemStations): 64 solarSystemName = GetShowInfoLink(const.typeSolarSystem, cfg.evelocations.Get(self.solarSystemID).name, self.solarSystemID) 65 now = blue.os.GetWallclockTime() 66 timeUntilAuto = FormatTimeIntervalShortWritten(long(max(0, self.autoDeliveryTimestamp - now))) 67 nearestItemID = self.nearestNPCStationInfo['itemID'] 68 stationName = cfg.evelocations.Get(nearestItemID).name 69 nearestNPCStationText = GetShowInfoLink(self.nearestNPCStationInfo['typeID'], stationName, nearestItemID) 70 stationsInSystem = len(systemStations) 71 if self.manualDeliveryTimestamp - now < 0: 72 if stationsInSystem: 73 path = 'UI/Inventory/AssetSafety/DeliveryExplanationText' 74 else: 75 path = 'UI/Inventory/AssetSafety/DeliveryExplanationTextNoStations' 76 text = GetByLabel(path, solarSystemName=solarSystemName, npcStationName=nearestNPCStationText, timeUntil=timeUntilAuto) 77 else: 78 timeUntilManual = FormatTimeIntervalShortWritten(long(max(0, self.manualDeliveryTimestamp - now))) 79 if stationsInSystem: 80 path = 'UI/Inventory/AssetSafety/DeliveryNotAvailableNowExplanationText' 81 else: 82 path = 'UI/Inventory/AssetSafety/DeliveryNotAvailableTextNoStations' 83 text = GetByLabel(path, solarSystemName=solarSystemName, timUntilManualDelivery=timeUntilManual, npcStationName=nearestNPCStationText, timeUntilAutoDelivery=timeUntilAuto) 84 self.explanationLabel.text = text 85 86 def OnContainerResized(self): 87 self.width = self.default_width 88 self.height = self.container.height + self.PADDING * 2 89 90 def ReloadContent(self): 91 if self.destroyed: 92 return 93 self.sameSolarSystem.DisableAutoSize() 94 self.sameSolarSystem.Flush() 95 systemStations, nearestNPCStation = sm.RemoteSvc('structureAssetSafety').GetStructuresICanDeliverTo(self.solarSystemID) 96 self.SetText(systemStations) 97 if systemStations: 98 stationIDs = [ station['itemID'] for station in systemStations ] 99 cfg.evelocations.Prime(stationIDs) 100 stations = [ s for s in systemStations if evetypes.GetCategoryID(s['typeID'] == const.categoryStation) ] 101 sortedStations = GetSortedStationList(self.solarSystemID, systemStations) 102 otherStructures = GetSortedStructures(self.solarSystemID, systemStations) 103 buttonIsDisabled = self.manualDeliveryTimestamp - blue.os.GetWallclockTime() > 0 104 for each in otherStructures + sortedStations: 105 self.AddStation(each, buttonIsDisabled) 106 107 self.sameSolarSystem.EnableAutoSize() 108 self.sameSolarSystemParent.height = min(MAX_STATIONCONT_HEIGHT, self.sameSolarSystem.height) 109 110 def AddStation(self, station, buttonIsDisabled): 111 parent = self.sameSolarSystem 112 container = ContainerAutoSize(parent=parent, align=uiconst.TOTOP, alignMode=uiconst.TOTOP, state=uiconst.UI_PICKCHILDREN, bgColor=(0.2, 0.2, 0.2, 0.3)) 113 container.DisableAutoSize() 114 label = GetShowInfoLink(station['typeID'], station['name'], station['itemID']) 115 EveLabelMediumBold(parent=container, height=30, align=uiconst.TOTOP, state=uiconst.UI_NORMAL, text=label, padding=(7, 8, 140, 5)) 116 btn = Button(parent=container, label=GetByLabel('UI/Inventory/AssetSafety/DeliverBtn'), align=uiconst.CENTERRIGHT, fontsize=13, fixedwidth=140, fixedheight=25, pos=(5, 0, 0, 0), func=self.DoDeliver, args=station['itemID']) 117 if buttonIsDisabled: 118 btn.Disable() 119 Line(parent=parent, align=uiconst.TOTOP, color=self.LINE_COLOR) 120 container.EnableAutoSize() 121 122 def DoDeliver(self, *args): 123 if prompt_player_fsd_dialog('SureYouWantToMoveAssetSafetyItemsToLocation', {}, uiconst.YESNO) != uiconst.ID_YES: 124 return 125 try: 126 sm.RemoteSvc('structureAssetSafety').MoveSafetyWrapToStructure(self.assetWrapID, self.solarSystemID, destinationID=args[0]) 127 finally: 128 AssetSafetyDeliverWindow.CloseIfOpen() 129 130 sm.GetService('objectCaching').InvalidateCachedMethodCall('structureAssetSafety', 'GetStructuresICanDeliverTo') 131 sm.GetService('objectCaching').InvalidateCachedMethodCall('structureAssetSafety', 'GetItemsInSafetyForCharacter') 132 sm.GetService('objectCaching').InvalidateCachedMethodCall('structureAssetSafety', 'GetItemsInSafetyForCorp') 133 134 135 def GetSortedStationList(solarSystemID, systemStations): 136 stations = [ s for s in systemStations if evetypes.GetCategoryID(s['typeID']) == const.categoryStation ] 137 solarsystemItems = {s.itemID:s for s in sm.GetService('map').GetSolarsystemItems(solarSystemID)} 138 sortedStations = [] 139 for eachStation in stations: 140 stationInfo = solarsystemItems.get(eachStation['itemID'], None) 141 if stationInfo is None: 142 continue 143 eachStation['name'] = stationInfo.itemName 144 sortValue = (stationInfo.celestialIndex, stationInfo.orbitIndex, stationInfo.itemName.lower()) 145 sortedStations.append((sortValue, eachStation)) 146 147 sortedStations = SortListOfTuples(sortedStations) 148 return sortedStations 149 150 151 def GetSortedStructures(solarSystemID, systemStations): 152 strucutres = [ s for s in systemStations if evetypes.GetCategoryID(s['typeID']) != const.categoryStation ] 153 sortedStructures = [] 154 for eachStructure in strucutres: 155 try: 156 name = cfg.evelocations.Get(eachStructure['itemID']).locationName 157 except KeyError: 158 name = None 159 160 if not name: 161 name = '%s - %s' % (cfg.evelocations.Get(solarSystemID).name, evetypes.GetName(eachStructure['typeID'])) 162 eachStructure['name'] = name 163 sortedStructures.append((name.lower(), eachStructure)) 164 165 return strucutres