Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_UITaskManagerComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Tasks", description: "This is a task manager related component that allows you to display the available tasks.", color: "0 0 255 255")]
2 class SCR_UITaskManagerComponentClass : ScriptComponentClass
3 {
4 }
5 
7 {
8  protected static const string NO_ASSIGNED_TASK = "#AR-Tasks_NoAssignedTaskTitle";
9  protected static const string ASSIGN_TASK_HINT = "#AR-Tasks_NoAssignedTaskDescription";
10 
11  protected ref array<SCR_BaseTask> m_aHUDIconUpdatedTasks = {};
12 
13  static const ref ScriptInvoker s_OnTaskListVisible = new ScriptInvoker();
14 
15  protected Widget m_wWidgetToFocus = null;
16  protected Widget m_wTasksUI = null;
17  protected Widget m_wParentWidget = null;
18  protected Widget m_wUI = null;
19  protected Widget m_wTaskDetail = null;
20  protected Widget m_wExpandButton = null;
21 
24 
25  ref array<Widget> m_aWidgets = {};
26  ref map<SCR_BaseTask, TextWidget> m_mTasksTimers = new map<SCR_BaseTask, TextWidget>();
27 
28  protected bool m_bVisible;
29  protected bool m_bDetailVisible;
30  protected bool m_bPickAssigneeVisible;
31  protected bool m_bCurrentTaskVisible;
32  protected bool m_bTaskContextEnabled;
33  protected bool m_bIsUnconscious; //Character is unconscious --> Task menu control is disabled
34  protected float m_fCurrentTaskTime;
37  protected bool m_bShowSelectedTaskOnMap;
38 
39  [Attribute("{ACCF501DD69CAF7B}UI/layouts/Tasks/TaskList.layout")]
40  ResourceName m_UIResource;
41 
42  [Attribute("{EE9497AB43F556F9}UI/layouts/Tasks/CurrentTask.layout")]
43  protected ResourceName m_sCurrentTaskLayout;
44 
45  [Attribute("{728FD22A081ABB36}UI/layouts/Tasks/TaskDetail.layout")]
46  protected ResourceName m_sTaskDetailLayout;
47 
48  [Attribute("5")]
49  protected float m_fCurrentTaskShowTime;
50 
51  [Attribute("1")]
52  protected bool m_bOpenTaskListOnMapOpen;
53 
54  [Attribute("{31C4EB3D607069C2}UI/layouts/Tasks/PickAssigneeListEntry.layout")]
55  protected ResourceName m_wPlayerListEntry;
56 
57  [Attribute("0.761 0.386 0.08 1")]
58  protected ref Color m_AssignedTaskColor;
59 
60  protected Widget m_wCurrentTask;
61 
62  //------------------------------------------------------------------------------------------------
65  {
66  return s_Instance;
67  }
68 
69  //------------------------------------------------------------------------------------------------
72  {
73  return m_bVisible;
74  }
75 
76  //------------------------------------------------------------------------------------------------
78  void SetSelectedWidget(Widget w)
79  {
80  m_wWidgetToFocus = w;
81  }
82 
83  //------------------------------------------------------------------------------------------------
87  static void PanMapToTask(int taskID = -1, SCR_BaseTask task = null)
88  {
89  SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
90  if (!mapEntity || !mapEntity.IsOpen())
91  return;
92 
93  if (!task)
94  {
95  if (taskID == -1)
96  return;
97 
98  task = GetTaskManager().GetTask(taskID);
99  if (!task)
100  return;
101  }
102 
103  vector taskPos = task.GetOrigin();
104  float screenX, screenY;
105  mapEntity.WorldToScreen(taskPos[0], taskPos[2], screenX, screenY);
106  mapEntity.PanSmooth(screenX, screenY);
107 
108  }
109 
110  //------------------------------------------------------------------------------------------------
114  {
115  m_aHUDIconUpdatedTasks.RemoveItem(task);
116  task.ToggleHUDIcon(false, false);
117  }
118 
119  //------------------------------------------------------------------------------------------------
123  void KeepHUDIconUpdated(int msTime, SCR_BaseTask task)
124  {
125  if (m_aHUDIconUpdatedTasks.Find(task) != 0)
126  return;
127 
128  m_aHUDIconUpdatedTasks.Insert(task);
129  GetGame().GetCallqueue().CallLater(StopHUDIconUpdates, msTime, false, task);
130  }
131 
132  //------------------------------------------------------------------------------------------------
135  {
136  if (m_aHUDIconUpdatedTasks.Find(task) != -1)
137  m_aHUDIconUpdatedTasks.RemoveItem(task);
138  }
139 
140  //------------------------------------------------------------------------------------------------
144  void SelectTask(SCR_BaseTask task, Widget w = null)
145  {
146  m_SelectedTask = task;
147  if (task)
148  m_LastSelectedTask = task;
149  }
150 
151  //------------------------------------------------------------------------------------------------
154  {
155  return m_SelectedTask;
156  }
157 
158  //------------------------------------------------------------------------------------------------
160  Widget GetRootWidget()
161  {
162  return m_wUI;
163  }
164 
165  //------------------------------------------------------------------------------------------------
168  {
169  return m_wParentWidget;
170  }
171 
172  //------------------------------------------------------------------------------------------------
174  array<Widget> GetWidgetsArray()
175  {
176  return m_aWidgets;
177  }
178 
179  //------------------------------------------------------------------------------------------------
183  {
184  if (m_mTasksTimers)
185  m_mTasksTimers.Remove(task);
186  }
187 
188  //------------------------------------------------------------------------------------------------
192  void RegisterTimer(SCR_BaseTask task, TextWidget timerWidget)
193  {
194  if (m_mTasksTimers)
195  m_mTasksTimers.Set(task, timerWidget);
196  }
197 
198  //------------------------------------------------------------------------------------------------
200  // This method is not used
201  void SetupAssigneeTexts(notnull SCR_BaseTask task, Widget parent)
202  {
203  TextWidget assigneeNames = TextWidget.Cast(parent.FindAnyWidget("TaskAssignees"));
204 
205  TextWidget assigneeTime = TextWidget.Cast(parent.FindAnyWidget("AssigneeTime"));
206  if (!assigneeTime)
207  return;
208 
209  if (task.IsIndividual())
210  {
211  if (assigneeTime)
212  {
213  RegisterTimer(task, assigneeTime);
214  assigneeTime.SetVisible(task.GetAssignee() && task.IsIndividual());
215 
216  float remainingTime = task.GetAssigneeTimeLeft();
217  string formattedTimerText = GetFormattedTimerText(remainingTime);
218  assigneeTime.SetText(formattedTimerText);
219  }
220  }
221  else
222  {
223  assigneeTime.SetVisible(false);
224  }
225 
226  if (!assigneeNames)
227  return;
228 
229  array<SCR_BaseTaskExecutor> assignees = {};
230  task.GetAssignees(assignees);
231 
232  bool hasAssignees = assignees.Count() > 0;
233  assigneeNames.SetVisible(hasAssignees);
234 
235  if (!hasAssignees)
236  return;
237 
238  string namesText = "";
239 
240  for (int i = 0, count = assignees.Count(); i < count; i++)
241  {
242  if (i > 0)
243  namesText += ", ";
244  namesText += assignees[i].GetPlayerName();
245  }
246 
247  assigneeNames.SetText(namesText);
248  }
249 
250  //------------------------------------------------------------------------------------------------
254  void GenerateUI(Widget rootWidget, SCR_BaseTask taskToFocus = null)
255  {
256  if (!GetTaskManager())
257  return;
258 
259  if (!rootWidget)
260  return;
261 
262  SCR_BaseTask locallyRequestedTask;
264  if (supportEntity)
265  locallyRequestedTask = supportEntity.GetLocallyRequestedTask();
266 
267  SCR_BaseTaskExecutor localTaskExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
268  if (!localTaskExecutor)
269  return;
270 
271  Faction faction;
272  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
273  if (factionManager)
274  faction = factionManager.GetLocalPlayerFaction();
275 
276  array<SCR_BaseTask> tasks = {};
277  GetTaskManager().GetFilteredTasks(tasks, faction);
278 
279  if (locallyRequestedTask)
280  {
281  if (!m_wWidgetToFocus)
282  m_wWidgetToFocus = locallyRequestedTask.GenerateTaskDescriptionUI(rootWidget, m_aWidgets);
283  else
284  locallyRequestedTask.GenerateTaskDescriptionUI(rootWidget, m_aWidgets);
285  }
286 
287  SCR_BaseTask locallyAssignedTask = SCR_BaseTaskExecutor.GetLocalExecutor().GetAssignedTask();
288 
289  Widget currentTaskUI;
290  foreach (SCR_BaseTask task : tasks)
291  {
292  if (!task)
293  {
294  Print("Null found in task list!", LogLevel.ERROR);
295  continue;
296  }
297 
298  if (task == locallyRequestedTask)
299  continue;
300 
301  currentTaskUI = task.GenerateTaskDescriptionUI(rootWidget, m_aWidgets);
302 
303  if (!m_wWidgetToFocus)
304  m_wWidgetToFocus = currentTaskUI;
305 
306  if (task == locallyAssignedTask)
307  {
308  RichTextWidget textWidget = RichTextWidget.Cast(currentTaskUI.FindAnyWidget("TaskTitle"));
309  textWidget.SetColor(m_AssignedTaskColor);
310  }
311 
312  if (task == taskToFocus)
313  {
314  m_wWidgetToFocus = currentTaskUI;
316  if (handler)
317  handler.SetCollapsed(false);
318  }
319  }
320 
321  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_HUD_TASK_MENU_OPEN);
322  }
323 
324  //------------------------------------------------------------------------------------------------
325  protected void GenerateRequestButtons()
326  {
327  // note: turned off now
328  return;
329  array<SCR_BaseTaskSupportEntity> supportedTasks = GetTaskManager().GetSupportedTasks();
330  if (!supportedTasks)
331  return;
332 
333  m_wParentWidget = m_wUI.FindAnyWidget("MainPanel");
334  if (!m_wParentWidget)
335  return;
336 
337  for (int i = supportedTasks.Count() - 1; i >= 0; i--)
338  {
339  supportedTasks[i].OnTaskListOpen(this);
340  }
341  }
342 
343  //------------------------------------------------------------------------------------------------
344  protected void ClearUI()
345  {
346  if (!m_aWidgets || !m_mTasksTimers)
347  return;
348 
349  m_mTasksTimers.Clear();
350 
351  foreach (Widget widget : m_aWidgets)
352  {
353  if (widget)
354  widget.RemoveFromHierarchy();
355  }
356 
357  m_aWidgets.Clear();
358  }
359 
360  //------------------------------------------------------------------------------------------------
361  override void EOnFrame(IEntity owner, float timeSlice)
362  {
363  for (int i = m_aHUDIconUpdatedTasks.Count() - 1; i >= 0; i--)
364  {
365  m_aHUDIconUpdatedTasks[i].UpdateHUDIcon();
366  }
367 
369  GetGame().GetInputManager().ActivateContext("TaskListContext");
370 
371  else if (m_bVisible)
372  {
373  if (m_MapEntity && m_MapEntity.IsOpen())
374  GetGame().GetInputManager().ActivateContext("TaskListMapContext");
375  else
376  GetGame().GetInputManager().ActivateContext("TaskListContext");
377  }
378 
380  {
381  if (m_fCurrentTaskTime > 0)
382  {
383  m_fCurrentTaskTime -= timeSlice;
384  if (m_fCurrentTaskTime < 0)
386  }
387  }
388  }
389 
390  //------------------------------------------------------------------------------------------------
393  // TODO: use SCR_DateTimeHelper
394  string GetFormattedTimerText(float time)
395  {
396  int minutes = Math.Floor(time / 60);
397  int seconds = Math.Floor(time - (minutes * 60));
398 
399  string minutesString;
400  if (minutes < 10)
401  minutesString = "0";
402  minutesString += minutes.ToString();
403 
404  string secondsString;
405  if (seconds < 10)
406  secondsString = "0";
407  secondsString += seconds.ToString();
408 
409  return minutesString + ":" + secondsString;
410  }
411 
412  //------------------------------------------------------------------------------------------------
416  {
417  return GetGame().GetWorkspace().CreateWidgets(m_sCurrentTaskLayout);
418  }
419 
420  //------------------------------------------------------------------------------------------------
424  {
425  if (!GetTaskManager())
426  return false;
427 
428  SCR_BaseTask locallyRequestedTask;
430  if (supportEntity)
431  locallyRequestedTask = supportEntity.GetLocallyRequestedTask();
432 
433  SCR_BaseTaskExecutor localTaskExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
434  if (!localTaskExecutor || !localTaskExecutor.GetAssignedTask())
435  return false;
436 
437  return true;
438  }
439 
440  //------------------------------------------------------------------------------------------------
443  void ToggleCurrentTask(bool fade = true)
444  {
446 
447  if (!m_wCurrentTask)
449 
450  SCR_BaseTaskExecutor localTaskExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
451  SCR_BaseTask assignedTask = localTaskExecutor.GetAssignedTask();
452 
453  float speed = 1;
454  float targetOpacity;
456  {
457  targetOpacity = 1;
458 
459  if (localTaskExecutor)
460  {
461  TextWidget textWidget = TextWidget.Cast(m_wCurrentTask.FindAnyWidget("TaskTitle"));
462 
463  if (assignedTask)
464  assignedTask.SetTitleWidgetText(textWidget, assignedTask.GetTaskListTaskTitle());
465  else
466  textWidget.SetTextFormat(NO_ASSIGNED_TASK);
467 
468  textWidget = TextWidget.Cast(m_wCurrentTask.FindAnyWidget("TaskDescription"));
469  if (assignedTask)
470  assignedTask.SetTitleWidgetText(textWidget, assignedTask.GetTaskListTaskText());
471  else
472  textWidget.SetTextFormat(ASSIGN_TASK_HINT);
473 
474  textWidget = TextWidget.Cast(m_wCurrentTask.FindAnyWidget("CurrentObjectiveText"));
475  if (assignedTask)
476  textWidget.SetVisible(true);
477  else
478  textWidget.SetVisible(false);
479  }
480  }
481  else
482  {
483  targetOpacity = 0;
484  }
485 
486  if (fade)
487  {
488  AnimateWidget.Opacity(m_wCurrentTask, targetOpacity, speed);
489  }
490  else
491  {
492  AnimateWidget.StopAnimation(m_wCurrentTask, WidgetAnimationOpacity);
493  m_wCurrentTask.SetOpacity(targetOpacity);
494  }
495 
497  }
498 
499  //------------------------------------------------------------------------------------------------
502  {
503  m_bPickAssigneeVisible = false;
504  GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.PickAssignee);
505  }
506 
507  //------------------------------------------------------------------------------------------------
509  void HideDetail()
510  {
511  GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.TaskDetail);
512  m_bDetailVisible = false;
513 
514  m_wUI.SetVisible(true);
515  }
516 
517  //------------------------------------------------------------------------------------------------
520  {
521  Widget pickAssigneeWidget;
522 
524  {
525  m_bPickAssigneeVisible = true;
526  MenuBase menu = GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.PickAssignee, DialogPriority.CRITICAL, 0, true);
527  pickAssigneeWidget = menu.GetRootWidget();
528  pickAssigneeWidget.SetZOrder(m_wUI.GetZOrder());
529 
530  Widget playerList = pickAssigneeWidget.FindAnyWidget("Players");
531  if (!playerList)
532  return;
533 
534  while (playerList.GetChildren())
535  {
536  playerList.RemoveChild(playerList.GetChildren());
537  }
538 
539  int entriesCount;
540  SCR_BaseTaskExecutor localExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
541  map<SCR_BaseTaskExecutor, int> taskExecutors = SCR_BaseTaskExecutor.GetTaskExecutorsMap();
542  for (int i = taskExecutors.Count() - 1; i >= 0; i--)
543  {
544  SCR_BaseTaskExecutor executor = taskExecutors.GetKey(i);
545 
546  if (executor == localExecutor)
547  continue;
548 
549  SCR_BaseTask executorTask = executor.GetAssignedTask();
550 
551  //Executor is already assigned to this task
552  if (executorTask == m_LastSelectedTask)
553  continue;
554 
555  entriesCount++;
556 
557  Widget playerEntry = playerList.GetWorkspace().CreateWidgets(m_wPlayerListEntry, playerList);
558  if (executorTask)
559  playerEntry.FindAnyWidget("IsAssigned").SetVisible(true);
560 
562  if (entryHandler)
563  entryHandler.SetExecutor(executor);
564 
565  TextWidget playerName = TextWidget.Cast(playerEntry.FindAnyWidget("PlayerName"));
566  if (playerName)
567  playerName.SetText(executor.GetPlayerName());
568  }
569 
570  if (entriesCount < 1)
572 
573  return;
574  }
575 
576  SCR_PickAssigneeDialog pickAssigneeMenu = SCR_PickAssigneeDialog.Cast(GetGame().GetMenuManager().FindMenuByPreset(ChimeraMenuPreset.PickAssignee));
577  if (!pickAssigneeMenu)
578  return;
579 
580  SCR_BaseTaskExecutor assignee = pickAssigneeMenu.GetSelectedExecutor();
581  if (!assignee)
582  return;
583 
584  m_bPickAssigneeVisible = false;
585 
587  if (taskNetworkComponent)
588  taskNetworkComponent.AssignTaskToPlayer(SCR_BaseTaskExecutor.GetLocalExecutorID(), m_LastSelectedTask.GetTaskID(), SCR_BaseTaskExecutor.GetTaskExecutorID(pickAssigneeMenu.GetSelectedExecutor()));
589 
590  GetGame().GetMenuManager().CloseMenu(pickAssigneeMenu);
591  }
592 
593  //------------------------------------------------------------------------------------------------
596  {
597  if (m_bIsUnconscious)
598  return;
599 
600  SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
601  if (mapEntity && !mapEntity.IsOpen())
602  GetGame().GetInputManager().AddActionListener("TasksClose", EActionTrigger.DOWN, Action_TasksClose);
603 
604  if (!m_bVisible)
606  else
608  }
609 
610  //------------------------------------------------------------------------------------------------
613  {
614  if (m_bIsUnconscious)
615  return;
616 
617  if (m_bVisible)
618  return;
619 
620  SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
621  if (!mapEntity || !mapEntity.IsOpen())
622  {
623  bool fade = !m_bCurrentTaskVisible;
624  ToggleCurrentTask(fade);
625  }
626  }
627 
628  //------------------------------------------------------------------------------------------------
631  {
632  m_SelectedTask = null;
633 
634  if (m_bVisible)
636 
637  GetGame().GetInputManager().RemoveActionListener("TasksClose", EActionTrigger.DOWN, Action_TasksClose);
638  }
639 
640  //------------------------------------------------------------------------------------------------
643  {
644  SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
645  if (!mapEntity)
646  return;
647 
648  if (m_bDetailVisible)
649  HideDetail();
650 
651  if (!mapEntity.IsOpen())
652  {
653  IEntity player = SCR_PlayerController.GetLocalControlledEntity();
654  if (!player)
655  return;
656 
657  SCR_GadgetManagerComponent gadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(player);
658  if (!gadgetManager)
659  return;
660 
661  IEntity mapGadget = gadgetManager.GetGadgetByType(EGadgetType.MAP);
662  if (!mapGadget)
663  return;
664 
666  gadgetManager.SetGadgetMode(mapGadget, EGadgetMode.IN_HAND);
667  }
668  else
669  {
670  PanMapToTask(task: m_SelectedTask);
671  }
672  }
673 
674  //------------------------------------------------------------------------------------------------
677  void Action_AssignTask(SCR_BaseTask task = null)
678  {
679  if (!task)
680  {
681  if (!m_SelectedTask)
682  return;
683  }
684 
686  if (!taskNetworkComp)
687  return;
688 
689  SCR_BaseTask curTask = SCR_BaseTaskExecutor.GetLocalExecutor().GetAssignedTask();
690  if (curTask)
691  {
692  int curTaskId = curTask.GetTaskID();
693  taskNetworkComp.AbandonTask(curTaskId);
694  }
695 
696  int taskId;
697  if (task)
698  taskId = task.GetTaskID();
699  else
700  taskId = m_SelectedTask.GetTaskID();
701 
702  if (curTask && curTask == m_SelectedTask)
703  {
704  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.TASK_CANCELED);
705  taskNetworkComp.AbandonTask(taskId);
706  }
707  else
708  {
709  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.TASK_ACCEPT);
710  taskNetworkComp.RequestAssignment(taskId);
711  }
712  }
713 
714  //------------------------------------------------------------------------------------------------
717  {
718  if (!m_SelectedTask)
719  return;
720 
721  if (m_bDetailVisible)
722  return;
723 
724  MenuBase menu;
725  if (!m_wTaskDetail)
726  {
727  menu = GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.TaskDetail, DialogPriority.CRITICAL, 0, true);
728  m_wTaskDetail = menu.GetRootWidget();
729  }
730 
731  m_wTaskDetail.SetZOrder(m_wUI.GetZOrder() + 1);
732  m_bDetailVisible = true;
733  m_wUI.SetOpacity(0);
734 
735  //richTextWidget is task title
736  RichTextWidget richTextWidget = RichTextWidget.Cast(m_wTaskDetail.FindAnyWidget("TaskTitle"));
737  m_SelectedTask.SetTitleWidgetText(richTextWidget, m_SelectedTask.GetTaskListTaskTitle());
738 
739  //richTextWidget is task description
740  richTextWidget = RichTextWidget.Cast(m_wTaskDetail.FindAnyWidget("TaskDescription"));
741  m_SelectedTask.SetDescriptionWidgetText(richTextWidget, m_SelectedTask.GetTaskListTaskText());
742 
743  ImageWidget image = ImageWidget.Cast(m_wTaskDetail.FindAnyWidget("TaskIcon"));
744  image.SetEnabled(false);
745  image.SetOpacity(0);
746  m_SelectedTask.SetWidgetIcon(image);
747  }
748 
749  //------------------------------------------------------------------------------------------------
752  {
753  if (!m_SelectedTask)
754  return;
755 
756  foreach (Widget w : m_aWidgets)
757  {
758  if (!w)
759  continue;
760 
762  if (handler && handler.GetTask() == m_SelectedTask)
763  handler.ExpandTaskLayout();
764  }
765  }
766 
767  //------------------------------------------------------------------------------------------------
769  void OnMapOpen(MapConfiguration cfg)
770  {
771  if (cfg.MapEntityMode == EMapEntityMode.EDITOR)
772  return;
773 
774  if (!SCR_PlayerController.GetLocalControlledEntity() || !m_bOpenTaskListOnMapOpen)
775  return;
776 
778  PanMapToTask(-1, m_LastSelectedTask);
779  }
780 
781  //------------------------------------------------------------------------------------------------
783  void OnMapClose(MapConfiguration config)
784  {
785  m_bTaskContextEnabled = false;
786 
787  if (m_bVisible)
789  }
790 
791  //------------------------------------------------------------------------------------------------
794  void HideAllHUDIcons(bool fade = true)
795  {
796  for (int i = m_aHUDIconUpdatedTasks.Count() - 1; i >= 0; i--)
797  {
798  m_aHUDIconUpdatedTasks[i].ToggleHUDIcon(false, fade);
799  m_aHUDIconUpdatedTasks.Remove(i);
800  }
801  }
802 
803  //------------------------------------------------------------------------------------------------
807  void Action_ShowTasks(Widget targetWidget = null, SCR_BaseTask taskToFocus = null)
808  {
809  ClearUI();
810  m_bVisible = true;
811 
812  if (!targetWidget)
813  targetWidget = GetRootWidget();
814 
815  m_wUI = targetWidget;
816 
817  GenerateUI(targetWidget, taskToFocus);
818  if (m_wUI)
819  m_wUI.SetVisible(true);
820 
821  s_OnTaskListVisible.Invoke(true);
822 
823  if (m_wWidgetToFocus)
824  GetGame().GetWorkspace().SetFocusedWidget(m_wWidgetToFocus);
825  }
826 
827  //------------------------------------------------------------------------------------------------
830  {
831  //HUD Icon
832  //HideAllHUDIcons(false);
833  m_bVisible = false;
834  ClearUI();
835  if (m_wUI)
836  m_wUI.SetVisible(false);
837  s_OnTaskListVisible.Invoke(false);
838 
839  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_HUD_TASK_MENU_CLOSE);
840  }
841 
842  //------------------------------------------------------------------------------------------------
845  void Action_SelectTask(notnull SCR_BaseTask task)
846  {
847  if (!task)
848  return;
849 
850  foreach (Widget w : m_aWidgets)
851  {
852  if (!w)
853  continue;
854 
856  if (handler && handler.GetTask() == task)
857  {
858  GetGame().GetWorkspace().SetFocusedWidget(w);
859  break;
860  }
861  }
862  }
863 
864  //------------------------------------------------------------------------------------------------
867  {
868  SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
869  if (!mapEntity)
870  return;
871 
872  SCR_MapTaskListUI taskListUI = SCR_MapTaskListUI.Cast(mapEntity.GetMapUIComponent(SCR_MapTaskListUI));
873  if (!taskListUI)
874  {
876  return;
877  }
878 
879  taskListUI.HandleTaskList();
880  }
881 
882  //------------------------------------------------------------------------------------------------
883  protected void RemoveTaskFromList(SCR_BaseTask task)
884  {
885  if (!task)
886  return;
887 
888  if (task == m_LastSelectedTask)
889  m_LastSelectedTask = null;
890 
891  foreach (Widget w : m_aWidgets)
892  {
893  if (!w)
894  continue;
895 
897  if (handler)
898  {
899  if (handler.GetTask() && handler.GetTask() == task)
900  w.RemoveFromHierarchy();
901  }
902  }
903 
904  task.ClearWidgetIcon();
905  }
906 
907  //------------------------------------------------------------------------------------------------
910  {
911  for (int i = 0, count = m_mTasksTimers.Count(); i < count; i++)
912  {
913  TextWidget timer = m_mTasksTimers.GetElement(i);
914  SCR_BaseTask task = m_mTasksTimers.GetKeyByValue(timer);
915  if (!task)
916  continue;
917 
918  float remainingTime = task.GetAssigneeTimeLeft();
919  if (remainingTime < 0)
920  continue;
921 
922  string formattedTimerText = GetFormattedTimerText(remainingTime);
923 
924  timer.SetText(formattedTimerText);
925  }
926  }
927 
928  //------------------------------------------------------------------------------------------------
931  void EnableTaskContext(bool enable)
932  {
933  m_bTaskContextEnabled = enable;
934  }
935 
936  //------------------------------------------------------------------------------------------------
937  protected void OnInputDeviceIsGamepad(bool isGamepad)
938  {
939  if (m_wExpandButton)
940  {
941  m_wExpandButton.SetVisible(isGamepad);
942  m_wExpandButton.SetEnabled(isGamepad);
943  }
944  }
945 
946  //------------------------------------------------------------------------------------------------
947  override void OnPostInit(IEntity owner)
948  {
949  SetEventMask(owner, EntityEvent.INIT | EntityEvent.FRAME);
950  }
951 
952  //------------------------------------------------------------------------------------------------
956  protected void OnDestroyed(Instigator killer, IEntity killerEntity)
957  {
958  m_bIsUnconscious = false;
959  }
960 
961  //------------------------------------------------------------------------------------------------
964  {
965  GetGame().GetInputManager().AddActionListener("TasksOpen", EActionTrigger.DOWN, Action_TasksOpen);
966  GetGame().GetInputManager().AddActionListener("TasksShowHint", EActionTrigger.DOWN, Action_ShowHint);
967  GetGame().GetInputManager().AddActionListener("TasksExpand", EActionTrigger.DOWN, Action_Expand);
968  }
969 
970  //------------------------------------------------------------------------------------------------
973  {
974  GetGame().GetInputManager().RemoveActionListener("TasksOpen", EActionTrigger.DOWN, Action_TasksOpen);
975  GetGame().GetInputManager().RemoveActionListener("TasksShowHint", EActionTrigger.DOWN, Action_ShowHint);
976  GetGame().GetInputManager().RemoveActionListener("TasksExpand", EActionTrigger.DOWN, Action_Expand);
977  }
978 
979  //------------------------------------------------------------------------------------------------
982  protected void OnControlledEntityChanged(IEntity from, IEntity to)
983  {
985 
986  if (from)
987  {
988  ChimeraCharacter character = ChimeraCharacter.Cast(from);
989  if (!character)
990  return;
991 
992  SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
993  if (controller)
994  controller.m_OnLifeStateChanged.Remove(LifeStateChanged);
995  }
996 
997  ChimeraCharacter character = ChimeraCharacter.Cast(to);
998  if (!character)
999  return;
1000 
1001  SCR_CharacterControllerComponent characterController = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
1002  if (!characterController)
1003  return;
1004 
1005  m_bIsUnconscious = characterController.IsUnconscious();
1006  characterController.m_OnLifeStateChanged.Insert(LifeStateChanged);
1007  }
1008 
1009  //------------------------------------------------------------------------------------------------
1010  protected void LifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
1011  {
1012  m_bIsUnconscious = newLifeState == ECharacterLifeState.INCAPACITATED;
1013 
1014  if (!m_bIsUnconscious)
1016  }
1017 
1018  //------------------------------------------------------------------------------------------------
1019  override void EOnInit(IEntity owner)
1020  {
1021  CreateTaskList();
1023 
1024  SCR_MapEntity.GetOnMapOpen().Insert(OnMapOpen);
1025  SCR_MapEntity.GetOnMapClose().Insert(OnMapClose);
1026 // SCR_RespawnSuperMenu.Event_OnMenuOpen.Insert(OnMapClose);
1027 
1029  if (!gameMode)
1030  return;
1031 
1032  gameMode.GetOnPlayerConnected().Insert(OnPlayerConnected);
1033 
1034  m_MapEntity = SCR_MapEntity.GetMapInstance();
1035  }
1036 
1037  //------------------------------------------------------------------------------------------------
1038  void OnPlayerConnected(int playerID)
1039  {
1041  if (!playerController)
1042  return;
1043 
1044  playerController.m_OnDestroyed.Insert(OnDestroyed);
1045  int localPlayerID = playerController.GetLocalPlayerId();
1046  if (playerID != localPlayerID)
1047  return;
1048 
1049  playerController.m_OnControlledEntityChanged.Insert(OnControlledEntityChanged);
1050  }
1051 
1052  //------------------------------------------------------------------------------------------------
1056  Widget CreateTaskList(Widget w = null)
1057  {
1058  if (w)
1059  m_wUI = GetGame().GetWorkspace().CreateWidgets(m_UIResource, w);
1060  else
1061  m_wUI = GetGame().GetWorkspace().CreateWidgets(m_UIResource);
1062 
1063  if (m_wUI)
1064  {
1065  m_wTasksUI = m_wUI.FindAnyWidget("Tasks");
1066  m_wUI.SetVisible(m_bVisible);
1067  m_wExpandButton = m_wUI.FindAnyWidget("ExpandTaskButton");
1068  }
1069 
1070  OnInputDeviceIsGamepad(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
1071  GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
1072 
1073  SCR_InputButtonComponent hideTasks = SCR_InputButtonComponent.GetInputButtonComponent("HideTasksButton", m_wUI);
1074  if (hideTasks)
1075  hideTasks.m_OnActivated.Insert(Action_RequestTasksClose);
1076 
1077  SCR_BaseTaskManager.s_OnTaskDeleted.Insert(RemoveTaskFromList);
1078  SCR_BaseTaskManager.s_OnTaskFinished.Insert(RemoveTaskFromList);
1079 
1080  return m_wUI;
1081  }
1082 
1083  //------------------------------------------------------------------------------------------------
1086  {
1087  if (m_wUI)
1088  m_wUI.RemoveFromHierarchy();
1089  }
1090 
1091  //------------------------------------------------------------------------------------------------
1092  // constructor
1096  void SCR_UITaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
1097  {
1098  if (!s_Instance)
1099  s_Instance = this;
1100  }
1101 
1102  //------------------------------------------------------------------------------------------------
1103  // destructor
1105  {
1106  s_Instance = null;
1107  if (m_wUI)
1108  m_wUI.RemoveFromHierarchy();
1109  }
1110 }
GenerateRequestButtons
protected void GenerateRequestButtons()
Definition: SCR_UITaskManagerComponent.c:325
m_wWidgetToFocus
protected Widget m_wWidgetToFocus
Definition: SCR_UITaskManagerComponent.c:15
ClearUI
protected void ClearUI()
Definition: SCR_UITaskManagerComponent.c:344
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
m_bIsUnconscious
protected bool m_bIsUnconscious
Definition: SCR_UITaskManagerComponent.c:33
m_mTasksTimers
ref map< SCR_BaseTask, TextWidget > m_mTasksTimers
Definition: SCR_UITaskManagerComponent.c:26
EnableTaskContext
void EnableTaskContext(bool enable)
Definition: SCR_UITaskManagerComponent.c:931
GenerateUI
void GenerateUI(Widget rootWidget, SCR_BaseTask taskToFocus=null)
Definition: SCR_UITaskManagerComponent.c:254
HasLocallyAssignedTask
bool HasLocallyAssignedTask()
Definition: SCR_UITaskManagerComponent.c:423
KeepHUDIconUpdated
void KeepHUDIconUpdated(int msTime, SCR_BaseTask task)
Definition: SCR_UITaskManagerComponent.c:123
Action_Expand
void Action_Expand()
Action expand task called from controller.
Definition: SCR_UITaskManagerComponent.c:751
SCR_PlayerController
Definition: SCR_PlayerController.c:31
OnMapClose
void OnMapClose(MapConfiguration config)
Definition: SCR_UITaskManagerComponent.c:783
EOnFrame
override void EOnFrame(IEntity owner, float timeSlice)
Definition: SCR_UITaskManagerComponent.c:361
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
OnDestroyed
protected void OnDestroyed(Instigator killer, IEntity killerEntity)
Definition: SCR_UITaskManagerComponent.c:956
GetFormattedTimerText
string GetFormattedTimerText(float time)
Definition: SCR_UITaskManagerComponent.c:394
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
ECharacterLifeState
ECharacterLifeState
Definition: ECharacterLifeState.c:12
OnControlledEntityChanged
protected void OnControlledEntityChanged(IEntity from, IEntity to)
Runs every time the controlled entity has been changed.
Definition: SCR_UITaskManagerComponent.c:982
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
GetSelectedTask
SCR_BaseTask GetSelectedTask()
Definition: SCR_UITaskManagerComponent.c:153
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
OnTaskDeleted
void OnTaskDeleted(SCR_BaseTask task)
Definition: SCR_UITaskManagerComponent.c:134
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_GadgetManagerComponent
Definition: SCR_GadgetManagerComponent.c:138
SCR_UITaskManagerComponentClass
Definition: SCR_UITaskManagerComponent.c:2
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
ClearWidget
void ClearWidget()
Definition: SCR_UITaskManagerComponent.c:1085
OnPlayerConnected
void OnPlayerConnected(int playerID)
Definition: SCR_UITaskManagerComponent.c:1038
NO_ASSIGNED_TASK
SCR_UITaskManagerComponentClass NO_ASSIGNED_TASK
OnInputDeviceIsGamepad
protected void OnInputDeviceIsGamepad(bool isGamepad)
Definition: SCR_UITaskManagerComponent.c:937
SCR_RequestedTaskSupportEntity
Definition: SCR_RequestedTaskSupportEntity.c:8
m_MapEntity
SCR_MapEntity m_MapEntity
Definition: SCR_UITaskManagerComponent.c:23
SCR_TaskListEntryHandler
Definition: SCR_TaskListEntryHandler.c:2
Action_ShowTasks
void Action_ShowTasks(Widget targetWidget=null, SCR_BaseTask taskToFocus=null)
Definition: SCR_UITaskManagerComponent.c:807
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
SCR_TaskPlayerListEntryHandler
Definition: SCR_TaskPlayerListEntryHandler.c:2
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
m_bPickAssigneeVisible
protected bool m_bPickAssigneeVisible
Definition: SCR_UITaskManagerComponent.c:30
m_wTasksUI
protected Widget m_wTasksUI
Definition: SCR_UITaskManagerComponent.c:16
Instigator
Definition: Instigator.c:6
SCR_UITaskManagerComponent
void SCR_UITaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_UITaskManagerComponent.c:1096
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
UnregisterTimer
void UnregisterTimer(SCR_BaseTask task)
Definition: SCR_UITaskManagerComponent.c:182
~SCR_UITaskManagerComponent
void ~SCR_UITaskManagerComponent()
Definition: SCR_UITaskManagerComponent.c:1104
SetSelectedWidget
void SetSelectedWidget(Widget w)
Definition: SCR_UITaskManagerComponent.c:78
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_TaskNetworkComponent
void SCR_TaskNetworkComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_TaskNetworkComponent.c:207
Action_TasksOpen
void Action_TasksOpen()
Definition: SCR_UITaskManagerComponent.c:595
UpdateTimers
void UpdateTimers()
Updates the timers in task descriptions.
Definition: SCR_UITaskManagerComponent.c:909
GetWidgetsArray
array< Widget > GetWidgetsArray()
Definition: SCR_UITaskManagerComponent.c:174
SetupAssigneeTexts
void SetupAssigneeTexts(notnull SCR_BaseTask task, Widget parent)
Creates assignee texts if needed.
Definition: SCR_UITaskManagerComponent.c:201
Action_ShowOnMap
void Action_ShowOnMap()
Definition: SCR_UITaskManagerComponent.c:642
s_Instance
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
InitCurrentTaskWidget
Widget InitCurrentTaskWidget()
Definition: SCR_UITaskManagerComponent.c:415
SCR_PickAssigneeDialog
Definition: SCR_PickAssigneeDialog.c:2
m_bCurrentTaskVisible
protected bool m_bCurrentTaskVisible
Definition: SCR_UITaskManagerComponent.c:31
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
HideAllHUDIcons
void HideAllHUDIcons(bool fade=true)
Definition: SCR_UITaskManagerComponent.c:794
HidePickAssignee
void HidePickAssignee()
Definition: SCR_UITaskManagerComponent.c:501
SCR_BaseTaskManager
Definition: SCR_BaseTaskManager.c:25
RemoveTaskFromList
protected void RemoveTaskFromList(SCR_BaseTask task)
Definition: SCR_UITaskManagerComponent.c:883
GetParentWidget
Widget GetParentWidget()
Definition: SCR_UITaskManagerComponent.c:167
m_wCurrentTask
protected Widget m_wCurrentTask
Definition: SCR_UITaskManagerComponent.c:60
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_UITaskManagerComponent.c:947
ToggleCurrentTask
void ToggleCurrentTask(bool fade=true)
Definition: SCR_UITaskManagerComponent.c:443
m_wTaskDetail
protected Widget m_wTaskDetail
Definition: SCR_UITaskManagerComponent.c:19
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
m_UIResource
ResourceName m_UIResource
Definition: SCR_UITaskManagerComponent.c:40
m_SelectedTask
protected SCR_BaseTask m_SelectedTask
Definition: SCR_UITaskManagerComponent.c:35
SCR_MapTaskListUI
Definition: SCR_MapTaskListUI.c:1
m_fCurrentTaskTime
protected float m_fCurrentTaskTime
Definition: SCR_UITaskManagerComponent.c:34
m_sTaskDetailLayout
protected ResourceName m_sTaskDetailLayout
Definition: SCR_UITaskManagerComponent.c:46
m_sCurrentTaskLayout
protected ResourceName m_sCurrentTaskLayout
Definition: SCR_UITaskManagerComponent.c:43
m_aWidgets
ref array< Widget > m_aWidgets
Definition: SCR_UITaskManagerComponent.c:25
m_wPlayerListEntry
protected ResourceName m_wPlayerListEntry
Definition: SCR_UITaskManagerComponent.c:55
EOnInit
override void EOnInit(IEntity owner)
Initialise this component with data from FactionsManager.
Definition: SCR_UITaskManagerComponent.c:1019
LifeStateChanged
protected void LifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
Definition: SCR_UITaskManagerComponent.c:1010
m_AssignedTaskColor
protected ref Color m_AssignedTaskColor
Definition: SCR_UITaskManagerComponent.c:58
m_LastSelectedTask
protected SCR_BaseTask m_LastSelectedTask
Definition: SCR_UITaskManagerComponent.c:36
Faction
Definition: Faction.c:12
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
m_fCurrentTaskShowTime
protected float m_fCurrentTaskShowTime
Definition: SCR_UITaskManagerComponent.c:49
m_bShowSelectedTaskOnMap
protected bool m_bShowSelectedTaskOnMap
Definition: SCR_UITaskManagerComponent.c:37
Action_TasksClose
void Action_TasksClose()
Definition: SCR_UITaskManagerComponent.c:630
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
IsTaskListOpen
bool IsTaskListOpen()
Definition: SCR_UITaskManagerComponent.c:71
Action_ShowHint
void Action_ShowHint()
Definition: SCR_UITaskManagerComponent.c:612
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
RegisterTimer
void RegisterTimer(SCR_BaseTask task, TextWidget timerWidget)
Definition: SCR_UITaskManagerComponent.c:192
m_aHUDIconUpdatedTasks
protected ref array< SCR_BaseTask > m_aHUDIconUpdatedTasks
Definition: SCR_UITaskManagerComponent.c:11
Action_PickAssignee
void Action_PickAssignee()
Definition: SCR_UITaskManagerComponent.c:519
OnMapOpen
void OnMapOpen(MapConfiguration cfg)
Definition: SCR_UITaskManagerComponent.c:769
m_wParentWidget
protected Widget m_wParentWidget
Definition: SCR_UITaskManagerComponent.c:17
m_wExpandButton
protected Widget m_wExpandButton
Definition: SCR_UITaskManagerComponent.c:20
Action_RequestTasksClose
void Action_RequestTasksClose()
Do not close task list directly, but request it on mapTaskListUI in ordero unregister all events and ...
Definition: SCR_UITaskManagerComponent.c:866
SelectTask
void SelectTask(SCR_BaseTask task, Widget w=null)
Definition: SCR_UITaskManagerComponent.c:144
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
StopHUDIconUpdates
void StopHUDIconUpdates(SCR_BaseTask task)
Definition: SCR_UITaskManagerComponent.c:113
HideDetail
void HideDetail()
Definition: SCR_UITaskManagerComponent.c:509
m_bTaskContextEnabled
protected bool m_bTaskContextEnabled
Definition: SCR_UITaskManagerComponent.c:32
m_bOpenTaskListOnMapOpen
protected bool m_bOpenTaskListOnMapOpen
Definition: SCR_UITaskManagerComponent.c:52
m_bVisible
protected bool m_bVisible
Definition: SCR_UITaskManagerComponent.c:28
EMapEntityMode
EMapEntityMode
Mode of the map.
Definition: SCR_MapConstants.c:28
AddActionListeners
void AddActionListeners()
Definition: SCR_UITaskManagerComponent.c:963
Action_AssignTask
void Action_AssignTask(SCR_BaseTask task=null)
Definition: SCR_UITaskManagerComponent.c:677
CreateTaskList
Widget CreateTaskList(Widget w=null)
Definition: SCR_UITaskManagerComponent.c:1056
Action_ShowDetail
void Action_ShowDetail()
Definition: SCR_UITaskManagerComponent.c:716
m_wUI
protected Widget m_wUI
Definition: SCR_UITaskManagerComponent.c:18
m_bDetailVisible
protected bool m_bDetailVisible
Definition: SCR_UITaskManagerComponent.c:29
Action_HideTasks
void Action_HideTasks()
Definition: SCR_UITaskManagerComponent.c:829
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1
RemoveActionListeners
void RemoveActionListeners()
Definition: SCR_UITaskManagerComponent.c:972
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
Action_SelectTask
void Action_SelectTask(notnull SCR_BaseTask task)
Definition: SCR_UITaskManagerComponent.c:845