infoPanelInsurgency.py (22236B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\infoPanels\infoPanelInsurgency.py 2 import carbonui.text.styles 3 from carbonui import TextColor 4 from carbonui.uianimations import animations 5 from eve.client.script.ui.services.insurgenceDashboardSvc import WrapCallbackWithErrorHandling 6 from functools import partial 7 import eveicon 8 import gametime 9 import localization 10 import uthread2 11 from carbonui.primitives.line import Line 12 from carbonui.primitives.fill import Fill 13 from eve.client.script.ui import eveColor 14 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveLabelSmall 15 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel 16 from eve.client.script.ui.shared.infoPanels.warehouseRaidUI.scoreboard import ScoreRow 17 from eve.common.script.util.facwarCommon import IsPirateFWFaction 18 from localization import GetByLabel 19 import carbonui 20 import carbonui.const as uiconst 21 import evelink 22 from carbonui.primitives.container import Container 23 from carbonui.primitives.containerAutoSize import ContainerAutoSize 24 from carbonui.primitives.sprite import Sprite 25 from eve.client.script.ui.shared.infoPanels.InfoPanelBase import InfoPanelBase 26 from eve.client.script.ui.shared.infoPanels.const import infoPanelConst 27 from pirateinsurgency.client.dashboard.const import GetCorruptionIconForStage, GetSuppressionIconForStage 28 from pirateinsurgency.client.dashboard.widgets.gauge import SuppressionGauge, CorruptionGauge 29 from pirateinsurgency.const import CAMPAIGN_STATE_FORECASTING 30 31 class InfoPanelInsurgency(InfoPanelBase): 32 default_name = 'InfoPanelInsurgency' 33 default_iconTexturePath = eveicon.pirate_insurgencies 34 default_state = uiconst.UI_PICKCHILDREN 35 default_height = 120 36 label = 'UI/PirateInsurgencies/dashboardCaption' 37 hasSettings = False 38 panelTypeID = infoPanelConst.PANEL_INSURGENCY 39 __notifyevents__ = InfoPanelBase.__notifyevents__ + ['OnCorruptionValueChanged_Local', 'OnSuppressionValueChanged_Local'] 40 ICE_HEIST_PIRATE_WIN_MESSAGE_ID = 706338 41 ICE_HEIST_EMPIRE_WIN_MESSAGE_ID = 706334 42 43 def ApplyAttributes(self, attributes): 44 self.dashboardSvc = sm.GetService('insurgencyDashboardSvc') 45 self.towGameSvc = sm.GetService('towGameSvc') 46 self.corruptionStages = None 47 self.suppressionsStages = None 48 self.snapshot = None 49 self.scoreRowsCont = None 50 self.currentNumerator = None 51 self.currentDenominator = None 52 self.currentVanguardNumerator = None 53 self.currentVanguardDenominator = None 54 InfoPanelBase.ApplyAttributes(self, attributes) 55 snapshot = None 56 for snapshot in self.dashboardSvc.GetCurrentCampaignSnapshots(): 57 if session.solarsystemid2 in snapshot.coveredSolarsystemIDs: 58 snapshot = snapshot 59 break 60 61 self.snapshot = snapshot 62 if self.snapshot is not None: 63 if self.snapshot.fsmState == CAMPAIGN_STATE_FORECASTING: 64 self.PredictionState(self.snapshot) 65 else: 66 self.ActiveInsurgencyState() 67 self.empireHeistScoreRow = None 68 self.pirateHeistScoreRow = None 69 self.scoreboardCont = ContainerAutoSize(name='scoreboardCont', parent=self.mainCont, align=uiconst.TOTOP) 70 self.currentTowGameSnapshot = self.towGameSvc.GetCurrentTowGame() 71 if self.currentTowGameSnapshot is not None: 72 self.OnTowGameAdded(self.currentTowGameSnapshot) 73 self.towGameSvc.SIGNAL_OnTowGameAdded.connect(self.OnTowGameAdded) 74 self.towGameSvc.SIGNAL_OnTowGameRemoved.connect(self.OnTowGameRemoved) 75 self.towGameSvc.SIGNAL_OnTowGameUpdated.connect(self.OnTowGameScoreUpdated) 76 77 def Close(self): 78 super(InfoPanelInsurgency, self).Close() 79 self.towGameSvc.SIGNAL_OnTowGameAdded.disconnect(self.OnTowGameAdded) 80 self.towGameSvc.SIGNAL_OnTowGameRemoved.disconnect(self.OnTowGameRemoved) 81 self.towGameSvc.SIGNAL_OnTowGameUpdated.disconnect(self.OnTowGameScoreUpdated) 82 83 def PredictionState(self, snapshot): 84 self.headerTextCont = ContainerAutoSize(name='headerTextCont', parent=self.headerCont, align=uiconst.CENTERLEFT, height=23, alignMode=uiconst.TOLEFT) 85 link = evelink.local_service_link(method='OpenInsurgencyDashboard', text=GetByLabel('UI/PirateInsurgencies/dashboardCaption')) 86 self.title = self.headerCls(name='title', text=link, parent=self.headerTextCont, align=uiconst.TOLEFT, state=uiconst.UI_NORMAL) 87 cont = Container(parent=self.mainCont, align=uiconst.TOTOP, height=100, width=50, state=uiconst.UI_NORMAL, hint=GetByLabel('UI/PirateInsurgencies/forecastingTooltip')) 88 carbonui.text.styles.TextDetail(parent=cont, align=uiconst.TOTOP, text=GetByLabel('UI/PirateInsurgencies/nextInsurgencyIn'), top=5) 89 timerCont = ContainerAutoSize(parent=cont, align=uiconst.TOTOP, alignMode=uiconst.TOTOP) 90 timeString = localization.formatters.FormatTimeIntervalShort(max(0, snapshot.stateExpiryTimestamp - gametime.GetWallclockTime()), showFrom='hour', showTo='second') 91 time = carbonui.text.styles.TextHeadline(parent=timerCont, align=uiconst.TOTOP, text=timeString) 92 93 def update_loop(): 94 while not self.destroyed: 95 timeString = localization.formatters.FormatTimeIntervalShort(max(0, snapshot.stateExpiryTimestamp - gametime.GetWallclockTime()), showFrom='hour', showTo='second') 96 time.SetText(timeString) 97 uthread2.Sleep(1) 98 99 uthread2.StartTasklet(update_loop) 100 101 def ActiveInsurgencyState(self): 102 self.headerTextCont = ContainerAutoSize(name='headerTextCont', parent=self.headerCont, align=uiconst.CENTERLEFT, height=23, alignMode=uiconst.TOLEFT) 103 link = evelink.local_service_link(method='OpenInsurgencyDashboard', text=GetByLabel('UI/PirateInsurgencies/dashboardCaption')) 104 self.title = self.headerCls(name='title', text=link, parent=self.headerTextCont, align=uiconst.TOLEFT, state=uiconst.UI_NORMAL) 105 self.headerCorruptionGauge = CorruptionGauge(parent=self.headerTextCont, name='CorruptionGauge', align=uiconst.TOLEFT, width=20, height=20, systemID=session.solarsystemid2, stages=[0.15, 106 0.35, 107 0.55, 108 0.75, 109 1.0], dashboardSvc=self.dashboardSvc, drawSprite=False, left=10) 110 self.headerSuppressionGauge = SuppressionGauge(parent=self.headerTextCont, name='SuppressionGauge', align=uiconst.TOLEFT, width=20, height=20, systemID=session.solarsystemid2, stages=[0.15, 111 0.35, 112 0.55, 113 0.75, 114 1.0], dashboardSvc=self.dashboardSvc, drawSprite=False, left=10) 115 self.headerCorruptionGauge.Hide() 116 self.headerSuppressionGauge.Hide() 117 contWidth = 180 118 self.cont = ContainerAutoSize(parent=self.mainCont, align=uiconst.TOTOP, height=64, maxWidth=contWidth, padTop=10, alignMode=uiconst.TOPLEFT) 119 self.corruptionCont = Container(name='CorruptionCont', parent=self.cont, align=uiconst.TOPLEFT, width=contWidth / 2, height=120) 120 self.suppressionCont = Container(name='suppressionCont', parent=self.cont, align=uiconst.TOPLEFT, width=contWidth / 2, left=contWidth / 2, height=120) 121 self.corruptionLoadingWheel = LoadingWheel(parent=ContainerAutoSize(parent=self.corruptionCont, align=uiconst.TOTOP), align=uiconst.TOTOP) 122 self.dashboardSvc.RequestCorruptionStages(WrapCallbackWithErrorHandling(self.CorruptionStagesCallback, parentContainer=self.corruptionCont, onErrorCallback=self.corruptionLoadingWheel.Hide)) 123 self.suppressionLoadingWheel = LoadingWheel(parent=ContainerAutoSize(parent=self.suppressionCont, align=uiconst.TOTOP), align=uiconst.TOTOP) 124 self.dashboardSvc.RequestSuppressionStages(WrapCallbackWithErrorHandling(self.SuppressionStagesCallback, parentContainer=self.suppressionCont, onErrorCallback=self.suppressionLoadingWheel.Hide)) 125 126 def OnTowGameAdded(self, towGameSnapshot): 127 self.scoreboardCont.Flush() 128 Fill(bgParent=self.scoreboardCont, color=eveColor.BLACK, opacity=0.15) 129 carbonui.text.styles.TextHeader(parent=self.scoreboardCont, align=uiconst.TOTOP, padding=(8, 3, 8, 8), text=GetByLabel('UI/PirateInsurgencies/warehouseRaid/warehouseRaidCaption')) 130 self.scoreRowsCont = ContainerAutoSize(parent=self.scoreboardCont, align=uiconst.TOTOP) 131 self.pirateHeistScoreRow = ScoreRow(iconTexturePath=eveicon.pirate_insurgencies, parent=self.scoreRowsCont, label=GetByLabel('UI/PirateInsurgencies/warehouseRaid/piratesProgress'), align=uiconst.TOTOP, padding=(8, 3, 8, 0), denominator=towGameSnapshot.winThreshold) 132 self.empireHeistScoreRow = ScoreRow(iconTexturePath=eveicon.factional_warfare, parent=self.scoreRowsCont, label=GetByLabel('UI/PirateInsurgencies/warehouseRaid/empiresProgress'), align=uiconst.TOTOP, padding=(8, 0, 8, 0), denominator=towGameSnapshot.winThreshold) 133 self.OnTowGameScoreUpdated(towGameSnapshot) 134 135 def OnTowGameRemoved(self, *args): 136 self.scoreboardCont.Flush() 137 138 def OnTowGameScoreUpdated(self, towGameSnapshot): 139 if self.scoreRowsCont is None or self.scoreRowsCont.destroyed: 140 return 141 self.currentTowGameSnapshot = towGameSnapshot 142 score = towGameSnapshot.scoreByFactionID 143 callback = None 144 for k, v in score.iteritems(): 145 if v == towGameSnapshot.winThreshold: 146 callback = partial(self.SetTowGameWinner, k) 147 if IsPirateFWFaction(k): 148 if self.pirateHeistScoreRow: 149 self.pirateHeistScoreRow.SetValue(v, callback=callback) 150 elif self.empireHeistScoreRow: 151 self.empireHeistScoreRow.SetValue(v, callback=callback) 152 153 def SetTowGameWinner(self, factionID): 154 155 def _setWinnerText(): 156 if self.scoreRowsCont is not None: 157 if IsPirateFWFaction(factionID): 158 message = localization.GetByMessageID(self.ICE_HEIST_PIRATE_WIN_MESSAGE_ID) 159 else: 160 message = GetByLabel(self.ICE_HEIST_EMPIRE_WIN_MESSAGE_ID) 161 self.scoreRowsCont.Flush() 162 self.scoreRowsCont = None 163 label = EveLabelSmall(parent=self.scoreboardCont, align=uiconst.TOTOP, text=message, padding=(16, 3, 8, 8), opacity=0, color=TextColor.NORMAL) 164 animations.FadeTo(label, endVal=TextColor.NORMAL.opacity, duration=uiconst.TIME_ENTRY) 165 166 if self.scoreRowsCont is not None: 167 animations.FadeOut(self.scoreRowsCont, callback=_setWinnerText) 168 169 def CorruptionStagesCallback(self, stages): 170 self.corruptionStages = stages 171 self.corruptionLoadingWheel.Hide() 172 self.corruptionGaugeCont = CorruptionGaugeCont(parent=self.corruptionCont, align=uiconst.TOTOP, height=64, stages=self.corruptionStages) 173 self.corruptionStageLabelCont = Container(parent=self.corruptionCont, align=uiconst.TOTOP, height=20) 174 self.corruptionLabelCont = Container(parent=self.corruptionCont, align=uiconst.TOTOP, height=20) 175 176 def SetCorruptionText(data): 177 self.currentNumerator = data.numerator 178 self.currentDenominator = data.denominator 179 self.currentVanguardNumerator = data.vanguardNumerator 180 self.currentVanguardDenominator = data.vanguardDenominator 181 self.SetCorruptionText(self.currentNumerator, self.currentDenominator, self.currentVanguardNumerator, self.currentVanguardDenominator, data.stage) 182 183 self.dashboardSvc.RequestLocalSystemCorruption(WrapCallbackWithErrorHandling(SetCorruptionText, parentContainer=None)) 184 185 def SetCorruptionText(self, currentCorruption, maxCorruption, vanguardNumerator, vanguardDenominator, stage): 186 percentageText = '{:.1%}'.format(float(currentCorruption) / float(maxCorruption)) 187 self.corruptionStageLabelCont.Flush() 188 self.corruptionLabelCont.Flush() 189 self.corruptionStageLabel = carbonui.text.styles.TextBody(parent=self.corruptionStageLabelCont, align=uiconst.CENTERTOP, text=GetByLabel('UI/PirateInsurgencies/stageLabel', stage=stage), bold=True) 190 carbonui.text.styles.TextBody(parent=self.corruptionLabelCont, align=uiconst.CENTERTOP, text=GetByLabel('UI/PirateInsurgencies/corruption')) 191 self.corruptionGaugeCont.corruptionPercentage.SetText(percentageText) 192 self.corruptionGaugeCont.corruptionGauge.SetIcon(GetCorruptionIconForStage(stage)) 193 systemEffectsTextList = [] 194 for i in range(1, stage + 1): 195 systemEffect = GetByLabel('UI/PirateInsurgencies/SystemEffects/CorruptionStage{}Effect'.format(i)) 196 if systemEffect == '': 197 continue 198 systemEffectsTextList.append(systemEffect) 199 200 systemEffectsText = '<br>'.join(systemEffectsTextList) 201 vanguardContribution = 0.0 202 if vanguardNumerator and vanguardDenominator: 203 vanguardContribution = float(vanguardNumerator) / float(vanguardDenominator) * 100 204 self.corruptionGaugeCont.SetSystemEffectHintText(systemEffectsText) 205 self.corruptionGaugeCont.SetVanguardContribtution(vanguardContribution) 206 207 def SuppressionStagesCallback(self, stages): 208 self.suppressionStages = stages 209 self.suppressionLoadingWheel.Hide() 210 self.suppressionGaugeCont = SuppressionGaugeCont(parent=self.suppressionCont, align=uiconst.TOTOP, height=64, stages=self.suppressionStages) 211 self.suppressionStageLabelCont = Container(parent=self.suppressionCont, align=uiconst.TOTOP, height=20) 212 self.suppressionLabelCont = Container(parent=self.suppressionCont, align=uiconst.TOTOP, height=20) 213 214 def SetSuppressionText(data): 215 self.SetSuppressionText(data.numerator, data.denominator, data.vanguardNumerator, data.vanguardDenominator, data.stage) 216 217 self.dashboardSvc.RequestLocalSystemSuppression(WrapCallbackWithErrorHandling(SetSuppressionText, parentContainer=None)) 218 219 def SetSuppressionText(self, currentSuppression, maxSuppression, vanguardNumerator, vanguardDenominator, stage): 220 percentageText = '{:.1%}'.format(float(currentSuppression) / float(maxSuppression)) 221 self.suppressionStageLabelCont.Flush() 222 self.suppressionLabelCont.Flush() 223 self.suppressionStageLabel = carbonui.text.styles.TextBody(parent=self.suppressionStageLabelCont, align=uiconst.CENTERTOP, text=GetByLabel('UI/PirateInsurgencies/stageLabel', stage=stage), bold=True) 224 carbonui.text.styles.TextBody(parent=self.suppressionLabelCont, align=uiconst.CENTERTOP, text=GetByLabel('UI/PirateInsurgencies/suppression')) 225 self.suppressionGaugeCont.suppressionPercentage.SetText(percentageText) 226 self.suppressionGaugeCont.suppressionGauge.SetIcon(GetSuppressionIconForStage(stage)) 227 systemEffectsTextList = [] 228 for i in range(1, stage + 1): 229 if i == 3: 230 systemEffect1 = GetByLabel('UI/PirateInsurgencies/SystemEffects/SuppressionStage{}Effect1'.format(i)) 231 systemEffect2 = GetByLabel('UI/PirateInsurgencies/SystemEffects/SuppressionStage{}Effect2'.format(i)) 232 if systemEffect1: 233 systemEffectsTextList.append(systemEffect1) 234 if systemEffect2: 235 systemEffectsTextList.append(systemEffect2) 236 else: 237 systemEffect = GetByLabel('UI/PirateInsurgencies/SystemEffects/SuppressionStage{}Effect'.format(i)) 238 if systemEffect: 239 systemEffectsTextList.append(systemEffect) 240 241 systemEffectsText = '<br>'.join(systemEffectsTextList) 242 vanguardContribution = 0.0 243 if vanguardNumerator and vanguardDenominator: 244 vanguardContribution = float(vanguardNumerator) / float(vanguardDenominator) * 100 245 self.suppressionGaugeCont.SetSystemEffectHintText(systemEffectsText) 246 self.suppressionGaugeCont.SetVanguardContribution(vanguardContribution) 247 248 def OnStartModeChanged(self, oldMode): 249 if self.snapshot.fsmState is not None and self.snapshot.fsmState != CAMPAIGN_STATE_FORECASTING: 250 if self.mode == infoPanelConst.MODE_COMPACT: 251 if oldMode: 252 self.headerCorruptionGauge.Show() 253 self.headerSuppressionGauge.Show() 254 else: 255 self.headerCorruptionGauge.Show() 256 self.headerSuppressionGauge.Show() 257 else: 258 self.headerCorruptionGauge.Hide() 259 self.headerSuppressionGauge.Hide() 260 261 @staticmethod 262 def IsAvailable(): 263 isinsurgencysystem = sm.GetService('insurgencyDashboardSvc').IsSystemAffectedByInsurgency(session.solarsystemid2) 264 return isinsurgencysystem 265 266 def OnSuppressionValueChanged_Local(self, systemID, data): 267 if systemID != session.solarsystemid2: 268 return 269 if self.suppressionStages is None: 270 return 271 self.SetSuppressionText(data.numerator, data.denominator, data.vanguardNumerator, data.vanguardDenominator, data.stage) 272 273 def OnCorruptionValueChanged_Local(self, systemID, data): 274 if systemID != session.solarsystemid2: 275 return 276 if self.corruptionStages is None: 277 return 278 self.SetCorruptionText(data.numerator, data.denominator, data.vanguardNumerator, data.vanguardDenominator, data.stage) 279 280 281 class CorruptionGaugeCont(Container): 282 283 def ApplyAttributes(self, attributes): 284 Container.ApplyAttributes(self, attributes) 285 self.dashboardSvc = sm.GetService('insurgencyDashboardSvc') 286 self.stages = attributes.get('stages') 287 self.hintText = '' 288 self.vanguardContribution = 0 289 self.ConstructLayout() 290 291 def ConstructLayout(self): 292 self.hintCont = Container(align=uiconst.CENTER, parent=self, state=uiconst.UI_NORMAL, height=64, width=64) 293 self.hintCont.LoadTooltipPanel = self.hintContTooltipFun 294 self.corruptionPercentage = carbonui.text.styles.TextBody(parent=self, align=uiconst.CENTER, text='-%') 295 self.corruptionGaugeOverlay = Sprite(align=uiconst.CENTER, parent=self, texturePath='res:/UI/Texture/classes/pirateinsurgencies/info_panel/circle.png', state=uiconst.UI_DISABLED, height=58, width=58) 296 self.corruptionPercentage.Hide() 297 self.corruptionGaugeOverlay.Hide() 298 self.corruptionGauge = CorruptionGauge(parent=self, name='CorruptionGauge', align=uiconst.TOTOP, width=64, height=64, systemID=session.solarsystemid2, stages=self.stages, dashboardSvc=self.dashboardSvc) 299 300 def SetSystemEffectHintText(self, hintText): 301 self.hintText = hintText 302 303 def SetVanguardContribtution(self, contribution): 304 self.vanguardContribution = contribution 305 306 def hintContTooltipFun(self, panel, *args): 307 showStagesInformation = self.hintText and self.hintText != '' 308 if self.vanguardContribution == 0 and not showStagesInformation: 309 return 310 panel.LoadGeneric2ColumnTemplate() 311 if showStagesInformation: 312 panel.AddLabelMedium(text=self.hintText, colSpan=2, rowSpan=1) 313 if self.vanguardContribution > 0: 314 if showStagesInformation: 315 panel.AddCell(Line(weight=1), colSpan=2) 316 panel.AddCell(Sprite(texturePath='res:/UI/Texture/classes/pirateinsurgencies/vanguard_logo_v.png', width=32, height=32, cellPadding=0)) 317 text = GetByLabel('UI/PirateInsurgencies/vanguardCorruptingThisSystemTooltip', contribution=self.vanguardContribution) 318 panel.AddLabelMedium(text=text) 319 320 def OnMouseEnter(self, *args): 321 self.corruptionPercentage.Show() 322 self.corruptionGaugeOverlay.Show() 323 324 def OnMouseExit(self, *args): 325 self.corruptionPercentage.Hide() 326 self.corruptionGaugeOverlay.Hide() 327 328 329 class SuppressionGaugeCont(Container): 330 331 def ApplyAttributes(self, attributes): 332 Container.ApplyAttributes(self, attributes) 333 self.dashboardSvc = sm.GetService('insurgencyDashboardSvc') 334 self.stages = attributes.get('stages') 335 self.hintText = '' 336 self.vanguardContribution = 0 337 self.ConstructLayout() 338 339 def ConstructLayout(self): 340 self.hintCont = Container(align=uiconst.CENTER, parent=self, state=uiconst.UI_NORMAL, height=64, width=64) 341 self.hintCont.LoadTooltipPanel = self.hintContTooltipFun 342 self.suppressionPercentage = carbonui.text.styles.TextBody(parent=self, align=uiconst.CENTER, text='-%') 343 self.suppressionGaugeOverlay = Sprite(align=uiconst.CENTER, parent=self, texturePath='res:/UI/Texture/classes/pirateinsurgencies/info_panel/circle.png', state=uiconst.UI_DISABLED, height=58, width=58) 344 self.suppressionPercentage.Hide() 345 self.suppressionGaugeOverlay.Hide() 346 self.suppressionGauge = SuppressionGauge(parent=self, name='SuppressionGauge', align=uiconst.TOTOP, width=64, height=64, systemID=session.solarsystemid2, stages=self.stages, dashboardSvc=self.dashboardSvc) 347 348 def SetSystemEffectHintText(self, hintText): 349 self.hintText = hintText 350 351 def SetVanguardContribution(self, contribution): 352 self.vanguardContribution = contribution 353 354 def hintContTooltipFun(self, panel, *args): 355 showStagesInformation = self.hintText and self.hintText != '' 356 if self.vanguardContribution == 0 and not showStagesInformation: 357 return 358 panel.LoadGeneric2ColumnTemplate() 359 if showStagesInformation: 360 panel.AddLabelMedium(text=self.hintText, colSpan=2, rowSpan=1) 361 if self.vanguardContribution > 0: 362 if showStagesInformation: 363 panel.AddCell(Line(weight=1), colSpan=2) 364 panel.AddCell(Sprite(texturePath='res:/UI/Texture/classes/pirateinsurgencies/vanguard_logo_v.png', width=32, height=32, cellPadding=0)) 365 text = GetByLabel('UI/PirateInsurgencies/vanguardSuppressingThisSystemTooltip', contribution=self.vanguardContribution) 366 panel.AddLabelMedium(text=text) 367 368 def OnMouseEnter(self, *args): 369 self.suppressionPercentage.Show() 370 self.suppressionGaugeOverlay.Show() 371 372 def OnMouseExit(self, *args): 373 self.suppressionPercentage.Hide() 374 self.suppressionGaugeOverlay.Hide()