infoPanelSeasons.py (9367B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\infoPanels\infoPanelSeasons.py 2 import uthread2 3 import carbonui.const as uiconst 4 from carbonui.control.button import Button 5 from carbonui.fontconst import EVE_MEDIUM_FONTSIZE 6 from carbonui.primitives.container import Container 7 from carbonui.primitives.containerAutoSize import ContainerAutoSize 8 from carbonui.primitives.fill import Fill 9 from carbonui.uianimations import animations 10 from eve.client.script.ui.control.eveLabel import EveLabelMedium 11 from eve.client.script.ui.shared.infoPanels.InfoPanelBase import InfoPanelBase 12 from eve.client.script.ui.shared.infoPanels.const.infoPanelConst import PANEL_SEASONS, MODE_HIDDEN 13 from eve.client.script.ui.shared.pointerTool.pointerToolConst import UNIQUE_NAME_SEASONS_INFO_PANEL 14 from eve.client.script.ui.util.uix import GetTextHeight 15 from localization import GetByLabel 16 from seasons.client.challengeinfopaneltaskentry import ChallengeInfoPanelTaskEntry 17 from carbonui.uicore import uicore 18 from uihider import UiHiderMixin 19 from seasons.client.util import OpenSeasonsWindow 20 COMPLETED_CHALLENGE_FADE_OUT_DURATION = 1.0 21 DEFAULT_PADDING = 6 22 23 class InfoPanelSeasons(UiHiderMixin, InfoPanelBase): 24 default_name = 'InfoPanelSeasons' 25 uniqueUiName = UNIQUE_NAME_SEASONS_INFO_PANEL 26 default_iconTexturePath = 'res:/UI/Texture/classes/Seasons/eventIcon_18x18.png' 27 default_state = uiconst.UI_PICKCHILDREN 28 label = 'UI/Seasons/InfoPanelChallengesTitle' 29 hasSettings = True 30 panelTypeID = PANEL_SEASONS 31 challengeContainer = None 32 __notifyevents__ = ['OnSeasonSelectionUpdated'] 33 34 def ApplyAttributes(self, attributes): 35 super(InfoPanelSeasons, self).ApplyAttributes(attributes) 36 sm.RegisterNotify(self) 37 self.seasonService = sm.GetService('seasonService') 38 self.ConstructMainContent() 39 40 def OnSeasonSelectionUpdated(self): 41 if self.seasonService.is_season_visible_in_agency(): 42 self.ConstructMainContent() 43 44 def ConstructMainContent(self): 45 self.mainCont.Flush() 46 self.SetTitle() 47 if self.seasonService.is_selection_needed(): 48 SeasonalSelectionPanel(parent=self, align=uiconst.TOTOP, descriptionText=self.seasonService.get_navigation_description()) 49 else: 50 SeasonalChallenges(parent=self, align=uiconst.TOTOP) 51 52 def ConstructHeaderButton(self): 53 return self.ConstructSimpleHeaderButton() 54 55 def SetTitle(self): 56 title = self.seasonService.get_navigation_season_title() 57 if title is None: 58 title = GetByLabel(self.label) 59 self.headerCont.Flush() 60 self.titleLabel = self.headerCls(name='title', text=title, parent=self.headerCont, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED) 61 62 @staticmethod 63 def IsAvailable(): 64 seasonSvc = sm.GetService('seasonService') 65 return seasonSvc.is_season_visible() 66 67 68 class SeasonalSelectionPanel(ContainerAutoSize): 69 default_name = 'SeasonalSelectionPanel' 70 default_state = uiconst.UI_PICKCHILDREN 71 72 def ApplyAttributes(self, attributes): 73 Container.ApplyAttributes(self, attributes) 74 self.descriptionText = attributes.descriptionText 75 self.ConstructSelectionPanel() 76 77 def ConstructSelectionPanel(self): 78 selectionCont = ContainerAutoSize(parent=self.parent.mainCont, align=uiconst.TOTOP, state=uiconst.UI_PICKCHILDREN) 79 Fill(name='selectionPanelBackground', bgParent=selectionCont, state=uiconst.UI_DISABLED, opacity=0.1, color=(1.0, 1.0, 1.0)) 80 textHeight = GetTextHeight(strng=self.descriptionText, width=256, fontsize=EVE_MEDIUM_FONTSIZE) + 8 81 descriptionContainer = Container(parent=selectionCont, align=uiconst.TOTOP, state=uiconst.UI_PICKCHILDREN, height=textHeight, left=DEFAULT_PADDING, top=2, padRight=DEFAULT_PADDING) 82 EveLabelMedium(parent=descriptionContainer, align=uiconst.TOTOP, state=uiconst.UI_NORMAL, text=self.descriptionText, linkStyle=uiconst.LINKSTYLE_SUBTLE) 83 buttonContainer = ContainerAutoSize(parent=selectionCont, align=uiconst.TOTOP, state=uiconst.UI_PICKCHILDREN) 84 Button(parent=buttonContainer, texturePath='res:/UI/Texture/classes/agency/icons/ContentTypes/agency.png', align=uiconst.BOTTOMRIGHT, label=GetByLabel('UI/Seasons/MultipleSeasonsTexts/selectButton'), left=DEFAULT_PADDING, top=DEFAULT_PADDING, func=self.OpenSeasonSelection) 85 86 def OpenSeasonSelection(self, *args): 87 OpenSeasonsWindow() 88 89 def _IsCollapsed(self): 90 if self.parent is None: 91 return False 92 return self.parent.mode == MODE_HIDDEN 93 94 95 class SeasonalChallenges(ContainerAutoSize): 96 default_name = 'SeasonalChallenges' 97 default_state = uiconst.UI_PICKCHILDREN 98 challengeContainer = None 99 __notifyevents__ = ['OnChallengeProgressUpdateInClient', 100 'OnChallengeCompletedInClient', 101 'OnChallengeRewardsGrantedInClient', 102 'OnChallengeExpiredInClient', 103 'OnSeasonsFsdDataChanged'] 104 105 def ApplyAttributes(self, attributes): 106 Container.ApplyAttributes(self, attributes) 107 sm.RegisterNotify(self) 108 self.seasonService = sm.GetService('seasonService') 109 self._LoadActiveChallenges() 110 self.challengeContainer = None 111 self.challengeTaskEntries = {} 112 self.openChallengesLinkGrid = None 113 self._ConstructChallengeContainer() 114 self._UpdateChallengeEntries() 115 116 def _LoadActiveChallenges(self): 117 self.activeChallenges = self.seasonService.get_active_challenges_by_character_id() 118 119 def _IsCollapsed(self): 120 if self.parent is None: 121 return False 122 return self.parent.mode == MODE_HIDDEN 123 124 def _ShouldShowChallengeDetails(self): 125 return not self._IsCollapsed() and settings.char.ui.Get('show_challenge_details_in_info_panel', True) 126 127 def _ConstructChallengeContainer(self): 128 if not self.challengeContainer or self.challengeContainer.destroyed: 129 self.parent.mainCont.Flush() 130 self.challengeContainer = ContainerAutoSize(parent=self.parent.mainCont, name='challengeContainer', align=uiconst.TOTOP) 131 if self.challengeContainer: 132 self.challengeContainer.Flush() 133 134 def _UpdateChallengeEntries(self): 135 updatedActiveChallenges = self.seasonService.get_active_challenges_by_character_id() 136 for challenge_id, challenge in self.activeChallenges.iteritems(): 137 self.seasonService.get_challenge(challenge_id) 138 if challenge_id not in updatedActiveChallenges: 139 challengeEntry = self.challengeTaskEntries.pop(challenge_id, None) 140 if challengeEntry: 141 challengeEntry.Close() 142 143 for challenge_id, challenge in updatedActiveChallenges.iteritems(): 144 if challenge.is_dormant: 145 challengeEntry = self.challengeTaskEntries.get(challenge_id, None) 146 if challengeEntry is not None: 147 animations.FadeIn(challengeEntry) 148 challengeEntry.show_dormant() 149 continue 150 idx = updatedActiveChallenges.keys().index(challenge_id) 151 if challenge_id not in self.challengeTaskEntries: 152 self.challengeTaskEntries[challenge_id] = ChallengeInfoPanelTaskEntry(name='challengeInfoPanelTaskEntry', parent=self.challengeContainer, align=uiconst.TOTOP, challenge=challenge, open_challenges_function=OpenSeasonsWindow, show_details=self._ShouldShowChallengeDetails(), idx=idx) 153 self.challengeTaskEntries[challenge_id].idx = idx 154 155 self.activeChallenges = updatedActiveChallenges 156 self.challengeContainer.UpdateAlignment() 157 158 def _GetChallenge(self, challengeID): 159 return self.seasonService.get_challenge(challengeID) 160 161 def OnChallengeProgressUpdateInClient(self, challengeID, newProgress): 162 self._UpdateChallengeEntries() 163 self.challengeTaskEntries[challengeID].update_challenge_progress(newProgress) 164 165 def OnChallengeCompletedInClient(self, oldChallengeID): 166 if oldChallengeID is None: 167 return 168 uthread2.start_tasklet(self._HideCompletedChallenge, oldChallengeID) 169 170 def OnChallengeExpiredInClient(self, challengeID): 171 uthread2.start_tasklet(self._HideCompletedChallenge, challengeID) 172 173 def OnChallengeRewardsGrantedInClient(self, challengeID): 174 challenge = self.activeChallenges.get(challengeID, None) 175 challengeEntry = self.challengeTaskEntries.get(challengeID, None) 176 if challengeEntry is not None: 177 challengeEntry.update_challenge_progress(challenge.max_progress) 178 179 def OnSeasonsFsdDataChanged(self): 180 if sm.GetService('seasonService').is_season_visible(): 181 self._UpdateChallengeEntries() 182 183 def _IsAnyChallengeShown(self): 184 return bool(self.activeChallenges) 185 186 def _IsChallengeAlreadyShown(self, challengeID): 187 return self._IsAnyChallengeShown() and challengeID in self.activeChallenges 188 189 def _HideCompletedChallenge(self, challengeID): 190 challengeEntry = self.challengeTaskEntries.get(challengeID, None) 191 if challengeEntry: 192 uicore.animations.FadeOut(challengeEntry, duration=COMPLETED_CHALLENGE_FADE_OUT_DURATION) 193 uthread2.call_after_wallclocktime_delay(self._UpdateChallengeEntries, COMPLETED_CHALLENGE_FADE_OUT_DURATION * 2)