animatedtransmissionwindow.py (6582B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\conversations\animatedtransmissionwindow.py 2 import carbonui.const as uiconst 3 from carbonui.primitives.container import Container 4 from carbonui.primitives.fill import Fill 5 from carbonui.primitives.frame import Frame 6 from carbonui.primitives.transform import Transform 7 from carbonui.control.window import Window 8 from eve.client.script.ui.control.themeColored import FrameThemeColored 9 import log 10 from uthread2 import StartTasklet 11 from carbonui.uicore import uicore 12 OUT_TRANSFORM_SCALING = (1.0, 0.0) 13 IN_TRANSFORM_SCALING = (1.0, 1.0) 14 ANIMATION_TIME_SCALE = 1.0 15 FADE_IN_TRANSFORM_DURATION = 0.2 16 FADE_OUT_TRANSFORM_DURATION = 0.3 17 FADE_IN_START_FADE_VALUE = 0.2 18 FADE_IN_END_FADE_VALUE = 0.5 19 FADE_OUT_START_FADE_VALUE = 0.2 20 FADE_OUT_END_FADE_VALUE = 0.05 21 FADE_IN_START_COLOR = (1, 1, 1, 0.125) 22 FADE_IN_END_COLOR = (0, 0, 0, 0.25) 23 FADE_OUT_START_COLOR = (0, 0, 0, 0.1) 24 FADE_OUT_END_COLOR = (1, 1, 1, 0.1) 25 26 class WindowTransition(Container): 27 default_align = uiconst.TOPLEFT 28 29 def ApplyAttributes(self, attributes): 30 Container.ApplyAttributes(self, attributes) 31 Frame(bgParent=self, color=(1, 1, 1, 0.1)) 32 self.cornerPoints = FrameThemeColored(name='bgFrame', colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, bgParent=self, texturePath='res:/UI/Texture/Shared/windowFrame.png', cornerSize=10, fillCenter=False, padding=1, opacity=0.5) 33 self.whiteFill = Fill(bgParent=self, color=(1, 1, 1, 0)) 34 35 def Close(self): 36 self.cornerPoints.Close() 37 self.whiteFill.Close() 38 super(WindowTransition, self).Close() 39 40 41 class AnimatedWindowFadeState: 42 DEFAULT_FADE_STATE = 1 43 FADING_IN = 2 44 FADING_OUT = 3 45 46 47 class AnimatedTransmissionWindow(Window): 48 _transmission_sound_effect = None 49 _transmission_sound_duration_seconds = 2.0 50 default_isOverlayed = True 51 52 def ApplyAttributes(self, attributes): 53 self.transform = None 54 Window.ApplyAttributes(self, attributes) 55 self.is_processing = True 56 self.time_scale = ANIMATION_TIME_SCALE 57 self.fade_state = AnimatedWindowFadeState.DEFAULT_FADE_STATE 58 59 def InitializeStatesAndPosition(self, *args, **kwds): 60 super(AnimatedTransmissionWindow, self).InitializeStatesAndPosition(*args, **kwds) 61 self._fade_in() 62 63 def notify_of_open(self): 64 pass 65 66 def notify_of_close(self): 67 pass 68 69 def _set_animation_transformation(self, scaling): 70 l, t, w, h = self.GetAbsolute() 71 idx = 0 72 if self.parent is not None: 73 idx = self.parent.children.index(self) 74 self.transform = Transform(parent=self.parent, state=uiconst.UI_DISABLED, align=uiconst.TOALL, scalingCenter=(float(l + w / 2) / uicore.desktop.width, float(t + h / 2) / uicore.desktop.height), scaling=scaling, idx=idx) 75 self.SetParent(self.transform) 76 self.transitionBox = WindowTransition(parent=self.transform, pos=self.pos) 77 78 def _fade_in(self): 79 if self.fade_state != AnimatedWindowFadeState.DEFAULT_FADE_STATE: 80 return 81 StartTasklet(self._play_fade_in_transition) 82 83 def _play_fade_in_transition(self): 84 try: 85 if self.transform: 86 self.transform.Close() 87 self.opacity = 0.0 88 self._set_animation_transformation(OUT_TRANSFORM_SCALING) 89 self._animate_show_static(FADE_IN_START_FADE_VALUE, FADE_IN_END_FADE_VALUE, FADE_IN_START_COLOR, FADE_IN_END_COLOR) 90 self._animate_window_fade_in_from_static() 91 self._animate_terminate_static() 92 except Exception as e: 93 log.LogException(extraText='Error playing AnimationWindow fade in animation', exc=e) 94 finally: 95 self.is_processing = False 96 97 def Close(self, *args, **kwargs): 98 if self.is_processing: 99 return 100 if self.IsMinimized(): 101 self.close_window() 102 else: 103 self.is_processing = True 104 self._fade_out_and_close() 105 106 def close_window(self): 107 Window.Close(self) 108 if self.transform: 109 self.transform.Close() 110 111 def _fade_out_and_close(self): 112 if self.fade_state != AnimatedWindowFadeState.DEFAULT_FADE_STATE: 113 return 114 StartTasklet(self._play_fade_out_transition_and_close) 115 116 def _play_fade_out_transition_and_close(self): 117 try: 118 self.fade_state = AnimatedWindowFadeState.FADING_OUT 119 self._set_animation_transformation(IN_TRANSFORM_SCALING) 120 self._animate_window_fade_to_static() 121 self._animate_show_static(FADE_OUT_START_FADE_VALUE, FADE_OUT_END_FADE_VALUE, FADE_OUT_START_COLOR, FADE_OUT_END_COLOR) 122 self._animate_terminate_window() 123 self._animate_transform_static(IN_TRANSFORM_SCALING, OUT_TRANSFORM_SCALING, FADE_OUT_TRANSFORM_DURATION, sleep=True) 124 self._animate_terminate_static() 125 except Exception as e: 126 log.LogException(extraText='Error playing AnimationWindow fadeout animation', exc=e) 127 finally: 128 self.notify_of_close() 129 self.close_window() 130 131 def _animate_window_fade_in_from_static(self): 132 uicore.animations.BlinkIn(obj=self.transitionBox.cornerPoints, loops=5, duration=0.3 * self.time_scale) 133 uicore.animations.FadeIn(obj=self, duration=0.3 * self.time_scale, sleep=True) 134 135 def _animate_window_fade_to_static(self): 136 uicore.animations.BlinkOut(self.transitionBox.cornerPoints, loops=5, duration=0.3 * self.time_scale) 137 uicore.animations.FadeOut(self, duration=0.2 * self.time_scale, sleep=True) 138 139 def _animate_show_static(self, start_fade_value, end_fade_value, start_color, end_color): 140 uicore.animations.FadeTo(obj=self.transitionBox.whiteFill, startVal=start_fade_value, endVal=end_fade_value, duration=0.1 * self.time_scale, sleep=True) 141 uicore.animations.SpColorMorphTo(obj=self.transitionBox.whiteFill, startColor=start_color, endColor=end_color, duration=0.1 * self.time_scale) 142 143 def _animate_terminate_window(self): 144 self.display = False 145 146 def _animate_transform_static(self, start_scale, end_scale, duration, sleep): 147 uicore.animations.Tr2DScaleTo(obj=self.transform, startScale=start_scale, endScale=end_scale, duration=duration * self.time_scale, sleep=sleep) 148 149 def _animate_terminate_static(self): 150 if not self.destroyed: 151 self.SetParent(uicore.layer.alwaysvisible, idx=0) 152 self.transform.Close() 153 self.fade_state = AnimatedWindowFadeState.DEFAULT_FADE_STATE