Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapUITask.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  protected bool m_bIsEnabled; // task is hovered over & and is clickable
5  protected SCR_BaseTask m_Task;
6  protected TextWidget m_wTaskTitle;
7  protected Widget m_wAssignees;
8  protected Widget m_wMapTask;
9  Widget m_wHorizLayout;
10 
11  //------------------------------------------------------------------------------
12  SCR_MapUITask InitTask(notnull SCR_BaseTask task)
13  {
14  SCR_MapDescriptorComponent descr = SCR_MapDescriptorComponent.Cast(task.FindComponent(SCR_MapDescriptorComponent));
15  if (descr)
16  m_MapItem = descr.Item();
17 
18  MapDescriptorProps props = m_MapItem.GetProps();
19  props.SetIconVisible(false);
20  props.SetTextVisible(false);
21  props.Activate(true);
22 
23  SCR_Faction targetFaction = SCR_Faction.Cast(task.GetTargetFaction());
24 
25  ImageWidget image = ImageWidget.Cast(m_wMapTask.FindAnyWidget("TaskIconBackground"));
26  if (image)
27  task.SetTaskIconWidget(image);
28 
29  image = ImageWidget.Cast(m_wMapTask.FindAnyWidget("TaskIconSymbol"));
30  if (image)
31  {
32  if (targetFaction)
33  image.SetColor(targetFaction.GetOutlineFactionColor());
34 
35  task.SetWidgetIcon(image);
36  }
37 
38  Widget widget = Widget.Cast(m_wMapTask.FindAnyWidget("TaskIconOutline"));
39  if (widget)
40  {
41  if (targetFaction)
42  widget.SetColor(targetFaction.GetOutlineFactionColor());
43  }
44 
45  if (!m_wMapTask)
46  return null;
47 
48  SCR_MapUITask handler = SCR_MapUITask.Cast(m_wMapTask.FindHandler(SCR_MapUITask));
49  if (!handler)
50  return null;
51 
52  SetTask(task);
53  SetEvents();
54 
55  return handler;
56  }
57 
58  //------------------------------------------------------------------------------
59  void SetTask(notnull SCR_BaseTask task)
60  {
61  m_Task = task;
62  SetImage(task.GetTaskMapIconName() + task.GetIconSuffix());
63 
64  if (m_wTaskTitle)
65  m_Task.SetTitleWidgetText(m_wTaskTitle, m_Task.GetTaskListTaskTitle());
66 
67  SetMapMarkerAssigneeCount();
68  }
69 
70  //------------------------------------------------------------------------------
71  SCR_BaseTask GetTask()
72  {
73  return m_Task;
74  }
75 
76  //------------------------------------------------------------------------------
77  Widget GetMapWidget()
78  {
79  return m_wMapTask;
80  }
81 
82  //------------------------------------------------------------------------------
83  override bool OnMouseEnter(Widget w, int x, int y)
84  {
85  super.OnMouseEnter(w, x, y);
86 
88  if (utm)
89  utm.EnableTaskContext(true);
90 
91  if (m_wMapTask)
92  m_wMapTask.SetZOrder(2);
93 
94  if (w.Type() == SizeLayoutWidget)
95  PlayHoverSound(m_sSoundHover);
96 
97  return false;
98  }
99 
100  //------------------------------------------------------------------------------
101  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
102  {
103  super.OnMouseLeave(w, enterW, x, y);
104 
106  if (utm)
107  utm.EnableTaskContext(false);
108 
109  if (m_wMapTask)
110  m_wMapTask.SetZOrder(0);
111 
112  return false;
113  }
114 
115  //------------------------------------------------------------------------------
116  override void HandlerAttached(Widget w)
117  {
118  super.HandlerAttached(w);
119 
120  m_eIconType = SCR_EIconType.TASK;
121  m_wTaskTitle = TextWidget.Cast(w.FindAnyWidget("Title"));
122  m_wImage = ImageWidget.Cast(w.FindAnyWidget("TaskIcon"));
123  m_wAssignees = Widget.Cast(w.FindAnyWidget("Assignee"));
124  m_wHorizLayout = w.FindAnyWidget("HorizLayout");
125  m_wMapTask = w;
126 
127  ButtonWidget taskIconButton;
128  Widget overlayWidget;
129  ButtonWidget taskAssignButton
130 
131  Widget widget = Widget.Cast(w.FindAnyWidget("TaskIconHover"));
132  if (widget)
133  {
134  widget.SetEnabled(false);
135  widget.SetOpacity(0);
136  }
137 
138  widget = Widget.Cast(w.FindAnyWidget("Border"));
139  if (widget)
140  {
141  widget.SetEnabled(false);
142  widget.SetOpacity(0);
143  }
144 
145  widget = Widget.Cast(w.FindAnyWidget("TaskTitleButton"));
146  if (widget)
147  {
148  widget.SetVisible(false);
149  }
150 
151  widget = Widget.Cast(w.FindAnyWidget("Assignee"));
152  if (widget)
153  {
154  widget.SetEnabled(false);
155  widget.SetOpacity(0);
156  }
157 
158  SCR_TaskSelectButton iconButtonHandler;
159  SCR_TaskOverlayButton overlayButtonHandler;
160  SCR_TaskAssignButton assignButtonHandler;
161 
162  taskIconButton = ButtonWidget.Cast(w.FindAnyWidget("TaskIconButton"));
163  if (taskIconButton)
164  {
165  iconButtonHandler = SCR_TaskSelectButton.Cast(taskIconButton.FindHandler(SCR_TaskSelectButton));
166  if (iconButtonHandler)
167  iconButtonHandler.SetRootWidgetHandler(this);
168  }
169 
170  overlayWidget = w.FindAnyWidget("OverlayWidget");
171  if (overlayWidget)
172  {
173  overlayButtonHandler = SCR_TaskOverlayButton.Cast(overlayWidget.FindHandler(SCR_TaskOverlayButton));
174  if (overlayButtonHandler)
175  overlayButtonHandler.SetRootWidgetHandler(this);
176  }
177 
178  taskAssignButton = ButtonWidget.Cast(w.FindAnyWidget("TaskTitleButton"));
179  if (taskAssignButton)
180  {
181  assignButtonHandler = SCR_TaskAssignButton.Cast(taskAssignButton.FindHandler(SCR_TaskAssignButton));
182  if (assignButtonHandler)
183  assignButtonHandler.SetRootWidgetHandler(this);
184  }
185 
186  if (GetTaskManager())
187  {
188  SCR_BaseTaskManager.s_OnTaskAssigned.Insert(GetAssignedPlayers);
189  SCR_BaseTaskManager.s_OnTaskUnassigned.Insert(GetAssignedPlayers);
190  }
191  }
192 
193  //------------------------------------------------------------------------------
194  override void HandlerDeattached(Widget w)
195  {
196  if (GetTaskManager())
197  {
198  SCR_BaseTaskManager.s_OnTaskAssigned.Remove(GetAssignedPlayers);
199  SCR_BaseTaskManager.s_OnTaskUnassigned.Remove(GetAssignedPlayers);
200  }
201  }
202 
203  //------------------------------------------------------------------------------
204  void AssignTask()
205  {
206  if (!m_Task)
207  return;
208 
210  if (!taskNetworkComp)
211  return;
212 
213  int taskId;
214  SCR_BaseTask curTask = SCR_BaseTaskExecutor.GetLocalExecutor().GetAssignedTask();
215  if (curTask)
216  {
217  taskId = curTask.GetTaskID();
218  taskNetworkComp.AbandonTask(taskId);
219  if (curTask != m_Task)
220  {
221  taskId = m_Task.GetTaskID();
222  taskNetworkComp.RequestAssignment(taskId);
223  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.TASK_ACCEPT);
224  }
225  else
226  {
227  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.TASK_CANCELED);
228  }
229  }
230  else
231  {
232  taskId = m_Task.GetTaskID();
233  taskNetworkComp.RequestAssignment(taskId);
234  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.TASK_ACCEPT);
235  }
236  }
237 
238  //------------------------------------------------------------------------------
239  void GetAssignedPlayers(SCR_BaseTask task = null)
240  {
241  if (!task || task != m_Task)
242  return;
243 
244  task.UpdateMapTaskIcon();
245 
246  array<SCR_BaseTaskExecutor> assignees = {};
247  m_Task.GetAssignees(assignees);
248  if (assignees.IsEmpty())
249  {
250  m_wAssignees.SetEnabled(false);
251  m_wAssignees.SetOpacity(0);
252  return;
253  }
254 
255  m_wAssignees.SetEnabled(true);
256  m_wAssignees.SetOpacity(1);
257 
258  SetMapMarkerAssigneeCount();
259  }
260 
261  //------------------------------------------------------------------------------
262  void SetMapMarkerAssigneeCount()
263  {
264  TextWidget assigneesCount = TextWidget.Cast(m_wAssignees.FindAnyWidget("AssigneesCount"));
265  if (assigneesCount)
266  assigneesCount.SetText(m_Task.GetAssigneeCount().ToString());
267  }
268 
269  //------------------------------------------------------------------------------
270  void UpdateFocusedTask()
271  {
273  if (utm)
274  utm.Action_SelectTask(m_Task);
275  }
276 
277  //------------------------------------------------------------------------------
278  void SetEvents()
279  {
280  ButtonWidget assignButton = ButtonWidget.Cast(m_wMapTask.FindAnyWidget("TaskTitleButton"));
281  if (assignButton)
282  {
283  SCR_TaskAssignButton handler = SCR_TaskAssignButton.Cast(assignButton.FindHandler(SCR_TaskAssignButton));
284  if (handler)
285  handler.GetOnMapIconClick().Insert(AssignTask);
286  }
287 
288  ButtonWidget selectButton = ButtonWidget.Cast(m_wMapTask.FindAnyWidget("TaskIconButton"));
289  if (selectButton)
290  {
291  SCR_TaskSelectButton handler = SCR_TaskSelectButton.Cast(selectButton.FindHandler(SCR_TaskSelectButton));
292  if (handler)
293  handler.GetOnMapIconClick().Insert(UpdateFocusedTask);
294  }
295  }
296 
297  //------------------------------------------------------------------------------
298  override vector GetPos()
299  {
300  if (!m_Task)
301  return vector.Zero;
302 
303  return m_Task.GetOrigin();
304  }
305 };
SetImage
void SetImage(BackendImage image)
image can be null
Definition: SCR_BackendImageComponent.c:36
m_MapItem
protected MapItem m_MapItem
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:14
m_Task
SCR_EditableTaskComponentClass m_Task
Editable SCR_BaseTask.
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
SCR_EIconType
SCR_EIconType
Definition: SCR_MapUIElement.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
SCR_UITaskManagerComponent
void SCR_UITaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_UITaskManagerComponent.c:1096
SCR_TaskNetworkComponent
void SCR_TaskNetworkComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_TaskNetworkComponent.c:207
MapDescriptorProps
Definition: MapDescriptorProps.c:12
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_BaseTaskManager
Definition: SCR_BaseTaskManager.c:25
SCR_TaskOverlayButton
Definition: SCR_TaskOverlayButton.c:1
SCR_MapUITask
Definition: SCR_MapUITask.c:2
SCR_MapUIElement
Definition: SCR_MapUIElement.c:12
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
m_wImage
protected ImageWidget m_wImage
Definition: SCR_BackendImageComponent.c:248
SCR_TaskAssignButton
Definition: SCR_TaskAssignButton.c:1
SCR_Faction
Definition: SCR_Faction.c:6
SCR_TaskSelectButton
Definition: SCR_TaskSelectButton.c:1