3 protected ref
Widget m_Root;
4 protected ref
Widget m_Spacer;
5 protected ref
Widget m_VoiceContent;
6 protected ref
Widget m_NotificationContent;
11 protected float m_Width;
12 protected float m_CurrentHeight;
13 protected float m_TargetHeight;
14 protected float m_BackupPosX;
15 protected float m_BackupPosY;
18 protected bool m_OffsetEnabled;;
22 m_Root =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/new_ui/notifications/notifications.layout");
23 m_Spacer =
m_Root.FindAnyWidget(
"NotificationSpacer" );
24 m_VoiceContent =
m_Root.FindAnyWidget(
"VoiceContent" );
25 m_NotificationContent =
m_Root.FindAnyWidget(
"NotificationContent" );
33 ntfSys.m_OnNotificationAdded.Insert( AddNotification );
34 ntfSys.m_OnNotificationRemoved.Insert( RemoveNotification );
43 ntfSys.m_OnNotificationAdded.Remove( AddNotification );
44 ntfSys.m_OnNotificationRemoved.Remove( RemoveNotification );
50 Widget notification =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/new_ui/notifications/notification_element.layout", m_NotificationContent);
52 ImageWidget icon = ImageWidget.Cast( notification.FindAnyWidget(
"Image" ) );
55 if ( data.GetIcon() !=
"" )
56 icon.LoadImageFile( 0, data.GetIcon() );
57 title.SetText( data.GetTitleText() );
59 if ( data.GetDetailText() !=
"" )
61 Widget bottom_spacer = notification.FindAnyWidget(
"BottomSpacer" );
63 bottom_spacer.Show(
true);
64 detail.SetText( data.GetDetailText() );
66 bottom_spacer.Update();
67 notification.Update();
70 m_Notifications.Insert( data, notification );
76 if ( m_Notifications.Contains( data ) )
78 Widget notification = m_Notifications.Get( data );
79 m_WidgetTimers.Insert( m_WidgetTimers.Count().ToString() + data.GetTime().ToString(), notification );
80 m_Notifications.Remove( data );
85 void AddVoiceNotification(
string player,
string name)
87 if (!m_VoiceNotifications.Contains(player))
90 if (!m_WidgetTimers.Contains(player))
92 notification =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/new_ui/notifications/notification_voice_element.layout", m_VoiceContent);
96 notification = m_WidgetTimers.Get(player);
97 m_WidgetTimers.Remove(player);
98 notification.SetAlpha( 120 / 255 );
99 Widget w_c = notification.FindAnyWidget(
"Name" );
107 m_VoiceNotifications.Insert(player, notification);
109 UpdateTargetHeight();
113 void RemoveVoiceNotification(
string player )
115 if ( m_VoiceNotifications.Contains( player ) )
117 Widget notification = m_VoiceNotifications.Get( player );
118 m_WidgetTimers.Insert( player, notification );
119 m_VoiceNotifications.Remove( player );
120 UpdateTargetHeight();
124 void ClearVoiceNotifications()
126 for (
int i = 0; i < m_VoiceNotifications.Count(); i++ )
128 Widget w = m_VoiceNotifications.GetElement( i );
131 m_VoiceNotifications.Clear();
132 UpdateTargetHeight();
135 void UpdateTargetHeight()
137 m_VoiceContent.Update();
138 m_NotificationContent.Update();
142 m_Spacer.GetScreenSize(
x, m_TargetHeight );
143 m_Root.GetScreenSize( m_Width, m_CurrentHeight );
153 Widget expNotification = menu.GetLayoutRoot().FindAnyWidget(
"notification_root");
154 if (expNotification && expNotification.IsVisible())
156 if (!m_OffsetEnabled)
158 m_Root.GetPos(m_BackupPosX, m_BackupPosY);
162 expNotification.GetScreenSize(w, h);
165 m_OffsetEnabled =
true;
168 else if (m_OffsetEnabled)
170 m_Root.SetPos(m_BackupPosX, m_BackupPosY);
171 m_OffsetEnabled =
false;
176 static float m_VelArr[1];
177 void Update(
float timeslice )
182 m_Spacer.GetScreenSize(
x, m_TargetHeight );
183 bool is_near = ( m_CurrentHeight + 0.01 < m_TargetHeight || m_CurrentHeight - 0.01 > m_TargetHeight );
186 m_CurrentHeight =
Math.SmoothCD(m_CurrentHeight, m_TargetHeight, m_VelArr, 0.2, 10000, timeslice);
187 m_Root.SetSize( m_Width, m_CurrentHeight );
189 else if ( m_TargetHeight != m_CurrentHeight )
191 m_CurrentHeight = m_TargetHeight;
192 m_Root.SetSize( m_Width, m_CurrentHeight );
196 for (
int i = 0; i < m_WidgetTimers.Count(); )
198 Widget w = m_WidgetTimers.GetElement( i );
199 float new_alpha =
Math.Clamp( w.GetAlpha() - timeslice /
NotificationSystem.NOTIFICATION_FADE_TIME, 0, 1 );
202 w.SetAlpha( new_alpha );
203 Widget w_c = w.FindAnyWidget(
"TopSpacer" );
204 Widget w_c2 = w.FindAnyWidget(
"BottomSpacer" );
205 Widget w_c3 = w.FindAnyWidget(
"Title" );
206 Widget w_c4 = w.FindAnyWidget(
"Detail" );
207 Widget w_c5 = w.FindAnyWidget(
"Name" );
210 float new_alpha_cont =
Math.Clamp( w_c.GetAlpha() - timeslice /
NotificationSystem.NOTIFICATION_FADE_TIME, 0, 1 );
211 w_c.SetAlpha( new_alpha_cont );
212 w_c2.SetAlpha( new_alpha_cont );
213 w_c3.SetAlpha( new_alpha_cont );
214 w_c4.SetAlpha( new_alpha_cont );
218 float new_alpha_voice =
Math.Clamp( w_c5.GetAlpha() - timeslice /
NotificationSystem.NOTIFICATION_FADE_TIME, 0, 1 );
219 w_c5.SetAlpha(new_alpha_voice);
226 m_WidgetTimers.RemoveElement( i );
227 UpdateTargetHeight();