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

resourceConts.py (15357B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\sov\sovHub\resourceConts.py
      2 import carbonui
      3 import carbonui.text.styles
      4 from carbon.common.script.util.format import FmtAmt
      5 from carbonui import TextColor
      6 from carbonui.primitives.container import Container
      7 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      8 from carbonui.primitives.fill import Fill
      9 from carbonui.primitives.layoutGrid import LayoutGrid
     10 from carbonui.uiconst import UI_HIDDEN
     11 from eve.client.script.ui import eveColor
     12 from eve.client.script.ui.control.gauge import GaugeMultiValue
     13 from eve.client.script.ui.control.infoIcon import MoreExtraInfoInTooltip
     14 from eve.client.script.ui.shared.sov.threadedLoader import ThreadedLoader
     15 from localization import GetByLabel
     16 from sovereignty.client.quasarCallWrapper import DATA_NOT_AVAILABLE
     17 
     18 class BaseResourceCont(ContainerAutoSize):
     19     headerPath = 'UI/Sovereignty/Resource'
     20     headerHintPath = 'Tooltips/StructureUI/ResourceMax'
     21     inUseHintPath = 'Tooltips/StructureUI/ResourceInUse'
     22     availableHintPath = 'Tooltips/StructureUI/ResourceInUse'
     23     maxHintPath = 'Tooltips/StructureUI/ResourceMax'
     24     default_minHeight = 40
     25     default_align = carbonui.Align.TOTOP
     26     default_alignMode = carbonui.Align.TOTOP
     27     default_gaugeHeight = 4
     28     default_useLegend = True
     29     default_isCompact = False
     30     gaugeOverlay = None
     31 
     32     def ApplyAttributes(self, attributes):
     33         self.legendCont = None
     34         self.threadedLoader = ThreadedLoader('BaseResourceCont')
     35         super(BaseResourceCont, self).ApplyAttributes(attributes)
     36         self.useLegend = attributes.Get('useLegend', self.default_useLegend)
     37         self.isCompact = attributes.Get('isCompact', self.default_isCompact)
     38         self.controller = attributes.controller
     39         self.gaugeHeight = attributes.Get('gaugeHeight', self.default_gaugeHeight)
     40         self.ConstructUI()
     41 
     42     def ConstructUI(self):
     43         header = carbonui.text.styles.TextDetail(parent=self, text=GetByLabel(self.headerPath), color=carbonui.TextColor.SECONDARY, align=carbonui.Align.TOTOP, pickState=carbonui.PickState.ON)
     44         header.hint = GetByLabel(self.headerHintPath)
     45         valueCont = Container(name='valueCont', parent=self, align=carbonui.Align.TOTOP, height=30)
     46         self.valueGrid = LayoutGrid(name='valueGrid', parent=valueCont, columns=4, cellSpacing=10)
     47         if self.isCompact:
     48             inUseClass = carbonui.text.styles.TextBody
     49             topOffset = 0
     50         else:
     51             inUseClass = carbonui.text.styles.TextHeadline
     52             topOffset = 2
     53         self.inUseLabel = inUseClass(name='inUseLabel', parent=self.valueGrid, text='', align=carbonui.Align.BOTTOMLEFT, pickState=carbonui.PickState.ON)
     54         self.inUseLabel.hint = GetByLabel(self.inUseHintPath)
     55         carbonui.text.styles.TextBody(parent=self.valueGrid, text='/', color=carbonui.TextColor.SECONDARY, align=carbonui.Align.BOTTOMLEFT, top=topOffset)
     56         self.totalLabel = carbonui.text.styles.TextBody(name='totalLabel', parent=self.valueGrid, text='', color=carbonui.TextColor.SECONDARY, align=carbonui.Align.BOTTOMLEFT, top=topOffset, pickState=carbonui.PickState.ON)
     57         self.totalLabel.hint = GetByLabel(self.availableHintPath)
     58         self.moreInfoCont = Container(parent=valueCont, align=carbonui.Align.TORIGHT, width=16, state=UI_HIDDEN)
     59         maxCont = ContainerAutoSize(parent=valueCont, align=carbonui.Align.TORIGHT)
     60         self.moreInfoIcon = MoreExtraInfoInTooltip(parent=self.moreInfoCont, align=carbonui.Align.BOTTOMRIGHT, top=6)
     61         self.moreInfoIcon.LoadTooltipPanel = self.LoadMoreInfoTooltip
     62         self.maxLabel = carbonui.text.styles.TextBody(parent=maxCont, text='', color=carbonui.TextColor.SECONDARY, align=carbonui.Align.BOTTOMRIGHT, top=2, pickState=carbonui.PickState.ON)
     63         self.maxLabel.hint = GetByLabel(self.maxHintPath)
     64         self.overlayCont = Container(parent=self, align=carbonui.Align.TOTOP_NOPUSH, height=self.gaugeHeight)
     65         self.gauge = GaugeMultiValue(parent=self, colors=(eveColor.SMOKE_BLUE, eveColor.CRYO_BLUE, eveColor.COPPER_OXIDE_GREEN), values=(0.0, 0.0), align=carbonui.Align.TOTOP, gaugeHeight=self.gaugeHeight)
     66         if self.useLegend:
     67             self.legendCont = Legend(parent=self, legendHints=self.GetLegendHints(), controller=self.controller)
     68         self.controller.on_legend_moused_over.connect(self.OnLegendMousedOver)
     69 
     70     def LoadContAsync(self, *args):
     71         self.threadedLoader.StartLoading(self.LoadCont, self)
     72 
     73     def LoadCont(self, *args):
     74         self.SetText()
     75         self.SetTotalText()
     76         self.SetMaxText()
     77         self.SetGauge()
     78         self.SetLegend()
     79         self.UpdateMoreIcon()
     80 
     81     def SetGauge(self):
     82         pass
     83 
     84     def SetText(self):
     85         pass
     86 
     87     def SetTotalText(self):
     88         pass
     89 
     90     def SetMaxText(self):
     91         pass
     92 
     93     def SetLegend(self):
     94         pass
     95 
     96     def GetLegendHints(self):
     97         return {}
     98 
     99     def OnLegendMousedOver(self, enter, legendType, resourceCont):
    100         pass
    101 
    102     def UpdateMoreIcon(self):
    103         pass
    104 
    105     def LoadMoreInfoTooltip(self, tooltipPanel, *args):
    106         pass
    107 
    108     def Close(self):
    109         self.threadedLoader = None
    110         super(BaseResourceCont, self).Close()
    111 
    112 
    113 class PowerCont(BaseResourceCont):
    114     headerPath = 'UI/Sovereignty/Power'
    115     headerHintPath = 'Tooltips/StructureUI/SovHubPowerWidgetHeader'
    116     inUseHintPath = 'Tooltips/StructureUI/SovHubPowerAllocated'
    117     availableHintPath = 'Tooltips/StructureUI/SovHubAvailablePower'
    118     maxHintPath = 'Tooltips/StructureUI/SovHubTotalPowerPotential'
    119 
    120     def SetGauge(self):
    121         power = self.controller.GetPowerAllocated()
    122         if power == DATA_NOT_AVAILABLE:
    123             inUsePercentage = 0
    124             available = 0
    125         else:
    126             maxPower = self.controller.GetTotalMaxPower()
    127             inUsePercentage = float(power) / maxPower
    128             available = float(self.controller.GetTotalAvailablePower()) / maxPower
    129         self.gauge.SetValue(0, inUsePercentage)
    130         self.gauge.SetValue(1, available)
    131 
    132     def SetText(self):
    133         power = self.controller.GetPowerAllocatedText()
    134         self.inUseLabel.text = power
    135 
    136     def SetTotalText(self):
    137         self.totalLabel.text = self.controller.GetTotalAvailablePowerText()
    138 
    139     def SetMaxText(self):
    140         self.maxLabel.text = FmtAmt(self.controller.GetTotalMaxPower())
    141 
    142     def SetLegend(self):
    143         if self.legendCont:
    144             power = self.controller.GetPowerAllocated()
    145             if power == DATA_NOT_AVAILABLE:
    146                 self.legendCont.SetLegendValues(0, 0, 0)
    147             else:
    148                 freePower = self.controller.GetTotalAvailablePower() - power
    149                 self.legendCont.SetLegendValues(power, freePower)
    150 
    151     def GetLegendHints(self):
    152         return {'inUse': GetByLabel('Tooltips/StructureUI/SovHubPowerBarAllocated'),
    153          'total': GetByLabel('Tooltips/StructureUI/SovHubPowerBarAvailable')}
    154 
    155     def UpdateMoreIcon(self):
    156         hasPowerProduction = bool(self.controller.GetSimulatedPowerProduction())
    157         self.moreInfoCont.display = hasPowerProduction
    158 
    159     def LoadMoreInfoTooltip(self, tooltipPanel, *args):
    160         tooltipPanel.LoadStandardSpacing()
    161         tooltipPanel.columns = 2
    162         tooltipPanel.AddTextBodyLabel(text=GetByLabel('UI/Sovereignty/SovHub/HubWnd/MaxSystemPower'))
    163         tooltipPanel.AddTextBodyLabel(text=FmtAmt(self.controller.GetMaxSystemPower()), align=carbonui.Align.CENTERRIGHT)
    164         generated = self.controller.GetSimulatedPowerProduction()
    165         if generated:
    166             tooltipPanel.AddTextBodyLabel(text=GetByLabel('UI/Sovereignty/SovHub/HubWnd/GeneratedPower'))
    167             tooltipPanel.AddTextBodyLabel(text=FmtAmt(generated), align=carbonui.Align.CENTERRIGHT)
    168             tooltipPanel.AddTextDetailsLabel(text=GetByLabel('UI/Sovereignty/SovHub/HubWnd/GeneratedPowerExplanation'), maxWidth=300, colSpan=2, top=8, color=TextColor.SECONDARY)
    169 
    170 
    171 class WorkforceCont(BaseResourceCont):
    172     headerPath = 'UI/Sovereignty/Workforce'
    173     headerHintPath = 'Tooltips/StructureUI/SovHubWorkforceWidgetHeader'
    174     inUseHintPath = 'Tooltips/StructureUI/SovHubWorkforceBarAllocated'
    175     availableHintPath = 'Tooltips/StructureUI/SovHubAvailableWorkforce'
    176     maxHintPath = 'Tooltips/StructureUI/SovHubTotalWorkforcePotential'
    177 
    178     def SetGauge(self):
    179         workforce = self.controller.GetWorkforce()
    180         maxWorkforceInSystem = self.controller.GetTotalMaxWorkforce()
    181         if workforce == DATA_NOT_AVAILABLE or not maxWorkforceInSystem:
    182             inUsePercentage = 0
    183             available = 0
    184             exportedPercentage = 0
    185         else:
    186             exportedValue = self.controller.GetExportedValue()
    187             inUsePercentage = float(workforce) / maxWorkforceInSystem
    188             exportedPercentage = float(exportedValue) / maxWorkforceInSystem
    189             available = float(self.controller.GetTotalAvailableWorkforce()) / maxWorkforceInSystem
    190         self.gauge.SetValue(0, inUsePercentage)
    191         self.gauge.SetValue(1, available)
    192         self.gauge.SetValue(2, available + exportedPercentage)
    193 
    194     def SetText(self):
    195         self.inUseLabel.text = self.controller.GetWorkforceText()
    196 
    197     def SetTotalText(self):
    198         self.totalLabel.text = self.controller.GetTotalAvailableWorkforceText()
    199 
    200     def SetMaxText(self):
    201         self.maxLabel.text = FmtAmt(self.controller.GetTotalMaxWorkforce())
    202 
    203     def SetLegend(self):
    204         workforce = self.controller.GetWorkforce()
    205         if workforce != DATA_NOT_AVAILABLE:
    206             freeWorkforce = self.controller.GetTotalAvailableWorkforce() - workforce
    207             exported = self.controller.GetExportedValue()
    208             if self.legendCont:
    209                 self.legendCont.SetLegendValues(workforce, freeWorkforce, exported)
    210 
    211     def GetLegendHints(self):
    212         return {'inUse': GetByLabel('Tooltips/StructureUI/SovHubWorkforceBarAllocated'),
    213          'total': GetByLabel('Tooltips/StructureUI/SovHubWorkforceBarAvailable'),
    214          'extraInfo': GetByLabel('Tooltips/StructureUI/SovHubWorkforceBarExported')}
    215 
    216     def OnLegendMousedOver(self, enter, legendType, resourceCont):
    217         if resourceCont != self:
    218             return
    219         if legendType == 'extraInfoLabel':
    220             if enter:
    221                 availableWorkforce = self.controller.GetAvailableSystemWorkforce()
    222                 imported = self.controller.GetImportedValue()
    223                 availableWithoutImported = availableWorkforce - imported
    224                 self.ConstructGaugeOverlay()
    225                 self.gaugeOverlay.Show()
    226                 maxWorkforceInSystem = self.controller._maxWorkforce
    227                 maxWorkforceInSystem += imported
    228                 self.gaugeOverlay.left = float(availableWithoutImported) / maxWorkforceInSystem
    229                 self.gaugeOverlay.width = float(imported) / maxWorkforceInSystem
    230             elif self.gaugeOverlay:
    231                 self.gaugeOverlay.Hide()
    232 
    233     def UpdateMoreIcon(self):
    234         hasWorkforce = bool(self.controller.GetSimulatedWorkforceProduction())
    235         importedValue = self.controller.GetImportedValue()
    236         self.moreInfoCont.display = bool(hasWorkforce or importedValue)
    237 
    238     def LoadMoreInfoTooltip(self, tooltipPanel, *args):
    239         tooltipPanel.LoadStandardSpacing()
    240         tooltipPanel.columns = 2
    241         tooltipPanel.AddTextBodyLabel(text=GetByLabel('UI/Sovereignty/SovHub/HubWnd/MaxSystemWorkforce'))
    242         tooltipPanel.AddTextBodyLabel(text=FmtAmt(self.controller.GetMaxSystemWorkforce()), align=carbonui.Align.CENTERRIGHT)
    243         importedValue = self.controller.GetImportedValue()
    244         if importedValue:
    245             tooltipPanel.AddTextBodyLabel(text=GetByLabel('UI/Sovereignty/SovHub/HubWnd/ImportedWorkforce'))
    246             tooltipPanel.AddTextBodyLabel(text=FmtAmt(importedValue), align=carbonui.Align.CENTERRIGHT)
    247         generated = self.controller.GetSimulatedWorkforceProduction()
    248         if generated:
    249             tooltipPanel.AddTextBodyLabel(text=GetByLabel('UI/Sovereignty/SovHub/HubWnd/GeneratedWorkforce'))
    250             tooltipPanel.AddTextBodyLabel(text=FmtAmt(generated), align=carbonui.Align.CENTERRIGHT)
    251             tooltipPanel.AddTextDetailsLabel(text=GetByLabel('UI/Sovereignty/SovHub/HubWnd/GeneratedWorkforceExplanation'), maxWidth=300, colSpan=2, top=8, color=TextColor.SECONDARY)
    252 
    253     def ConstructGaugeOverlay(self):
    254         if self.gaugeOverlay is None or self.gaugeOverlay.destroyed:
    255             self.gaugeOverlay = Fill(parent=self.overlayCont, align=carbonui.Align.TOLEFT_PROP, idx=0, color=eveColor.COPPER_OXIDE_GREEN, outputMode=carbonui.uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=0.5)
    256 
    257 
    258 class Legend(Container):
    259     default_name = 'legendCont'
    260     default_height = 30
    261     default_top = 7
    262     default_align = carbonui.Align.TOTOP
    263 
    264     def ApplyAttributes(self, attributes):
    265         super(Legend, self).ApplyAttributes(attributes)
    266         legendHints = attributes.legendHints
    267         self.controller = attributes.controller
    268         FILL_SIZE = 8
    269         legendGrid = LayoutGrid(parent=self, columns=6, cellSpacing=10)
    270         cont = ContainerAutoSize(parent=legendGrid, align=carbonui.Align.CENTERLEFT, pickState=carbonui.PickState.ON)
    271         f = Fill(parent=cont, pos=(0,
    272          0,
    273          FILL_SIZE,
    274          FILL_SIZE), align=carbonui.Align.CENTERLEFT, color=eveColor.SMOKE_BLUE)
    275         self.inUseLegendLabel = carbonui.text.styles.TextDetail(parent=cont, text='', color=carbonui.TextColor.SECONDARY, align=carbonui.Align.CENTERLEFT, left=16)
    276         cont.hint = legendHints.get('inUse', '')
    277         cont = ContainerAutoSize(parent=legendGrid, align=carbonui.Align.CENTERLEFT, pickState=carbonui.PickState.ON, left=20)
    278         f = Fill(parent=cont, pos=(0,
    279          0,
    280          FILL_SIZE,
    281          FILL_SIZE), align=carbonui.Align.CENTERLEFT, color=eveColor.CRYO_BLUE)
    282         self.availableLegendLabel = carbonui.text.styles.TextDetail(parent=cont, text='', color=carbonui.TextColor.SECONDARY, align=carbonui.Align.CENTERLEFT, left=16)
    283         cont.hint = legendHints.get('total', '')
    284         self.extraInfoCont = ContainerAutoSize(parent=legendGrid, align=carbonui.Align.CENTERLEFT, pickState=carbonui.PickState.ON, left=20)
    285         self.extraInfoLegend = Fill(parent=self.extraInfoCont, pos=(0,
    286          0,
    287          FILL_SIZE,
    288          FILL_SIZE), align=carbonui.Align.CENTERLEFT, color=eveColor.COPPER_OXIDE_GREEN)
    289         self.extraLabel = carbonui.text.styles.TextDetail(parent=self.extraInfoCont, text='', color=carbonui.TextColor.SECONDARY, align=carbonui.Align.CENTERLEFT, left=16)
    290         self.extraInfoCont.hint = legendHints.get('extraInfo', '')
    291         self.extraInfoCont.display = False
    292         self.extraInfoCont.OnMouseEnter = lambda *args: self.controller.on_legend_moused_over(True, 'extra', self)
    293         self.extraInfoCont.OnMouseExit = lambda *args: self.controller.on_legend_moused_over(False, 'extra', self)
    294 
    295     def SetLegendValues(self, inUse, available, exported = None):
    296         self.inUseLegendLabel.text = FmtAmt(inUse)
    297         self.availableLegendLabel.text = FmtAmt(available)
    298         if exported:
    299             self.extraInfoCont.display = True
    300             self.extraLabel.text = FmtAmt(exported)
    301             self.extraInfoLegend.display = True
    302         else:
    303             self.extraLabel.text = ''
    304             self.extraInfoLegend.display = False