LinkContainer.py (16786B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\planet\pinContainers\LinkContainer.py 2 import eveformat 3 from carbonui import uiconst 4 from carbonui.primitives.container import Container 5 from carbonui.primitives.frame import Frame 6 from carbonui.uianimations import animations 7 from eve.client.script.ui.control import eveScroll 8 from carbonui.button.group import ButtonGroup 9 from eve.client.script.ui.control.entries.generic import Generic 10 from eve.client.script.ui.control.entries.item import Item 11 from eve.client.script.ui.control.entries.util import GetFromClass 12 from eve.client.script.ui.control.eveLabel import Label 13 import evetypes 14 import localization 15 from eve.client.script.ui.control.gauge import Gauge 16 from eve.client.script.ui.shared.planet.pinContainers.BasePinContainer import BasePinContainer, CaptionAndSubtext 17 from eve.client.script.ui.shared.planet import planetCommon as planetCommonUI 18 import eve.common.script.util.planetCommon as planetCommon 19 20 class LinkContainer(BasePinContainer): 21 default_name = 'LinkContainer' 22 INFO_CONT_HEIGHT = 70 23 panelIDs = [planetCommonUI.PANEL_UPGRADELINK, 24 planetCommonUI.PANEL_STATS, 25 planetCommonUI.PANEL_ROUTES, 26 planetCommonUI.PANEL_DECOMMISSION] 27 28 def _GetPinName(self): 29 return evetypes.GetName(self.pin.typeID) 30 31 def GetID(self): 32 return self.pin.GetIDTuple() 33 34 def PanelUpgrade(self): 35 cont = Container(parent=self.actionCont, state=uiconst.UI_HIDDEN) 36 link = self.pin.link 37 nextLevel = link.level + 1 38 currentCpu = link.GetCpuUsage() 39 currentPower = link.GetPowerUsage() 40 nextLvlCpu = planetCommon.GetCpuUsageForLink(link.typeID, link.GetDistance(), nextLevel) 41 nextLvlPower = planetCommon.GetPowerUsageForLink(link.typeID, link.GetDistance(), nextLevel) 42 addlCpu = max(0, nextLvlCpu - currentCpu) 43 addlPower = max(0, nextLvlPower - currentPower) 44 colony = self.planetUISvc.GetCurrentPlanet().GetColony(session.charid) 45 if not colony or colony.colonyData is None: 46 raise RuntimeError('Unable to upgrade link - colony not set up') 47 colonyCpuUsage = colony.colonyData.GetColonyCpuUsage() 48 colonyCpuSupply = colony.colonyData.GetColonyCpuSupply() 49 colonyPowerUsage = colony.colonyData.GetColonyPowerUsage() 50 colonyPowerSupply = colony.colonyData.GetColonyPowerSupply() 51 if addlPower + colonyPowerUsage > colonyPowerSupply or addlCpu + colonyCpuUsage > colonyCpuSupply: 52 text = localization.GetByLabel('UI/PI/Common/LinkCannotUpgradePowerCPU', linkTypeName=evetypes.GetName(link.typeID)) 53 Label(parent=cont, text=text, align=uiconst.TOTOP) 54 self.upgradeStatsScroll = eveScroll.Scroll(parent=cont, name='upgradeStatsScroll', align=uiconst.TOALL, padTop=4) 55 self.upgradeStatsScroll.sr.id = 'planetLinkUpgradeStats' 56 scrolllist = [] 57 strCurrentCpu = localization.GetByLabel('UI/PI/Common/TeraFlopsAmount', amount=currentCpu) 58 strNextCpu = localization.GetByLabel('UI/PI/Common/TeraFlopsAmount', amount=nextLvlCpu) 59 cpuDeficit = nextLvlCpu - (colonyCpuSupply - colonyCpuUsage) 60 if cpuDeficit > 0: 61 cerberusLabel = 'UI/PI/Common/TeraFlopsAmountRed' 62 else: 63 cerberusLabel = 'UI/PI/Common/TeraFlopsAmountGreen' 64 strCpuDeficit = localization.GetByLabel(cerberusLabel, amount=max(0, cpuDeficit)) 65 strCurrentPower = localization.GetByLabel('UI/PI/Common/MegaWattsAmount', amount=currentPower) 66 strNextPower = localization.GetByLabel('UI/PI/Common/MegaWattsAmount', amount=nextLvlPower) 67 powerDeficit = nextLvlPower - (colonyPowerSupply - colonyPowerUsage) 68 if powerDeficit > 0: 69 cerberusLabel = 'UI/PI/Common/MegaWattsAmountRed' 70 else: 71 cerberusLabel = 'UI/PI/Common/MegaWattsAmountGreen' 72 strPowerDeficit = localization.GetByLabel(cerberusLabel, amount=max(0, powerDeficit)) 73 scrolllist.append(GetFromClass(Generic, {'label': '%s<t>%s<t>%s<t>%s' % (localization.GetByLabel('UI/PI/Common/CpuUsage'), 74 strCurrentCpu, 75 strNextCpu, 76 strCpuDeficit)})) 77 scrolllist.append(GetFromClass(Generic, {'label': '%s<t>%s<t>%s<t>%s' % (localization.GetByLabel('UI/PI/Common/PowerUsage'), 78 strCurrentPower, 79 strNextPower, 80 strPowerDeficit)})) 81 self.upgradeStatsScroll.Load(contentList=scrolllist, headers=['', 82 localization.GetByLabel('UI/Common/Current'), 83 localization.GetByLabel('UI/PI/Common/UpgradeNoun'), 84 localization.GetByLabel('UI/PI/Common/PowerOrCPUDeficit')]) 85 elif nextLevel > planetCommon.LINK_MAX_UPGRADE: 86 text = localization.GetByLabel('UI/PI/Common/LinkMaxUpgradeReached', linkTypeName=evetypes.GetName(link.typeID)) 87 Label(parent=cont, align=uiconst.TOTOP, text=text) 88 else: 89 text = localization.GetByLabel('UI/PI/Common/LinkUpgradePrompt', level=nextLevel) 90 self.upgradeStatsScroll = scroll = eveScroll.Scroll(parent=cont, name='UpgradeStatsScroll', align=uiconst.TOALL) 91 self.upgradeStatsScroll.sr.id = 'planetLinkUpgradeStats' 92 scroll.HideUnderLay() 93 Frame(parent=scroll, color=(1.0, 1.0, 1.0, 0.2)) 94 scrolllist = [] 95 link = self.pin.link 96 totalBandwidth = link.GetTotalBandwidth() 97 nextLvlBandwidth = link.GetBandwidthForLevel(nextLevel) 98 strCurrentBandwidth = totalBandwidth 99 strNextLvlBandwidth = nextLvlBandwidth 100 strBandwidthDelta = max(0, nextLvlBandwidth - totalBandwidth) 101 strBandwidthUsage = link.GetBandwidthUsage() 102 strCurrentCpu = localization.GetByLabel('UI/PI/Common/TeraFlopsAmount', amount=currentCpu) 103 strNextCpu = localization.GetByLabel('UI/PI/Common/TeraFlopsAmount', amount=nextLvlCpu) 104 strCpuDelta = localization.GetByLabel('UI/PI/Common/TeraFlopsAmount', amount=max(0, nextLvlCpu - currentCpu)) 105 strCpuUsage = localization.GetByLabel('UI/PI/Common/TeraFlopsAmount', amount=int(colonyCpuUsage)) 106 strCurrentPower = localization.GetByLabel('UI/PI/Common/MegaWattsAmount', amount=currentPower) 107 strNextPower = localization.GetByLabel('UI/PI/Common/MegaWattsAmount', amount=nextLvlPower) 108 strPowerDelta = localization.GetByLabel('UI/PI/Common/MegaWattsAmount', amount=max(0, nextLvlPower - currentPower)) 109 strPowerUsage = localization.GetByLabel('UI/PI/Common/MegaWattsAmount', amount=int(colonyPowerUsage)) 110 scrolllist.append(GetFromClass(Generic, {'label': '%s<t>%s<t>%s<t>%s' % (localization.GetByLabel('UI/Common/Current'), 111 localization.formatters.FormatNumeric(strCurrentBandwidth, decimalPlaces=1), 112 strCurrentCpu, 113 strCurrentPower)})) 114 scrolllist.append(GetFromClass(Generic, {'label': '%s<t>%s<t>%s<t>%s' % (localization.GetByLabel('UI/PI/Common/UpgradeNoun'), 115 localization.formatters.FormatNumeric(strNextLvlBandwidth, decimalPlaces=1), 116 strNextCpu, 117 strNextPower)})) 118 scrolllist.append(GetFromClass(Generic, {'label': '%s<t>%s<t>%s<t>%s' % (localization.GetByLabel('UI/PI/Common/ChangeNoun'), 119 localization.formatters.FormatNumeric(strBandwidthDelta, decimalPlaces=1), 120 strCpuDelta, 121 strPowerDelta)})) 122 scrolllist.append(GetFromClass(Generic, {'label': '%s<t>%s<t>%s<t>%s' % (localization.GetByLabel('UI/Common/Usage'), 123 localization.formatters.FormatNumeric(strBandwidthUsage, decimalPlaces=1), 124 strCpuUsage, 125 strPowerUsage)})) 126 scroll.Load(contentList=scrolllist, headers=['', 127 localization.GetByLabel('UI/PI/Common/Capacity'), 128 localization.GetByLabel('UI/Common/Cpu'), 129 localization.GetByLabel('UI/Common/Power')]) 130 btns = [[localization.GetByLabel('UI/PI/Common/Upgrade'), self._UpgradeSelf, (link.endpoint1.id, link.endpoint2.id, nextLevel)]] 131 Label(parent=cont, text=text, align=uiconst.TOBOTTOM, idx=0, padTop=4) 132 ButtonGroup(btns=btns, parent=cont, line=False, idx=0, padTop=16) 133 return cont 134 135 def PanelDecommissionPin(self): 136 cont = Container(parent=self.actionCont, state=uiconst.UI_HIDDEN) 137 text = localization.GetByLabel('UI/PI/Common/DecommissionLink', typeName=evetypes.GetName(self.pin.link.typeID)) 138 Label(parent=cont, text=text, align=uiconst.TOTOP) 139 btns = [[localization.GetByLabel('UI/PI/Common/Proceed'), self._DecommissionSelf, None]] 140 ButtonGroup(btns=btns, parent=cont, idx=0) 141 return cont 142 143 def LoadRouteScroll(self): 144 if not self or self.destroyed: 145 return 146 link = self.pin.link 147 scrolllist = [] 148 colony = sm.GetService('planetUI').GetCurrentPlanet().GetColony(link.endpoint1.ownerID) 149 for routeID in link.routesTransiting: 150 route = colony.GetRoute(routeID) 151 typeID = route.GetType() 152 qty = route.GetQuantity() 153 typeName = evetypes.GetName(typeID) 154 scrolllist.append(GetFromClass(Item, {'label': '<t>%s<t>%s<t>%s' % (typeName, qty, localization.GetByLabel('UI/PI/Common/CapacityAmount', amount=route.GetBandwidthUsage())), 155 'typeID': typeID, 156 'itemID': None, 157 'getIcon': True, 158 'OnMouseEnter': self.OnRouteEntryHover, 159 'OnMouseExit': self.OnRouteEntryExit, 160 'routeID': route.routeID, 161 'OnClick': self.OnRouteEntryClick})) 162 163 self.routeScroll.Load(contentList=scrolllist, noContentHint=localization.GetByLabel('UI/PI/Common/NoRoutesThroughLink'), headers=['', 164 localization.GetByLabel('UI/Common/Commodity'), 165 localization.GetByLabel('UI/Common/Quantity'), 166 localization.GetByLabel('UI/PI/Common/CapacityUsed')]) 167 168 def OnRouteEntryHover(self, entry): 169 self.planetUISvc.myPinManager.ShowRoute(entry.sr.node.routeID) 170 171 def OnRouteEntryExit(self, entry): 172 self.planetUISvc.myPinManager.StopShowingRoute(entry.sr.node.routeID) 173 174 def OnRouteEntryClick(self, *args): 175 if not self or self.destroyed: 176 return 177 selectedRoutes = self.routeScroll.GetSelected() 178 if len(selectedRoutes) < 1: 179 self.routeInfo.state = uiconst.UI_HIDDEN 180 self.UpdateWindowHeight() 181 return 182 selectedRouteData = selectedRoutes[0] 183 selectedRouteID = None 184 for routeID in self.pin.link.routesTransiting: 185 if routeID == selectedRouteData.routeID: 186 selectedRouteID = routeID 187 break 188 189 if selectedRouteID is None: 190 return 191 colony = sm.GetService('planetUI').GetCurrentPlanet().GetColony(self.pin.link.endpoint1.ownerID) 192 selectedRoute = colony.GetRoute(selectedRouteID) 193 if selectedRoute is None: 194 return 195 sourcePin = colony.GetPin(selectedRoute.GetSourcePinID()) 196 self.routeInfoSource.SetSubtext(planetCommon.GetGenericPinName(sourcePin.typeID, sourcePin.id)) 197 destPin = colony.GetPin(selectedRoute.GetDestinationPinID()) 198 self.routeInfoDest.SetSubtext(planetCommon.GetGenericPinName(destPin.typeID, destPin.id)) 199 routeTypeID = selectedRoute.GetType() 200 routeQty = selectedRoute.GetQuantity() 201 self.routeInfoType.SetSubtext(localization.GetByLabel('UI/PI/Common/ItemAmount', itemName=evetypes.GetName(routeTypeID), amount=int(routeQty))) 202 self.routeInfoBandwidth.SetSubtext(localization.GetByLabel('UI/PI/Common/CapacityAmount', amount=selectedRoute.GetBandwidthUsage())) 203 self.routeInfo.opacity = 0.0 204 self.routeInfo.state = uiconst.UI_PICKCHILDREN 205 animations.FadeIn(self.routeInfo, duration=0.125, sleep=True) 206 207 def GetCaptionForUpgradeLevel(self, level): 208 if level >= planetCommon.LINK_MAX_UPGRADE: 209 return localization.GetByLabel('UI/PI/Common/LinkUpgradeLevel10') 210 elif level == 9: 211 return localization.GetByLabel('UI/PI/Common/LinkUpgradeLevel9') 212 elif level == 8: 213 return localization.GetByLabel('UI/PI/Common/LinkUpgradeLevel8') 214 elif level == 7: 215 return localization.GetByLabel('UI/PI/Common/LinkUpgradeLevel7') 216 elif level == 6: 217 return localization.GetByLabel('UI/PI/Common/LinkUpgradeLevel6') 218 elif level == 5: 219 return localization.GetByLabel('UI/PI/Common/LinkUpgradeLevel5') 220 elif level == 4: 221 return localization.GetByLabel('UI/PI/Common/LinkUpgradeLevel4') 222 elif level == 3: 223 return localization.GetByLabel('UI/PI/Common/LinkUpgradeLevel3') 224 elif level == 2: 225 return localization.GetByLabel('UI/PI/Common/LinkUpgradeLevel2') 226 elif level == 1: 227 return localization.GetByLabel('UI/PI/Common/LinkUpgradeLevel1') 228 else: 229 return localization.GetByLabel('UI/PI/Common/LinkUpgradeLevel0') 230 231 def _DecommissionSelf(self, *args): 232 sm.GetService('audio').SendUIEvent('msg_pi_build_decommission_play') 233 self.planetUISvc.myPinManager.RemoveLink(self.pin.GetIDTuple()) 234 235 def _UpgradeSelf(self, *args): 236 self.planetUISvc.myPinManager.UpgradeLink(*args) 237 self.CloseByUser() 238 239 def _GetInfoCont(self): 240 link = self.pin.link 241 totalBandwidth = localization.GetByLabel('UI/PI/Common/CapacityAmount', amount=link.GetTotalBandwidth()) 242 bandwidthUsed = localization.GetByLabel('UI/PI/Common/CapacityAmount', amount=link.GetBandwidthUsage()) 243 self.totalBandwidth = CaptionAndSubtext(parent=self.infoContLeft, caption=localization.GetByLabel('UI/PI/Common/LinkMaxCapacity'), subtext=totalBandwidth, align=uiconst.TOTOP) 244 self.bandwidthUsed = CaptionAndSubtext(parent=self.infoContLeft, caption=localization.GetByLabel('UI/PI/Common/CapacityUsed'), subtext=bandwidthUsed, align=uiconst.TOTOP) 245 self.bandwidthGauge = Gauge(parent=self.infoContRight, value=link.GetBandwidthUsage() / link.GetTotalBandwidth(), color=planetCommonUI.PLANET_COLOR_BANDWIDTH, label=localization.GetByLabel('UI/PI/Common/CapacityUsed'), align=uiconst.TOTOP, padding=(0, 0, 10, 4)) 246 levelStr = localization.GetByLabel('UI/PI/Common/LinkUpgradeLevelAndName', upgradeLevel=eveformat.number_roman(link.level, zero_text='N/A'), upgradeLevelName=self.GetCaptionForUpgradeLevel(link.level)) 247 self.upgradeLevel = CaptionAndSubtext(parent=self.infoContRight, caption=localization.GetByLabel('UI/PI/Common/UpgradeLevel'), subtext=levelStr, align=uiconst.TOTOP) 248 249 def _UpdateInfoCont(self): 250 if not self or self.destroyed: 251 return 252 link = self.pin.link 253 totalBandwidth = localization.GetByLabel('UI/PI/Common/CapacityAmount', amount=link.GetTotalBandwidth()) 254 bandwidthUsed = localization.GetByLabel('UI/PI/Common/CapacityAmount', amount=link.GetBandwidthUsage()) 255 self.totalBandwidth.SetSubtext(totalBandwidth) 256 self.bandwidthUsed.SetSubtext(bandwidthUsed) 257 levelStr = localization.GetByLabel('UI/PI/Common/LinkUpgradeLevelAndName', upgradeLevel=eveformat.number_roman(link.level, zero_text='N/A'), upgradeLevelName=self.GetCaptionForUpgradeLevel(link.level)) 258 self.upgradeLevel.SetSubtext(levelStr) 259 self.bandwidthGauge.SetValue(link.GetBandwidthUsage() / link.GetTotalBandwidth()) 260 261 def PanelShowStats(self, *args): 262 cont = Container(parent=self.actionCont, state=uiconst.UI_HIDDEN) 263 self.statsScroll = scroll = eveScroll.Scroll(parent=cont, name='StatsScroll', align=uiconst.TOALL) 264 scrolllist = [] 265 link = self.pin.link 266 strCpuUsage = localization.GetByLabel('UI/PI/Common/TeraFlopsAmount', amount=int(link.GetCpuUsage())) 267 scrolllist.append(GetFromClass(Generic, {'label': '%s<t>%s' % (localization.GetByLabel('UI/PI/Common/CpuUsage'), strCpuUsage)})) 268 strPowerUsage = localization.GetByLabel('UI/PI/Common/MegaWattsAmount', amount=int(link.GetPowerUsage())) 269 scrolllist.append(GetFromClass(Generic, {'label': '%s<t>%s' % (localization.GetByLabel('UI/PI/Common/PowerUsage'), strPowerUsage)})) 270 scroll.Load(contentList=scrolllist, headers=[localization.GetByLabel('UI/PI/Common/Attribute'), localization.GetByLabel('UI/Common/Value')]) 271 return cont