empireStepContainer.py (13455B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation\empireStepContainer.py 2 import random 3 import carbonui.const as uiconst 4 from carbonui.primitives.container import Container 5 from carbonui.primitives.sprite import Sprite 6 from carbonui.uianimations import animations 7 from carbonui.uicore import uicore 8 import charactercreator.client.scalingUtils as ccScalingUtils 9 import eve.client.script.ui.login.charcreation.ccUtil as ccUtil 10 from eve.client.script.ui.login.charcreation.empireui.empireBanner import EmpireBanner, BannerHeader 11 from eve.client.script.ui.login.charcreation.empireui.empireBanner import CURVED_GRADIENT_TEXTURE_BASE, CURVED_GRADIENT_OPACITY 12 from eve.common.lib import appConst 13 from localization import GetByLabel 14 from math import pi 15 from uthread2 import call_after_wallclocktime_delay, StartTasklet 16 from characterdata.races import CHARACTER_CREATION_RACE_IDS 17 HORIZONTAL_BANNER_FRAME = 'res:/UI/Texture/classes/EmpireSelection/panelSideDeco.png' 18 HORIZONTAL_BANNER_OPACITY = 0.3 19 EMPIRE_STEP_BANNER_HEADER_LABEL = 'UI/CharacterCreation/ChooseEmpire' 20 FORCE_TERMINATE_ANIMATION_SECS = 1.0 21 ANIMATION_THREAD_WAIT_MSECS = 100 22 PLAY_SOUNDS_ON_HOVER_DELAY_SECS = 0.1 23 FLARE_SOUND_PLAY = 'ui_es_enlist_flare_play' 24 FLARE_SOUND_STOP = 'ui_es_enlist_flare_stop' 25 BANNER_OPACITY_LIGHT = 1.0 26 BANNER_OPACITY_DARK = 0.3 27 BANNER_OPACITY_CHANGE_DURATION_SECS = 0.5 28 BANNER_FADEOUT_DURATION_SECS = 1.0 29 30 class EmpireBannerAnimationType: 31 MOUSE_ENTER = 1 32 MOUSE_EXIT = 2 33 MOUSE_CLICK = 3 34 35 36 class EmpireStepContainer(Container): 37 38 def ApplyAttributes(self, attributes): 39 super(EmpireStepContainer, self).ApplyAttributes(attributes) 40 self.step = attributes.step 41 self.expandedRace = None 42 self.currentAnimation = None 43 self.processingAnimation = None 44 self.nextAnimation = None 45 self.isSelectingRace = False 46 self.bannerFadeTasklet = None 47 self.audioSvc = sm.GetService('audio') 48 self.ConstructContents() 49 self.PlayNoRaceMusic() 50 51 def Close(self): 52 if self.bannerFadeTasklet is not None: 53 self.bannerFadeTasklet.kill() 54 self.bannerFadeTasklet = None 55 super(EmpireStepContainer, self).Close() 56 57 def PlayNoRaceMusic(self): 58 self.audioSvc.SendUIEvent('music_switch_race_norace') 59 60 def ConstructContents(self): 61 info = self.step.GetInfo() 62 self.empireBanners = [] 63 self.header = BannerHeader(name='empireStepBannerHeader', parent=self, align=uiconst.TOTOP, width=self.width, height=ccScalingUtils.GetBannerHeaderHeight(), text=GetByLabel(EMPIRE_STEP_BANNER_HEADER_LABEL)) 64 self.buttonCont = Container(parent=self, name='buttonContainer', align=uiconst.CENTER, pos=(0, 65 0, 66 ccScalingUtils.GetBannersWidth(), 67 ccScalingUtils.GetBannerHeight()), top=ccScalingUtils.GetBannerHeaderHeight()) 68 self.bannersContainer = Container(parent=self.buttonCont, name='bannersContainer', align=uiconst.CENTER, width=ccScalingUtils.GetBannersWidth(), height=ccScalingUtils.GetBannerHeight()) 69 padLeft = 0 70 races = CHARACTER_CREATION_RACE_IDS 71 random.shuffle(races) 72 for raceID in races: 73 factionID = appConst.factionByRace[raceID] 74 isDisabled = ccUtil.IsFactionSelectionDisabled(factionID) 75 banner = EmpireBanner(name='empireBanner', parent=self.bannersContainer, width=ccScalingUtils.GetBannerWidth(), height=ccScalingUtils.GetBannerHeight(), align=uiconst.TOLEFT, padLeft=padLeft, raceID=raceID, animationEnder=self.OnAnimationEnded, bannerEnterer=self.OnBannerEntered, bannerClicker=self.OnBannerClicked, bannerExiter=self.OnBannerExited, isDisabled=isDisabled) 76 self.empireBanners.append(banner) 77 padLeft = ccScalingUtils.BANNER_SEPARATION 78 79 if info.raceID: 80 self.raceID = info.raceID 81 self.AddViewCaps() 82 self.UpdateLayout() 83 84 def UpdateLayout(self): 85 self.TerminateAllAnimations() 86 self.height = uicore.desktop.height - ccScalingUtils.GetTopNavHeight() - ccScalingUtils.GetBottomNavHeight() 87 self.width = ccScalingUtils.GetMainPanelWidth() 88 self._UpdateHeader() 89 self._UpdateViewCaps() 90 if self.expandedRace: 91 self._UpdateExpandedBannerLayout() 92 else: 93 self._UpdateLayoutButtons() 94 for child in self.children: 95 if hasattr(child, 'UpdateLayout'): 96 child.UpdateLayout() 97 98 def _UpdateLayoutButtons(self): 99 self._UpdateLayoutButtonContainer() 100 self._UpdateLayoutBannersContainer() 101 self._UpdateLayoutBanners() 102 103 def _UpdateHeader(self): 104 self.header.height = ccScalingUtils.GetBannerHeaderHeight() 105 self.header.ResizeContent() 106 107 def _UpdateViewCaps(self): 108 width = ccScalingUtils.GetMainPanelWidth() 109 height = ccScalingUtils.GetBannerHeaderHeight() 110 self.topViewCap.width = width 111 self.topViewCap.height = height 112 self.topViewCap.top = -height 113 self.bottomViewCap.width = width 114 self.bottomViewCap.height = height 115 116 def _UpdateExpandedBannerLayout(self): 117 bannerWidth = ccScalingUtils.GetMainPanelWidth() 118 bannerHeight = ccScalingUtils.GetMainPanelHeight() 119 self.bannersContainer.width = bannerWidth 120 self.bannersContainer.height = bannerHeight 121 for banner in self.empireBanners: 122 banner.Resize(bannerWidth, bannerHeight) 123 124 def _UpdateLayoutButtonContainer(self): 125 bannersWidthExpanded = ccScalingUtils.GetBannersWidth() 126 bannersHeightExpanded = ccScalingUtils.GetBannerHeight() 127 self.buttonCont.pos = (0, 128 ccScalingUtils.GetBannerHeaderHeight(), 129 bannersWidthExpanded, 130 bannersHeightExpanded) 131 132 def _UpdateLayoutBannersContainer(self): 133 bannersWidth = ccScalingUtils.GetBannersWidth() 134 bannersHeight = ccScalingUtils.GetBannerHeight() 135 self.bannersContainer.width = bannersWidth 136 self.bannersContainer.height = bannersHeight 137 138 def _UpdateLayoutBanners(self): 139 bannerWidth = ccScalingUtils.GetBannerWidth() 140 bannerHeight = ccScalingUtils.GetBannerHeight() 141 for banner in self.empireBanners: 142 banner.width = bannerWidth 143 banner.height = bannerHeight 144 banner.ResizeContents(bannerWidth, bannerHeight) 145 146 self.OnBannerExited() 147 148 def ExpandRace(self, raceID): 149 self.TerminateAllAnimations() 150 self.expandedRace = raceID 151 self.bannersContainer.width = ccScalingUtils.GetMainPanelWidth() 152 self.bannersContainer.height = ccScalingUtils.GetMainPanelHeight() 153 for banner in self.empireBanners: 154 banner.padLeft = 0 155 if banner.raceID != raceID: 156 banner.Hide() 157 else: 158 banner.Show() 159 banner.Expand() 160 161 self.buttonCont.state = uiconst.UI_DISABLED 162 self.header.Hide() 163 164 def OnAnimationEnded(self, raceID): 165 if self.processingAnimation and raceID in self.processingAnimation: 166 self.processingAnimation[raceID] = None 167 if not self.processingAnimation or not any(self.processingAnimation.values()): 168 self.processingAnimation = None 169 170 def OnBannerEntered(self, raceID): 171 if self.isSelectingRace: 172 return 173 animation = {} 174 for banner in self.empireBanners: 175 if banner.raceID == raceID: 176 animation[banner.raceID] = EmpireBannerAnimationType.MOUSE_ENTER 177 else: 178 animation[banner.raceID] = EmpireBannerAnimationType.MOUSE_EXIT 179 180 self.nextAnimation = animation 181 self.TriggerAnimation() 182 183 def OnBannerExited(self): 184 if self.isSelectingRace: 185 return 186 animation = {} 187 for banner in self.empireBanners: 188 animation[banner.raceID] = EmpireBannerAnimationType.MOUSE_EXIT 189 190 self.nextAnimation = animation 191 self.TriggerAnimation() 192 193 def TriggerAnimation(self): 194 StartTasklet(self.ProcessAnimations) 195 196 def TerminateAllAnimations(self): 197 self.currentAnimation = None 198 self.processingAnimation = None 199 self.nextAnimation = None 200 self.StopFlareSound() 201 202 def TerminateAnimation(self, animation): 203 if self.processingAnimation == animation: 204 self.processingAnimation = None 205 self.StopFlareSound() 206 207 def ProcessAnimations(self): 208 if self.nextAnimation: 209 self.currentAnimation = self.nextAnimation 210 self.nextAnimation = None 211 call_after_wallclocktime_delay(self.TerminateAnimation, FORCE_TERMINATE_ANIMATION_SECS, self.currentAnimation) 212 self.ProcessAnimation() 213 214 def ProcessAnimation(self): 215 animationToProcess = {} 216 enteredBannerRaceID = None 217 isClickAnimation = False 218 for banner in self.empireBanners: 219 raceID = banner.raceID 220 if raceID in self.currentAnimation: 221 animationType = self.currentAnimation[raceID] 222 if animationType == EmpireBannerAnimationType.MOUSE_ENTER: 223 banner.AnimateEntered() 224 call_after_wallclocktime_delay(banner.PlaySoundsOnEntered, PLAY_SOUNDS_ON_HOVER_DELAY_SECS) 225 enteredBannerRaceID = raceID 226 elif animationType == EmpireBannerAnimationType.MOUSE_EXIT: 227 banner.AnimateExited() 228 elif animationType == EmpireBannerAnimationType.MOUSE_CLICK: 229 self.AnimateClick(raceID) 230 isClickAnimation = True 231 animationToProcess[raceID] = animationType 232 233 self.processingAnimation = animationToProcess 234 self.currentAnimation = None 235 if isClickAnimation: 236 self.TerminateAllAnimations() 237 return 238 self.AnimateBannerOpacityChange(enteredBannerRaceID) 239 if enteredBannerRaceID is None: 240 self.StopFlareSound() 241 else: 242 call_after_wallclocktime_delay(self.PlayFlareSound, PLAY_SOUNDS_ON_HOVER_DELAY_SECS) 243 244 def AnimateBannerOpacityChange(self, enteredBannerRaceID): 245 animation = animations.MorphScalar 246 for banner in self.empireBanners: 247 duration = BANNER_OPACITY_CHANGE_DURATION_SECS 248 oldOpacity = banner.opacity 249 showLightOpacity = enteredBannerRaceID is None or banner.raceID == enteredBannerRaceID 250 newOpacity = BANNER_OPACITY_LIGHT if showLightOpacity else BANNER_OPACITY_DARK 251 animation(banner, 'opacity', startVal=oldOpacity, endVal=newOpacity, duration=duration) 252 253 def PlayFlareSound(self): 254 self.audioSvc.SendUIEvent(FLARE_SOUND_PLAY) 255 256 def StopFlareSound(self): 257 self.audioSvc.SendUIEvent(FLARE_SOUND_STOP) 258 259 def ShowBackgroundBanner(self, raceID): 260 self.Flush() 261 self.ConstructContents() 262 self.ExpandRace(raceID) 263 264 def SetTitle(self, text): 265 for banner in self.empireBanners: 266 banner.ConstructHeader(text) 267 268 def AddViewCaps(self): 269 width = ccScalingUtils.GetMainPanelWidth() 270 height = ccScalingUtils.GetBannerHeaderHeight() 271 texturePath = CURVED_GRADIENT_TEXTURE_BASE 272 self.topViewCap = Sprite(name='topViewCap', parent=self, align=uiconst.TOTOP_NOPUSH, texturePath=texturePath, state=uiconst.UI_DISABLED, width=width, height=height, top=-height, rotation=pi, opacity=0.0) 273 self.bottomViewCap = Sprite(name='bottomViewCap', parent=self, align=uiconst.TOBOTTOM_NOPUSH, texturePath=texturePath, state=uiconst.UI_DISABLED, width=width, height=height, rotation=0.0, opacity=0.0) 274 275 def ShowViewCaps(self): 276 self.topViewCap.opacity = CURVED_GRADIENT_OPACITY 277 self.bottomViewCap.opacity = CURVED_GRADIENT_OPACITY 278 279 def HideViewCaps(self): 280 self.topViewCap.opacity = 0.0 281 self.bottomViewCap.opacity = 0.0 282 283 def SetBannerCapsForMenu(self): 284 for banner in self.empireBanners: 285 banner.ShowTopBlackGradient() 286 banner.ShowBottomPanelCap() 287 banner.HideTopPanelCap() 288 289 def SetBannerCapsForView(self): 290 for banner in self.empireBanners: 291 banner.ShowTopPanelCap() 292 banner.ShowBottomPanelCap() 293 banner.HideTopBlackGradient() 294 295 def HideBannerCaps(self): 296 for banner in self.empireBanners: 297 banner.HideTopPanelCap() 298 banner.HideBottomPanelCap() 299 banner.HideTopBlackGradient() 300 301 def OnBannerClicked(self, raceID): 302 if self.isSelectingRace: 303 return 304 self.isSelectingRace = True 305 animation = {} 306 for banner in self.empireBanners: 307 if banner.raceID == raceID: 308 animation[banner.raceID] = EmpireBannerAnimationType.MOUSE_CLICK 309 310 self.nextAnimation = animation 311 self.TriggerAnimation() 312 313 def AnimateClick(self, raceID): 314 animation = animations.FadeOut 315 for banner in self.empireBanners: 316 animation(banner, duration=BANNER_FADEOUT_DURATION_SECS) 317 318 self.bannerFadeTasklet = call_after_wallclocktime_delay(self.SelectRace, BANNER_FADEOUT_DURATION_SECS, raceID) 319 320 def SelectRace(self, raceID): 321 self.bannerFadeTasklet = None 322 uicore.layer.charactercreation.controller.SelectRace(raceID) 323 self.isSelectingRace = False