dockingHeroNotificationService.py (8606B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\view\dockingHeroNotificationService.py 2 import datetime 3 import gametime 4 import langutils 5 import localization 6 import uthread2 7 import weakref 8 from carbon.client.script.environment.AudioUtil import PlaySound 9 from carbon.common.script.sys.service import Service 10 from carbon.common.script.sys.serviceManager import ServiceManager 11 from carbonui import fontconst, TextColor, uiconst 12 from carbonui.uianimations import animations 13 from eve.client.script.ui.control.eveLabel import Label 14 from eve.client.script.ui.heronotification.animation import garble_reveal_label 15 from eve.client.script.ui.heronotification.golden import GoldenPositionContainerAutoSize 16 from eve.client.script.ui.heronotification.video import LoopPolicy, SegmentedVideoHeroNotification 17 from eve.client.script.ui.view.viewStateConst import ViewState 18 DOCKING_HERO_NOTIFICATION_PRIORITY = 100 19 20 class DockingHeroNotificationService(Service): 21 __guid__ = 'svc.dockingHeroNotification' 22 __servicename__ = 'dockingHeroNotification' 23 __startupdependencies__ = ('heroNotification',) 24 __notifyevents__ = ('OnDockingAccepted', 'OnUndockingAborted', 'OnUndockingStarted', 'OnViewLoaded') 25 26 def __init__(self): 27 self._active_notification_cancellation_tokens = weakref.WeakSet() 28 super(DockingHeroNotificationService, self).__init__() 29 30 def GetHeroNotificationPriority(self): 31 return DOCKING_HERO_NOTIFICATION_PRIORITY 32 33 def OnDockingAccepted(self, location_id): 34 self._show_docking_hero_notification() 35 36 def OnUndockingAborted(self, location_id): 37 self._cancel_active_and_pending_hero_notifications() 38 39 def OnUndockingStarted(self, location_id): 40 self._show_undocking_hero_notification() 41 42 def OnViewLoaded(self, from_view, to_view): 43 if to_view.name != from_view.name: 44 self._cancel_active_and_pending_hero_notifications() 45 46 def _show_docking_hero_notification(self): 47 cancellation_token = self.heroNotification.play(create_animation(text=localization.GetByLabel('UI/Inflight/Messages/Docking'), letter_space=get_docking_letter_space(), loop_policy=DockingLoopPolicy()), priority=DOCKING_HERO_NOTIFICATION_PRIORITY) 48 self._active_notification_cancellation_tokens.add(cancellation_token) 49 50 def _show_undocking_hero_notification(self): 51 cancellation_token = self.heroNotification.play(create_animation(text=localization.GetByLabel('UI/Station/Undocking'), letter_space=get_undocking_letter_space(), loop_policy=UndockingLoopPolicy()), priority=DOCKING_HERO_NOTIFICATION_PRIORITY) 52 self._active_notification_cancellation_tokens.add(cancellation_token) 53 54 def _cancel_active_and_pending_hero_notifications(self): 55 while self._active_notification_cancellation_tokens: 56 self._active_notification_cancellation_tokens.pop().cancel() 57 58 59 LETTER_SPACE_DEFAULT = 10 60 DOCKING_LETTER_SPACE_BY_LANGUAGE_ID = {langutils.LANG_FR: 6, 61 langutils.LANG_RU: 4} 62 63 def get_docking_letter_space(): 64 return DOCKING_LETTER_SPACE_BY_LANGUAGE_ID.get(langutils.get_session_language(), LETTER_SPACE_DEFAULT) 65 66 67 UNDOCKING_LETTER_SPACE_BY_LANGUAGE_ID = {langutils.LANG_DE: 4, 68 langutils.LANG_ES: 4, 69 langutils.LANG_FR: 8, 70 langutils.LANG_RU: 4} 71 72 def get_undocking_letter_space(): 73 return UNDOCKING_LETTER_SPACE_BY_LANGUAGE_ID.get(langutils.get_session_language(), LETTER_SPACE_DEFAULT) 74 75 76 class DockingLoopPolicy(LoopPolicy): 77 __notifyevents__ = ('OnDockingFinished', 'OnViewLoaded') 78 SCENE_LOADING_TIMEOUT = datetime.timedelta(seconds=30) 79 LOOPING_TIMEOUT = datetime.timedelta(minutes=1) 80 81 def __init__(self): 82 self._view_loaded = False 83 self._docking_finished = False 84 self._docking_finished_at = None 85 self._looping_started_at = None 86 super(DockingLoopPolicy, self).__init__() 87 ServiceManager.Instance().RegisterNotify(self) 88 89 def should_stop(self): 90 now = gametime.now() 91 return self._view_loaded or self._docking_finished and now - self._docking_finished_at > self.SCENE_LOADING_TIMEOUT or self._looping_started_at is not None and now - self._looping_started_at > self.LOOPING_TIMEOUT 92 93 def on_start_looping(self): 94 self._looping_started_at = gametime.now() 95 view_state_service = ServiceManager.Instance().GetService('viewState') 96 active_view = view_state_service.GetPrimaryView().name 97 if active_view in (ViewState.Hangar, ViewState.Structure): 98 self._view_loaded = True 99 100 def dispose(self): 101 ServiceManager.Instance().UnregisterNotify(self) 102 103 def OnDockingFinished(self, location_id): 104 self._docking_finished = True 105 self._docking_finished_at = gametime.now() 106 107 def OnViewLoaded(self, from_view, to_view): 108 if to_view.name in (ViewState.Hangar, ViewState.Structure): 109 self._view_loaded = True 110 111 112 class UndockingLoopPolicy(LoopPolicy): 113 __notifyevents__ = ('OnUndockingAborted', 'OnUndockingCompleted', 'OnUndockingStarted', 'OnViewLoaded') 114 SCENE_LOADING_TIMEOUT = datetime.timedelta(seconds=30) 115 LOOPING_TIMEOUT = datetime.timedelta(minutes=1) 116 117 def __init__(self): 118 self._aborted = False 119 self._undocking_completed = False 120 self._undocking_completed_at = None 121 self._in_space_scene_loaded = False 122 self._looping_started_at = None 123 self._looping_finished = False 124 ServiceManager.Instance().RegisterNotify(self) 125 126 def dispose(self): 127 ServiceManager.Instance().UnregisterNotify(self) 128 129 def should_stop(self): 130 now = gametime.now() 131 return self._aborted or self._in_space_scene_loaded or self._undocking_completed and now - self._undocking_completed_at > self.SCENE_LOADING_TIMEOUT or self._looping_started_at is not None and now - self._looping_started_at > self.LOOPING_TIMEOUT 132 133 def on_start_looping(self): 134 self._looping_started_at = gametime.now() 135 view_state_service = ServiceManager.Instance().GetService('viewState') 136 active_view = view_state_service.GetPrimaryView().name 137 if active_view == ViewState.Space: 138 self._in_space_scene_loaded = True 139 140 def on_loop_finished(self): 141 self._looping_finished = True 142 143 def OnUndockingAborted(self, location_id): 144 self._aborted = True 145 146 def OnUndockingCompleted(self, location_id): 147 self._undocking_completed = True 148 self._undocking_completed_at = gametime.now() 149 150 def OnUndockingStarted(self, location_id): 151 if not self._looping_finished: 152 self._aborted = False 153 154 def OnViewLoaded(self, from_view, to_view): 155 if to_view.name == ViewState.Space: 156 self._in_space_scene_loaded = True 157 158 159 def play_intro_sound(): 160 PlaySound('docking_overlay_start_play') 161 162 163 def play_loop_sound(): 164 PlaySound('docking_overlay_waiting_play') 165 166 167 def play_outro_sound(): 168 PlaySound('docking_overlay_waiting_stop') 169 PlaySound('docking_overlay_end_play') 170 PlaySound('docking_overlay_outro_play') 171 172 173 def create_animation(text, letter_space, loop_policy): 174 175 def animation(parent, cancellation_token): 176 container = GoldenPositionContainerAutoSize(parent=parent, alignMode=uiconst.CENTER) 177 video = SegmentedVideoHeroNotification(video_intro_path='res:/UI/Texture/classes/Docking/intro.webm', video_loop_path='res:/UI/Texture/classes/Docking/loop.webm', video_outro_path='res:/UI/Texture/classes/Docking/outro.webm', video_width=860, video_height=220, loop_policy=loop_policy) 178 video_tasklet = uthread2.start_tasklet(video.play, container, cancellation_token) 179 video.on_intro_start.connect(play_intro_sound) 180 video.on_loop_start.connect(play_loop_sound) 181 video.on_outro_start.connect(play_outro_sound) 182 183 def show_main_label(): 184 main_label = Label(parent=container, align=uiconst.CENTER, top=-4, left=letter_space / 2.0, fontsize=18, fontStyle=fontconst.STYLE_HEADER, uppercase=True, letterspace=letter_space, maxLines=1, shadowOffset=(0, 0), color=TextColor.HIGHLIGHT, opacity=0.0) 185 video.wait_for_intro_start() 186 garble_reveal_label(label=main_label, text=text, step_duration=datetime.timedelta(milliseconds=50), time_offset=datetime.timedelta(milliseconds=500), opacity=TextColor.HIGHLIGHT.opacity) 187 video.wait_for_outro_start() 188 animations.FadeOut(main_label, duration=0.5, timeOffset=0.5) 189 190 main_label_tasklet = uthread2.start_tasklet(show_main_label) 191 main_label_tasklet.get() 192 video_tasklet.get() 193 194 return animation