offensePanel.py (9418B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\fittingScreen\fittingPanels\offensePanel.py 2 import eveui 3 import uthread 4 from carbonui import const as uiconst 5 from carbonui.primitives.sprite import Sprite 6 from dogma.attributes.format import GetFormattedAttributeAndValueAllowZero 7 from eve.client.script.ui.control.eveLabel import EveLabelMedium 8 from eve.client.script.ui.shared.fittingScreen.fittingPanels.basePanel import BaseMenuPanel 9 from eve.client.script.ui.shared.fittingScreen.fittingUtil import GetColoredText 10 from eve.client.script.ui.station.fitting.fittingTooltipUtils import SetFittingTooltipInfo, GetTooltipPathFromTooltipName 11 from fighters import GetAbilityNameID 12 from localization import GetByLabel, GetByMessageID 13 from shipfitting.fittingDogmaLocationUtil import GetAllDpsInfo 14 import eveicon 15 16 class OffensePanel(BaseMenuPanel): 17 default_iconSize = 20 18 damageStats = (('totalDps', 'res:/UI/Texture/classes/Fitting/StatsIcons/turretDPS.png', ''), ('alphaStrike', 'res:/UI/Texture/classes/Fitting/StatsIcons/alphaStrike.png', 'AlpaStrike')) 19 20 def ApplyAttributes(self, attributes): 21 BaseMenuPanel.ApplyAttributes(self, attributes) 22 23 def LoadPanel(self, initialLoad = False): 24 self.Flush() 25 self.ResetStatsDicts() 26 self.display = True 27 parentGrid = self.GetValueParentGrid() 28 for dps, texturePath, tooltipName in self.damageStats: 29 c = self.GetValueCont(self.iconSize) 30 parentGrid.AddCell(cellObject=c) 31 icon = self._AddIcon(c, texturePath) 32 label = EveLabelMedium(text='', parent=c, state=uiconst.UI_DISABLED, align=uiconst.CENTERLEFT) 33 self.statsLabelsByIdentifier[dps] = label 34 self.statsIconsByIdentifier[dps] = icon 35 self.statsContsByIdentifier[dps] = c 36 if dps == 'totalDps': 37 c.LoadTooltipPanel = self.LoadDpsTooltipPanel 38 else: 39 SetFittingTooltipInfo(targetObject=c, tooltipName=tooltipName) 40 41 BaseMenuPanel.FinalizePanelLoading(self, initialLoad) 42 43 def UpdateOffenseStats(self): 44 uthread.new(self._UpdateOffenseStats) 45 46 @eveui.skip_if_destroyed 47 def _UpdateOffenseStats(self): 48 if not self.IsCurrentShipReady(): 49 return 50 try: 51 totalDpsInfo = self.controller.GetTotalDps() 52 except KeyError: 53 self.SetStatusText('-') 54 self.SetLabel('totalDps', '-') 55 self.SetLabel('alphaStrike', '-') 56 return 57 58 totalDps = totalDpsInfo.value 59 totalDpsText = GetByLabel('UI/Fitting/FittingWindow/DpsLabel', dps=totalDps) 60 totalDpsColoredText = GetColoredText(isBetter=totalDpsInfo.isBetterThanBefore, text=totalDpsText) 61 self.SetStatusText(totalDpsColoredText) 62 if self.destroyed: 63 return 64 totalDpsWithReloadInfo = self.controller.GetTotalDpsWithReload() 65 totalDpsWithReload = totalDpsWithReloadInfo.value 66 if totalDpsWithReload and totalDpsWithReload != totalDps: 67 withReload = GetByLabel('UI/Fitting/FittingWindow/DpsLabel', dps=totalDpsWithReload) 68 withReloadColoredText = GetColoredText(isBetter=totalDpsInfo.isBetterThanBefore, text=withReload) 69 totalDpsColoredText += ' (%s)' % withReloadColoredText 70 self.SetLabel('totalDps', totalDpsColoredText) 71 alphaStrikeInfo = self.controller.GetAlphaStrike() 72 alphaText = GetFormattedAttributeAndValueAllowZero(const.attributeDamage, int(round(alphaStrikeInfo.value))).value 73 alphaStrikeColoredText = GetColoredText(isBetter=alphaStrikeInfo.isBetterThanBefore, text=alphaText) 74 self.SetLabel('alphaStrike', alphaStrikeColoredText) 75 76 def LoadDpsTooltipPanel(self, tooltipPanel, *args): 77 tooltipPanel.LoadGeneric3ColumnTemplate() 78 tooltipPanel.cellSpacing = (10, 0) 79 shipItem = self.controller.dogmaLocation.GetShip() 80 if not shipItem: 81 return 82 isStructure = shipItem.categoryID == const.categoryStructure 83 labelPaths = GetTooltipPathFromTooltipName('DamagePerSecond') 84 headerLabelPath, descriptionLabelPath = labelPaths 85 tooltipPanel.AddLabelMedium(text=GetByLabel(headerLabelPath), bold=True, colSpan=tooltipPanel.columns) 86 tooltipPanel.AddLabelMedium(text=GetByLabel(descriptionLabelPath), align=uiconst.TOPLEFT, wrapWidth=200, colSpan=tooltipPanel.columns, color=(0.6, 0.6, 0.6, 1)) 87 itemID = self.dogmaLocation.GetCurrentShipID() 88 dpsInfo = GetAllDpsInfo(itemID, self.dogmaLocation) 89 if dpsInfo.turretDps: 90 self._AddSpacer(tooltipPanel) 91 self._AddIcon(tooltipPanel, 'res:/UI/Texture/classes/Fitting/StatsIcons/turretDPS.png') 92 label = GetByLabel('UI/Fitting/FittingWindow/TurretsDps') 93 tooltipPanel.AddLabelMedium(text=label, align=uiconst.CENTERLEFT, bold=True) 94 self._AddDpsText(tooltipPanel, dpsInfo.turretDps, dpsInfo.turretDpsWithReload, dpsInfo.maxTurretDps, dpsInfo.maxTurretDpsWithReload) 95 if dpsInfo.missileDps: 96 self._AddSpacer(tooltipPanel) 97 self._AddIcon(tooltipPanel, 'res:/UI/Texture/classes/Fitting/StatsIcons/missileDPS.png') 98 label = GetByLabel('UI/Fitting/FittingWindow/MissilesDps') 99 tooltipPanel.AddLabelMedium(text=label, align=uiconst.CENTERLEFT, bold=True) 100 self._AddDpsText(tooltipPanel, dpsInfo.missileDps, dpsInfo.missileDpsWithReload) 101 if dpsInfo.dotDps: 102 self._AddSpacer(tooltipPanel) 103 self._AddIcon(tooltipPanel, eveicon.damage_over_time) 104 label = GetByLabel('UI/Fitting/FittingWindow/DotDps') 105 tooltipPanel.AddLabelMedium(text=label, align=uiconst.CENTERLEFT, bold=True) 106 self._AddDpsText(tooltipPanel, dpsInfo.dotDps, None) 107 if dpsInfo.droneDps: 108 self._AddSpacer(tooltipPanel) 109 self._AddIcon(tooltipPanel, 'res:/UI/Texture/classes/Fitting/StatsIcons/droneDPS.png') 110 label = GetByLabel('UI/Fitting/FittingWindow/DronesDps') 111 tooltipPanel.AddLabelMedium(text=label, align=uiconst.CENTERLEFT, bold=True) 112 self._AddDpsText(tooltipPanel, dpsInfo.droneDps, None) 113 if dpsInfo.fighterDps: 114 self._AddSpacer(tooltipPanel) 115 self._AddIcon(tooltipPanel, 'res:/UI/Texture/classes/Fitting/StatsIcons/droneDPS.png') 116 label = GetByLabel('UI/Fitting/FittingWindow/StandardAttack') 117 tooltipPanel.AddLabelMedium(text=label, align=uiconst.CENTERLEFT, bold=True) 118 standardDps = sum(dpsInfo.dpsByPrimaryAbilityID.values()) 119 self._AddDpsText(tooltipPanel, standardDps, None) 120 specialAbilityInfo = [] 121 for eachAbilityID, eachDps in dpsInfo.dpsBySecondaryAbilityID.iteritems(): 122 name = GetAbilityNameID(eachAbilityID) 123 if eachDps: 124 specialAbilityInfo.append((GetByMessageID(name), eachDps)) 125 126 specialAbilityInfo.sort(key=lambda x: x[0]) 127 for eachName, eachDps in specialAbilityInfo: 128 self._AddIcon(tooltipPanel, 'res:/UI/Texture/classes/Fitting/StatsIcons/droneDPS.png') 129 tooltipPanel.AddLabelMedium(text=eachName, align=uiconst.CENTERLEFT, bold=True) 130 self._AddDpsText(tooltipPanel, eachDps, None) 131 132 if dpsInfo.aoeDps: 133 self._AddSpacer(tooltipPanel) 134 if isStructure: 135 label = GetByLabel('UI/Fitting/FittingWindow/PointDefenseBatteryDps') 136 else: 137 label = GetByLabel('UI/Fitting/FittingWindow/SmartbombsDps') 138 self._AddIcon(tooltipPanel, 'res:/UI/Texture/Icons/26_64_1.png') 139 tooltipPanel.AddLabelMedium(text=label, align=uiconst.CENTERLEFT, bold=True) 140 self._AddDpsText(tooltipPanel, dpsInfo.aoeDps, None) 141 142 def _AddDpsText(self, tooltipPanel, dps, dpsWithReload, maxDps = None, maxDpsWithReload = None): 143 turretDpsText, withReload = self._GetDpsText(dps, dpsWithReload, maxDps, maxDpsWithReload) 144 tooltipPanel.AddLabelMedium(text=turretDpsText, align=uiconst.CENTERLEFT) 145 if withReload: 146 tooltipPanel.AddCell() 147 tooltipPanel.AddLabelMedium(text=GetByLabel('UI/Fitting/FittingWindow/WithReloadTimeText'), align=uiconst.CENTERLEFT, bold=True) 148 tooltipPanel.AddLabelMedium(text=withReload, align=uiconst.TOPLEFT) 149 150 def _GetDpsText(self, dps, dpsWithReload, maxDps, maxDpsWithReload): 151 if maxDps: 152 dpsLabelPath = 'UI/Fitting/FittingWindow/DpsLabelWithRange' 153 else: 154 dpsLabelPath = 'UI/Fitting/FittingWindow/DpsLabel' 155 text = GetByLabel(dpsLabelPath, dps=dps, maxDps=maxDps) 156 if dpsWithReload and dpsWithReload != dps: 157 withReload = GetByLabel(dpsLabelPath, dps=dpsWithReload, maxDps=maxDpsWithReload) 158 withReload = '(%s)' % withReload 159 else: 160 withReload = None 161 return (text, withReload) 162 163 def _AddIcon(self, tooltipPanel, texturePath): 164 icon = Sprite(texturePath=texturePath, parent=tooltipPanel, align=uiconst.CENTERLEFT, pos=(3, 165 0, 166 self.iconSize, 167 self.iconSize), state=uiconst.UI_DISABLED) 168 return icon 169 170 def _AddSpacer(self, tooltipPanel): 171 tooltipPanel.AddSpacer(width=0, height=10) 172 tooltipPanel.FillRow()