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

fittingLayout.py (9338B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\fittingScreen\fittingLayout.py
      2 import math
      3 from carbon.common.script.util.format import FmtAmt
      4 from carbon.common.script.util.timerstuff import AutoTimer
      5 from carbonui import uiconst
      6 from carbonui.primitives.container import Container
      7 from carbonui.primitives.sprite import Sprite
      8 from carbonui.uicore import uicore
      9 from carbonui.util.color import Color
     10 from eve.client.script.ui.control.gaugeCircular import GaugeCircular
     11 from eve.client.script.ui.control.themeColored import SpriteThemeColored
     12 from eve.client.script.ui.shared.fitting.fittingUtil import GetScaleFactor, GetBaseShapeSize
     13 from eve.client.script.ui.shared.fittingScreen.fittingUtil import GetColoredText
     14 from eve.client.script.ui.station.fitting.fittingTooltipUtils import GetTooltipPathFromTooltipName
     15 from localization import GetByLabel
     16 import trinity
     17 import telemetry
     18 
     19 class FittingLayout(Container):
     20     default_name = 'fittingBase'
     21     default_width = 640
     22     default_height = 640
     23     default_align = uiconst.CENTERLEFT
     24     default_state = uiconst.UI_HIDDEN
     25 
     26     def ApplyAttributes(self, attributes):
     27         Container.ApplyAttributes(self, attributes)
     28         self.scaleFactor = GetScaleFactor()
     29         self.baseShapeSize = GetBaseShapeSize()
     30         self.width = self.baseShapeSize
     31         self.height = self.baseShapeSize
     32         overlay = Sprite(parent=self, name='overlay', align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Fitting/fittingbase_overlay.png', color=(1.0, 1.0, 1.0, 0.39))
     33         radius = int(self.baseShapeSize * 0.885 / 2)
     34         self.calibrationGaugePreview = CalibrationGaugePreview(parent=self, radius=radius, state=uiconst.UI_DISABLED)
     35         self.powerGaugePreview = PowergridGaugePreview(parent=self, radius=radius, state=uiconst.UI_DISABLED)
     36         self.cpuGaugePreview = CPUGaugePreview(parent=self, radius=radius, state=uiconst.UI_DISABLED)
     37         self.calibrationGauge = CalibrationGauge(parent=self, radius=radius)
     38         self.powerGauge = PowergridGauge(parent=self, radius=radius)
     39         self.cpuGauge = CPUGauge(parent=self, radius=radius)
     40         baseDOT = Sprite(parent=self, name='baseDOT', align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Fitting/fittingbase_dotproduct.png', spriteEffect=trinity.TR2_SFX_DOT, blendMode=trinity.TR2_SBM_ADD)
     41         self.sr.baseColor = SpriteThemeColored(parent=self, name='baseColor', align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Fitting/fittingbase_basecircle.png', colorType=uiconst.COLORTYPE_UIBASE)
     42         self.sr.baseShape = Sprite(parent=self, name='baseShape', align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/Fitting/fittingbase.png', color=(0.0, 0.0, 0.0, 0.86))
     43 
     44 
     45 class BaseFittingGauge(GaugeCircular):
     46     gaugeRange = 45
     47     default_align = uiconst.CENTER
     48     default_state = uiconst.UI_PICKCHILDREN
     49     default_colorMarker = (1.0, 1.0, 1.0, 0.0)
     50     default_colorBg = (1.0, 1.0, 1.0, 0.0)
     51     default_lineWidth = 11.0
     52     hintPath = ''
     53 
     54     @telemetry.ZONE_METHOD
     55     def ApplyAttributes(self, attributes):
     56         GaugeCircular.ApplyAttributes(self, attributes)
     57         self.currentValue = 0
     58 
     59     def SetValue(self, value, animate = True):
     60         if value > 1.0:
     61             uicore.animations.FadeTo(self, 0.25, 1.0, duration=0.5, loops=uiconst.ANIM_REPEAT)
     62         else:
     63             uicore.animations.FadeIn(self, duration=0.5)
     64         trueValue = max(0.0, value)
     65         value = min(1.0, trueValue)
     66         self.currentValue = 100 * value
     67         self.currentTrueValue = 100 * trueValue
     68         value *= self.gaugeRange / 360.0
     69         GaugeCircular.SetValue(self, value, animate)
     70 
     71 
     72 class FittingGauge(BaseFittingGauge):
     73 
     74     @telemetry.ZONE_METHOD
     75     def ApplyAttributes(self, attributes):
     76         BaseFittingGauge.ApplyAttributes(self, attributes)
     77         self.gauge.OnMouseMove = self.OnMouseMove
     78         self.bgGauge.OnMouseMove = self.OnMouseMove
     79         self.gauge.GetTooltipPosition = self.GetTooltipPosition
     80         self.bgGauge.GetTooltipPosition = self.GetTooltipPosition
     81 
     82     def OnMouseMove(self, *args):
     83         value = FmtAmt(self.currentTrueValue, showFraction=2)
     84         if self.currentTrueValue > 100:
     85             value = GetColoredText(False, value)
     86         hintText = GetByLabel(self.hintPath, state=value)
     87         self.gauge.hint = hintText
     88         self.bgGauge.hint = hintText
     89 
     90     def GetTooltipPosition(self):
     91         return (uicore.uilib.x - 5,
     92          uicore.uilib.y - 5,
     93          10,
     94          10)
     95 
     96 
     97 POWER_RANGE = 45
     98 POWER_START_ANGLE = 45
     99 POWER_COLOR = (0.40625, 0.078125, 0.03125, 0.8)
    100 
    101 class PowergridGauge(FittingGauge):
    102     gaugeRange = POWER_RANGE
    103     default_name = 'powergridGauge'
    104     default_colorStart = POWER_COLOR
    105     default_colorEnd = POWER_COLOR
    106     default_colorMarker = (1.0, 1.0, 1.0, 0.0)
    107     default_startAngle = math.radians(POWER_START_ANGLE)
    108     default_bgPortion = gaugeRange / 360.0
    109     hintPath = 'UI/Fitting/FittingWindow/PowerGridState'
    110 
    111 
    112 POWER_COLOR2 = Color(*POWER_COLOR).SetBrightness(0.6).SetAlpha(0.8).GetRGBA()
    113 
    114 class PowergridGaugePreview(FittingGauge):
    115     gaugeRange = POWER_RANGE
    116     default_name = 'powergridGaugePreview'
    117     default_colorStart = POWER_COLOR2
    118     default_colorEnd = POWER_COLOR2
    119     default_colorMarker = (1.0, 1.0, 1.0, 0.0)
    120     default_startAngle = math.radians(POWER_START_ANGLE)
    121     default_bgPortion = gaugeRange / 360.0
    122 
    123 
    124 CPU_RANGE = 45
    125 CPU_COLOR = (0.203125, 0.3828125, 0.37890625, 0.8)
    126 CPU_START_ANGLE = 135
    127 
    128 class CPUGauge(FittingGauge):
    129     gaugeRange = CPU_RANGE
    130     default_name = 'cpuGauge'
    131     default_colorStart = CPU_COLOR
    132     default_colorEnd = CPU_COLOR
    133     default_startAngle = math.radians(CPU_START_ANGLE)
    134     default_clockwise = False
    135     default_bgPortion = gaugeRange / 360.0
    136     hintPath = 'UI/Fitting/FittingWindow/CpuState'
    137 
    138 
    139 CPU_COLOR2 = Color(*CPU_COLOR).SetBrightness(0.7).SetAlpha(0.8).GetRGBA()
    140 
    141 class CPUGaugePreview(BaseFittingGauge):
    142     gaugeRange = CPU_RANGE
    143     default_name = 'cpuGaugePreview'
    144     default_colorStart = CPU_COLOR2
    145     default_colorEnd = CPU_COLOR2
    146     default_startAngle = math.radians(CPU_START_ANGLE)
    147     default_clockwise = False
    148     default_bgPortion = gaugeRange / 360.0
    149 
    150 
    151 CALIBRATION_RANGE = 30
    152 CALIBRATION_COLOR = (0.29296875, 0.328125, 0.33984375, 0.8)
    153 CALIBRATION_START_ANGLE = 318
    154 
    155 class CalibrationGauge(FittingGauge):
    156     gaugeRange = CALIBRATION_RANGE
    157     default_name = 'calibrationGauge'
    158     default_colorStart = CALIBRATION_COLOR
    159     default_colorEnd = CALIBRATION_COLOR
    160     default_startAngle = math.radians(CALIBRATION_START_ANGLE)
    161     default_clockwise = False
    162     default_bgPortion = gaugeRange / 360.0
    163     hintPath = 'UI/Fitting/FittingWindow/CalibrationState'
    164 
    165     def ApplyAttributes(self, attributes):
    166         FittingGauge.ApplyAttributes(self, attributes)
    167         self.calibrationLoad = 0.0
    168         self.calibrationOutput = 0.0
    169         self.bgGauge.LoadTooltipPanel = self.LoadTooltipPanel
    170         self.gauge.LoadTooltipPanel = self.LoadTooltipPanel
    171 
    172     def SetCalibrationNumbers(self, calibrationLoad, calibrationOutput):
    173         self.calibrationLoad = calibrationLoad
    174         self.calibrationOutput = calibrationOutput
    175 
    176     def LoadTooltipPanel(self, tooltipPanel, *args, **kwds):
    177         tooltipPanel.LoadGeneric3ColumnTemplate()
    178         tooltipPanel.cellSpacing = (10, 4)
    179         self._LoadTooltipPanel(tooltipPanel)
    180         self._tooltipUpdateTimer = AutoTimer(250, self._LoadTooltipPanel, tooltipPanel)
    181 
    182     def _LoadTooltipPanel(self, tooltipPanel):
    183         if tooltipPanel.destroyed:
    184             self._tooltipUpdateTimer = None
    185             return
    186         if not getattr(tooltipPanel, 'initialized', False):
    187             tooltipPanel.Flush()
    188             headerLabelPath, descriptionLabelPath = GetTooltipPathFromTooltipName('Calibration')
    189             tooltipPanel.LoadGeneric1ColumnTemplate()
    190             tooltipPanel.AddLabelMedium(text=GetByLabel(headerLabelPath), bold=True, colSpan=tooltipPanel.columns - 1)
    191             tooltipPanel.AddLabelMedium(text=GetByLabel(descriptionLabelPath), align=uiconst.TOPLEFT, wrapWidth=200, colSpan=tooltipPanel.columns, color=(0.6, 0.6, 0.6, 1))
    192             tooltipPanel.valueLabel = tooltipPanel.AddLabelMedium(text='', colSpan=tooltipPanel.columns, padTop=10)
    193             tooltipPanel.initialized = True
    194         calibrationLoadText = FmtAmt(self.calibrationLoad, showFraction=1)
    195         calibrationOutputText = FmtAmt(self.calibrationOutput, showFraction=1)
    196         percentage = GetByLabel('UI/Common/Percentage', percentage=self.currentTrueValue)
    197         if self.currentTrueValue > 100:
    198             percentage = GetColoredText(False, percentage)
    199         tooltipPanel.valueLabel.text = '%s / %s = %s' % (calibrationLoadText, calibrationOutputText, percentage)
    200 
    201 
    202 CALIBRATION_COLOR2 = Color(*CALIBRATION_COLOR).SetBrightness(0.5).SetAlpha(0.8).GetRGBA()
    203 
    204 class CalibrationGaugePreview(BaseFittingGauge):
    205     gaugeRange = CALIBRATION_RANGE
    206     default_name = 'calibrationGaugePreview'
    207     default_colorStart = CALIBRATION_COLOR2
    208     default_colorEnd = CALIBRATION_COLOR2
    209     default_startAngle = math.radians(CALIBRATION_START_ANGLE)
    210     default_clockwise = False
    211     default_bgPortion = gaugeRange / 360.0