technologiesView.py (12080B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation\technologiesView.py 2 import carbonui.const as uiconst 3 from carbonui.primitives.container import Container 4 from carbonui.uicore import uicore 5 from charactercreator.client.empireSelectionData import GetTechnologyData 6 from charactercreator.client.scalingUtils import GetBannerHeaderHeight, GetEnlistButtonWidth, GetEnlistButtonHeight, GetScaleFactor, GetBottomNavHeight 7 from eve.client.script.ui.login.charcreation.empireTechnologyViews.allegianceView import AllegianceView 8 from eve.client.script.ui.login.charcreation.empireTechnologyViews.propagandaView import PropagandaView 9 from eve.client.script.ui.login.charcreation.empireTechnologyViews.shipsView import ShipsView 10 from eve.client.script.ui.login.charcreation.empireTechnologyViews.weaponsView import WeaponsView 11 from eve.client.script.ui.login.charcreation.empireui.empireThemedButtons import GetSealHeight, EmpireThemedButton, EmpireThemedButtonState, EmpireThemedDecoration, GetEmpireThemedDecorationSize, BUTTON_TEXT_FONTSIZE_MIN_RES 12 from eve.client.script.ui.login.charcreation.label import CCLabel 13 from eve.client.script.ui.login.charcreation.technologyViewUtils import ARROW_TEXTURE, GetTechNavArrowSize, GetTechNavArrowIconSize, GetTechNavArrowSpacingSize, GetTechNavButtonSizeLarge, GetTechNavButtonSizeSmall, GetTechNavButtonFontsize, TechNavigationButton, ArrowTechButton 14 from eve.client.script.ui.util.uix import GetTextWidth 15 from eve.common.lib.appConst import raceAmarr, raceCaldari, raceGallente, raceMinmatar 16 from localization import GetByLabel 17 from math import pi 18 TECHNOLOGY_TITLE_OPACITY = 0.25 19 EMPIRE_SEAL_TOP = -24 20 EMPIRE_SEAL_OPACITY = 0.1 21 TECH_ORDER_TO_VIEW = {1: PropagandaView, 22 2: ShipsView, 23 3: WeaponsView, 24 4: AllegianceView} 25 DEFAULT_TECH_EXAMPLE = 1 26 ENLIST_BUTTON_TOP = 10 27 ENLIST_BUTTON_TEXT_BY_RACE = {raceAmarr: 'UI/CharacterCreation/EnlistAmarr', 28 raceCaldari: 'UI/CharacterCreation/EnlistCaldari', 29 raceGallente: 'UI/CharacterCreation/EnlistGallente', 30 raceMinmatar: 'UI/CharacterCreation/EnlistMinmatar'} 31 ENLIST_BUTTON_MIN_TEXT_PADDING = 10 32 ENLIST_FLARE_SOUND_INTRO = 'ui_es_enlist_flare_play' 33 ENLIST_FLARE_SOUND_OUTRO = 'ui_es_enlist_flare_stop' 34 ENLIST_MOUSEOVER_SOUND = 'ui_es_mouse_over_enlist_play' 35 ENLIST_MOUSEEXIT_SOUND = 'ui_es_mouse_over_enlist_stop' 36 ENLIST_POPUP_SOUND = 'ui_es_enlist_pop_up_play' 37 ENLIST_POPUP_END_SOUND = 'ui_es_enlist_pop_up_stop' 38 ENLIST_SOUND = 'ui_es_button_mouse_down_enlist_play' 39 40 class EmpireTechnologiesView(Container): 41 42 def ApplyAttributes(self, attributes): 43 self.raceID = attributes.raceID 44 self.stepContainer = attributes.stepContainer 45 self.buttonContainer = attributes.buttonContainer 46 self.technologyViewsTracker = attributes.Get('technologyViewsTracker') 47 self.techView = None 48 self.enlistButton = None 49 self.enlistButtonDecoration = None 50 self.isUpdatingTechView = False 51 self.techNavigationContainer = None 52 self.audioSvc = sm.GetService('audio') 53 self.technologies = GetTechnologyData() 54 self.firstTechOrder = self.technologies.GetFirstOrder() 55 shouldGoBackToStart = attributes.Get('shouldGoBackToStart', True) 56 self.techOrder = self._GetTechOrder(shouldGoBackToStart) 57 self.PlayIntroSound() 58 super(EmpireTechnologiesView, self).ApplyAttributes(attributes) 59 hasDiscoveredSwitch = self.technologyViewsTracker.has_discovered_technology_switch() 60 shouldMarkDiscovery = not shouldGoBackToStart and hasDiscoveredSwitch 61 if shouldMarkDiscovery: 62 self.technologyViewsTracker.mark_technology_switch_as_discovered() 63 self.UpdateTechnologyView() 64 65 def _GetTechOrder(self, shouldGoBackToStart): 66 if shouldGoBackToStart: 67 return self.firstTechOrder 68 return self._GetTechOrderSetting() 69 70 def _GetTechOrderSetting(self): 71 return settings.user.ui.Get('last_viewed_tech', self.firstTechOrder) 72 73 def _SetLastViewedTech(self): 74 settings.user.ui.Set('last_viewed_tech', self.techOrder) 75 self.technologyViewsTracker.mark_technology_as_viewed(self.raceID, self.techOrder) 76 77 def SetTechNavigation(self): 78 self.ClearUIElement(self.techNavigationContainer) 79 techNavigationWidth = self._GetTechNavigationWidth() 80 self.techNavigationContainer = Container(name='techNavigationContainer', align=uiconst.CENTERTOP, parent=self, width=techNavigationWidth, height=GetBannerHeaderHeight()) 81 arrowSize = GetTechNavArrowSize() 82 arrowIconSize = GetTechNavArrowIconSize() 83 arrowSpacingSize = GetTechNavArrowSpacingSize() 84 self._AddTechNavLeftArrow(arrowSize, arrowIconSize, arrowSpacingSize) 85 self._AddTechNavButtons() 86 self._AddTechNavRightArrow(arrowSize, arrowIconSize, arrowSpacingSize) 87 88 def _AddTechNavButtons(self): 89 for techOrder in xrange(1, self.technologies.GetNumberOfTechs() + 1): 90 isActive = techOrder == self.techOrder 91 buttonSize = GetTechNavButtonSizeLarge() if isActive else GetTechNavButtonSizeSmall() 92 tech = self.technologies.GetTech(techOrder) 93 techIconTexture = tech.GetIconTexture() 94 techNavigationButtonContainer = Container(name='techNavigationButtonContainer%d' % techOrder, align=uiconst.TOLEFT, parent=self.techNavigationContainer, width=buttonSize, height=buttonSize) 95 TechNavigationButton(name='techNavigationButton%d' % techOrder, parent=techNavigationButtonContainer, align=uiconst.CENTER, width=buttonSize, height=buttonSize, order=techOrder, techSetter=self.SetTech, raceID=self.raceID, iconTexture=techIconTexture, iconSize=buttonSize, isActive=isActive) 96 if isActive: 97 techTitle = tech.GetTechTitle() 98 bannerHeight = self.techNavigationContainer.height 99 extraHeight = (buttonSize - bannerHeight) / 2 100 labelTop = bannerHeight + extraHeight 101 techTitleLabel = CCLabel(text=techTitle, name='techNavigationButtonTitle%d' % techOrder, parent=self.techNavigationContainer, align=uiconst.TOLEFT_NOPUSH, uppercase=1, bold=False, fontsize=GetTechNavButtonFontsize(), top=labelTop) 102 techTitleLabel.left = -buttonSize / 2 - techTitleLabel.width / 2 103 104 def _AddTechNavLeftArrow(self, arrowSize, arrowIconSize, arrowSpacingSize): 105 leftArrowTechNavigationContainer = Container(name='leftArrowTechNavigationContainer', align=uiconst.TOLEFT, parent=self.techNavigationContainer, width=arrowSize, height=self.techNavigationContainer.height, padRight=arrowSpacingSize) 106 if self.techOrder > 1: 107 ArrowTechButton(name='leftArrow', parent=leftArrowTechNavigationContainer, align=uiconst.CENTER, width=arrowSize, height=arrowSize, iconTexture=ARROW_TEXTURE, iconSize=arrowIconSize, order=self.techOrder - 1, techSetter=self.SetTech, rotation=pi) 108 109 def _AddTechNavRightArrow(self, arrowSize, arrowIconSize, arrowSpacingSize): 110 rightArrowTechNavigationContainer = Container(name='rightArrowTechNavigationContainer', align=uiconst.TOLEFT, parent=self.techNavigationContainer, width=arrowSize, height=self.techNavigationContainer.height, padLeft=arrowSpacingSize) 111 if self.techOrder < self.technologies.GetNumberOfTechs(): 112 ArrowTechButton(name='rightArrow', parent=rightArrowTechNavigationContainer, align=uiconst.CENTER, width=arrowSize, height=arrowSize, iconTexture=ARROW_TEXTURE, iconSize=arrowIconSize, order=self.techOrder + 1, techSetter=self.SetTech) 113 114 def Enlist(self): 115 self.audioSvc.SendUIEvent(ENLIST_SOUND) 116 uicore.layer.charactercreation.controller.Approve() 117 118 def SetEnlistButton(self): 119 if self.enlistButton and not self.enlistButton.destroyed: 120 self.enlistButton.Close() 121 enlistButtonLabel = GetByLabel(ENLIST_BUTTON_TEXT_BY_RACE[self.raceID]) 122 enlistButtonLabelFontsize = BUTTON_TEXT_FONTSIZE_MIN_RES * GetScaleFactor() 123 enlistButtonLabelWidth = GetTextWidth(strng=enlistButtonLabel, fontsize=enlistButtonLabelFontsize, hspace=0, uppercase=1) 124 minWidth = enlistButtonLabelWidth + 2 * ENLIST_BUTTON_MIN_TEXT_PADDING 125 enlistButtonWidth = max(minWidth, GetEnlistButtonWidth()) 126 enlistButtonTop = GetBottomNavHeight() - ENLIST_BUTTON_TOP - GetEnlistButtonHeight() 127 self.enlistButton = EmpireThemedButton(name='EnlistButton', parent=self.buttonContainer, align=uiconst.CENTERBOTTOM, label=enlistButtonLabel.upper(), raceID=self.raceID, width=enlistButtonWidth, height=GetEnlistButtonHeight(), top=enlistButtonTop, buttonState=EmpireThemedButtonState.NORMAL, mouseOverSound=ENLIST_MOUSEOVER_SOUND, mouseExitSound=ENLIST_MOUSEEXIT_SOUND) 128 self.enlistButton.OnClick = self.Enlist 129 130 def SetEnlistButtonDecoration(self): 131 if not self.enlistButtonDecoration: 132 width, height = GetEmpireThemedDecorationSize() 133 enlistButtonDecorationContainer = Container(name='EnlistButtonDecoration_Container', parent=self.buttonContainer, align=uiconst.TOTOP_NOPUSH, width=width, height=height, top=-GetSealHeight(), state=uiconst.UI_DISABLED) 134 self.enlistButtonDecoration = EmpireThemedDecoration(name='EnlistButtonDecoration', parent=enlistButtonDecorationContainer, align=uiconst.CENTERTOP, width=width, height=height, flareSoundIntro=ENLIST_FLARE_SOUND_INTRO) 135 enlistButtonState = EmpireThemedButtonState.NORMAL 136 self.enlistButtonDecoration.UpdateDecoration(self.raceID, enlistButtonState) 137 138 def UpdateTechnologyView(self): 139 if self.isUpdatingTechView: 140 return 141 self.isUpdatingTechView = True 142 self._SetLastViewedTech() 143 technology = self.technologies.GetTech(self.techOrder) 144 self.SetEnlistButtonDecoration() 145 self.SetEnlistButton() 146 self.SetTechNavigation() 147 techExampleOrder = DEFAULT_TECH_EXAMPLE 148 if self.techView: 149 techExampleOrder = getattr(self.techView, 'techExampleOrder', DEFAULT_TECH_EXAMPLE) 150 self.ClearUIElement(self.techView) 151 techStepOrder = technology.GetTechStepOrder() 152 techViewClass = TECH_ORDER_TO_VIEW[techStepOrder] 153 self.techView = techViewClass(name='techView%d' % self.techOrder, parent=self, align=uiconst.ANCH_TOPLEFT, width=self.width, height=self.height - self.padTop, raceID=self.raceID, technology=technology, techExampleOrder=techExampleOrder, internalPadTop=GetBannerHeaderHeight()) 154 self.isUpdatingTechView = False 155 156 def SetRace(self, raceID): 157 super(EmpireTechnologiesView, self).SetRace(raceID) 158 uicore.layer.charactercreation.controller.raceID = self.raceID 159 if self.techView: 160 self.UpdateTechnologyView() 161 162 def SetTech(self, techOrder): 163 if techOrder != self.techOrder: 164 self.technologyViewsTracker.mark_technology_switch_as_discovered() 165 self.SetTechAuto(techOrder) 166 167 def SetTechAuto(self, techOrder): 168 if techOrder == self.techOrder: 169 return 170 self.techOrder = techOrder 171 self.PlayIntroSound() 172 if self.techView: 173 self.UpdateTechnologyView() 174 175 def PlayIntroSound(self): 176 technology = self.technologies.GetTech(self.techOrder) 177 techStepOrder = technology.GetTechStepOrder() 178 self.audioSvc.SendUIEvent('es_screen_2_%d_play' % techStepOrder) 179 180 def ClearUIElement(self, uiElement): 181 if uiElement and not uiElement.destroyed: 182 uiElement.Close() 183 184 def UpdateLayout(self, width, height): 185 if width != self.width or height != self.height: 186 self.width = width 187 self.height = height 188 self.UpdateTechnologyView() 189 190 def _GetTechNavigationWidth(self): 191 numberOfTechs = self.technologies.GetNumberOfTechs() 192 arrowsWidth = 2 * GetTechNavArrowSize() + 2 * GetTechNavArrowSpacingSize() 193 buttonsWidth = GetTechNavButtonSizeLarge() + max(0, numberOfTechs - 1) * GetTechNavButtonSizeSmall() 194 return arrowsWidth + buttonsWidth