def UpdateRubberLinkLabels(self, surfacePointA, surfacePointB):
     self.rubberLinkLabelContainer.left = uicore.uilib.x + 3
     self.rubberLinkLabelContainer.top = uicore.uilib.y + 3
     if surfacePointA == surfacePointB:
         length = 0.0
     else:
         length = surfacePointA.GetDistanceToOther(
             surfacePointB) * self.planetUISvc.planet.radius
     self.rubberLinkLabels.distance.text = util.FmtDist(length)
     powerUsage = planetCommon.GetPowerUsageForLink(
         const.typeTestPlanetaryLink, length, 0, self.linkParams)
     cpuUsage = planetCommon.GetCpuUsageForLink(const.typeTestPlanetaryLink,
                                                length, 0, self.linkParams)
     self.rubberLinkLabels.power.text = localization.GetByLabel(
         'UI/PI/Common/MegaWattsAmount', amount=powerUsage)
     self.rubberLinkLabels.cpu.text = localization.GetByLabel(
         'UI/PI/Common/TeraFlopsAmount', amount=cpuUsage)
 def PanelUpgrade(self):
     """
     Upgrade link
     """
     cont = uiprimitives.Container(parent=self.actionCont,
                                   pos=(0, 0, 0, 0),
                                   align=uiconst.TOTOP,
                                   state=uiconst.UI_HIDDEN)
     link = self.pin.link
     nextLevel = link.level + 1
     currentCpu = link.GetCpuUsage()
     currentPower = link.GetPowerUsage()
     nextLvlCpu = planetCommon.GetCpuUsageForLink(link.typeID,
                                                  link.GetDistance(),
                                                  nextLevel)
     nextLvlPower = planetCommon.GetPowerUsageForLink(
         link.typeID, link.GetDistance(), nextLevel)
     addlCpu = max(0, nextLvlCpu - currentCpu)
     addlPower = max(0, nextLvlPower - currentPower)
     colony = self.planetUISvc.GetCurrentPlanet().GetColony(session.charid)
     if not colony or colony.colonyData is None:
         raise RuntimeError('Unable to upgrade link - colony not set up')
     colonyCpuUsage = colony.colonyData.GetColonyCpuUsage()
     colonyCpuSupply = colony.colonyData.GetColonyCpuSupply()
     colonyPowerUsage = colony.colonyData.GetColonyPowerUsage()
     colonyPowerSupply = colony.colonyData.GetColonyPowerSupply()
     if addlPower + colonyPowerUsage > colonyPowerSupply or addlCpu + colonyCpuUsage > colonyCpuSupply:
         text = localization.GetByLabel(
             'UI/PI/Common/LinkCannotUpgradePowerCPU',
             linkTypeName=cfg.invtypes.Get(link.typeID).name)
         editBox = self._DrawEditBox(cont, text)
         self.upgradeStatsScroll = scroll = uicontrols.Scroll(
             parent=cont,
             name='upgradeStatsScroll',
             align=uiconst.TOTOP,
             height=58)
         self.upgradeStatsScroll.sr.id = 'planetLinkUpgradeStats'
         scroll.HideUnderLay()
         uicontrols.Frame(parent=scroll, color=(1.0, 1.0, 1.0, 0.2))
         scrolllist = []
         link = self.pin.link
         strCurrentCpu = localization.GetByLabel(
             'UI/PI/Common/TeraFlopsAmount', amount=currentCpu)
         strNextCpu = localization.GetByLabel(
             'UI/PI/Common/TeraFlopsAmount', amount=nextLvlCpu)
         cpuDeficit = nextLvlCpu - (colonyCpuSupply - colonyCpuUsage)
         if cpuDeficit > 0:
             cerberusLabel = 'UI/PI/Common/TeraFlopsAmountRed'
         else:
             cerberusLabel = 'UI/PI/Common/TeraFlopsAmountGreen'
         strCpuDeficit = localization.GetByLabel(cerberusLabel,
                                                 amount=max(0, cpuDeficit))
         strCurrentPower = localization.GetByLabel(
             'UI/PI/Common/MegaWattsAmount', amount=currentPower)
         strNextPower = localization.GetByLabel(
             'UI/PI/Common/MegaWattsAmount', amount=nextLvlPower)
         powerDeficit = nextLvlPower - (colonyPowerSupply -
                                        colonyPowerUsage)
         if powerDeficit > 0:
             cerberusLabel = 'UI/PI/Common/MegaWattsAmountRed'
         else:
             cerberusLabel = 'UI/PI/Common/MegaWattsAmountGreen'
         strPowerDeficit = localization.GetByLabel(cerberusLabel,
                                                   amount=max(
                                                       0, powerDeficit))
         data = util.KeyVal(
             label='%s<t>%s<t>%s<t>%s' %
             (localization.GetByLabel('UI/PI/Common/CpuUsage'),
              strCurrentCpu, strNextCpu, strCpuDeficit))
         scrolllist.append(listentry.Get('Generic', data=data))
         data = util.KeyVal(
             label='%s<t>%s<t>%s<t>%s' %
             (localization.GetByLabel('UI/PI/Common/PowerUsage'),
              strCurrentPower, strNextPower, strPowerDeficit))
         scrolllist.append(listentry.Get('Generic', data=data))
         scroll.Load(
             contentList=scrolllist,
             headers=[
                 '',
                 localization.GetByLabel('UI/Common/Current'),
                 localization.GetByLabel('UI/PI/Common/UpgradeNoun'),
                 localization.GetByLabel('UI/PI/Common/PowerOrCPUDeficit')
             ])
         cont.height = editBox.height + 58
     elif nextLevel > planetCommon.LINK_MAX_UPGRADE:
         text = localization.GetByLabel(
             'UI/PI/Common/LinkMaxUpgradeReached',
             linkTypeName=cfg.invtypes.Get(link.typeID).name)
         editBox = self._DrawEditBox(cont, text)
         cont.height = editBox.height
     else:
         text = localization.GetByLabel('UI/PI/Common/LinkUpgradePrompt',
                                        level=nextLevel)
         self.upgradeStatsScroll = scroll = uicontrols.Scroll(
             parent=cont,
             name='UpgradeStatsScroll',
             align=uiconst.TOTOP,
             height=96)
         self.upgradeStatsScroll.sr.id = 'planetLinkUpgradeStats'
         scroll.HideUnderLay()
         uicontrols.Frame(parent=scroll, color=(1.0, 1.0, 1.0, 0.2))
         scrolllist = []
         link = self.pin.link
         totalBandwidth = link.GetTotalBandwidth()
         nextLvlBandwidth = link.GetBandwidthForLevel(nextLevel)
         strCurrentBandwidth = totalBandwidth
         strNextLvlBandwidth = nextLvlBandwidth
         strBandwidthDelta = max(0, nextLvlBandwidth - totalBandwidth)
         strBandwidthUsage = link.GetBandwidthUsage()
         strCurrentCpu = localization.GetByLabel(
             'UI/PI/Common/TeraFlopsAmount', amount=currentCpu)
         strNextCpu = localization.GetByLabel(
             'UI/PI/Common/TeraFlopsAmount', amount=nextLvlCpu)
         strCpuDelta = localization.GetByLabel(
             'UI/PI/Common/TeraFlopsAmount',
             amount=max(0, nextLvlCpu - currentCpu))
         strCpuUsage = localization.GetByLabel(
             'UI/PI/Common/TeraFlopsAmount', amount=int(colonyCpuUsage))
         strCurrentPower = localization.GetByLabel(
             'UI/PI/Common/MegaWattsAmount', amount=currentPower)
         strNextPower = localization.GetByLabel(
             'UI/PI/Common/MegaWattsAmount', amount=nextLvlPower)
         strPowerDelta = localization.GetByLabel(
             'UI/PI/Common/MegaWattsAmount',
             amount=max(0, nextLvlPower - currentPower))
         strPowerUsage = localization.GetByLabel(
             'UI/PI/Common/MegaWattsAmount', amount=int(colonyPowerUsage))
         data = util.KeyVal(label='%s<t>%s<t>%s<t>%s' %
                            (localization.GetByLabel('UI/Common/Current'),
                             localization.formatters.FormatNumeric(
                                 strCurrentBandwidth, decimalPlaces=1),
                             strCurrentCpu, strCurrentPower))
         scrolllist.append(listentry.Get('Generic', data=data))
         data = util.KeyVal(
             label='%s<t>%s<t>%s<t>%s' %
             (localization.GetByLabel('UI/PI/Common/UpgradeNoun'),
              localization.formatters.FormatNumeric(strNextLvlBandwidth,
                                                    decimalPlaces=1),
              strNextCpu, strNextPower))
         scrolllist.append(listentry.Get('Generic', data=data))
         data = util.KeyVal(
             label='%s<t>%s<t>%s<t>%s' %
             (localization.GetByLabel('UI/PI/Common/ChangeNoun'),
              localization.formatters.FormatNumeric(strBandwidthDelta,
                                                    decimalPlaces=1),
              strCpuDelta, strPowerDelta))
         scrolllist.append(listentry.Get('Generic', data=data))
         data = util.KeyVal(label='%s<t>%s<t>%s<t>%s' %
                            (localization.GetByLabel('UI/Common/Usage'),
                             localization.formatters.FormatNumeric(
                                 strBandwidthUsage, decimalPlaces=1),
                             strCpuUsage, strPowerUsage))
         scrolllist.append(listentry.Get('Generic', data=data))
         scroll.Load(contentList=scrolllist,
                     headers=[
                         '',
                         localization.GetByLabel('UI/PI/Common/Capacity'),
                         localization.GetByLabel('UI/Common/Cpu'),
                         localization.GetByLabel('UI/Common/Power')
                     ])
         btns = [[
             localization.GetByLabel('UI/PI/Common/Upgrade'),
             self._UpgradeSelf,
             (link.endpoint1.id, link.endpoint2.id, nextLevel)
         ]]
         uicontrols.ButtonGroup(btns=btns,
                                parent=cont,
                                line=False,
                                alwaysLite=True)
         editBox = self._DrawEditBox(cont, text)
         cont.height = editBox.height + 115
     return cont
Exemple #3
0
 def GetPowerUsage(self, params=None):
     return planetCommon.GetPowerUsageForLink(self.typeID,
                                              self.GetDistance(),
                                              self.level,
                                              params=params)