hpGauges.py (7289B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\shipHud\hpGauges.py 2 import math 3 from carbon.common.script.util.timerstuff import AutoTimer 4 from carbonui.primitives.container import Container 5 from carbonui.primitives.sprite import Sprite 6 import carbonui.const as uiconst 7 from localization import GetByLabel 8 from localization.formatters.numericFormatters import FormatNumeric 9 import trinity 10 from carbonui.uicore import uicore 11 GAUGE_HIGHLIGHT_COLOR = (0.30196078431372547, 0.5764705882352941, 0.7568627450980392) 12 GAUGE_HIGHLIGHT_TEXTURE_PATH = 'res:/UI/Texture/Classes/Animations/swoopGradient.png' 13 14 class HPGauges(Container): 15 default_name = 'HPGauges' 16 17 def ApplyAttributes(self, attributes): 18 Container.ApplyAttributes(self, attributes) 19 self.controller = attributes.controller 20 self.lastStructure = None 21 self.lastArmor = None 22 self.lastShield = None 23 self.structureGauge = ShipHudSpriteGauge(parent=self, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/ShipUI/gauge3.png', spriteEffect=trinity.TR2_SFX_MODULATE, pickRadius=54, name='structureGauge') 24 self.armorGauge = ShipHudSpriteGauge(parent=self, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/ShipUI/gauge2.png', spriteEffect=trinity.TR2_SFX_MODULATE, pickRadius=64, name='armorGauge') 25 self.shieldGauge = ShipHudSpriteGauge(parent=self, texturePath='res:/UI/Texture/classes/ShipUI/gauge1.png', spriteEffect=trinity.TR2_SFX_MODULATE, pickRadius=74, name='shieldGauge') 26 self.shieldGauge.LoadTooltipPanel = self.LoadDamageTooltip 27 28 def Update(self): 29 if self.destroyed: 30 return 31 self.shieldGauge.UpdateValue(self.controller.GetShieldHPPortion()) 32 self.armorGauge.UpdateValue(self.controller.GetArmorHPPortion()) 33 self.structureGauge.UpdateValue(self.controller.GetStructureHPPortion()) 34 35 def LoadDamageTooltip(self, tooltipPanel, *args): 36 self._LoadDamageTooltip(tooltipPanel) 37 38 def _LoadDamageTooltip(self, tooltipPanel): 39 tooltipPanel.LoadGeneric3ColumnTemplate() 40 tooltipPanel.margin = (6, 4, 8, 4) 41 for key, iconNo, labelText in (('Shield', 'res:/UI/Texture/Icons/1_64_13.png', GetByLabel('Tooltips/Hud/Shield')), ('Armor', 'res:/UI/Texture/Icons/1_64_9.png', GetByLabel('Tooltips/Hud/Armor')), ('Structure', 'res:/UI/Texture/Icons/2_64_12.png', GetByLabel('Tooltips/Hud/Structure'))): 42 iconObj, labelObj, valueObj = tooltipPanel.AddIconLabelValue(iconNo, labelText, '', iconSize=36) 43 valueObj.fontsize = 16 44 valueObj.bold = True 45 valueObj.top = -2 46 labelObj.bold = False 47 setattr(tooltipPanel, 'label' + key, labelObj) 48 setattr(tooltipPanel, 'valueLabel' + key, valueObj) 49 50 tooltipPanel.AddCell() 51 f = Container(align=uiconst.TOPLEFT, width=100, height=1) 52 tooltipPanel.AddCell(f, colSpan=2) 53 self._UpdateDamageTooltip(tooltipPanel) 54 self._damageTooltipUpdate = AutoTimer(10, self._UpdateDamageTooltip, tooltipPanel) 55 56 def _UpdateDamageTooltip(self, tooltipPanel): 57 if tooltipPanel.destroyed: 58 self._damageTooltipUpdate = None 59 return 60 if not self.controller.IsLoaded(): 61 self._damageTooltipUpdate = None 62 return 63 structure = self.controller.GetStructureHPPortion() 64 armor = self.controller.GetArmorHPPortion() 65 shield = self.controller.GetShieldHPPortion() 66 shieldString = '<b>' + GetByLabel('Tooltips/Hud/Shield') 67 shieldString += '</b><br>' 68 shieldString += '%s / %s' % (FormatNumeric(self.controller.GetShieldHP(), useGrouping=True, decimalPlaces=0), FormatNumeric(self.controller.GetShieldHPMax(), useGrouping=True, decimalPlaces=0)) 69 tooltipPanel.labelShield.text = shieldString 70 tooltipPanel.valueLabelShield.text = GetByLabel('UI/Common/Formatting/Percentage', percentage=shield * 100) 71 armorString = '<b>' + GetByLabel('Tooltips/Hud/Armor') 72 armorString += '</b><br>' 73 armorString += '%s / %s' % (FormatNumeric(self.controller.GetArmorHP(), useGrouping=True, decimalPlaces=0), FormatNumeric(self.controller.GetArmorHPMax(), useGrouping=True, decimalPlaces=0)) 74 tooltipPanel.labelArmor.text = armorString 75 tooltipPanel.valueLabelArmor.text = GetByLabel('UI/Common/Formatting/Percentage', percentage=armor * 100) 76 structureString = '<b>' + GetByLabel('Tooltips/Hud/Structure') 77 structureString += '</b><br>' 78 structureString += '%s / %s' % (FormatNumeric(self.controller.GetStructureHP(), useGrouping=True, decimalPlaces=0), FormatNumeric(self.controller.GetStructureHPMax(), useGrouping=True, decimalPlaces=0)) 79 tooltipPanel.labelStructure.text = structureString 80 tooltipPanel.valueLabelStructure.text = GetByLabel('UI/Common/Formatting/Percentage', percentage=structure * 100) 81 82 83 BLEND_MODE_NORMAL = trinity.TR2_SBM_BLEND 84 BLEND_MODE_HIGHLIGHT = trinity.TR2_SBM_ADDX2 85 86 class ShipHudSpriteGauge(Sprite): 87 default_width = 148 88 default_height = 148 89 default_textureSecondaryPath = 'res:/UI/Texture/classes/ShipUI/gaugeFill.png' 90 default_shadowOffset = (0, 1) 91 92 def ApplyAttributes(self, attributes): 93 super(ShipHudSpriteGauge, self).ApplyAttributes(attributes) 94 self.textureSecondary.useTransform = True 95 self.textureSecondary.rotation = 0.0 96 self.originalTextureSecondaryPath = self.textureSecondary.resPath 97 self.originalRGBA = self.GetRGBA() 98 self.isHighlightActive = False 99 self._lastValue = None 100 self.blendMode = BLEND_MODE_NORMAL 101 102 @property 103 def value(self): 104 return self._lastValue 105 106 @value.setter 107 def value(self, value): 108 rotation = math.pi * (1.0 - value) 109 self.textureSecondary.rotation = rotation 110 111 def UpdateValue(self, value): 112 if self._lastValue is None: 113 self.StopAnimations() 114 self.value = value 115 else: 116 self.AnimGauge(value) 117 self._lastValue = value 118 119 def AnimGauge(self, value): 120 uicore.animations.MorphScalar(self, 'value', self._lastValue, value, duration=0.5) 121 122 def ClearHighlight(self): 123 if self.destroyed: 124 return 125 self.rotationSecondary = 0 126 self.StopAnimations() 127 self.spriteEffect = trinity.TR2_SFX_MODULATE 128 self.SetSecondaryTexturePath(self.originalTextureSecondaryPath) 129 self.SetRGBA(*self.originalRGBA) 130 self.AnimGauge(self._lastValue) 131 self.rotationSecondary = 0.75 * math.pi 132 self.isHighlightActive = False 133 self.blendMode = BLEND_MODE_NORMAL 134 135 def HighlightGauge(self): 136 if self.destroyed or self.isHighlightActive: 137 return 138 self.isHighlightActive = True 139 self.SetSecondaryTexturePath(GAUGE_HIGHLIGHT_TEXTURE_PATH) 140 self.SetRGBA(*GAUGE_HIGHLIGHT_COLOR) 141 self.rotationSecondary = 0.75 * math.pi 142 self.blendMode = BLEND_MODE_HIGHLIGHT 143 uicore.animations.SpSecondaryTextureMove(self, startVal=(-1.0, 0.0), endVal=(2.0, 0.0), duration=1.0, loops=3, curveType=uiconst.ANIM_LINEAR, callback=self.ClearHighlight, sleep=False, timeOffset=0.0)