15 static const string TASK_AMOUNT_COMPLETED_TEXT =
"#AR-Tasks_AmountCompleted";
16 static const string TASK_PROGRESS_TEXT =
"#AR-Tasks_StatusProgress-UC";
17 static const string TASK_FINISHED_TEXT =
"#AR-Tasks_StatusFinished-UC";
18 static const string TASK_AVAILABLE_TEXT =
"#AR-Tasks_StatusNew-UC";
19 static const string TASK_HINT_TEXT =
"#AR-Tasks_Hint";
20 static const string TASK_CANCELLED_TEXT =
"#AR-Tasks_StatusCancelled-UC";
21 static const string TASK_COMPLETED_TEXT =
"#AR-Tasks_StatusCompleted-UC";
22 static const string TASK_FAILED_TEXT =
"#AR-Tasks_StatusFailed-UC";
23 static const float DEFAULT_ASSIGNEE_TIME_LIMIT = 1800;
24 static const float DEFAULT_ASSIGNEE_TIMEOUT_TIME = 60;
25 static const int INVALID_TIMESTAMP = -1;
26 static const int INVALID_TASK_ID = -1;
27 static int s_iCurrentTaskID = 0;
33 [
Attribute(defvalue:
"Task name.",
desc:
"The task name visible to the player.")]
34 protected string m_sName;
36 [
Attribute(defvalue:
"Task description.",
desc:
"The task description visible to the player.")]
37 protected string m_sDescription;
40 protected bool m_bAssignable;
42 [
Attribute(
desc:
"Is this task supposed to be completed just by an individual?")]
43 protected bool m_bIndividualTask;
46 protected string m_sMapIconName;
49 protected string m_sTaskListIconName;
51 [
Attribute(
"{EAB5D9841F081D07}UI/layouts/Campaign/TaskElementNew.layout")]
52 protected ResourceName m_sMapUIElementResourceName;
54 [
Attribute(
"{10C0A9A305E8B3A4}UI/Imagesets/Tasks/Task_Icons.imageset",
category:
"Task icon")]
55 protected ResourceName m_sIconImageset;
61 protected bool m_bNotifyAssignment;
67 protected bool m_bNotifyUnassign;
69 [
Attribute(
"{6FE28246710CA6B1}UI/layouts/Tasks/TaskHUDIcon.layout")]
70 protected ResourceName m_sHUDIcon;
76 protected Faction m_TargetFaction =
null;
77 protected int m_iTaskID = INVALID_TASK_ID;
78 protected float m_fAssigneeTimeLimit = DEFAULT_ASSIGNEE_TIME_LIMIT;
79 protected float m_fLastAssigneeAddedTimestamp = INVALID_TIMESTAMP;
80 protected ref array<SCR_BaseTaskExecutor> m_aAssignees =
new array<SCR_BaseTaskExecutor>();
83 protected float m_fAssigneeTimeoutTimestamp = INVALID_TIMESTAMP;
84 protected SCR_MapDescriptorComponent m_MapDescriptor;
85 protected ImageWidget m_wHUDIcon;
86 protected Widget m_wMapTaskIcon;
87 protected Widget m_wTaskListDescription;
88 protected bool m_bIsPriority;
90 const string TASK_BG_M =
"Icon_M_Task_BG";
91 const string TASK_O_M =
"Icon_M_Task_Outline";
92 const string TASK_BG =
"Icon_Task_BG";
93 const string TASK_O =
"Icon_Task_Outline";
94 const string TASK_H =
"Icon_M_Task_Hover";
110 bool NotifyAssignment()
112 return m_bNotifyAssignment;
116 bool NotifyUnassign()
118 return m_bNotifyUnassign;
122 void DoNotifyAssignment(
int assigneeID)
124 SCR_CampaignNetworkComponent assigneeNetworkComponent = SCR_CampaignNetworkComponent.GetCampaignNetworkComponent(assigneeID);
125 if (!assigneeNetworkComponent)
128 assigneeNetworkComponent.SendPlayerMessage(GetAssignMessage());
132 void DoNotifyUnassign(
int assigneeID)
134 SCR_CampaignNetworkComponent assigneeNetworkComponent = SCR_CampaignNetworkComponent.GetCampaignNetworkComponent(assigneeID);
135 if (!assigneeNetworkComponent)
138 assigneeNetworkComponent.SendPlayerMessage(GetUnassignMessage());
144 return m_eAssignMessage;
150 return m_eUnassignMessage;
154 ResourceName GetMapUIElementResourceName()
156 return m_sMapUIElementResourceName;
160 string GetMapDescriptorText()
162 return GetTaskListTaskText();
166 void OnMapOpen(MapConfiguration config)
176 string GetTaskMapIconName()
178 return m_sMapIconName;
182 string GetTaskListIconName()
184 return m_sTaskListIconName;
188 string GetTaskListTaskTitle()
195 string GetTaskListTaskText()
197 return GetDescription();
201 Widget GetParentWidget(notnull Widget rootWidget)
203 return rootWidget.FindAnyWidget(
"Tasks");
206 ResourceName GetIconImageset()
208 return m_sIconImageset;
214 SetWidgetIcon(m_wHUDIcon);
218 void SetWidgetIcon(ImageWidget image)
223 image.LoadImageFromSet(0, m_sIconImageset, GetTaskListIconName() + GetIconSuffix());
229 void ClearWidgetIcon()
231 if (m_wMapTaskIcon && m_wMapTaskIcon.GetParent())
232 m_wMapTaskIcon.GetParent().RemoveFromHierarchy();
236 void UpdateMapTaskIcon()
241 m_wMapTaskIcon.SetColor(Color.FromInt(Color.WHITE));
245 ImageWidget outline = ImageWidget.Cast(m_wMapTaskIcon.GetParent().FindAnyWidget(
"TaskIconOutline"));
246 ImageWidget background = ImageWidget.Cast(m_wMapTaskIcon.GetParent().FindAnyWidget(
"TaskIconBackground"));
247 ImageWidget hover = ImageWidget.Cast(m_wMapTaskIcon.GetParent().FindAnyWidget(
"TaskIconHover"));
249 if (!outline || !background || !hover)
254 background.LoadImageFromSet(0, m_sIconImageset,TASK_BG_M);
255 outline.LoadImageFromSet(0, m_sIconImageset,TASK_O_M);
256 hover.LoadImageFromSet(0,m_sIconImageset,TASK_H);
261 bool AssignTaskToAI(AIAgent agent)
273 return GetTaskMapIconName() + GetIconSuffix();
277 ResourceName GetImageSetName()
279 return GetMapUIElementResourceName();
283 string GetIconSuffix()
289 string GetTitleIconString()
291 return string.Format(
"<image set='%1' name='%2' />", GetMapUIElementResourceName(), GetIconName() + GetIconSuffix());
295 void SetTitleWidgetText(notnull TextWidget textWidget,
string taskText)
297 textWidget.SetTextFormat(taskText);
301 string GetTitleText()
307 void SetDescriptionWidgetText(notnull TextWidget textWidget,
string taskText)
309 textWidget.SetTextFormat(taskText);
313 Widget GenerateTaskDescriptionUI(notnull Widget rootWidget, array<Widget> widgets)
315 Widget parentWidget = GetParentWidget(rootWidget);
319 WorkspaceWidget workspaceWidget = rootWidget.GetWorkspace();
320 if (!workspaceWidget)
327 ResourceName taskDescriptionWidgetResourceName = supportClass.GetTaskDescriptionWidgetResource();
328 if (taskDescriptionWidgetResourceName ==
string.Empty)
331 Widget taskDescriptionWidget = workspaceWidget.CreateWidgets(taskDescriptionWidgetResourceName, parentWidget);
332 widgets.Insert(taskDescriptionWidget);
333 VerticalLayoutSlot.SetPadding(taskDescriptionWidget, 4, 4, 4, 4);
335 m_wTaskListDescription = taskDescriptionWidget;
340 handler.SetTask(
this);
341 handler.UpdateTask(
this);
344 Widget doneLayout = taskDescriptionWidget.FindAnyWidget(
"DoneLayout");
348 doneLayout.SetOpacity(1);
350 doneLayout.SetOpacity(0);
353 RichTextWidget textWidgetRich = RichTextWidget.Cast(taskDescriptionWidget.FindAnyWidget(
"TaskDescription"));
355 return taskDescriptionWidget;
357 string taskText = GetTaskListTaskText();
359 textWidgetRich.SetText(taskText);
361 TextWidget textWidget = TextWidget.Cast(taskDescriptionWidget.FindAnyWidget(
"TaskTitle"));
363 return taskDescriptionWidget;
365 string taskTextTitle = GetTaskListTaskTitle();
367 SetTitleWidgetText(textWidget, taskTextTitle);
368 SetWidgetIcon(ImageWidget.Cast(taskDescriptionWidget.FindAnyWidget(
"TaskIcon")));
370 UpdateTaskListAssignee();
372 return taskDescriptionWidget;
376 void UpdateTaskListAssignee()
378 if (!m_wTaskListDescription)
381 TextWidget textWidget = TextWidget.Cast(m_wTaskListDescription.FindAnyWidget(
"TaskAssignee"));
385 string assigneeNames =
"";
387 assigneeNames =
"#AR-DeployMenu_AssignedPlayers \n" + GetAllAssigneeNamesString();
389 textWidget.SetTextFormat(assigneeNames);
393 void OnAssigneeKilled()
399 void CreateMapUIIcon()
413 void SetTargetFaction(
Faction targetFaction)
425 string GetFinishText()
427 return TASK_FINISHED_TEXT;
434 if (!m_aAssignees || m_aAssignees.Count() <= 0)
442 string GetAllAssigneeNamesString()
448 for (
int i = 0, count = m_aAssignees.Count(); i < count; i++)
450 names += m_aAssignees[i].GetPlayerName();
460 void CheckAssigneeTimeout()
462 if (!m_bIndividualTask || !m_aAssignees || !IsAssigned() || !
GetTaskManager())
469 if (GetAssigneeTimeLeft() <= 0)
476 supportEntity.UnassignTask(
this, assignee, SCR_EUnassignReason.ASSIGNEE_TIMEOUT);
482 void SetLastAssigneeAddedTimestamp(
float timestamp)
484 m_fLastAssigneeAddedTimestamp = timestamp;
489 void SetIndividual(
bool individual)
491 m_bIndividualTask = individual;
498 return m_bIndividualTask;
502 void SetIsPriority(
bool isPrio)
504 m_bIsPriority = isPrio;
510 return m_bIsPriority;
516 return m_bAssignable;
529 SCR_BaseTask localExecutorTask = localExecutor.GetAssignedTask();
530 if (localExecutorTask)
532 if (localExecutorTask !=
this)
541 executor = localExecutor;
545 if (m_bAssignable && !m_bIndividualTask)
548 if (m_bIndividualTask)
556 if (m_TimedOutAssignee == executor && m_fAssigneeTimeoutTimestamp >
GetTaskManager().GetTimestamp())
585 float GetLastAssigneeAddedTimestamp()
587 return m_fLastAssigneeAddedTimestamp;
592 float GetAssigneeTimeLeft()
595 float timeLeft = m_fAssigneeTimeLimit - (currentTimestamp - m_fLastAssigneeAddedTimestamp);
602 void SetTaskID(
int taskID)
622 void SetTitle(
string title)
636 void SetDescription(
string description)
644 string GetDescription()
653 if (!m_aAssignees || m_aAssignees.Count() <= 0)
656 return m_aAssignees[0];
661 int GetAssignees(out array<SCR_BaseTaskExecutor> assignees)
663 return assignees.Copy(m_aAssignees);
667 int GetAssigneeCount()
669 return m_aAssignees.Count();
673 void Cancel(
bool showMsg =
true)
691 assignee.OnAssignedTaskRemoved();
701 void Create(
bool showMsg =
true)
707 void Finish(
bool showMsg =
true)
714 assignee.OnAssignedTaskFinished();
724 void Fail(
bool showMsg =
true)
731 assignee.OnAssignedTaskFailed();
741 void RemoveAllAssignees()
748 for (
int i = m_aAssignees.Count() - 1; i >= 0; i --)
750 removedAssignee = m_aAssignees[i];
751 m_aAssignees[i].OnAssignedTaskRemoved();
752 m_aAssignees.Remove(i);
755 if (m_bIndividualTask)
758 m_fAssigneeTimeoutTimestamp =
GetTaskManager().GetTimestamp() + DEFAULT_ASSIGNEE_TIMEOUT_TIME;
759 m_TimedOutAssignee = removedAssignee;
773 if (!m_aAssignees || !assignee)
776 int index = m_aAssignees.Find(assignee);
781 m_aAssignees.Remove(
index);
783 ShowPopUpNotification(
"#AR-Tasks_UnassignPopup");
785 OnAssigneeRemoved(assignee);
787 if (m_bIndividualTask)
791 case SCR_EUnassignReason.ASSIGNEE_TIMEOUT:
793 m_fAssigneeTimeoutTimestamp =
GetTaskManager().GetTimestamp() + DEFAULT_ASSIGNEE_TIMEOUT_TIME;
794 m_TimedOutAssignee = assignee;
796 case SCR_EUnassignReason.ASSIGNEE_DISCONNECT:
798 case SCR_EUnassignReason.ASSIGNEE_ABANDON:
800 case SCR_EUnassignReason.GM_REASSIGN:
804 ShowAvailableTask(
true);
816 if (!m_aAssignees || !assignee)
819 IEntity assigneeEntity = assignee.GetControlledEntity();
823 if (characterControllerComponent)
824 characterControllerComponent.GetOnPlayerDeath().Insert(OnAssigneeKilled);
831 gameMode.GetOnPlayerSpawned().Insert(InitOnSpawn);
835 if (m_bIndividualTask && m_aAssignees.Count() > 0)
838 int index = m_aAssignees.Find(assignee);
843 SetLastAssigneeAddedTimestamp(timestamp);
845 m_aAssignees.Insert(assignee);
847 ShowPopUpNotification(
"#AR-Tasks_AssignPopup");
849 OnAssigneeAdded(assignee);
857 void InitOnSpawn(
int pid, IEntity ent)
861 charCtrlComp.GetOnPlayerDeath().Insert(OnAssigneeKilled);
864 gameMode.GetOnPlayerSpawned().Remove(InitOnSpawn);
868 void ToggleHUDIcon(
bool show,
bool fade =
true)
872 AnimateWidget.StopAnimation(m_wHUDIcon, WidgetAnimationOpacity);
873 m_wHUDIcon.SetOpacity(1);
880 AnimateWidget.Opacity(m_wHUDIcon, 0, 1);
884 AnimateWidget.StopAnimation(m_wHUDIcon, WidgetAnimationOpacity);
885 m_wHUDIcon.SetOpacity(0);
893 vector pos =
GetGame().GetWorkspace().ProjWorldToScreen(
GetOrigin(), GetWorld());
896 if (!AnimateWidget.IsAnimating(m_wHUDIcon))
897 m_wHUDIcon.SetOpacity(1);
898 FrameSlot.SetPos(m_wHUDIcon, pos[0], pos[1]);
901 m_wHUDIcon.SetOpacity(0);
905 Widget GetTaskIconkWidget()
907 return m_wMapTaskIcon;
911 void SetTaskIconWidget(Widget w)
920 protected void ShowPopUpNotification(
string subtitle)
926 protected void UpdateMapInfo()
931 protected bool DoneByAssignee()
936 protected void ShowTaskProgress(
bool showMsg =
true)
942 protected void ShowAvailableTask(
bool afterAssigneeRemoved =
false)
948 protected bool IsAssignedToLocalPlayer()
959 if (assigneeID == localExecutorID)
989 oldAssignee.AssignNewTask(
null);
991 if (m_aAssignees.Count() <= 0)
995 UpdateTaskListAssignee();
1003 newAssignee.AssignNewTask(
this);
1005 UpdateMapTaskIcon();
1006 UpdateTaskListAssignee();
1024 void Serialize(ScriptBitWriter writer)
1026 FactionManager factionManager =
GetGame().GetFactionManager();
1027 if (!factionManager)
1031 writer.Write(factionIndex, 4);
1032 writer.WriteInt(m_iTaskID);
1033 writer.WriteInt(GetTaskState());
1035 writer.WriteBool(m_bIndividualTask);
1036 writer.WriteFloat(GetLastAssigneeAddedTimestamp());
1037 writer.WriteString(GetTitle());
1038 writer.WriteString(GetDescription());
1040 int assigneesCount = m_aAssignees.Count();
1041 writer.Write(assigneesCount, 7);
1043 for (
int i = 0; i < assigneesCount; i++)
1046 writer.WriteInt(assigneeID);
1053 void Deserialize(ScriptBitReader reader)
1055 FactionManager factionManager =
GetGame().GetFactionManager();
1056 if (!factionManager)
1060 int factionIndex = 0;
1061 reader.Read(factionIndex, 4);
1063 SetTargetFaction(factionManager.GetFactionByIndex(factionIndex));
1066 reader.ReadInt(m_iTaskID);
1070 reader.ReadInt(taskState);
1071 SetState(taskState);
1075 reader.ReadInt(taskMask);
1079 reader.ReadBool(m_bIndividualTask);
1082 reader.ReadFloat(m_fLastAssigneeAddedTimestamp);
1086 reader.ReadString(text);
1090 reader.ReadString(text);
1091 SetDescription(text);
1095 reader.Read(assigneesCount, 7);
1098 for (
int i = 0; i < assigneesCount; i++)
1101 reader.ReadInt(assigneeID);
1103 m_aAssignees.Insert(assignee);
1108 reader.ReadVector(origin);
1115 override void EOnInit(IEntity owner)
1122 m_iTaskID = s_iCurrentTaskID;
1132 m_MapDescriptor = SCR_MapDescriptorComponent.Cast(FindComponent(SCR_MapDescriptorComponent));
1148 SetEventMask(EntityEvent.INIT);
1153 Widget HUDIconRoot =
GetGame().GetWorkspace().CreateWidgets(m_sHUDIcon);
1154 m_wHUDIcon = ImageWidget.Cast(HUDIconRoot.FindAnyWidget(
"TaskIcon"));
1155 m_wHUDIcon.SetOpacity(0);
1165 m_aAssignees.Clear();
1166 m_aAssignees =
null;