infoPanelRecommendations.py (9879B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\infoPanels\infoPanelRecommendations.py 2 import carbonui.const as uiconst 3 import logging 4 from carbon.client.script.environment.AudioUtil import PlaySound 5 from carbonui import ButtonStyle 6 from carbonui.control.button import Button 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.containerAutoSize import ContainerAutoSize 9 from carbonui.primitives.fill import Fill 10 from carbonui.primitives.frame import Frame 11 from carbonui.uianimations import animations 12 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveLabelLarge 13 from eve.client.script.ui.control.infoIcon import MoreInfoIcon 14 from eve.client.script.ui.shared.infoPanels.const import infoPanelConst 15 from eve.client.script.ui.shared.infoPanels.infoPanelMissions import InfoPanelMissions 16 from eve.client.script.ui.shared.infoPanels.infoPanelOperations import InfoPanelOperationRecommendationsData 17 from eve.client.script.ui.shared.pointerTool.pointerToolConst import UNIQUE_NAME_RECOMMENDATIONS_INFO_PANEL 18 from eve.client.script.ui.shared.recommendation.const import Sounds 19 from eve.client.script.ui.shared.recommendation.recommendationWnd import RecommendationWnd 20 from eve.client.script.ui.shared.recommendation.uiConst import HAS_INTERACTED_WITH, INFO_PANEL_ICON, TREATMENT_ACTIVE_COLORS_BTN, TREATMENT_COMPLETED_COLORS_BTN, TREATMENT_NORMAL_COLORS_BTN 21 from localization import GetByLabel 22 from eve.client.script.ui.shared.infoPanels.const.infoPanelUIConst import PANELWIDTH, LEFTPAD 23 from operations.client.operationscontroller import GetOperationsController 24 from operations.common.const import OPERATION_CATEGORY_RECOMMENDATIONS 25 from uihider import UiHiderMixin 26 logger = logging.getLogger(__name__) 27 HEADER_WIDTH = PANELWIDTH - LEFTPAD 28 HEADER_HEIGHT = 29 29 HEADER_ICON_SIZE = 20 30 PADDING_HEADER_TO_OBJECTIVE_HEADER = 4 31 PADDING_ICON_TO_TITLE = 4 32 PADDING_EDGE_TO_TITLE = 8 33 POINT_RIGHT_HEADER_FRAME_TEXTURE_PATH = 'res:/UI/Texture/classes/Achievements/pointRightHeaderFrame.png' 34 POINT_RIGHT_HEADER_FRAME_CORNER_SIZE = 16 35 POINT_RIGHT_HEADER_FRAME_OFFSET = -14 36 POINT_RIGHT_HEADER_COLOR = (1, 1, 1, 0.25) 37 38 class InfoPanelRecommendations(UiHiderMixin, InfoPanelMissions): 39 __guid__ = 'uicls.InfoPanelRecommendations' 40 default_name = 'InfoPanelRecommendations' 41 uniqueUiName = UNIQUE_NAME_RECOMMENDATIONS_INFO_PANEL 42 panelTypeID = infoPanelConst.PANEL_RECOMMENDATIONS 43 label = 'UI/recommendations/InfoPanel/Header' 44 default_iconTexturePath = INFO_PANEL_ICON 45 default_mode = infoPanelConst.MODE_NORMAL 46 default_are_objectives_collapsable = False 47 __notifyevents__ = InfoPanelMissions.__notifyevents__ + ['OnRecommendationsChanged', 'OnOperationRecommendationCompleted', 'OnOperationTaskTransition'] 48 49 def __init__(self, *args, **kwargs): 50 self.recommendationSvc = sm.GetService('recommendationSvc') 51 self.includePreviousTask = False 52 super(InfoPanelRecommendations, self).__init__(*args, **kwargs) 53 54 def GetTitle(self): 55 return GetByLabel('UI/recommendations/InfoPanel/Header') 56 57 @staticmethod 58 def IsAvailable(): 59 if not sm.GetService('recommendationSvc').IsFeatureEnabled(): 60 return False 61 if GetOperationsController().is_non_recommendation_operation_active(): 62 return False 63 return True 64 65 def Update(self, oldMode = None): 66 if self.header: 67 self.header.text = self.GetTitle() 68 super(InfoPanelRecommendations, self).Update(oldMode) 69 70 def OnRecommendationsChanged(self, *args): 71 self.Update(self.mode) 72 73 def OnOperationRecommendationCompleted(self, operationID): 74 self.UpdateButton() 75 76 def OnOperationTaskTransition(self, categoryID, operationID, taskID, fromState, toState): 77 if categoryID != OPERATION_CATEGORY_RECOMMENDATIONS: 78 return 79 if not GetOperationsController().is_any_operation_active(): 80 return 81 self.includePreviousTask = True 82 self.ConstructNormal() 83 self.AnimateTransition() 84 self.includePreviousTask = False 85 86 def AnimateTransition(self): 87 for eachMission in self.missionContainers.itervalues(): 88 for objCont in eachMission.missionObjectiveContainers.itervalues(): 89 if objCont.objective.IsActive(): 90 animations.MorphScalar(objCont, 'padBottom', startVal=-objCont.height, endVal=objCont.padBottom, duration=0.35) 91 animations.FadeTo(objCont, duration=0.35) 92 else: 93 animations.MorphScalar(objCont, 'top', startVal=objCont.top, endVal=-objCont.height, duration=1.0, timeOffset=1.0) 94 95 def ConstructNormal(self): 96 self.mainCont.Flush() 97 self.state = uiconst.UI_NORMAL 98 if GetOperationsController().is_active_operation_a_recommendation() or self.recommendationSvc.ShowLastCompleted(): 99 super(InfoPanelRecommendations, self).ConstructNormal() 100 else: 101 self.ConstructHeaderFrame() 102 if not self.recommendationSvc.HasEverAcceptedARecommendation(): 103 textCont = ContainerAutoSize(name='textCont', parent=self.mainCont, align=uiconst.TOTOP, alignMode=uiconst.TOTOP) 104 Fill(bgParent=textCont, color=(0.2, 0.2, 0.2, 0.4)) 105 EveLabelMedium(parent=textCont, text=GetByLabel('UI/recommendations/InfoPanel/Description'), align=uiconst.TOTOP, padding=(6, 10, 6, 10)) 106 buttonCont = Container(name='buttonCont', parent=self.mainCont, align=uiconst.TOTOP, padTop=0) 107 if not getattr(self, 'btn', None) or self.btn.destroyed: 108 self.btn = Button(parent=buttonCont, align=uiconst.TOTOP, label=GetByLabel('UI/recommendations/InfoPanel/ViewOpportunities'), texturePath='res:/UI/Texture/classes/war/leftArrow.png', func=self.OpenRecommendationsWindow) 109 buttonCont.height = self.btn.height 110 self.UpdateButton() 111 112 def ConstructHeaderFrame(self): 113 missionHeaderPadBottom = PADDING_HEADER_TO_OBJECTIVE_HEADER 114 missionHeaderContainer = Container(name='recommendations_containerHeader', parent=self.mainCont, align=uiconst.TOTOP, state=uiconst.UI_NORMAL, height=HEADER_HEIGHT + missionHeaderPadBottom, padBottom=missionHeaderPadBottom) 115 Frame(name='recommendations_containerHeader_frame', texturePath=POINT_RIGHT_HEADER_FRAME_TEXTURE_PATH, cornerSize=POINT_RIGHT_HEADER_FRAME_CORNER_SIZE, offset=POINT_RIGHT_HEADER_FRAME_OFFSET, parent=missionHeaderContainer, color=POINT_RIGHT_HEADER_COLOR, align=uiconst.TOALL) 116 paddingLeft = PADDING_EDGE_TO_TITLE 117 paddingRight = PADDING_ICON_TO_TITLE 118 titleWidth = HEADER_WIDTH - paddingLeft - paddingRight 119 missionTitleContainer = Container(name='recommendations_containerTitle', parent=missionHeaderContainer, align=uiconst.TOLEFT, state=uiconst.UI_DISABLED, width=titleWidth, height=HEADER_HEIGHT, left=PADDING_EDGE_TO_TITLE) 120 titleLabel = EveLabelLarge(name='recommendations_title', parent=missionTitleContainer, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, text=GetByLabel('UI/recommendations/InfoPanel/RecommendedForYou')) 121 titleLabel.SetRightAlphaFade(fadeEnd=missionTitleContainer.width, maxFadeWidth=3) 122 optionsMenuIconContainer = Container(name='recommendations_containerIconOptionsMenu', parent=missionHeaderContainer, align=uiconst.TORIGHT, state=uiconst.UI_PICKCHILDREN, width=HEADER_ICON_SIZE, height=HEADER_HEIGHT) 123 self.helpIcon = MoreInfoIcon(parent=optionsMenuIconContainer, align=uiconst.CENTERRIGHT, left=1, hint=GetByLabel('UI/recommendations/InfoPanel/OpportunitiesHint')) 124 125 def UpdateButton(self): 126 btn = getattr(self, 'btn', None) 127 if not btn or btn.destroyed: 128 return 129 btn.SetLabel(GetByLabel('UI/recommendations/InfoPanel/ViewOpportunities')) 130 shouldBlink = self.recommendationSvc.ShouldInfoPanelBlink() 131 if self.recommendationSvc.ShowLastCompleted(): 132 btn.label = GetByLabel('UI/recommendations/InfoPanel/OpportunityCompleted') 133 btn.style = ButtonStyle.SUCCESS 134 if shouldBlink: 135 btn.Blink(1) 136 elif GetOperationsController().is_active_operation_a_recommendation(): 137 btn.style = ButtonStyle.NORMAL 138 else: 139 btn.style = ButtonStyle.NORMAL 140 if shouldBlink: 141 btn.Blink(1) 142 143 def OpenRecommendationsWindow(self, *args): 144 btn = getattr(self, 'btn', None) 145 if btn: 146 btn.Blink(0) 147 hasInteractedWith = settings.char.ui.Get(HAS_INTERACTED_WITH, False) 148 wnd = RecommendationWnd.Open() 149 wnd.ShowDialog(modal=True, state=uiconst.UI_PICKCHILDREN, closeWhenClicked=True) 150 PlaySound(Sounds.OPEN) 151 settings.char.ui.Set(HAS_INTERACTED_WITH, True) 152 if not hasInteractedWith: 153 sm.ScatterEvent('OnRecommendationsUpdated') 154 155 def GetMissions(self): 156 missions = [] 157 if GetOperationsController().is_any_operation_active(): 158 activeOperationData = InfoPanelOperationRecommendationsData(includePrveviousTask=self.includePreviousTask) 159 missions.append(activeOperationData) 160 elif self.recommendationSvc.ShowLastCompleted(): 161 lastActiveOperationInfo = self.recommendationSvc.activeRecommendation 162 activeOperationData = InfoPanelOperationRecommendationsData(lastActiveOperationInfo.categoryID, lastActiveOperationInfo.operation, lastActiveOperationInfo.taskList) 163 missions.append(activeOperationData) 164 return missions 165 166 def GetFirstActiveObjective(self): 167 for mission in self.missions: 168 for objective in mission.GetObjectives(): 169 if objective.IsActive(): 170 return objective 171 172 def GetOptionsMenu(self, menuParent, mission): 173 pass