insurgency.py (6489B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\theatersOfWar\landingPage\insurgency.py 2 import eveicon 3 import gametime 4 import uthread2 5 from carbon.common.script.util.format import FmtDate 6 from carbonui import Align, TextColor 7 from carbonui.primitives.containerAutoSize import ContainerAutoSize 8 from carbonui.text.styles import TextHeader, TextBody 9 from eve.client.script.ui.shared.theatersOfWar.landingPage.landingPageWidgets import WidgetContWithContentWithIcon 10 from eveformat.client import solar_system_security_status 11 from localization.formatters.timeIntervalFormatters import GetByLabel 12 from pirateinsurgency.const import CAMPAIGN_STATE_ACTIVE, CAMPAIGN_STATE_PIRATE_WIN, CAMPAIGN_STATE_ANTIPIRATE_WIN, CAMPAIGN_STATE_NO_WINNER, CAMPAIGN_STATE_FORECASTING 13 14 class InsurgencyCont(WidgetContWithContentWithIcon): 15 default_name = 'insurgencyCont' 16 default_iconsSize = 96 17 18 def ApplyAttributes(self, attributes): 19 self._count_down_thread = None 20 self.pirate_faction_id = attributes.pirate_faction_id 21 super(InsurgencyCont, self).ApplyAttributes(attributes) 22 self.text_cont = ContainerAutoSize(parent=self.content_cont, align=Align.TOTOP) 23 self.texturePath = attributes.texturePath 24 insurgency_name = attributes.insurgency_name 25 self.set_header(insurgency_name) 26 self.load_texture(self.texturePath) 27 28 def load_campaign(self, campaign_snapshot): 29 self.text_cont.Flush() 30 self.load_texture(self.texturePath) 31 if campaign_snapshot.fsmState == CAMPAIGN_STATE_ACTIVE: 32 self._load_active_campaign(campaign_snapshot) 33 elif campaign_snapshot.fsmState == CAMPAIGN_STATE_NO_WINNER: 34 self._load_now_winner() 35 elif campaign_snapshot.fsmState == CAMPAIGN_STATE_ANTIPIRATE_WIN: 36 self._load_empire_win() 37 elif campaign_snapshot.fsmState == CAMPAIGN_STATE_PIRATE_WIN: 38 self._load_pirate_win() 39 elif campaign_snapshot.fsmState == CAMPAIGN_STATE_FORECASTING: 40 self._load_forecasting_campaign(campaign_snapshot) 41 else: 42 self._load_other_states() 43 44 def _load_active_campaign(self, campaign_snapshot): 45 self.add_small_header(GetByLabel('UI/TheatersOfWar/InsurgencyPirateFob')) 46 location_text = '%s %s' % (cfg.evelocations.Get(campaign_snapshot.originSolarsystemID).name, solar_system_security_status(campaign_snapshot.originSolarsystemID)) 47 self.add_big_header(location_text) 48 self.add_small_header(GetByLabel('UI/TheatersOfWar/InsurgencyScore')) 49 empire_score = campaign_snapshot.antipiratePointsScored 50 empire_required = campaign_snapshot.antipiratePointsRequired 51 pirate_score = campaign_snapshot.piratePointsScored 52 pirate_required = campaign_snapshot.piratePointsRequired 53 pirate_name = cfg.eveowners.Get(self.pirate_faction_id).name 54 self.AddTextLine(GetByLabel('UI/TheatersOfWar/InsurgencyEmpiresAntiPirates'), '%s/%s' % (empire_score, empire_required)) 55 self.AddTextLine(pirate_name, '%s/%s' % (pirate_score, pirate_required)) 56 57 def AddTextLine(self, label_text, value_text): 58 cont = ContainerAutoSize(parent=self.text_cont, align=Align.TOTOP, alignMode=Align.TOTOP, top=2) 59 value_label = TextBody(name='valueText', parent=cont, align=Align.TORIGHT, color=TextColor.SECONDARY, text=value_text) 60 labelClipper = ContainerAutoSize(name='labelClipper', parent=cont, align=Align.TOTOP) 61 label = TextBody(parent=labelClipper, text=label_text, align=Align.CENTERLEFT, maxLines=1, autoFadeSides=25, color=TextColor.SECONDARY) 62 63 def add_big_header(self, text): 64 header_label = TextHeader(parent=self.text_cont, align=Align.TOTOP, text=text, padBottom=8, color=TextColor.HIGHLIGHT) 65 return header_label 66 67 def add_small_header(self, text): 68 TextBody(parent=self.text_cont, text=text, color=TextColor.DISABLED, align=Align.TOTOP) 69 70 def _load_now_winner(self): 71 self._load_winnder(GetByLabel('UI/TheatersOfWar/InsurgencyNoWinner'), GetByLabel('UI/TheatersOfWar/InsurgencyTimedOut'), eveicon.pirates) 72 73 def _load_empire_win(self): 74 self._load_winnder(GetByLabel('UI/TheatersOfWar/InsurgencyEmpiresAntiPirates'), GetByLabel('UI/TheatersOfWar/InsurgencyEnded'), eveicon.empires_victory) 75 76 def _load_pirate_win(self): 77 pirate_name = cfg.eveowners.Get(self.pirate_faction_id).name 78 self._load_winnder(pirate_name, GetByLabel('UI/TheatersOfWar/InsurgencyEnded'), self.texturePath) 79 80 def _load_winnder(self, winner_text, winner_state, texture_path): 81 self.add_small_header(GetByLabel('UI/TheatersOfWar/InsurgencyWinner')) 82 self.add_big_header(winner_text) 83 self.add_small_header(GetByLabel('UI/TheatersOfWar/InsurgencyState')) 84 TextBody(parent=self.text_cont, align=Align.TOTOP, color=TextColor.SECONDARY, text=winner_state) 85 self.load_texture(texture_path) 86 87 def _load_forecasting_campaign(self, campaign_snapshot): 88 self.add_small_header(GetByLabel('UI/TheatersOfWar/InsurgencyNext')) 89 time_label = self.add_big_header('') 90 self.add_small_header(GetByLabel('UI/TheatersOfWar/InsurgencyFobSpawn')) 91 location_text = '%s %s' % (cfg.evelocations.Get(campaign_snapshot.originSolarsystemID).name, solar_system_security_status(campaign_snapshot.originSolarsystemID)) 92 TextBody(parent=self.text_cont, align=Align.TOTOP, color=TextColor.SECONDARY, text=location_text) 93 self._kill_count_down_thread() 94 self._count_down_thread = uthread2.StartTasklet(self._count_down, time_label, campaign_snapshot.stateExpiryTimestamp) 95 96 def _kill_count_down_thread(self): 97 if self._count_down_thread: 98 self._count_down_thread.kill() 99 self.count_down_thread = None 100 101 def _load_other_states(self): 102 TextBody(parent=self.text_cont, align=Align.TOTOP, color=TextColor.SECONDARY, text=GetByLabel('UI/TheatersOfWar/InsurgencyOtherState')) 103 104 def _count_down(self, label, timestamp): 105 while label and not label.destroyed: 106 now = gametime.GetWallclockTimeNow() 107 diff = timestamp - now 108 if diff <= 0: 109 text = 'Imminent' 110 else: 111 text = FmtDate(diff, 'ns') 112 label.SetText(text) 113 uthread2.Sleep(0.5) 114 115 def Close(self): 116 super(InsurgencyCont, self).Close() 117 self._kill_count_down_thread()