NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

CommandCenterContainer.py (17643B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\planet\pinContainers\CommandCenterContainer.py
      2 import evetypes
      3 import blue
      4 import localization
      5 from carbon.common.script.util.format import FmtTime, IntToRoman
      6 from carbonui import TextAlign, uiconst
      7 from carbonui.control.button import Button
      8 from carbonui.primitives.container import Container
      9 from carbonui.util.color import Color
     10 from carbonui.util.various_unsorted import SortListOfTuples
     11 from eve.client.script.ui.control import eveLabel, eveScroll
     12 from carbonui.button.group import ButtonGroup
     13 from eve.client.script.ui.control.clickableboxbar import ClickableBoxBar
     14 from eve.client.script.ui.control.entries.item import Item
     15 from eve.client.script.ui.control.entries.util import GetFromClass
     16 from eve.client.script.ui.control.eveLabel import EveLabelSmall
     17 from eve.client.script.ui.control.gauge import Gauge, GaugeMultiValue
     18 from eve.client.script.ui.shared.planet import planetCommon as planetCommonUI
     19 from eve.client.script.ui.shared.planet.pinContainers.BasePinContainer import CaptionAndSubtext
     20 from eve.client.script.ui.shared.planet.pinContainers.StorageFacilityContainer import StorageFacilityContainer
     21 from eve.common.lib import appConst as const
     22 from eve.common.script.util import planetCommon
     23 from eve.common.script.util.eveFormat import FmtISK
     24 from eveexceptions import UserError
     25 
     26 class CommandCenterContainer(StorageFacilityContainer):
     27     default_name = 'CommandCenterContainer'
     28     INFO_CONT_HEIGHT = 110
     29     panelIDs = [planetCommonUI.PANEL_UPGRADE, planetCommonUI.PANEL_LAUNCH] + StorageFacilityContainer.panelIDs
     30 
     31     def _GetInfoCont(self):
     32         self.storageGauge = Gauge(parent=self.infoContLeft, value=0.0, color=planetCommonUI.PLANET_COLOR_STORAGE, label=localization.GetByLabel('UI/PI/Common/Capacity'), align=uiconst.TOTOP, padding=(0, 0, 10, 4))
     33         self.launchTimeTxt = CaptionAndSubtext(parent=self.infoContLeft, caption=localization.GetByLabel('UI/PI/Common/NextLaunchTime'), align=uiconst.TOTOP)
     34         self.cooldownTimer = CaptionAndSubtext(parent=self.infoContLeft, caption=localization.GetByLabel('UI/PI/Common/NextTransferAvailable'), align=uiconst.TOTOP)
     35         self.cpuGauge = Gauge(parent=self.infoContRight, value=0.0, color=planetCommonUI.PLANET_COLOR_CPU, align=uiconst.TOTOP, padding=(0, 0, 10, 4))
     36         self.powerGauge = Gauge(parent=self.infoContRight, value=0.0, color=planetCommonUI.PLANET_COLOR_POWER, align=uiconst.TOTOP, padding=(0, 0, 10, 4))
     37         self.upgradeLevelGauge = Gauge(parent=self.infoContRight, value=self._GetUpgradeLevelGaugeValue(), color=planetCommonUI.PLANET_COLOR_CURRLEVEL, backgroundColor=Color.GetGrayRGBA(0.5, 0.5), label=localization.GetByLabel('UI/PI/Common/UpgradeLevel'), align=uiconst.TOTOP, padding=(0, 0, 10, 4))
     38         self.upgradeLevelGauge.ShowMarkers([0.167,
     39          0.333,
     40          0.5,
     41          0.667,
     42          0.833], color=Color.BLACK)
     43 
     44     def _UpdateInfoCont(self):
     45         nextLaunchTime = self.pin.GetNextLaunchTime()
     46         if nextLaunchTime is not None and nextLaunchTime > blue.os.GetWallclockTime():
     47             nextLaunchTime = FmtTime(nextLaunchTime - blue.os.GetWallclockTime())
     48         else:
     49             nextLaunchTime = localization.GetByLabel('UI/Common/Now')
     50         self.launchTimeTxt.SetSubtext(nextLaunchTime)
     51         self.storageGauge.SetValue(float(self.pin.capacityUsed) / self.pin.GetCapacity())
     52         text = localization.GetByLabel('UI/PI/Common/StorageUsed', capacityUsed=self.pin.capacityUsed, capacityMax=self.pin.GetCapacity())
     53         if not self.pin.GetCapacityRemaining():
     54             text = '<color=red>%s</color>' % text
     55         self.storageGauge.SetSubText(text)
     56         colony = sm.GetService('planetUI').GetCurrentPlanet().GetColony(self.pin.ownerID)
     57         if colony is None or colony.colonyData is None:
     58             raise RuntimeError('Unable to find colony to update info container')
     59         cpuUsage = colony.colonyData.GetColonyCpuUsage()
     60         cpuSupply = colony.colonyData.GetColonyCpuSupply()
     61         if cpuSupply > 0:
     62             percentage = min(1.0, float(cpuUsage) / cpuSupply)
     63         else:
     64             percentage = 0.0
     65         self.cpuGauge.SetValue(percentage)
     66         self.cpuGauge.SetText(localization.GetByLabel('UI/PI/Common/CPUPercentage', usedPercentage=percentage * 100))
     67         self.cpuGauge.SetSubText(localization.GetByLabel('UI/PI/Common/CPUUsed', teraFlopsUsed=int(cpuUsage), teraFlopsMax=cpuSupply))
     68         powerUsage = colony.colonyData.GetColonyPowerUsage()
     69         powerSupply = colony.colonyData.GetColonyPowerSupply()
     70         if powerSupply > 0:
     71             percentage = min(1.0, float(powerUsage) / powerSupply)
     72         else:
     73             percentage = 0.0
     74         self.powerGauge.SetValue(percentage)
     75         self.powerGauge.SetText(localization.GetByLabel('UI/PI/Common/PowerPercentage', usedPercentage=percentage * 100))
     76         self.powerGauge.SetSubText(localization.GetByLabel('UI/PI/Common/PowerUsed', megaWattsUsed=int(powerUsage), megaWattsMax=powerSupply))
     77         self.upgradeLevelGauge.SetValue(self._GetUpgradeLevelGaugeValue())
     78         if self.pin.lastRunTime is None or self.pin.lastRunTime <= blue.os.GetWallclockTime():
     79             self.cooldownTimer.SetSubtext(localization.GetByLabel('UI/Common/Now'))
     80         else:
     81             self.cooldownTimer.SetSubtext(FmtTime(self.pin.lastRunTime - blue.os.GetWallclockTime()))
     82 
     83     def _GetUpgradeLevelGaugeValue(self):
     84         currLevel = self.planetUISvc.planet.GetCommandCenterLevel(session.charid)
     85         return float(currLevel + 1) / (planetCommonUI.PLANET_COMMANDCENTERMAXLEVEL + 1)
     86 
     87     def PanelLaunch(self):
     88         self.ResetPayloadContents()
     89         cont = Container(name='panelLaunch', parent=self.actionCont, state=uiconst.UI_HIDDEN)
     90         topCont = Container(name='topCont', align=uiconst.TOTOP_PROP, height=0.5, parent=cont, padBottom=8)
     91         bottomCont = Container(name='bottomCont', align=uiconst.TOTOP_PROP, height=0.5, parent=cont, padTop=8)
     92         self.contentsScroll = eveScroll.Scroll(parent=topCont, name='contentsScroll', hasUnderlay=True)
     93         manipBtns = [[localization.GetByLabel('UI/PI/Common/Add'), self._AddCommodities, None], [localization.GetByLabel('UI/PI/Common/Remove'), self._RemCommodities, None]]
     94         self.manipBtns = ButtonGroup(btns=manipBtns, parent=topCont, idx=0, padTop=4)
     95         self.payloadScroll = eveScroll.Scroll(name='payloadScroll', parent=bottomCont, hasUnderlay=True)
     96         btns = [[localization.GetByLabel('UI/PI/Common/Launch'), self._DoLaunch, None]]
     97         self.launchBtns = ButtonGroup(btns=btns, parent=bottomCont, idx=0, padTop=4)
     98         self.launchCostText = eveLabel.EveLabelMedium(name='launchCostText', parent=bottomCont, align=uiconst.TOBOTTOM, state=uiconst.UI_DISABLED, textAlign=TextAlign.CENTER, padTop=4, idx=0)
     99         self._ReloadScrolls()
    100         return cont
    101 
    102     def _ReloadScrolls(self):
    103         scrolllist = []
    104         for typeID, amount in self.contentsCommodities.iteritems():
    105             sortBy = amount
    106             scrolllist.append((sortBy, GetFromClass(Item, {'label': '<t>%s<t>%s' % (evetypes.GetName(typeID), amount),
    107               'typeID': typeID,
    108               'itemID': None,
    109               'getIcon': True})))
    110 
    111         scrolllist = SortListOfTuples(scrolllist)
    112         self.contentsScroll.Load(contentList=scrolllist, noContentHint=localization.GetByLabel('UI/PI/Common/StorehouseIsEmpty'), headers=['', localization.GetByLabel('UI/PI/Common/Type'), localization.GetByLabel('UI/Common/Quantity')])
    113         scrolllist = []
    114         for typeID, amount in self.payloadCommodities.iteritems():
    115             sortBy = amount
    116             scrolllist.append((sortBy, GetFromClass(Item, {'label': '<t>%s<t>%s' % (evetypes.GetName(typeID), amount),
    117               'typeID': typeID,
    118               'itemID': None,
    119               'getIcon': True})))
    120 
    121         scrolllist = SortListOfTuples(scrolllist)
    122         self.payloadScroll.Load(contentList=scrolllist, noContentHint=localization.GetByLabel('UI/PI/Common/PayloadIsEmpty'), headers=['', localization.GetByLabel('UI/PI/Common/Type'), localization.GetByLabel('UI/Common/Quantity')])
    123         if self.payloadCommodities:
    124             self.launchCostText.text = localization.GetByLabel('UI/PI/Common/LaunchCost', iskAmount=FmtISK(self.pin.GetExportTax(self.payloadCommodities)))
    125             self.launchCostText.Show()
    126         else:
    127             self.launchCostText.Hide()
    128 
    129     def _DoLaunch(self, *args):
    130         if len(self.payloadCommodities) < 1:
    131             raise UserError('PleaseSelectCommoditiesToLaunch')
    132         if not self.pin.CanLaunch(self.payloadCommodities):
    133             raise UserError('CannotLaunchCommandPinNotReady')
    134         if sm.GetService('planetUI').GetCurrentPlanet().IsInEditMode():
    135             raise UserError('CannotLaunchInEditMode')
    136         if len(self.payloadCommodities) == 0:
    137             return
    138         sm.GetService('audio').SendUIEvent('msg_pi_spaceports_launch_play')
    139         try:
    140             self.planetUISvc.myPinManager.LaunchCommodities(self.pin.id, self.payloadCommodities)
    141         except UserError:
    142             self.ResetPayloadContents()
    143             self._ReloadScrolls()
    144             raise
    145         finally:
    146             self._ToggleButtons()
    147 
    148         self._CancelLaunch()
    149 
    150     def _CancelLaunch(self, *args):
    151         self.ShowPanel(planetCommonUI.PANEL_LAUNCH)
    152 
    153     def _ToggleButtons(self):
    154         if self.launchBtns.state == uiconst.UI_HIDDEN:
    155             self.launchBtns.state = uiconst.UI_PICKCHILDREN
    156         else:
    157             self.launchBtns.state = uiconst.UI_HIDDEN
    158         if self.manipBtns.state == uiconst.UI_HIDDEN:
    159             self.manipBtns.state = uiconst.UI_PICKCHILDREN
    160         else:
    161             self.manipBtns.state = uiconst.UI_HIDDEN
    162 
    163     def ResetPayloadContents(self):
    164         self.contentsCommodities = self.pin.GetContents()
    165         self.payloadCommodities = {}
    166 
    167     def _AddCommodities(self, *args):
    168         selected = self.contentsScroll.GetSelected()
    169         toMove = {}
    170         for entry in selected:
    171             toMove[entry.typeID] = self.contentsCommodities[entry.typeID]
    172 
    173         for typeID, qty in toMove.iteritems():
    174             self.contentsCommodities[typeID] -= qty
    175             if self.contentsCommodities[typeID] <= 0:
    176                 del self.contentsCommodities[typeID]
    177             if typeID not in self.payloadCommodities:
    178                 self.payloadCommodities[typeID] = 0
    179             self.payloadCommodities[typeID] += qty
    180 
    181         self._ReloadScrolls()
    182 
    183     def _RemCommodities(self, *args):
    184         selected = self.payloadScroll.GetSelected()
    185         toMove = {}
    186         for entry in selected:
    187             toMove[entry.typeID] = self.payloadCommodities[entry.typeID]
    188 
    189         for typeID, qty in toMove.iteritems():
    190             self.payloadCommodities[typeID] -= qty
    191             if self.payloadCommodities[typeID] <= 0:
    192                 del self.payloadCommodities[typeID]
    193             if typeID not in self.contentsCommodities:
    194                 self.contentsCommodities[typeID] = 0
    195             self.contentsCommodities[typeID] += qty
    196 
    197         self._ReloadScrolls()
    198 
    199     def _DrawStoredCommoditiesIcons(self):
    200         pass
    201 
    202     def PanelUpgrade(self):
    203         cont = Container(parent=self.actionCont, state=uiconst.UI_HIDDEN)
    204         self.currLevel = self.planetUISvc.planet.GetCommandCenterLevel(session.charid)
    205         self.newLevel = self.currLevel
    206         self.currPowerOutput = self.pin.GetPowerOutput()
    207         self.maxPowerOutput = float(planetCommon.GetPowerOutput(level=planetCommonUI.PLANET_COMMANDCENTERMAXLEVEL))
    208         self.currCPUOutput = self.pin.GetCpuOutput()
    209         self.maxCPUOutput = float(planetCommon.GetCPUOutput(level=planetCommonUI.PLANET_COMMANDCENTERMAXLEVEL))
    210         colorDict = {ClickableBoxBar.COLOR_BELOWMINIMUM: planetCommonUI.PLANET_COLOR_CURRLEVEL,
    211          ClickableBoxBar.COLOR_SELECTED: planetCommonUI.PLANET_COLOR_UPGRADELEVEL,
    212          ClickableBoxBar.COLOR_UNSELECTED: Color.GetGrayRGBA(0.4, alpha=0.7),
    213          ClickableBoxBar.COLOR_ABOVEMAXIMUM: (1.0, 0.0, 0.0, 0.25)}
    214         boxBarCont = Container(parent=cont, align=uiconst.TOTOP, state=uiconst.UI_PICKCHILDREN, height=33)
    215         upgradeSkill = sm.GetService('skills').GetSkill(const.typeCommandCenterUpgrade)
    216         upgradeSkillLevel = 0
    217         if upgradeSkill is not None:
    218             upgradeSkillLevel = upgradeSkill.effectiveSkillLevel
    219         boxBar = ClickableBoxBar(align=uiconst.CENTERTOP, width=280, height=16, parent=boxBarCont, numBoxes=6, boxValues=range(0, 6), boxWidth=45, boxHeight=14, readonly=False, backgroundColor=(0.0, 0.0, 0.0, 0.0), colorDict=colorDict, minimumValue=self.currLevel + 1, hintformat=None, maximumValue=upgradeSkillLevel, aboveMaxHint=localization.GetByLabel('UI/PI/Common/UpgradeFailedInsufficientSkill', skillName=evetypes.GetName(const.typeCommandCenterUpgrade)))
    220         boxBar.OnValueChanged = self.OnUpgradeBarValueChanged
    221         boxBar.OnAttemptBoxClicked = self.OnUpgradeBarBoxClicked
    222         self.upgradeText = EveLabelSmall(parent=boxBarCont, text=localization.GetByLabel('UI/PI/Common/NoUpgradeSelected'), align=uiconst.CENTERBOTTOM)
    223         if self.currLevel == planetCommonUI.PLANET_COMMANDCENTERMAXLEVEL:
    224             self.upgradeText.SetText(localization.GetByLabel('UI/PI/Common/MaximumUpgradeLevelReached'))
    225             return cont
    226         bottomCont = Container(name='bottomCont', align=uiconst.TOTOP, parent=cont, height=50, padTop=16)
    227         leftBottomCont = Container(name='leftBottomCont', align=uiconst.TOLEFT_PROP, width=0.5, parent=bottomCont)
    228         rightBottomCont = Container(name='rightBottomCont', align=uiconst.TOLEFT_PROP, width=0.5, parent=bottomCont)
    229         powerValue = float(self.currPowerOutput) / self.maxPowerOutput
    230         self.upgradePowerGauge = GaugeMultiValue(parent=leftBottomCont, value=0.0, colors=[planetCommonUI.PLANET_COLOR_POWER, planetCommonUI.PLANET_COLOR_POWERUPGRADE], values=[powerValue, 0.0], label=localization.GetByLabel('UI/PI/Common/PowerOutput'))
    231         self.upgradePowerGauge.ShowMarker(value=powerValue, color=Color.GetGrayRGBA(0.0, 0.5))
    232         self.costText = CaptionAndSubtext(parent=leftBottomCont, caption=localization.GetByLabel('UI/Common/Cost'), subtext=localization.GetByLabel('UI/PI/Common/NoCost'), top=42)
    233         cpuValue = float(self.currCPUOutput) / self.maxCPUOutput
    234         self.upgradeCPUGauge = GaugeMultiValue(parent=rightBottomCont, colors=[planetCommonUI.PLANET_COLOR_CPU, planetCommonUI.PLANET_COLOR_CPUUPGRADE], values=[cpuValue, 0.0], label=localization.GetByLabel('UI/PI/Common/CpuOutput'))
    235         self.upgradeCPUGauge.ShowMarker(value=cpuValue, color=Color.GetGrayRGBA(0.0, 0.5))
    236         btnGroup = ButtonGroup(parent=cont, align=uiconst.TOBOTTOM)
    237         self.upgradeButton = Button(parent=btnGroup, label=localization.GetByLabel('UI/PI/Common/Upgrade'), func=self._ApplyUpgrade, args=None, enabled=False)
    238         return cont
    239 
    240     def OnUpgradeBarValueChanged(self, oldValue, newValue):
    241         self.newLevel = newValue
    242         txt = localization.GetByLabel('UI/PI/Common/UpgradeFromLevelXToY', currLevel=IntToRoman(self.currLevel + 1), newLevel=IntToRoman(self.newLevel + 1))
    243         skill = sm.GetService('skills').GetSkill(const.typeCommandCenterUpgrade)
    244         commandCenterSkillLevel = 0
    245         if skill is not None:
    246             commandCenterSkillLevel = skill.effectiveSkillLevel
    247         if commandCenterSkillLevel < newValue:
    248             hint = localization.GetByLabel('UI/PI/Common/NeedSkillToUpgrade', skillLevel=IntToRoman(newValue), skillName=evetypes.GetName(const.typeCommandCenterUpgrade))
    249             txt = localization.GetByLabel('UI/PI/Common/InsufficientSkillForUpgrade')
    250             self.upgradeButton.Disable()
    251         else:
    252             hint = ''
    253             self.upgradeButton.Enable()
    254         self.upgradeText.SetText(txt)
    255         self.upgradeText.hint = hint
    256         newPowerOutput = planetCommon.GetPowerOutput(self.newLevel)
    257         self.upgradePowerGauge.SetValue(gaugeNum=1, value=newPowerOutput / self.maxPowerOutput)
    258         self.upgradePowerGauge.hint = self._GetPowerGaugeHint(newPowerOutput)
    259         self._SetPowerGaugeSubText(newPowerOutput)
    260         newCPUOutput = planetCommon.GetCPUOutput(self.newLevel)
    261         self.upgradeCPUGauge.SetValue(gaugeNum=1, value=newCPUOutput / self.maxCPUOutput)
    262         self.upgradeCPUGauge.hint = self._GetCPUGaugeHint(newCPUOutput)
    263         self._SetCPUGaugeSubText(newCPUOutput)
    264         iskCost = FmtISK(planetCommon.GetUpgradeCost(self.currLevel, self.newLevel), showFractionsAlways=0)
    265         self.costText.SetSubtext(iskCost)
    266 
    267     def _SetPowerGaugeSubText(self, newPowerOutput):
    268         diff = newPowerOutput - self.currPowerOutput
    269         subText = '+%s MW' % diff
    270         self.upgradePowerGauge.SetSubText(subText)
    271 
    272     def _GetPowerGaugeHint(self, newOutput):
    273         return localization.GetByLabel('UI/PI/Common/UpgradeHintPower', current=self.currPowerOutput, after=newOutput)
    274 
    275     def _GetCPUGaugeHint(self, newOutput):
    276         return localization.GetByLabel('UI/PI/Common/UpgradeHintCPU', current=self.currCPUOutput, after=newOutput)
    277 
    278     def _SetCPUGaugeSubText(self, newCPUOutput):
    279         diff = newCPUOutput - self.currCPUOutput
    280         subText = localization.GetByLabel('UI/PI/Common/CPUAdded', teraFlops=diff)
    281         self.upgradeCPUGauge.SetSubText(subText)
    282 
    283     def OnUpgradeBarBoxClicked(self, oldValue, newValue):
    284         return True
    285 
    286     def _ApplyUpgrade(self, *args):
    287         self.planetUISvc.planet.UpgradeCommandCenter(self.pin.id, self.newLevel)
    288         sm.GetService('audio').SendUIEvent('msg_pi_upgrade_play')
    289         self.HideCurrentPanel()