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

capacitorPanel.py (7028B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\fittingScreen\fittingPanels\capacitorPanel.py
      2 import math
      3 import dogma.data as dogma_data
      4 import eveformat
      5 from carbonui import const as uiconst
      6 from carbonui.primitives.container import Container
      7 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      8 from carbonui.primitives.sprite import Sprite
      9 from carbonui.primitives.transform import Transform
     10 from carbonui.util.color import Color
     11 from dogma import const as dogmaConst
     12 from dogma.attributes.format import GetFormatAndValue
     13 from eve.client.script.ui import eveColor
     14 from eve.client.script.ui.control.eveLabel import EveLabelMedium
     15 from eve.client.script.ui.shared.fittingScreen.fittingUtil import GetColoredText
     16 from eve.client.script.ui.shared.fittingScreen.fittingPanels.basePanel import BaseMenuPanel
     17 from localization import GetByLabel
     18 import trinity
     19 BAD_COLOR = (70 / 256.0, 26 / 256.0, 13.0 / 256.0)
     20 GOOD_COLOR = (240 / 256.0, 90 / 256.0, 50.0 / 256.0)
     21 EMPTY_COLOR = (0.25, 0.25, 0.25, 0.75)
     22 
     23 class CapacitorPanel(BaseMenuPanel):
     24 
     25     def ApplyAttributes(self, attributes):
     26         BaseMenuPanel.ApplyAttributes(self, attributes)
     27         self.capCapacityAttribute = dogma_data.get_attribute(dogmaConst.attributeCapacitorCapacity)
     28         self.rechargeRateAttribute = dogma_data.get_attribute(dogmaConst.attributeRechargeRate)
     29         self.maxcap = None
     30 
     31     def LoadPanel(self, initialLoad = False):
     32         self.Flush()
     33         self.display = True
     34         self.DrawPowerCoreCont()
     35         self.AddLabels()
     36         BaseMenuPanel.FinalizePanelLoading(self, initialLoad)
     37 
     38     def DrawPowerCoreCont(self):
     39         self.powerCoreCont = Container(parent=self, name='powercore', pos=(5, 5, 30, 30), align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED)
     40 
     41     def AddLabels(self):
     42         textCont = ContainerAutoSize(parent=self, align=uiconst.CENTERLEFT, left=45, width=200, idx=0)
     43         self.capAndRechargeLabel = EveLabelMedium(text='', parent=textCont, state=uiconst.UI_NORMAL, align=uiconst.TOTOP)
     44         self.capAndRechargeLabel.hint = GetByLabel('UI/Fitting/FittingWindow/CapacityAndRechargeRate')
     45         self.delteLabel = EveLabelMedium(text='', parent=textCont, state=uiconst.UI_NORMAL, align=uiconst.TOTOP)
     46         self.delteLabel.hint = GetByLabel('UI/Fitting/FittingWindow/ExcessCapacitor')
     47 
     48     def UpdateCapacitorPanel(self):
     49         deltaInfo, deltaPercentageInfo, loadBalanceInfo, ttlInfo = self.controller.GetCapSimulatorInfos()
     50         self.SetHeaderText(ttlInfo.value, loadBalanceInfo.value)
     51         if not self.panelLoaded or self.powerCoreCont.destroyed:
     52             return
     53         self.SetRechargeText()
     54         self.SetDeltaText(deltaInfo, deltaPercentageInfo)
     55         self.RedrawPowercore()
     56         self.ColorPowerCore(self.powerUnits, loadBalanceInfo.value, ttlInfo.value)
     57 
     58     def SetHeaderText(self, TTL, loadBalance):
     59         if loadBalance > 0:
     60             sustainableText = eveformat.color(GetByLabel('UI/Fitting/FittingWindow/Stable'), color=eveColor.SUCCESS_GREEN)
     61             capHint = GetByLabel('UI/Fitting/FittingWindow/ModulesSustainable')
     62         else:
     63             sustainableText = eveformat.color(GetByLabel('UI/Fitting/FittingWindow/CapacitorNotStable', time=long(TTL)), color=eveColor.DANGER_RED)
     64             capHint = GetByLabel('UI/Fitting/FittingWindow/ModulesNotSustainable')
     65         self.SetStatusText(text=sustainableText, hintText=capHint)
     66 
     67     def SetRechargeText(self):
     68         maxCapInfo = self.controller.GetCapacitorCapacity()
     69         maxCapFormattedValue = GetFormatAndValue(self.capCapacityAttribute, int(maxCapInfo.value))
     70         maxCapText = GetColoredText(isBetter=maxCapInfo.isBetterThanBefore, text=maxCapFormattedValue)
     71         rechargeRate = self.controller.GetCapRechargeRate()
     72         rechargeFormattedValue = GetFormatAndValue(self.rechargeRateAttribute, int(rechargeRate.value))
     73         rechargeRateText = GetColoredText(isBetter=rechargeRate.isBetterThanBefore, text=rechargeFormattedValue)
     74         capText = GetByLabel('UI/Fitting/FittingWindow/CapacitorCapAndRechargeTime', capacitorCapacity=maxCapText, capacitorRechargeTime=rechargeRateText, startColorTag1='', startColorTag2='', endColorTag='')
     75         self.capAndRechargeLabel.text = capText
     76 
     77     def SetDeltaText(self, deltaInfo, deltaPercentageInfo):
     78         deltaText = GetByLabel('UI/Fitting/FittingWindow/CapacitorDelta', delta=deltaInfo.value, percentage=deltaPercentageInfo.value)
     79         deltaText = GetColoredText(isBetter=deltaInfo.isBetterThanBefore, text=deltaText)
     80         self.delteLabel.text = deltaText
     81 
     82     def RedrawPowercore(self):
     83         self.powerCoreCont.Flush()
     84         maxCapInfo = self.controller.GetCapacitorCapacity()
     85         numcol = min(10, int(maxCapInfo.value / 50))
     86         rotStep = 360.0 / max(1, numcol)
     87         colWidth = max(12, min(16, numcol and int(192 / numcol)))
     88         colHeight = self.powerCoreCont.height
     89         self.powerUnits = []
     90         for colIdx in xrange(numcol):
     91             powerColumn = self.AddPowerColumn(self.powerCoreCont, colIdx, rotStep, colWidth, colHeight)
     92             for cellIdx in xrange(3):
     93                 newCell = self.AddCell(powerColumn, cellIdx)
     94                 self.powerUnits.insert(0, newCell)
     95 
     96         self.maxcap = maxCapInfo.value
     97 
     98     def AddPowerColumn(self, parent, colIdx, rotStep, colWidth, colHeight):
     99         rotation = math.radians(colIdx * -rotStep)
    100         powerColumn = Transform(parent=parent, name='powerColumn', pos=(0,
    101          0,
    102          colWidth,
    103          colHeight), align=uiconst.CENTER, state=uiconst.UI_DISABLED, rotation=rotation, idx=0)
    104         return powerColumn
    105 
    106     def AddCell(self, parent, cellIdx):
    107         newcell = Sprite(parent=parent, name='pmark', pos=(0,
    108          cellIdx * 4,
    109          8 - cellIdx * 2,
    110          4), align=uiconst.CENTERTOP, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/ShipUI/capacitorCell.png', color=(0.94, 0.35, 0.19, 1.0), idx=0, blendMode=trinity.TR2_SBM_ADD)
    111         return newcell
    112 
    113     def ScaleColor(self, colorTuple, scale):
    114         return Color(colorTuple[0] * scale, colorTuple[1] * scale, colorTuple[2] * scale)
    115 
    116     def ColorPowerCore(self, powerUnits, loadBalance, TTL):
    117         badColor = self.ScaleColor(BAD_COLOR, 1.0 - loadBalance)
    118         goodColor = self.ScaleColor(GOOD_COLOR, loadBalance)
    119         visible = max(0, min(len(powerUnits), int(loadBalance * len(powerUnits))))
    120         for cellIdx, each in enumerate(powerUnits):
    121             if cellIdx >= visible:
    122                 each.SetRGBA(*EMPTY_COLOR)
    123             else:
    124                 r = badColor.r + goodColor.r
    125                 g = badColor.g + goodColor.g
    126                 b = badColor.b + goodColor.b
    127                 each.SetRGBA(r, g, b, 1.0)
    128 
    129         if loadBalance == 0:
    130             hint = GetByLabel('UI/Fitting/FittingWindow/CapRunsOutBy', ttl=long(TTL))
    131         else:
    132             hint = GetByLabel('UI/Fitting/FittingWindow/CapSustainableBy', balance=loadBalance * 100)
    133         self.hint = hint