capacitorContainer.py (8045B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\shipHud\capacitorContainer.py 2 import math 3 import random 4 from carbon.common.script.util.timerstuff import AutoTimer 5 from carbonui.primitives.container import Container 6 import carbonui.const as uiconst 7 from carbonui.primitives.sprite import Sprite 8 from carbonui.primitives.transform import Transform 9 from localization import GetByLabel 10 from localization.formatters.numericFormatters import FormatNumeric 11 import uthread 12 import trinity 13 import blue 14 import telemetry 15 from carbonui.uicore import uicore 16 import eve.client.script.ui.shared.pointerTool.pointerToolConst as pConst 17 COLOR_ORANGE = (0.9375, 0.3515625, 0.1953125) 18 COLOR_DARK_ORANGE = (70 / 256.0, 26 / 256.0, 13.0 / 256.0) 19 20 class CapacitorContainer(Container): 21 default_name = 'CapacitorContainer' 22 uniqueUiName = pConst.UNIQUE_NAME_CAPACITOR 23 default_state = uiconst.UI_NORMAL 24 default_align = uiconst.TOPLEFT 25 default_pickRadius = 30 26 default_width = 60 27 default_height = 60 28 29 def ApplyAttributes(self, attributes): 30 Container.ApplyAttributes(self, attributes) 31 self.powerBlink = None 32 self.lastSetCapacitor = None 33 self.controller = attributes.controller 34 self.InitCapacitor() 35 uthread.new(self.UpdateThread) 36 37 def LoadTooltipPanel(self, tooltipPanel, *args): 38 tooltipPanel.LoadGeneric3ColumnTemplate() 39 tooltipPanel.margin = (6, 4, 8, 4) 40 iconObj, labelObj, valueObj = tooltipPanel.AddIconLabelValue('ui_1_64_1', GetByLabel('Tooltips/Hud/Capacitor'), '', iconSize=40) 41 valueObj.fontsize = 16 42 valueObj.bold = True 43 valueObj.top = -2 44 setattr(tooltipPanel, 'labelCapacitor', labelObj) 45 setattr(tooltipPanel, 'valueLabelCapacitor', valueObj) 46 tooltipPanel.AddCell() 47 f = Container(align=uiconst.TOPLEFT, width=100, height=1) 48 tooltipPanel.AddCell(f, colSpan=2) 49 self._UpdateCapacitorTooltip(tooltipPanel) 50 self._capacitorTooltipUpdate = AutoTimer(10, self._UpdateCapacitorTooltip, tooltipPanel) 51 sm.ScatterEvent('OnCapacitorContainerTooltipShown') 52 53 def _UpdateCapacitorTooltip(self, tooltipPanel): 54 if tooltipPanel.destroyed: 55 self._capacitorTooltipUpdate = None 56 sm.ScatterEvent('OnCapacitorContainerTooltipClosed') 57 return 58 maxCap = self.controller.GetCapacitorCapacityMax() 59 if maxCap is not None: 60 if not self.controller.IsLoaded(): 61 self._capacitorTooltipUpdate = None 62 return 63 maxcap = self.controller.GetCapacitorCapacityMax() 64 load = self.controller.GetCapacitorCapacity() 65 portion = maxCap * max(0.0, min(1.0, maxcap and float(load / maxcap) or maxcap)) 66 if portion: 67 capString = GetByLabel('Tooltips/Hud/Capacitor') 68 capString += '<br>' 69 capString += '%s / %s' % (FormatNumeric(portion, useGrouping=True, decimalPlaces=0), FormatNumeric(maxCap, useGrouping=True, decimalPlaces=0)) 70 tooltipPanel.labelCapacitor.text = capString 71 value = portion / maxCap 72 tooltipPanel.valueLabelCapacitor.text = GetByLabel('UI/Common/Formatting/Percentage', percentage=value * 100) 73 74 @telemetry.ZONE_FUNCTION 75 def InitCapacitor(self): 76 self.initialized = 0 77 self.lastSetCapacitor = None 78 if self.powerBlink: 79 self.powerBlink.Close() 80 self.powerBlink = None 81 self.AnimateCapacitorOut(self.children[:], 0.5) 82 self.powerCells = [] 83 maxCap = self.controller.GetCapacitorCapacityMax() 84 numcol = min(18, int(maxCap / 50)) 85 rotstep = 360.0 / max(1, numcol) 86 colWidth = max(12, min(16, numcol and int(192 / numcol))) 87 newColumns = [] 88 for i in range(numcol): 89 powerColumn = Transform(parent=self, name='powerColumn', pos=(0, 90 0, 91 colWidth, 92 56), align=uiconst.CENTER, state=uiconst.UI_DISABLED, rotation=math.radians(i * -rotstep), idx=0) 93 newColumns.append(powerColumn) 94 for ci in xrange(4): 95 newcell = Sprite(parent=powerColumn, name='pmark', pos=(0, 96 ci * 5, 97 10 - ci * 2, 98 7), align=uiconst.CENTERTOP, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/classes/ShipUI/capacitorCell_2.png', color=(0, 0, 0, 0)) 99 self.powerCells.insert(0, newcell) 100 101 self.AnimateCapacitorIn(newColumns, 1.0) 102 self.initialized = 1 103 104 def AnimateCapacitorOut(self, conts, duration): 105 uthread.new(self.AnimateCapacitorOut_Thread, conts, duration) 106 107 def AnimateCapacitorOut_Thread(self, conts, duration): 108 for c in conts: 109 uicore.animations.FadeOut(c, duration=0.1, timeOffset=random.random() * duration * 0.75) 110 111 blue.synchro.Sleep(duration * 1000) 112 for cont in conts: 113 cont.Close() 114 115 def AnimateCapacitorIn(self, containers, duration): 116 for i, cont in enumerate(containers): 117 cont.opacity = 0.0 118 pos = float(i) / len(containers) 119 uicore.animations.FadeIn(cont, duration=duration, timeOffset=duration + duration * pos, curveType=uiconst.ANIM_OVERSHOT) 120 121 def UpdateThread(self): 122 while True: 123 blue.synchro.SleepWallclock(500) 124 if self.destroyed: 125 break 126 if self.controller.IsLoaded(): 127 self.Update() 128 129 @telemetry.ZONE_FUNCTION 130 def Update(self): 131 load = self.controller.GetCapacitorCapacity() 132 maxcap = self.controller.GetCapacitorCapacityMax() 133 proportion = max(0.0, min(1.0, round(maxcap and load / maxcap or maxcap, 2))) 134 if self.lastSetCapacitor == proportion: 135 return 136 sm.ScatterEvent('OnCapacitorChange', load, maxcap, proportion) 137 good = trinity.TriColor(*COLOR_ORANGE) 138 bad = trinity.TriColor(*COLOR_DARK_ORANGE) 139 bad.Scale(1.0 - proportion) 140 good.Scale(proportion) 141 maxCap = self.controller.GetCapacitorCapacityMax() 142 if maxCap is not None and self.initialized and self.powerCells: 143 totalCells = len(self.powerCells) 144 visible = max(0, min(totalCells, int(proportion * totalCells))) 145 for ci, each in enumerate(self.powerCells): 146 if ci >= visible: 147 each.SetRGBA(0.5, 0.5, 0.5, 0.5) 148 each.glowColor = (0, 0, 0, 1) 149 each.glowFactor = 0.0 150 each.glowExpand = 0.1 151 each.shadowOffset = (0, 0) 152 else: 153 each.SetRGBA(0.125, 0.125, 0.125, 1) 154 each.glowColor = (bad.r + good.r, 155 bad.g + good.g, 156 bad.b + good.b, 157 1.0) 158 each.glowFactor = 0.0 159 each.glowExpand = 0.1 160 each.shadowOffset = (0, 1) 161 162 if self.powerBlink is None: 163 self.powerBlink = Sprite(parent=self, name='powerblink', state=uiconst.UI_HIDDEN, texturePath='res:/UI/Texture/classes/ShipUI/capacitorCellGlow.png', align=uiconst.CENTERTOP, blendMode=trinity.TR2_SBM_ADDX2, color=COLOR_ORANGE) 164 r, g, b = COLOR_ORANGE 165 uicore.effect.BlinkSpriteRGB(self.powerBlink, r, g, b, 750, None) 166 if visible != 0 and visible < totalCells: 167 active = self.powerCells[visible - 1] 168 self.powerBlink.SetParent(active.parent, 0) 169 self.powerBlink.top = active.top 170 self.powerBlink.width = active.width + 3 171 self.powerBlink.height = active.height 172 self.powerBlink.state = uiconst.UI_DISABLED 173 else: 174 self.powerBlink.state = uiconst.UI_HIDDEN 175 self.lastSetCapacitor = proportion 176 177 def GetMenu(self): 178 return self.controller.GetMenu()