Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TaskListEntryHandler.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  protected SCR_CollapseWidgetComponent m_CollapseHandler;
5 
6  protected SCR_InputButtonComponent m_AssignButton;
7  protected SCR_InputButtonComponent m_ShowOnMapButton;
8 
9  protected SCR_BaseTask m_Task;
10  protected Widget m_wMainWidget;
11 
12  protected static const string ACCEPT_TASK = "#AR-CampaignTasks_ButtonAccept";
13  protected static const string ABANDON_TASK = "#AR-CampaignTasks_ButtonAbandon";
14  protected static const string CANCEL_TASK = "#AR-CampaignTasks_ButtonCancel";
15  protected static const string LOCAL_EXECUTOR_IS_ASSIGNED_TEXT = "#AR-CampaignTasks_ButtonBusy";
16  protected static const string ASSIGNEE_TIMEOUT_TEXT = "#AR-CampaignTasks_ButtonWait";
17  protected static const string TASK_ABANDONED_TEXT = "#AR-CampaignTasks_ButtonWait";
18 
19  protected static const float ANIM_SPEED = UIConstants.FADE_RATE_SUPER_FAST;
20 
21  protected string m_sAssignees = "AssigneesLayout";
22  protected Widget m_wAssignees;
23  protected Widget m_wRootWidget;
24 
25  [Attribute("0.761 0.386 0.08 1")]
26  protected ref Color m_AssignedTaskColor;
27 
28  [Attribute("{10C0A9A305E8B3A4}UI/Imagesets/Tasks/Task_Icons.imageset", category: "Task icon", params: "imageset")]
29  protected ResourceName m_sIconImageset;
30 
31  //------------------------------------------------------------------------------------------------
32  SCR_BaseTask GetTask()
33  {
34  return m_Task;
35  }
36 
37  //------------------------------------------------------------------------------------------------
38  void SetTask(SCR_BaseTask task)
39  {
40  m_Task = task;
41  }
42 
43  //------------------------------------------------------------------------------------------------
44  void SetAssigneeCount(int count)
45  {
46  TextWidget text = TextWidget.Cast(m_wAssignees.FindAnyWidget("Text"));
47  if (text)
48  text.SetText(count.ToString());
49  m_wAssignees.SetVisible(count > 0);
50  }
51 
52  //------------------------------------------------------------------------------------------------
53  void SetTaskTextColor()
54  {
55  SCR_BaseTask localTask = SCR_BaseTaskExecutor.GetLocalExecutor().GetAssignedTask();
56  RichTextWidget textWidget = RichTextWidget.Cast(m_wRoot.FindAnyWidget("TaskTitle"));
57  if (m_Task == localTask)
58  textWidget.SetColor(m_AssignedTaskColor);
59  else
60  textWidget.SetColor(Color.FromInt(Color.WHITE));
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  void SetTaskIconColor()
65  {
66  SCR_BaseTask localTask = SCR_BaseTaskExecutor.GetLocalExecutor().GetAssignedTask();
67  ImageWidget outline = ImageWidget.Cast(m_wRoot.FindAnyWidget("Icon_Outline"));
68  ImageWidget symbol = ImageWidget.Cast(m_wRoot.FindAnyWidget("Icon_Symbol"));
69  ImageWidget background = ImageWidget.Cast(m_wRoot.FindAnyWidget("Icon_Background"));
70 
71  if (!outline || !symbol || !background || !m_Task)
72  return;
73 
74  SCR_Faction faction = SCR_Faction.Cast(m_Task.GetTargetFaction());
75  if (!faction)
76  return;
77 
78  if (m_Task == localTask)
79  {
80  background.SetColor(faction.GetFactionColor());
81  }
82  else if (m_Task.IsPriority())
83  {
84  background.LoadImageFromSet(0,m_sIconImageset, SCR_BaseTask.TASK_BG_M);
85  background.SetColor(Color.FromInt(Color.WHITE));
86  outline.LoadImageFromSet(0,m_sIconImageset, SCR_BaseTask.TASK_O_M);
87  }
88  else
89  {
90  background.LoadImageFromSet(0,m_sIconImageset, SCR_BaseTask.TASK_BG);
91  background.SetColor(Color.FromInt(Color.WHITE));
92  outline.LoadImageFromSet(0,m_sIconImageset, SCR_BaseTask.TASK_O);
93  }
94 
95  symbol.LoadImageFromSet(0, m_Task.GetIconImageset(), m_Task.GetTaskListIconName() + m_Task.GetIconSuffix());
96  outline.SetColor(faction.GetOutlineFactionColor());
97  symbol.SetColor(faction.GetOutlineFactionColor());
98  }
99 
100  //------------------------------------------------------------------------------------------------
101  void UpdateTask(SCR_BaseTask task)
102  {
103  ImageWidget outline = ImageWidget.Cast(m_wRoot.FindAnyWidget("Icon_Outline"));
104  ImageWidget symbol = ImageWidget.Cast(m_wRoot.FindAnyWidget("Icon_Symbol"));
105  ImageWidget background = ImageWidget.Cast(m_wRoot.FindAnyWidget("Icon_Background"));
106 
107  if (!outline || !symbol || !background || !m_Task)
108  return;
109 
110  if (task == m_Task)
111  {
112  SetAssigneeCount(task.GetAssigneeCount());
113  UpdateAssignButtonText(task);
114  SetTaskTextColor();
115  SetTaskIconColor();
116 
117  TextWidget textWidget = TextWidget.Cast(m_wRoot.FindAnyWidget("TaskTitle"));
118  if (textWidget)
119  task.SetTitleWidgetText(textWidget, task.GetTaskListTaskTitle());
120 
121  textWidget = TextWidget.Cast(m_wRoot.FindAnyWidget("TaskDescription"));
122  if (textWidget)
123  task.SetTitleWidgetText(textWidget, task.GetTaskListTaskText());
124  }
125 
126  if (m_Task.IsPriority())
127  {
128  background.LoadImageFromSet(0,m_sIconImageset, SCR_BaseTask.TASK_BG_M);
129  outline.LoadImageFromSet(0,m_sIconImageset, SCR_BaseTask.TASK_O_M);
130  }
131  else
132  {
133  background.LoadImageFromSet(0,m_sIconImageset, SCR_BaseTask.TASK_BG);
134  outline.LoadImageFromSet(0,m_sIconImageset, SCR_BaseTask.TASK_O);
135  }
136  }
137 
138  //------------------------------------------------------------------------------------------------
139  protected void UpdateAssignButtonText(SCR_BaseTask task)
140  {
142  if (task.CanBeAssigned(reason))
143  {
144  if (m_AssignButton)
145  m_AssignButton.SetLabel(ACCEPT_TASK);
146  }
147  else
148  {
149  switch (reason)
150  {
151  case SCR_ECannotAssignReasons.TASK_IS_ASSIGNED:
152  {
153  m_AssignButton.SetLabel(ABANDON_TASK)
154  } break;
155 
156  case SCR_ECannotAssignReasons.TASK_IS_ASSIGNED_TO_LOCAL_EXECUTOR:
157  {
158  m_AssignButton.SetLabel(ABANDON_TASK);
159  } break;
160 
161  case SCR_ECannotAssignReasons.IS_TASK_REQUESTER:
162  {
163  m_AssignButton.SetLabel(CANCEL_TASK);
164  } break;
165 
166  // Another task is already assigned to a local executor, so CanBeAssigned returns false. However in this case the task can be assigned by clicking on assign button.
167  case SCR_ECannotAssignReasons.LOCAL_EXECUTOR_IS_ASSIGNED:
168  {
169  m_AssignButton.SetLabel(ACCEPT_TASK);
170  } break;
171  }
172  }
173  }
174 
175  //------------------------------------------------------------------------------------------------
176  void Expand(bool expand)
177  {
178  float targetOpacity = 0;
179  if (expand)
180  targetOpacity = 1;
181 
182  m_AssignButton.SetEnabled(expand);
183  Widget assignBtn = m_wRoot.FindAnyWidget("AcceptButton");
184  AnimateWidget.Opacity(assignBtn, targetOpacity, ANIM_SPEED);
185 
186  Widget mapBtn = m_wRoot.FindAnyWidget("MapButton");
187  AnimateWidget.Opacity(mapBtn, targetOpacity, ANIM_SPEED);
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  override bool OnClick(Widget w, int x, int y, int button)
192  {
193  super.OnClick(w, x, y, button);
194 
195  InputManager im = GetGame().GetInputManager();
196  if (!im.IsUsingMouseAndKeyboard() || !IsAnyButtonHovered())
197  return false;
198 
199  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.TASK_ACCEPT);
200  ExpandTaskLayout();
201 
202  return false;
203  }
204 
205  //------------------------------------------------------------------------------------------------
206  void ExpandTaskLayout()
207  {
208  if (!m_CollapseHandler)
209  return;
210 
211  m_CollapseHandler.SetCollapsed(!m_CollapseHandler.IsCollapsed());
212  Expand(!m_CollapseHandler.IsCollapsed());
213 
214  SCR_UITaskManagerComponent uiTaskManager = SCR_UITaskManagerComponent.GetInstance();
215  if (!uiTaskManager)
216  return;
217 
218  foreach (Widget task : uiTaskManager.GetWidgetsArray())
219  {
221  if (collapse && collapse != this && !collapse.IsCollapsed())
222  {
223  collapse.Expand(false);
224  collapse.SetCollapsed(true);
225  }
226  }
227  }
228 
229  //------------------------------------------------------------------------------------------------
230  override bool OnFocusLost(Widget w, int x, int y)
231  {
232  super.OnFocusLost(w, x, y);
233 
235  if (!tm)
236  return false;
237 
238  tm.SelectTask(null);
239  tm.SetSelectedWidget(w);
240 
241  return false;
242  }
243 
244  //------------------------------------------------------------------------------------------------
245  override bool OnFocus(Widget w, int x, int y)
246  {
247  super.OnFocus(w, x, y);
249  if (!tm)
250  return false;
251 
252  tm.SelectTask(m_Task);
253 
254  return false;
255  }
256 
257  //------------------------------------------------------------------------------------------------
258  void SetCollapsed(bool collapse, bool anim = true)
259  {
260  int opacity = 1;
261  if (collapse)
262  opacity = 0;
263 
264  m_CollapseHandler.SetCollapsed(collapse, anim);
265  Widget assignBtns = m_wRoot.FindAnyWidget("AcceptButton");
266  if (assignBtns)
267  {
268  assignBtns.SetOpacity(opacity);
269  assignBtns.SetEnabled(opacity);
270 
271  Widget mapBtn = m_wRoot.FindAnyWidget("MapButton");
272  if (mapBtn)
273  {
274  mapBtn.SetOpacity(opacity);
275  mapBtn.SetEnabled(opacity);
276  }
277  }
278  }
279 
280  //------------------------------------------------------------------------------------------------
281  protected bool IsAnyButtonHovered()
282  {
283  return (!m_ShowOnMapButton.IsHovering() &&
284  !m_AssignButton.IsHovering());
285  }
286 
287  //------------------------------------------------------------------------------------------------
288  protected bool IsCollapsed()
289  {
290  return m_CollapseHandler.IsCollapsed();
291  }
292 
293  //------------------------------------------------------------------------------------------------
294  protected void AcceptTask()
295  {
297  if (utm)
298  utm.Action_AssignTask(m_Task);
299  }
300 
301  //------------------------------------------------------------------------------------------------
302  protected void PickAssignee()
303  {
305  if (utm)
306  utm.Action_PickAssignee();
307  }
308 
309  //------------------------------------------------------------------------------------------------
310  protected void ShowOnMap()
311  {
313  if (utm)
314  utm.Action_ShowOnMap();
315  }
316 
317  //------------------------------------------------------------------------------------------------
318  override void HandlerAttached(Widget w)
319  {
320  super.HandlerAttached(w);
321 
322  SCR_BaseTaskManager.s_OnTaskUpdate.Insert(UpdateTask);
323 
324  m_wAssignees = w.FindAnyWidget(m_sAssignees);
325 
326  m_AssignButton = SCR_InputButtonComponent.GetInputButtonComponent("AcceptButton", w);
327  if (m_AssignButton)
328  {
329  m_AssignButton.SetEnabled(false);
330  m_AssignButton.m_OnActivated.Insert(AcceptTask);
331  }
332 
333  m_ShowOnMapButton = SCR_InputButtonComponent.GetInputButtonComponent("MapButton", w);
334  if (m_ShowOnMapButton)
335  m_ShowOnMapButton.m_OnActivated.Insert(ShowOnMap);
336 
337  Widget collapse = w.FindAnyWidget("Description");
338  if (collapse)
339  {
340  m_CollapseHandler = SCR_CollapseWidgetComponent.Cast(collapse.FindHandler(SCR_CollapseWidgetComponent));
341  //GetGame().GetCallqueue().CallLater(SetCollapsed, 10, false, true, false);
342  }
343 
344  m_wRootWidget = w;
345 
346  Widget assignBtn = m_wRoot.FindAnyWidget("AcceptButton");
347  if (assignBtn)
348  assignBtn.SetOpacity(0);
349 
350  Widget mapBtn = m_wRoot.FindAnyWidget("MapButton");
351  if (mapBtn)
352  mapBtn.SetOpacity(0);
353  }
354 
355  //------------------------------------------------------------------------------------------------
356  override void HandlerDeattached(Widget w)
357  {
358  super.HandlerDeattached(w);
359 
360  SCR_BaseTaskManager.s_OnTaskUpdate.Remove(UpdateTask);
361  }
362 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
m_Task
SCR_EditableTaskComponentClass m_Task
Editable SCR_BaseTask.
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
SCR_TaskListEntryHandler
Definition: SCR_TaskListEntryHandler.c:2
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
SCR_UITaskManagerComponent
void SCR_UITaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_UITaskManagerComponent.c:1096
SCR_ECannotAssignReasons
SCR_ECannotAssignReasons
Definition: SCR_ECampaignTaskReasons.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_BaseTaskManager
Definition: SCR_BaseTaskManager.c:25
CANCEL_TASK
@ CANCEL_TASK
Definition: SCR_ETaskButtonActions.c:6
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition: SCR_ButtonBaseComponent.c:3
m_AssignedTaskColor
protected ref Color m_AssignedTaskColor
Definition: SCR_UITaskManagerComponent.c:58
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
SCR_CollapseWidgetComponent
Definition: SCR_CollapseWidgetComponent.c:9
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
ABANDON_TASK
@ ABANDON_TASK
Definition: SCR_ETaskButtonActions.c:5
SCR_Faction
Definition: SCR_Faction.c:6
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180