9 string m_aTextParams[4] = {
"",
"",
"",
""};
10 string m_aSubtitleParams[4] = {
"",
"",
"",
""};
12 WorldTimestamp m_fProgressStart;
13 WorldTimestamp m_fProgressEnd;
14 WorldTimestamp m_fHideTimestamp;
26 protected static const int INVALID_ID = -1;
27 protected static const float FADE_DURATION = 1;
28 protected static const ResourceName LAYOUT_NAME =
"{8EF935F196AADE33}UI/layouts/Common/PopupUI.layout";
29 protected static const int POPUP_OFFSET = 35;
34 static const float DEFAULT_DURATION = 4;
35 static const string TASKS_KEY_IMAGE_FORMAT =
"<color rgba='226, 168, 79, 200'><shadow mode='image' color='0, 0, 0' size='1' offset='1, 1' opacity = '0.5'><action name='TasksOpen'/></shadow></color>";
37 protected ref array<ref SCR_PopupMessage> m_aQueue = {};
39 protected RichTextWidget m_wPopupMsg;
40 protected RichTextWidget m_wPopupMsgSmall;
41 protected ProgressBarWidget m_wStatusProgress;
43 protected float m_fDefaultAlpha;
44 protected float m_fDefaultHorizontalOffset = -1;
46 protected bool m_bInventoryOpen;
47 protected bool m_bOffset;
49 protected IEntity m_Player;
58 BaseWorld world =
GetGame().GetWorld();
74 void Offset(
bool down)
76 if (!m_wPopupMsg || !m_wPopupMsgSmall || !m_wStatusProgress)
79 if (down == m_bOffset)
84 int offset = POPUP_OFFSET;
89 FrameSlot.SetPosY(m_wPopupMsg, FrameSlot.GetPosY(m_wPopupMsg) + offset);
90 FrameSlot.SetPosY(m_wPopupMsgSmall, FrameSlot.GetPosY(m_wPopupMsgSmall) + offset);
91 FrameSlot.SetPosY(m_wStatusProgress, FrameSlot.GetPosY(m_wStatusProgress) + offset);
95 protected void ProcessInit()
100 PlayerController pc =
GetGame().GetPlayerController();
102 if (!pc || !pc.GetControlledEntity())
105 Widget root =
GetGame().GetHUDManager().CreateLayout(LAYOUT_NAME,
EHudLayers.MEDIUM, 0);
111 GetGame().GetCallqueue().Remove(ProcessInit);
114 m_wPopupMsg = RichTextWidget.Cast(root.FindAnyWidget(
"Popup"));
115 m_wPopupMsgSmall = RichTextWidget.Cast(root.FindAnyWidget(
"PopupSmall"));
116 m_wStatusProgress = ProgressBarWidget.Cast(root.FindAnyWidget(
"Progress"));
117 m_fDefaultAlpha = m_wPopupMsg.GetColor().A();
118 m_wPopupMsg.SetVisible(
false);
119 m_wPopupMsgSmall.SetVisible(
false);
120 m_wStatusProgress.SetVisible(
false);
122 GetGame().GetCallqueue().CallLater(SetDefaultHorizontalPosition, 500);
126 if (playerController)
127 playerController.m_OnControlledEntityChanged.Insert(RefreshInventoryInvoker);
136 MapConfiguration config = mapEntity.GetMapConfig();
141 Widget mapWidget = config.RootWidgetRef;
144 root.SetZOrder(mapWidget.GetZOrder() - 1);
149 protected void RefreshInventoryInvoker(IEntity previousPlayer, IEntity currentPlayer)
151 SCR_InventoryStorageManagerComponent inventory;
155 inventory = SCR_InventoryStorageManagerComponent.Cast(previousPlayer.FindComponent(SCR_InventoryStorageManagerComponent));
158 inventory.m_OnInventoryOpenInvoker.Remove(OnInventoryToggle);
164 inventory = SCR_InventoryStorageManagerComponent.Cast(currentPlayer.FindComponent(SCR_InventoryStorageManagerComponent));
170 inventory.m_OnInventoryOpenInvoker.Remove(OnInventoryToggle);
171 inventory.m_OnInventoryOpenInvoker.Insert(OnInventoryToggle);
175 void OnInventoryToggle(
bool open)
177 m_bInventoryOpen = open;
191 void PopupMsg(
string text,
float duration = DEFAULT_DURATION,
string text2 =
"",
int prio = -1,
string param1 =
"",
string param2 =
"",
string param3 =
"",
string param4 =
"",
string text2param1 =
"",
string text2param2 =
"",
string text2param3 =
"",
string text2param4 =
"",
string sound =
"",
SCR_EPopupMsgFilter category =
SCR_EPopupMsgFilter.ALL,
192 WorldTimestamp progressStart =
null,
193 WorldTimestamp progressEnd =
null
197 if (System.IsConsoleApp())
205 if ((text.IsEmpty() && text2.IsEmpty()) || duration == 0)
214 msg.m_sSubtitle = text2;
215 msg.m_fDuration = duration;
216 msg.m_iPriority = prio;
217 msg.m_sSound = sound;
218 msg.m_aTextParams = {param1, param2, param3, param4};
219 msg.m_aSubtitleParams = {text2param1, text2param2, text2param3, text2param4};
221 msg.m_fProgressStart = progressStart;
222 msg.m_fProgressEnd = progressEnd;
234 void HideCurrentMsg()
240 m_ShownMsg.m_fHideTimestamp = world.GetServerTimestamp();
244 void ChangeProgressBarFinish(WorldTimestamp progressEnd)
246 if (!m_ShownMsg || m_ShownMsg.m_fProgressEnd == 0)
250 WorldTimestamp curTime = world.GetServerTimestamp();
253 float totalTime = m_ShownMsg.m_fProgressEnd.DiffMilliseconds(m_ShownMsg.m_fProgressStart);
254 float elapsedTime = curTime.DiffMilliseconds(m_ShownMsg.m_fProgressStart);
255 float curProgress = elapsedTime / totalTime;
258 if (curProgress == 1)
261 m_ShownMsg.m_fProgressEnd = progressEnd;
264 float newRemainingTime = progressEnd.DiffMilliseconds(curTime);
265 float newTotalTime = newRemainingTime / (1 - curProgress);
266 float newElapsedTime = newTotalTime * curProgress;
267 m_ShownMsg.m_fProgressStart = curTime.PlusMilliseconds(-newElapsedTime);
270 m_wStatusProgress.SetVisible(
false);
274 protected void FadeWidget(notnull Widget widget,
bool fadeOut =
false)
276 float alpha, targetAlpha;
280 alpha = m_fDefaultAlpha;
286 targetAlpha = m_fDefaultAlpha;
289 widget.SetOpacity(alpha);
290 AnimateWidget.Opacity(widget, targetAlpha, FADE_DURATION, !fadeOut || widget.IsVisible());
298 int index = m_aQueue.Find(msg);
305 for (
int i = 0, cnt = m_aQueue.Count(); i < cnt; i++)
307 checkedMsg = m_aQueue[i];
310 if (msg.m_fDuration == -1)
312 if (checkedMsg.m_fDuration != -1 || checkedMsg.m_iPriority < msg.m_iPriority)
315 else if (checkedMsg.m_fDuration != -1 && checkedMsg.m_iPriority < msg.m_iPriority)
325 m_aQueue.Insert(msg);
327 m_aQueue.InsertAt(msg,
index);
331 m_aQueue.RemoveOrdered(
index);
335 if (m_aQueue.IsEmpty())
337 ClearEventMask(EntityEvent.FRAME);
339 else if (m_wPopupMsg)
341 if (m_aQueue[0] != m_ShownMsg)
342 ShowMsg(m_aQueue[0]);
344 SetEventMask(EntityEvent.FRAME);
351 if (msg == m_ShownMsg)
357 if (msg.m_fDuration != -1)
360 msg.m_fHideTimestamp = world.GetServerTimestamp().PlusSeconds(msg.m_fDuration);
363 m_wPopupMsg.SetTextFormat(msg.m_sText, msg.m_aTextParams[0], msg.m_aTextParams[1], msg.m_aTextParams[2], msg.m_aTextParams[3]);
364 FadeWidget(m_wPopupMsg);
366 if (!msg.m_sSubtitle.IsEmpty())
368 m_wPopupMsgSmall.SetTextFormat(msg.m_sSubtitle, msg.m_aSubtitleParams[0], msg.m_aSubtitleParams[1], msg.m_aSubtitleParams[2], msg.m_aSubtitleParams[3]);
369 FadeWidget(m_wPopupMsgSmall);
372 if (msg.m_fProgressStart != 0 && msg.m_fProgressEnd != 0)
374 m_wStatusProgress.SetMin(0);
375 m_wStatusProgress.SetMax(msg.m_fProgressEnd.DiffMilliseconds(msg.m_fProgressStart));
376 m_wStatusProgress.SetVisible(
false);
377 FadeWidget(m_wStatusProgress);
380 if (!msg.m_sSound.IsEmpty())
389 if (msg == m_ShownMsg)
393 FadeWidget(m_wPopupMsg,
true);
394 FadeWidget(m_wPopupMsgSmall,
true);
395 FadeWidget(m_wStatusProgress,
true);
402 void SetDefaultHorizontalPosition()
405 m_wPopupMsg.GetScreenPos(x, y);
406 m_fDefaultHorizontalOffset = y;
410 override void EOnFrame(IEntity owner,
float timeSlice)
415 if (m_bInventoryOpen)
417 m_wPopupMsg.SetVisible(
false);
418 m_wPopupMsgSmall.SetVisible(
false);
419 m_wStatusProgress.SetVisible(
false);
423 BaseWorld world =
GetGame().GetWorld();
429 WorldTimestamp curTime = chimWorld.GetServerTimestamp();
430 if (m_ShownMsg.m_fHideTimestamp != 0 && curTime.GreaterEqual(m_ShownMsg.m_fHideTimestamp))
436 if (m_ShownMsg.m_sText && !m_wPopupMsg.IsVisible())
437 m_wPopupMsg.SetVisible(
true);
439 if (m_ShownMsg.m_sSubtitle && !m_wPopupMsgSmall.IsVisible())
440 m_wPopupMsgSmall.SetVisible(
true);
442 if (m_ShownMsg.m_fProgressEnd.Greater(curTime))
444 if (!m_wStatusProgress.IsVisible())
446 m_wStatusProgress.SetVisible(
true);
447 m_wStatusProgress.SetMin(0);
448 m_wStatusProgress.SetMax(m_ShownMsg.m_fProgressEnd.DiffMilliseconds(m_ShownMsg.m_fProgressStart));
451 m_wStatusProgress.SetCurrent(curTime.DiffMilliseconds(m_ShownMsg.m_fProgressStart));
453 else if (m_wStatusProgress.IsVisible())
455 m_wStatusProgress.SetVisible(
false);
462 SetFlags(EntityFlags.NO_TREE | EntityFlags.NO_LINK);
465 if (System.IsConsoleApp())
469 GetGame().GetCallqueue().Remove(ProcessInit);
470 GetGame().GetCallqueue().CallLater(ProcessInit, 1000,
true);
477 m_wPopupMsg.GetParent().RemoveFromHierarchy();
481 GetGame().GetCallqueue().Remove(ProcessInit);