proximitylockcontroller.py (3786B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\spacecomponents\proximitylockcontroller.py 2 import blue 3 import localization 4 from carbon.common.lib.const import SEC 5 from eve.client.script.spacecomponents.countercontroller import BaseCounterController 6 from spacecomponents.client.messages import MSG_ON_PROXIMITY_LOCK_TIMER_UPDATED 7 from spacecomponents.common.componentConst import PROXIMITY_LOCK_CLASS 8 COLOR_TIMER = (0.6, 0.1, 0.0, 1.0) 9 LABEL_UNLOCKING = 'UI/Inflight/SpaceComponents/ProximityLock/Unlocking' 10 LABEL_CONTESTED = 'UI/Inflight/SpaceComponents/ProximityLock/Contested' 11 SOUND_END = 'counter_proximity_lock_end_play' 12 SOUND_PAUSED = 'counter_proximity_lock_paused_play' 13 SOUND_RESUMED = 'counter_proximity_lock_resumed_play' 14 SOUND_START = 'counter_proximity_lock_start_play' 15 16 class ProximityLockCounterController(BaseCounterController): 17 __componentClass__ = PROXIMITY_LOCK_CLASS 18 __counterColor__ = COLOR_TIMER 19 __counterLabel__ = LABEL_UNLOCKING 20 __timerFunc__ = blue.os.GetSimTime 21 __countsDown__ = True 22 __soundFinishedEvent__ = SOUND_END 23 24 def __init__(self, *args): 25 super(ProximityLockCounterController, self).__init__(*args) 26 self._unlocks_at = None 27 self.paused_at = None 28 self.duration = None 29 self.subscribe(MSG_ON_PROXIMITY_LOCK_TIMER_UPDATED, self.UpdateTimerState) 30 31 @property 32 def unlocks_at(self): 33 if self.is_paused: 34 time_remaining = self._unlocks_at - self.paused_at 35 return self.get_current_time() + time_remaining 36 else: 37 return self._unlocks_at 38 39 @unlocks_at.setter 40 def unlocks_at(self, unlocks_at): 41 self._unlocks_at = unlocks_at 42 43 @property 44 def is_paused(self): 45 return self.paused_at is not None 46 47 def on_finished(self): 48 self.RemoveTimer() 49 50 def on_paused(self): 51 if self.timer is None: 52 self.AddTimer(self.unlocks_at, self.duration / SEC) 53 self.timer.SetExpiryTime(self.unlocks_at, self.duration, timerPaused=self.paused_at) 54 PlaySound(SOUND_PAUSED) 55 56 def on_resumed(self): 57 if self.timer is None: 58 self.AddTimer(self.unlocks_at, self.duration / SEC) 59 else: 60 self.timer.SetExpiryTime(self.unlocks_at, self.duration) 61 PlaySound(SOUND_RESUMED) 62 63 def on_started(self): 64 if not self.timer: 65 self.AddTimer(self.unlocks_at, self.duration / SEC) 66 PlaySound(SOUND_START) 67 68 def get_current_time(self): 69 return self.__timerFunc__() 70 71 def subscribe(self, message_type, callback): 72 self.componentRegistry.SubscribeToItemMessage(self.itemID, message_type, callback) 73 74 @property 75 def endTime(self): 76 endTime = self.unlocks_at 77 if endTime is None: 78 endTime = 0 79 return endTime 80 81 @endTime.setter 82 def endTime(self, endTime): 83 self.unlocks_at = endTime 84 85 def UpdateTimerState(self, instance, _): 86 if instance.time_remaining is None: 87 return 88 self.duration = instance.duration 89 self.paused_at = instance.paused_at 90 self.unlocks_at = self.get_current_time() + instance.time_remaining 91 if self.is_paused: 92 self.on_paused() 93 elif instance.time_remaining == instance.attributes.durationSeconds * SEC: 94 self.on_started() 95 elif not self.is_paused: 96 self.on_resumed() 97 else: 98 self.on_finished() 99 100 def GetCounterLabel(self): 101 if self.is_paused: 102 return localization.GetByLabel(LABEL_CONTESTED) 103 else: 104 return super(ProximityLockCounterController, self).GetCounterLabel() 105 106 107 def PlaySound(sound_event): 108 sm.GetService('audio').SendUIEvent(sound_event)