Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_UITaskManagerComponent.c
Go to the documentation of this file.
1[Obsolete(), 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")]
5
6[Obsolete("Replaced with SCR_TaskManagerUIComponent")]
7class SCR_UITaskManagerComponent : ScriptComponent
8{
9 /*
10 protected static const string NO_ASSIGNED_TASK = "#AR-Tasks_NoAssignedTaskTitle";
11 protected static const string ASSIGN_TASK_HINT = "#AR-Tasks_NoAssignedTaskDescription";
12
13 protected ref array<SCR_BaseTask> m_aHUDIconUpdatedTasks = {};
14
15 static const ref ScriptInvoker s_OnTaskListVisible = new ScriptInvoker();
16
17 protected Widget m_wWidgetToFocus = null;
18 protected Widget m_wTasksUI = null;
19 protected Widget m_wParentWidget = null;
20 protected Widget m_wUI = null;
21 protected Widget m_wTaskDetail = null;
22 protected Widget m_wExpandButton = null;
23
24 static SCR_UITaskManagerComponent s_Instance;
25 SCR_MapEntity m_MapEntity;
26
27 ref array<Widget> m_aWidgets = {};
28 ref map<SCR_BaseTask, TextWidget> m_mTasksTimers = new map<SCR_BaseTask, TextWidget>();
29
30 protected bool m_bVisible;
31 protected bool m_bDetailVisible;
32 protected bool m_bPickAssigneeVisible;
33 protected bool m_bCurrentTaskVisible;
34 protected bool m_bTaskContextEnabled;
35 protected bool m_bIsUnconscious; //Character is unconscious --> Task menu control is disabled
36 protected float m_fCurrentTaskTime;
37 protected SCR_BaseTask m_SelectedTask;
38 protected SCR_BaseTask m_LastSelectedTask;
39 protected bool m_bShowSelectedTaskOnMap;
40
41 protected SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp;
42
43 [Attribute("{10C0A9A305E8B3A4}UI/Imagesets/Tasks/Task_Icons.imageset", category: "Task icon")]
44 protected ResourceName m_sIconImageset;
45
46 [Attribute("{ACCF501DD69CAF7B}UI/layouts/Tasks/TaskListWrapper.layout")]
47 ResourceName m_UIResource;
48
49 [Attribute("{EE9497AB43F556F9}UI/layouts/Tasks/CurrentTask.layout")]
50 protected ResourceName m_sCurrentTaskLayout;
51
52 [Attribute("{728FD22A081ABB36}UI/layouts/Tasks/TaskDetail.layout")]
53 protected ResourceName m_sTaskDetailLayout;
54
55 [Attribute("5")]
56 protected float m_fCurrentTaskShowTime;
57
58 [Attribute("1")]
59 protected bool m_bOpenTaskListOnMapOpen;
60
61 [Attribute("{31C4EB3D607069C2}UI/layouts/Tasks/PickAssigneeListEntry.layout")]
62 protected ResourceName m_wPlayerListEntry;
63
64 [Attribute("0.761 0.386 0.08 1")]
65 protected ref Color m_AssignedTaskColor;
66
67 protected Widget m_wCurrentTask;
68
69 //------------------------------------------------------------------------------------------------
71 static SCR_UITaskManagerComponent GetInstance()
72 {
73 return s_Instance;
74 }
75
76 //------------------------------------------------------------------------------------------------
78 bool IsTaskListOpen()
79 {
80 return m_bVisible;
81 }
82
83 //------------------------------------------------------------------------------------------------
85 void SetSelectedWidget(Widget w)
86 {
87 m_wWidgetToFocus = w;
88 }
89
90 //------------------------------------------------------------------------------------------------
94 static void PanMapToTask(int taskID = -1, SCR_BaseTask task = null)
95 {
96 SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
97 if (!mapEntity || !mapEntity.IsOpen())
98 return;
99
100 if (!task)
101 {
102 if (taskID == -1)
103 return;
104
105 task = GetTaskManager().GetTask(taskID);
106 if (!task)
107 return;
108 }
109
110 vector taskPos = task.GetOrigin();
111 float screenX, screenY;
112 mapEntity.WorldToScreen(taskPos[0], taskPos[2], screenX, screenY);
113 mapEntity.PanSmooth(screenX, screenY);
114
115 }
116
117 //------------------------------------------------------------------------------------------------
120 void StopHUDIconUpdates(SCR_BaseTask task)
121 {
122 m_aHUDIconUpdatedTasks.RemoveItem(task);
123 task.ToggleHUDIcon(false, false);
124 }
125
126 //------------------------------------------------------------------------------------------------
130 void KeepHUDIconUpdated(int msTime, SCR_BaseTask task)
131 {
132 if (m_aHUDIconUpdatedTasks.Find(task) != 0)
133 return;
134
135 m_aHUDIconUpdatedTasks.Insert(task);
136 GetGame().GetCallqueue().CallLater(StopHUDIconUpdates, msTime, false, task);
137 }
138
139 //------------------------------------------------------------------------------------------------
141 void OnTaskDeleted(SCR_BaseTask task)
142 {
143 if (m_aHUDIconUpdatedTasks.Find(task) != -1)
144 m_aHUDIconUpdatedTasks.RemoveItem(task);
145 }
146
147 //------------------------------------------------------------------------------------------------
151 void SelectTask(SCR_BaseTask task, Widget w = null)
152 {
153 m_SelectedTask = task;
154 if (task)
155 m_LastSelectedTask = task;
156 }
157
158 //------------------------------------------------------------------------------------------------
160 SCR_BaseTask GetSelectedTask()
161 {
162 return m_SelectedTask;
163 }
164
165 //------------------------------------------------------------------------------------------------
167 Widget GetRootWidget()
168 {
169 return m_wUI;
170 }
171
172 //------------------------------------------------------------------------------------------------
174 Widget GetParentWidget()
175 {
176 return m_wParentWidget;
177 }
178
179 //------------------------------------------------------------------------------------------------
181 array<Widget> GetWidgetsArray()
182 {
183 return m_aWidgets;
184 }
185
186 //------------------------------------------------------------------------------------------------
189 void UnregisterTimer(SCR_BaseTask task)
190 {
191 if (m_mTasksTimers)
192 m_mTasksTimers.Remove(task);
193 }
194
195 //------------------------------------------------------------------------------------------------
199 void RegisterTimer(SCR_BaseTask task, TextWidget timerWidget)
200 {
201 if (m_mTasksTimers)
202 m_mTasksTimers.Set(task, timerWidget);
203 }
204
205 //------------------------------------------------------------------------------------------------
207 // This method is not used
208 void SetupAssigneeTexts(notnull SCR_BaseTask task, Widget parent)
209 {
210 TextWidget assigneeNames = TextWidget.Cast(parent.FindAnyWidget("TaskAssignees"));
211
212 TextWidget assigneeTime = TextWidget.Cast(parent.FindAnyWidget("AssigneeTime"));
213 if (!assigneeTime)
214 return;
215
216 if (task.IsIndividual())
217 {
218 if (assigneeTime)
219 {
220 RegisterTimer(task, assigneeTime);
221 assigneeTime.SetVisible(task.GetAssignee() && task.IsIndividual());
222
223 float remainingTime = task.GetAssigneeTimeLeft();
224 string formattedTimerText = GetFormattedTimerText(remainingTime);
225 assigneeTime.SetText(formattedTimerText);
226 }
227 }
228 else
229 {
230 assigneeTime.SetVisible(false);
231 }
232
233 if (!assigneeNames)
234 return;
235
236 array<SCR_BaseTaskExecutor> assignees = {};
237 task.GetAssignees(assignees);
238
239 bool hasAssignees = assignees.Count() > 0;
240 assigneeNames.SetVisible(hasAssignees);
241
242 if (!hasAssignees)
243 return;
244
245 string namesText = "";
246
247 for (int i = 0, count = assignees.Count(); i < count; i++)
248 {
249 if (i > 0)
250 namesText += ", ";
251 namesText += assignees[i].GetPlayerName();
252 }
253
254 assigneeNames.SetText(namesText);
255 }
256
257 //------------------------------------------------------------------------------------------------
261 void GenerateUI(Widget rootWidget, SCR_BaseTask taskToFocus = null)
262 {
263 if (!GetTaskManager())
264 return;
265
266 if (!rootWidget)
267 return;
268
269 SCR_BaseTask locallyRequestedTask;
270 SCR_RequestedTaskSupportEntity supportEntity = SCR_RequestedTaskSupportEntity.Cast(GetTaskManager().FindSupportEntity(SCR_RequestedTaskSupportEntity));
271 if (supportEntity)
272 locallyRequestedTask = supportEntity.GetLocallyRequestedTask();
273
274 SCR_BaseTaskExecutor localTaskExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
275 if (!localTaskExecutor)
276 return;
277
278 Faction faction;
279 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
280 if (factionManager)
281 faction = factionManager.GetLocalPlayerFaction();
282
283 array<SCR_BaseTask> tasks = {};
284 GetTaskManager().GetFilteredTasks(tasks, faction);
285
286 if (locallyRequestedTask)
287 {
288 if (!m_wWidgetToFocus)
289 m_wWidgetToFocus = locallyRequestedTask.GenerateTaskDescriptionUI(rootWidget, m_aWidgets);
290 else
291 locallyRequestedTask.GenerateTaskDescriptionUI(rootWidget, m_aWidgets);
292 }
293
294 SCR_BaseTask locallyAssignedTask = SCR_BaseTaskExecutor.GetLocalExecutor().GetAssignedTask();
295
296 Widget currentTaskUI;
297 foreach (SCR_BaseTask task : tasks)
298 {
299 if (!task)
300 {
301 Print("Null found in task list!", LogLevel.ERROR);
302 continue;
303 }
304
305 if (task == locallyRequestedTask)
306 continue;
307
308 currentTaskUI = task.GenerateTaskDescriptionUI(rootWidget, m_aWidgets);
309
310 if (!m_wWidgetToFocus)
311 m_wWidgetToFocus = currentTaskUI;
312
313 if (task == locallyAssignedTask)
314 {
315 RichTextWidget textWidget = RichTextWidget.Cast(currentTaskUI.FindAnyWidget("TaskTitle"));
316 textWidget.SetColor(m_AssignedTaskColor);
317 }
318
319 if (task == taskToFocus)
320 {
321 m_wWidgetToFocus = currentTaskUI;
322
323 SCR_TaskListEntryHandler handler = SCR_TaskListEntryHandler.Cast(m_wWidgetToFocus.FindHandler(SCR_TaskListEntryHandler));
324 if (handler)
325 handler.SetCollapsed(false);
326
327 }
328 }
329
330 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_HUD_TASK_MENU_OPEN);
331 }
332
333 //------------------------------------------------------------------------------------------------
334
335 protected void GenerateRequestButtons()
336 {
337 // note: turned off now
338 return;
339 array<SCR_BaseTaskSupportEntity> supportedTasks = GetTaskManager().GetSupportedTasks();
340 if (!supportedTasks)
341 return;
342
343 m_wParentWidget = m_wUI.FindAnyWidget("MainPanel");
344 if (!m_wParentWidget)
345 return;
346
347 for (int i = supportedTasks.Count() - 1; i >= 0; i--)
348 {
349 supportedTasks[i].OnTaskListOpen(this);
350 }
351 }
352
353 //------------------------------------------------------------------------------------------------
354 protected void ClearUI()
355 {
356 if (!m_aWidgets || !m_mTasksTimers)
357 return;
358
359 m_mTasksTimers.Clear();
360
361 foreach (Widget widget : m_aWidgets)
362 {
363 if (widget)
364 widget.RemoveFromHierarchy();
365 }
366
367 m_aWidgets.Clear();
368 }
369
370 //------------------------------------------------------------------------------------------------
371 override void EOnFrame(IEntity owner, float timeSlice)
372 {
373 for (int i = m_aHUDIconUpdatedTasks.Count() - 1; i >= 0; i--)
374 {
375 m_aHUDIconUpdatedTasks[i].UpdateHUDIcon();
376 }
377
378 if (m_bTaskContextEnabled)
379 GetGame().GetInputManager().ActivateContext("TaskListContext");
380
381 else if (m_bVisible)
382 {
383 if (m_MapEntity && m_MapEntity.IsOpen())
384 GetGame().GetInputManager().ActivateContext("TaskListMapContext");
385 else
386 GetGame().GetInputManager().ActivateContext("TaskListContext");
387 }
388
389 if (m_bCurrentTaskVisible)
390 {
391 if (m_fCurrentTaskTime > 0)
392 {
393 m_fCurrentTaskTime -= timeSlice;
394 if (m_fCurrentTaskTime < 0)
395 ToggleCurrentTask();
396 }
397 }
398 }
399
400 //------------------------------------------------------------------------------------------------
403 // TODO: use SCR_DateTimeHelper
404 string GetFormattedTimerText(float time)
405 {
406 int minutes = Math.Floor(time / 60);
407 int seconds = Math.Floor(time - (minutes * 60));
408
409 string minutesString;
410 if (minutes < 10)
411 minutesString = "0";
412 minutesString += minutes.ToString();
413
414 string secondsString;
415 if (seconds < 10)
416 secondsString = "0";
417 secondsString += seconds.ToString();
418
419 return minutesString + ":" + secondsString;
420 }
421
422 //------------------------------------------------------------------------------------------------
425 Widget InitCurrentTaskWidget()
426 {
427 return GetGame().GetWorkspace().CreateWidgets(m_sCurrentTaskLayout);
428 }
429
430 //------------------------------------------------------------------------------------------------
433 bool HasLocallyAssignedTask()
434 {
435 if (!GetTaskManager())
436 return false;
437
438 SCR_BaseTask locallyRequestedTask;
439 SCR_RequestedTaskSupportEntity supportEntity = SCR_RequestedTaskSupportEntity.Cast(GetTaskManager().FindSupportEntity(SCR_RequestedTaskSupportEntity));
440 if (supportEntity)
441 locallyRequestedTask = supportEntity.GetLocallyRequestedTask();
442
443 SCR_BaseTaskExecutor localTaskExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
444 if (!localTaskExecutor || !localTaskExecutor.GetAssignedTask())
445 return false;
446
447 return true;
448 }
449
450 //------------------------------------------------------------------------------------------------
453 void ToggleCurrentTask(bool fade = true)
454 {
455 m_bCurrentTaskVisible = !m_bCurrentTaskVisible;
456
457 if (!m_wCurrentTask)
458 m_wCurrentTask = InitCurrentTaskWidget();
459
460 SCR_BaseTaskExecutor localTaskExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
461 SCR_BaseTask assignedTask = localTaskExecutor.GetAssignedTask();
462
463 const float speed = 1; // TODO: check for good const usage
464 float targetOpacity;
465 if (m_bCurrentTaskVisible)
466 {
467 targetOpacity = 1;
468
469 if (localTaskExecutor)
470 {
471 TextWidget textWidget = TextWidget.Cast(m_wCurrentTask.FindAnyWidget("TaskTitle"));
472
473 //Main frame of the task
474 FrameWidget m_wTaskIconWidget = FrameWidget.Cast(m_wCurrentTask.FindAnyWidget("CurrentTaskIcon"));
475 if (!m_wTaskIconWidget)
476 return;
477
478 PlayerController m_playerController = GetGame().GetPlayerController();
479 if (!m_playerController)
480 return;
481
482 m_PlyFactionAffilComp = SCR_PlayerFactionAffiliationComponent.Cast(m_playerController.FindComponent(SCR_PlayerFactionAffiliationComponent));
483 if (!m_PlyFactionAffilComp)
484 return;
485
486 SCR_Faction m_faction = SCR_Faction.Cast(m_PlyFactionAffilComp.GetAffiliatedFaction());
487 if (!m_faction)
488 return;
489
490 //Setting visibility, color and symbol of task icon
491 if (assignedTask)
492 {
493 ImageWidget m_wTaskIconBackground = ImageWidget.Cast(m_wCurrentTask.FindAnyWidget("TaskIconBackground"));
494 ImageWidget m_wTaskIconOutline = ImageWidget.Cast(m_wCurrentTask.FindAnyWidget("TaskIconOutline"));
495 ImageWidget m_wTaskIconSymbol = ImageWidget.Cast(m_wCurrentTask.FindAnyWidget("TaskIconSymbol"));
496 if (!m_wTaskIconBackground || !m_wTaskIconOutline || !m_wTaskIconSymbol)
497 return;
498
499 m_wTaskIconWidget.SetVisible(true);
500 assignedTask.SetTitleWidgetText(textWidget, assignedTask.GetTaskListTaskTitle());
501
502 string IconName = assignedTask.GetIconName();
503 m_wTaskIconSymbol.LoadImageFromSet(0, m_sIconImageset, IconName);
504
505 //set color
506 Faction LightFaction = assignedTask.GetTargetFaction();
507 Color lightfactioncolor = LightFaction.GetFactionColor();
508
509 m_wTaskIconOutline.SetColor(m_faction.GetOutlineFactionColor());
510 m_wTaskIconSymbol.SetColor(m_faction.GetOutlineFactionColor());
511
512 //priority colors
513 if (assignedTask.IsPriority())
514 m_wTaskIconBackground.SetColor(UIColors.CONTRAST_COLOR);
515 else
516 m_wTaskIconBackground.SetColor(lightfactioncolor);
517 }
518 else
519 {
520 m_wTaskIconWidget.SetVisible(false);
521 textWidget.SetTextFormat(NO_ASSIGNED_TASK);
522 }
523
524 textWidget = TextWidget.Cast(m_wCurrentTask.FindAnyWidget("TaskDescription"));
525 if (assignedTask)
526 assignedTask.SetTitleWidgetText(textWidget, assignedTask.GetTaskListTaskText());
527 else
528 textWidget.SetTextFormat(ASSIGN_TASK_HINT);
529 }
530 }
531 else
532 {
533 targetOpacity = 0;
534 }
535
536 if (fade)
537 {
538 AnimateWidget.Opacity(m_wCurrentTask, targetOpacity, speed);
539 }
540 else
541 {
542 AnimateWidget.StopAnimation(m_wCurrentTask, WidgetAnimationOpacity);
543 m_wCurrentTask.SetOpacity(targetOpacity);
544 }
545
546 m_fCurrentTaskTime = m_fCurrentTaskShowTime;
547 }
548
549 //------------------------------------------------------------------------------------------------
551 void HidePickAssignee()
552 {
553 m_bPickAssigneeVisible = false;
554 GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.PickAssignee);
555 }
556
557 //------------------------------------------------------------------------------------------------
559 void HideDetail()
560 {
561 GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.TaskDetail);
562 m_bDetailVisible = false;
563
564 m_wUI.SetVisible(true);
565 }
566
567 //------------------------------------------------------------------------------------------------
569
570 void Action_PickAssignee()
571 {
572 Widget pickAssigneeWidget;
573
574 if (!m_bPickAssigneeVisible)
575 {
576 m_bPickAssigneeVisible = true;
577 MenuBase menu = GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.PickAssignee, DialogPriority.CRITICAL, 0, true);
578 pickAssigneeWidget = menu.GetRootWidget();
579 pickAssigneeWidget.SetZOrder(m_wUI.GetZOrder());
580
581 Widget playerList = pickAssigneeWidget.FindAnyWidget("Players");
582 if (!playerList)
583 return;
584
585 while (playerList.GetChildren())
586 {
587 playerList.RemoveChild(playerList.GetChildren());
588 }
589
590 int entriesCount;
591 SCR_BaseTaskExecutor localExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
592 map<SCR_BaseTaskExecutor, int> taskExecutors = SCR_BaseTaskExecutor.GetTaskExecutorsMap();
593 for (int i = taskExecutors.Count() - 1; i >= 0; i--)
594 {
595 SCR_BaseTaskExecutor executor = taskExecutors.GetKey(i);
596
597 if (executor == localExecutor)
598 continue;
599
600 SCR_BaseTask executorTask = executor.GetAssignedTask();
601
602 //Executor is already assigned to this task
603 if (executorTask == m_LastSelectedTask)
604 continue;
605
606 entriesCount++;
607
608 Widget playerEntry = playerList.GetWorkspace().CreateWidgets(m_wPlayerListEntry, playerList);
609 if (executorTask)
610 playerEntry.FindAnyWidget("IsAssigned").SetVisible(true);
611
612 SCR_TaskPlayerListEntryHandler entryHandler = SCR_TaskPlayerListEntryHandler.Cast(playerEntry.FindHandler(SCR_TaskPlayerListEntryHandler));
613 if (entryHandler)
614 entryHandler.SetExecutor(executor);
615
616 TextWidget playerName = TextWidget.Cast(playerEntry.FindAnyWidget("PlayerName"));
617 if (playerName)
618 playerName.SetText(executor.GetPlayerName());
619 }
620
621 if (entriesCount < 1)
622 HidePickAssignee();
623
624 return;
625 }
626
627 SCR_PickAssigneeDialog pickAssigneeMenu = SCR_PickAssigneeDialog.Cast(GetGame().GetMenuManager().FindMenuByPreset(ChimeraMenuPreset.PickAssignee));
628 if (!pickAssigneeMenu)
629 return;
630
631 SCR_BaseTaskExecutor assignee = pickAssigneeMenu.GetSelectedExecutor();
632 if (!assignee)
633 return;
634
635 m_bPickAssigneeVisible = false;
636
637 SCR_TaskNetworkComponent taskNetworkComponent = SCR_TaskNetworkComponent.Cast(GetGame().GetPlayerController().FindComponent(SCR_TaskNetworkComponent));
638 if (taskNetworkComponent)
639 taskNetworkComponent.AssignTaskToPlayer(SCR_BaseTaskExecutor.GetLocalExecutorID(), m_LastSelectedTask.GetTaskID(), SCR_BaseTaskExecutor.GetTaskExecutorID(pickAssigneeMenu.GetSelectedExecutor()));
640
641 GetGame().GetMenuManager().CloseMenu(pickAssigneeMenu);
642 }
643
644
645 //------------------------------------------------------------------------------------------------
647 void Action_TasksOpen()
648 {
649 if (m_bIsUnconscious)
650 return;
651
652 SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
653 if (mapEntity && mapEntity.IsOpen())
654 return;
655
656 if (mapEntity && !mapEntity.IsOpen())
657 GetGame().GetInputManager().AddActionListener("TasksClose", EActionTrigger.DOWN, Action_TasksClose);
658
659 if (!m_bVisible)
660 Action_ShowTasks(GetRootWidget());
661 else
662 Action_TasksClose();
663 }
664
665 //------------------------------------------------------------------------------------------------
667 void Action_ShowHint()
668 {
669 if (m_bIsUnconscious)
670 return;
671
672 if (m_bVisible)
673 return;
674
675 SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
676 if (!mapEntity || !mapEntity.IsOpen())
677 {
678 bool fade = !m_bCurrentTaskVisible;
679 ToggleCurrentTask(fade);
680 }
681 }
682
683 //------------------------------------------------------------------------------------------------
685 void Action_TasksClose()
686 {
687 m_SelectedTask = null;
688
689 if (m_bVisible)
690 Action_HideTasks();
691
692 GetGame().GetInputManager().RemoveActionListener("TasksClose", EActionTrigger.DOWN, Action_TasksClose);
693 }
694
695 //------------------------------------------------------------------------------------------------
697 void Action_ShowOnMap()
698 {
699
700 SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
701 if (!mapEntity)
702 return;
703
704 if (m_bDetailVisible)
705 HideDetail();
706
707 if (!mapEntity.IsOpen())
708 {
709 Action_TasksClose();
710
711 IEntity player = SCR_PlayerController.GetLocalControlledEntity();
712 if (!player)
713 return;
714
715 SCR_GadgetManagerComponent gadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(player);
716 if (!gadgetManager)
717 return;
718
719 IEntity mapGadget = gadgetManager.GetGadgetByType(EGadgetType.MAP);
720 if (!mapGadget)
721 return;
722
723 m_bShowSelectedTaskOnMap = true;
724 gadgetManager.SetGadgetMode(mapGadget, EGadgetMode.IN_HAND);
725 }
726 else
727 {
728 PanMapToTask(task: m_SelectedTask);
729 }
730 }
731
732 //------------------------------------------------------------------------------------------------
735 void Action_AssignTask(SCR_BaseTask task = null)
736 {
737 if (!task)
738 {
739 if (!m_SelectedTask)
740 return;
741 }
742
743 SCR_TaskNetworkComponent taskNetworkComp = SCR_TaskNetworkComponent.Cast(GetGame().GetPlayerController().FindComponent(SCR_TaskNetworkComponent));
744 if (!taskNetworkComp)
745 return;
746
747 SCR_BaseTask curTask = SCR_BaseTaskExecutor.GetLocalExecutor().GetAssignedTask();
748 if (curTask)
749 {
750 int curTaskId = curTask.GetTaskID();
751 taskNetworkComp.AbandonTask(curTaskId);
752 }
753
754 int taskId;
755 if (task)
756 taskId = task.GetTaskID();
757 else
758 taskId = m_SelectedTask.GetTaskID();
759
760 if (curTask && curTask == m_SelectedTask)
761 {
762 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.TASK_CANCELED);
763 taskNetworkComp.AbandonTask(taskId);
764 }
765 else
766 {
767 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.TASK_ACCEPT);
768 taskNetworkComp.RequestAssignment(taskId);
769 }
770 }
771
772 //------------------------------------------------------------------------------------------------
774 void Action_ShowDetail()
775 {
776 if (!m_SelectedTask)
777 return;
778
779 if (m_bDetailVisible)
780 return;
781
782 MenuBase menu;
783 if (!m_wTaskDetail)
784 {
785 menu = GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.TaskDetail, DialogPriority.CRITICAL, 0, true);
786 m_wTaskDetail = menu.GetRootWidget();
787 }
788
789 m_wTaskDetail.SetZOrder(m_wUI.GetZOrder() + 1);
790 m_bDetailVisible = true;
791 m_wUI.SetOpacity(0);
792
793 //richTextWidget is task title
794 RichTextWidget richTextWidget = RichTextWidget.Cast(m_wTaskDetail.FindAnyWidget("TaskTitle"));
795 m_SelectedTask.SetTitleWidgetText(richTextWidget, m_SelectedTask.GetTaskListTaskTitle());
796
797 //richTextWidget is task description
798 richTextWidget = RichTextWidget.Cast(m_wTaskDetail.FindAnyWidget("TaskDescription"));
799 m_SelectedTask.SetDescriptionWidgetText(richTextWidget, m_SelectedTask.GetTaskListTaskText());
800
801 ImageWidget image = ImageWidget.Cast(m_wTaskDetail.FindAnyWidget("TaskIcon"));
802 image.SetEnabled(false);
803 image.SetOpacity(0);
804 m_SelectedTask.SetWidgetIcon(image);
805 }
806
807 //------------------------------------------------------------------------------------------------
809 void Action_Expand()
810 {
811 if (!m_SelectedTask)
812 return;
813
814 foreach (Widget w : m_aWidgets)
815 {
816 if (!w)
817 continue;
818
819 SCR_TaskListEntryHandler handler = SCR_TaskListEntryHandler.Cast(w.FindHandler(SCR_TaskListEntryHandler));
820 if (handler && handler.GetTask() == m_SelectedTask)
821 handler.ExpandTaskLayout();
822
823 }
824 }
825
826 //------------------------------------------------------------------------------------------------
828 void OnMapOpen(MapConfiguration cfg)
829 {
830 if (cfg.MapEntityMode == EMapEntityMode.EDITOR)
831 return;
832
833 if (!SCR_PlayerController.GetLocalControlledEntity() || !m_bOpenTaskListOnMapOpen)
834 return;
835
836 if (m_bShowSelectedTaskOnMap && m_LastSelectedTask)
837 PanMapToTask(-1, m_LastSelectedTask);
838 }
839
840 //------------------------------------------------------------------------------------------------
842 void OnMapClose(MapConfiguration config)
843 {
844 m_bTaskContextEnabled = false;
845
846 if (m_bVisible)
847 Action_HideTasks();
848 }
849
850 //------------------------------------------------------------------------------------------------
853 void HideAllHUDIcons(bool fade = true)
854 {
855 for (int i = m_aHUDIconUpdatedTasks.Count() - 1; i >= 0; i--)
856 {
857 m_aHUDIconUpdatedTasks[i].ToggleHUDIcon(false, fade);
858 m_aHUDIconUpdatedTasks.Remove(i);
859 }
860 }
861
862 //------------------------------------------------------------------------------------------------
866 void Action_ShowTasks(Widget targetWidget = null, SCR_BaseTask taskToFocus = null)
867 {
868 ClearUI();
869 m_bVisible = true;
870
871 if (!targetWidget)
872 targetWidget = GetRootWidget();
873
874 m_wUI = targetWidget;
875
876 GenerateUI(targetWidget, taskToFocus);
877 if (m_wUI)
878 m_wUI.SetVisible(true);
879
880 s_OnTaskListVisible.Invoke(true);
881
882 if (m_wWidgetToFocus)
883 GetGame().GetWorkspace().SetFocusedWidget(m_wWidgetToFocus);
884 }
885
886 //------------------------------------------------------------------------------------------------
888 void Action_HideTasks()
889 {
890 //HUD Icon
891 //HideAllHUDIcons(false);
892 m_bVisible = false;
893 ClearUI();
894 if (m_wUI)
895 m_wUI.SetVisible(false);
896 s_OnTaskListVisible.Invoke(false);
897
898 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_HUD_TASK_MENU_CLOSE);
899 }
900
901 //------------------------------------------------------------------------------------------------
904 void Action_SelectTask(notnull SCR_BaseTask task)
905 {
906 if (!task)
907 return;
908
909 foreach (Widget w : m_aWidgets)
910 {
911 if (!w)
912 continue;
913
914 SCR_TaskListEntryHandler handler = SCR_TaskListEntryHandler.Cast(w.FindHandler(SCR_TaskListEntryHandler));
915 if (handler && handler.GetTask() == task)
916 {
917 GetGame().GetWorkspace().SetFocusedWidget(w);
918 break;
919 }
920 }
921
922 }
923
924 //------------------------------------------------------------------------------------------------
926 void Action_RequestTasksClose()
927 {
928 SCR_MapEntity mapEntity = SCR_MapEntity.GetMapInstance();
929 if (!mapEntity)
930 return;
931
932 SCR_MapTaskListUI taskListUI = SCR_MapTaskListUI.Cast(mapEntity.GetMapUIComponent(SCR_MapTaskListUI));
933 if (!taskListUI)
934 {
935 Action_TasksClose();
936 return;
937 }
938
939 //taskListUI.HandleTaskList();
940 }
941
942 //------------------------------------------------------------------------------------------------
943 protected void RemoveTaskFromList(SCR_BaseTask task)
944 {
945 if (!task)
946 return;
947
948 if (task == m_LastSelectedTask)
949 m_LastSelectedTask = null;
950
951 foreach (Widget w : m_aWidgets)
952 {
953 if (!w)
954 continue;
955
956 SCR_TaskListEntryHandler handler = SCR_TaskListEntryHandler.Cast(w.FindHandler(SCR_TaskListEntryHandler));
957 if (handler)
958 {
959 if (handler.GetTask() && handler.GetTask() == task)
960 w.RemoveFromHierarchy();
961 }
962 }
963
964 task.ClearWidgetIcon();
965 }
966
967 //------------------------------------------------------------------------------------------------
969 void UpdateTimers()
970 {
971 for (int i = 0, count = m_mTasksTimers.Count(); i < count; i++)
972 {
973 TextWidget timer = m_mTasksTimers.GetElement(i);
974 SCR_BaseTask task = m_mTasksTimers.GetKeyByValue(timer);
975 if (!task)
976 continue;
977
978 float remainingTime = task.GetAssigneeTimeLeft();
979 if (remainingTime < 0)
980 continue;
981
982 string formattedTimerText = GetFormattedTimerText(remainingTime);
983
984 timer.SetText(formattedTimerText);
985 }
986 }
987
988 //------------------------------------------------------------------------------------------------
991 void EnableTaskContext(bool enable)
992 {
993 m_bTaskContextEnabled = enable;
994 }
995
996 //------------------------------------------------------------------------------------------------
997 protected void OnInputDeviceIsGamepad(bool isGamepad)
998 {
999 if (m_wExpandButton)
1000 {
1001 m_wExpandButton.SetVisible(isGamepad);
1002 m_wExpandButton.SetEnabled(isGamepad);
1003 }
1004 }
1005
1006 //------------------------------------------------------------------------------------------------
1007 override void OnPostInit(IEntity owner)
1008 {
1009 SetEventMask(owner, EntityEvent.INIT | EntityEvent.FRAME);
1010 }
1011
1012 //------------------------------------------------------------------------------------------------
1016 protected void OnDestroyed(Instigator killer, IEntity killerEntity)
1017 {
1018 m_bIsUnconscious = false;
1019 }
1020
1021 //------------------------------------------------------------------------------------------------
1023 void AddActionListeners()
1024 {
1025 GetGame().GetInputManager().AddActionListener("TasksOpen", EActionTrigger.DOWN, Action_TasksOpen);
1026 GetGame().GetInputManager().AddActionListener("TasksShowHint", EActionTrigger.DOWN, Action_ShowHint);
1027 GetGame().GetInputManager().AddActionListener("TasksExpand", EActionTrigger.DOWN, Action_Expand);
1028 }
1029
1030 //------------------------------------------------------------------------------------------------
1032 void RemoveActionListeners()
1033 {
1034 GetGame().GetInputManager().RemoveActionListener("TasksOpen", EActionTrigger.DOWN, Action_TasksOpen);
1035 GetGame().GetInputManager().RemoveActionListener("TasksShowHint", EActionTrigger.DOWN, Action_ShowHint);
1036 GetGame().GetInputManager().RemoveActionListener("TasksExpand", EActionTrigger.DOWN, Action_Expand);
1037 }
1038
1039 //------------------------------------------------------------------------------------------------
1042 protected void OnControlledEntityChanged(IEntity from, IEntity to)
1043 {
1044 Action_TasksClose();
1045
1046 if (from)
1047 {
1048 ChimeraCharacter character = ChimeraCharacter.Cast(from);
1049 if (!character)
1050 return;
1051
1052 SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
1053 if (controller)
1054 controller.m_OnLifeStateChanged.Remove(LifeStateChanged);
1055 }
1056
1057 ChimeraCharacter character = ChimeraCharacter.Cast(to);
1058 if (!character)
1059 return;
1060
1061 SCR_CharacterControllerComponent characterController = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
1062 if (!characterController)
1063 return;
1064
1065 m_bIsUnconscious = characterController.IsUnconscious();
1066 characterController.m_OnLifeStateChanged.Insert(LifeStateChanged);
1067 }
1068
1069 //------------------------------------------------------------------------------------------------
1070 protected void LifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
1071 {
1072 m_bIsUnconscious = newLifeState == ECharacterLifeState.INCAPACITATED;
1073
1074 if (!m_bIsUnconscious)
1075 Action_TasksClose();
1076 }
1077
1078 //------------------------------------------------------------------------------------------------
1079 override void EOnInit(IEntity owner)
1080 {
1081 CreateTaskList();
1082 AddActionListeners();
1083
1084 SCR_MapEntity.GetOnMapOpen().Insert(OnMapOpen);
1085 SCR_MapEntity.GetOnMapClose().Insert(OnMapClose);
1086// SCR_RespawnSuperMenu.Event_OnMenuOpen.Insert(OnMapClose);
1087
1088 SCR_BaseGameMode gameMode = SCR_BaseGameMode.Cast(GetGame().GetGameMode());
1089 if (!gameMode)
1090 return;
1091
1092 gameMode.GetOnPlayerConnected().Insert(OnPlayerConnected);
1093
1094 m_MapEntity = SCR_MapEntity.GetMapInstance();
1095 }
1096
1097 //------------------------------------------------------------------------------------------------
1098 void OnPlayerConnected(int playerID)
1099 {
1100 SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerController());
1101 if (!playerController)
1102 return;
1103
1104 playerController.m_OnDestroyed.Insert(OnDestroyed);
1105 int localPlayerID = playerController.GetLocalPlayerId();
1106 if (playerID != localPlayerID)
1107 return;
1108
1109 playerController.m_OnControlledEntityChanged.Insert(OnControlledEntityChanged);
1110 }
1111
1112 //------------------------------------------------------------------------------------------------
1116 Widget CreateTaskList(Widget w = null)
1117 {
1118 if (w)
1119 {
1120 m_wUI = GetGame().GetWorkspace().CreateWidgets(m_UIResource, w);
1121 }
1122 else
1123 {
1124 m_wUI = GetGame().GetWorkspace().CreateWidgets(m_UIResource);
1125 FrameSlot.SetAlignment(m_wUI, 0, -0.25);
1126 }
1127
1128 if (m_wUI)
1129 {
1130 m_wTasksUI = m_wUI.FindAnyWidget("Tasks");
1131 m_wUI.SetVisible(m_bVisible);
1132 m_wExpandButton = m_wUI.FindAnyWidget("ExpandTaskButton");
1133 }
1134
1135 OnInputDeviceIsGamepad(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
1136 GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
1137
1138 SCR_InputButtonComponent hideTasks = SCR_InputButtonComponent.GetInputButtonComponent("HideTasksButton", m_wUI);
1139 if (hideTasks)
1140 hideTasks.m_OnActivated.Insert(Action_RequestTasksClose);
1141
1142 SCR_BaseTaskManager.s_OnTaskDeleted.Insert(RemoveTaskFromList);
1143 SCR_BaseTaskManager.s_OnTaskFinished.Insert(RemoveTaskFromList);
1144
1145 return m_wUI;
1146 }
1147
1148 //------------------------------------------------------------------------------------------------
1150 void ClearWidget()
1151 {
1152 if (m_wUI)
1153 m_wUI.RemoveFromHierarchy();
1154 }
1155
1156 //------------------------------------------------------------------------------------------------
1157 // constructor
1161 void SCR_UITaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
1162 {
1163 if (!s_Instance)
1164 s_Instance = this;
1165 }
1166
1167 //------------------------------------------------------------------------------------------------
1168 // destructor
1169 void ~SCR_UITaskManagerComponent()
1170 {
1171 s_Instance = null;
1172 if (m_wUI)
1173 m_wUI.RemoveFromHierarchy();
1174 }
1175 */
1176}
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.