Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actiontargetscursor.c
Go to the documentation of this file.
2 {
3  protected Object m_CachedObject;
4  protected vector m_CursorWPos;
5  protected vector m_ScreenPos;
6  protected int m_CompIdx;
7 
8  void ATCCachedTarget()
9  {
10  m_CachedObject = null;
11  m_ScreenPos = vector.Zero;
12  m_CompIdx = -1;
13  }
14 
16  void Store(Object obj, vector pos, int compIdx)
17  {
18  if (!m_CachedObject)
19  {
20  m_CachedObject = obj;
21  m_CursorWPos = pos;
22  m_CompIdx = compIdx;
23  }
24  }
25 
27  void Invalidate()
28  {
29  if (m_CachedObject)
30  {
31  m_CachedObject = null;
32  m_CursorWPos = vector.Zero;
33  m_CompIdx = -1;
34  }
35  }
36 
37  Object Get()
38  {
39  return m_CachedObject;
40  }
41 
42  vector GetCursorWorldPos()
43  {
44  return m_CursorWPos;
45  }
46 
47  int GetCursorCompIdx()
48  {
49  return m_CompIdx;
50  }
51 };
52 
54 {
55  private const ref array<typename> VISION_OBSTRUCTION_PPEFFECTS_TYPES = {
56  PPERequester_BurlapSackEffects,
57  PPERequester_FlashbangEffects
58  };
59 
60  protected PlayerBase m_Player;
61  protected ActionTarget m_Target;
62  protected ref ATCCachedObject m_CachedObject;
63  protected Object m_DisplayInteractTarget;
64 
65  protected ActionBase m_Interact;
66  protected ActionBase m_ContinuousInteract;
67  protected ActionBase m_Single;
68  protected ActionBase m_Continuous;
69  protected ActionManagerClient m_AM;
70  protected IngameHud m_Hud;
71 
72  protected UAIDWrapper m_UseActionWrapper;
73 
74  protected int m_InteractActionsNum;
75  protected int m_ContinuousInteractActionsNum;
76  protected int m_ItemActionsNum;
77  protected int m_ContinuousItemActionsNum;
78  protected typename m_SelectedActionCategory;
79  protected bool m_HealthEnabled;
80  protected bool m_QuantityEnabled;
81  protected bool m_FixedOnPosition;
82  protected bool m_Hidden;
83 
84  protected Widget m_Root;
85  protected Widget m_Container;
86  protected Widget m_ItemLeft;
87 
89  protected float m_MaxWidthChild;
90  protected float m_RootWidth;
91  protected float m_RootHeight;
92 
93  void ActionTargetsCursor()
94  {
95  m_Interact = null;
96  m_ContinuousInteract = null;
97  m_Single = null;
98  m_Continuous = null;
99  m_AM = null;
100 
101  m_HealthEnabled = true;
102  m_QuantityEnabled = true;
103 
104  m_CachedObject = new ATCCachedObject;
105  m_Hidden = false;
106  m_DisplayInteractTarget = null;
107 
108  m_Hud = GetHud();
109 
110  m_UseActionWrapper = GetUApi().GetInputByID(UAAction).GetPersistentWrapper();
111 
112  GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
113  GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
114  }
115 
116  void ~ActionTargetsCursor() {}
117 
118  // Controls appearance of the builded cursor
119  void SetHealthVisibility(bool state)
120  {
121  m_HealthEnabled = state;
122  }
123 
124  void SetQuantityVisibility(bool state)
125  {
126  m_QuantityEnabled = state;
127  }
128 
130  void SetInteractXboxIcon(string imageset_name, string image_name);
131  void SetContinuousInteractXboxIcon(string imageset_name, string image_name);
132  void SetSingleXboxIcon(string imageset_name, string image_name);
133  void SetContinuousXboxIcon(string imageset_name, string image_name);
134  protected void SetXboxIcon(string name, string imageset_name, string image_name);
136 
137  protected void SetControllerIcon(string pWidgetName, string pInputName)
138  {
139  RichTextWidget w = RichTextWidget.Cast(m_Root.FindAnyWidget(pWidgetName + "_btn_icon_xbox"));
140  w.SetText(InputUtils.GetRichtextButtonIconFromInputAction(pInputName, "", EUAINPUT_DEVICE_CONTROLLER));
141  }
142 
143  protected void OnWidgetScriptInit(Widget w)
144  {
145  m_Root = w;
146  m_Root.Show(false);
147  m_Root.SetHandler(this);
148 
150  UpdateControllerInputIcons();
151  UpdatePCIconsVisibility();
152 
153  m_Container = w.FindAnyWidget("container");
154  m_ItemLeft = w.FindAnyWidget("item_left");
155 
156  m_Root.Update();
157  }
158 
159  protected void OnInputPresetChanged()
160  {
161  #ifdef PLATFORM_CONSOLE
162  UpdateControllerInputIcons();
163  #endif
164  }
165 
166  protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
167  {
168  UpdatePCIconsVisibility();
169  }
170 
172  private void UpdateControllerInputIcons()
173  {
174  SetControllerIcon("interact", "UAAction");
175  SetControllerIcon("continuous_interact", "UAAction");
176  SetControllerIcon("single", "UADefaultAction");
177  SetControllerIcon("continuous", "UADefaultAction");
178  }
179 
181  private void UpdatePCIconsVisibility()
182  {
183  bool showConsoleIcons = false;
184  #ifdef PLATFORM_CONSOLE
185  showConsoleIcons = GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER || !GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
186  #endif
187 
188  ShowXboxHidePCIcons("interact", showConsoleIcons);
189  ShowXboxHidePCIcons("continuous_interact", showConsoleIcons);
190  ShowXboxHidePCIcons("continuous", showConsoleIcons);
191  ShowXboxHidePCIcons("single", showConsoleIcons);
192  }
193 
194  protected void PrepareCursorContent()
195  {
196  int health = -1;
197  int cargoCount = 0;
198  int q_type = 0;
199  int q_min, q_max = -1;
200  float q_cur = -1.0;
201 
203  health = GetItemHealth();
204  SetItemHealth(health, "item", "item_health_mark", m_HealthEnabled);
206  GetItemQuantity(q_type, q_cur, q_min, q_max);
208  GetItemCargoCount(cargoCount);
210  SetItemQuantity(q_type, q_cur, q_min, q_max, "item", "item_quantity_pb", "item_quantity_text", m_QuantityEnabled);
211  SetInteractActionIcon("interact", "interact_icon_frame", "interact_btn_inner_icon", "interact_btn_text");
212  SetItemDesc(GetItemDesc(m_Interact), cargoCount, "item", "item_desc");
213  SetActionWidget(m_Interact, GetActionDesc(m_Interact), "interact", "interact_action_name");
214 
215  SetInteractActionIcon("continuous_interact", "continuous_interact_icon_frame", "continuous_interact_btn_inner_icon", "continuous_interact_btn_text");
216  SetActionWidget(m_ContinuousInteract, GetActionDesc(m_ContinuousInteract), "continuous_interact", "continuous_interact_action_name");
217 
218  SetActionWidget(m_Single, GetActionDesc(m_Single), "single", "single_action_name");
219  SetActionWidget(m_Continuous, GetActionDesc(m_Continuous), "continuous", "continuous_action_name");
220  SetMultipleItemAction("single_mlt_wrapper", "single_mlt_wrapper_not_select");
221  SetMultipleContinuousItemAction("continuous_mlt_wrapper", "continuous_mlt_wrapper_not_select");
222  SetMultipleInteractAction("interact_mlt_wrapper", "interact_mlt_wrapper_not_select");
223  SetMultipleContinuousInteractAction("continuous_interact_mlt_wrapper", "continuous_interact_mlt_wrapper_not_select");
224  }
225 
226  protected void BuildFixedCursor()
227  {
228  int w, h, x, y;
229 
230  PrepareCursorContent();
231  GetScreenSize(w, h);
232  x = w/2 + 32;
233  y = h/2 + 32;
234 
235  m_Root.SetPos(x, y);
236  }
237 
238  protected void BuildFloatingCursor(bool forceRebuild)
239  {
240  float pos_x, pos_y = 0.0;
241 
242  PrepareCursorContent();
243 
245  if (forceRebuild || m_Target.GetComponentIndex() != m_CachedObject.GetCursorCompIdx())
246  {
247  GetOnScreenPosition(pos_x, pos_y);
248  }
250  else
251  {
252  vector screen_pos = TransformToScreenPos(m_CachedObject.GetCursorWorldPos());
253 
254  pos_x = screen_pos[0];
255  pos_y = screen_pos[1];
256  }
257 
258  pos_x = Math.Ceil(pos_x);
259  pos_y = Math.Ceil(pos_y);
260 
261  Widget parentWdg = m_Root.GetParent();
262 
263  float screen_w = 0;
264  float screen_h = 0;
265 
266  float wdg_w = 0;
267  float wdg_h = 0;
268 
269  parentWdg.GetScreenSize(screen_w, screen_h);
270  m_Root.GetSize(wdg_w, wdg_h);
271 
272  if (pos_x + wdg_w > screen_w)
273  pos_x = screen_w - wdg_w;
274 
275  if (pos_y + wdg_h > screen_h)
276  pos_y = screen_h - wdg_h;
277 
278  m_Root.SetPos(pos_x, pos_y);
279  }
280 
281  override bool OnUpdate(Widget w)
282  {
283  if (m_Root == w)
284  {
285  Update();
286  return true;
287  }
288 
289  return false;
290  }
291 
292  protected void HideWidget()
293  {
294  if (m_Root.IsVisible())
295  {
296  m_Root.Show(false);
297  m_CachedObject.Invalidate();
298  }
299  }
300 
301  void Update()
302  {
303  if (m_Player && !m_Player.IsAlive()) // handle respawn
304  {
305  m_Player = null;
306  m_AM = null;
307  }
308 
309  if (!m_Player)
310  GetPlayer();
311 
312  if (!m_AM)
313  GetActionManager();
314 
315  if (m_Player.IsInVehicle() || m_AM.GetRunningAction())
316  m_Hidden = true;
317 
318 
319  /*
320  #ifdef DIAG_DEVELOPER
321  if (DeveloperFreeCamera.IsFreeCameraEnabled())
322  HideWidget();
323  return;
324  #endif
325  */
326 
327  bool isVisionObstructionActive = PPEManagerStatic.GetPPEManager().IsAnyRequesterRunning(VISION_OBSTRUCTION_PPEFFECTS_TYPES);
328 
330  if (GetGame().GetUIManager().GetMenu() || !g_Game.GetProfileOption(EDayZProfilesOptions.HUD) || m_Hud.IsHideHudPlayer() || m_Player.IsUnconscious() || isVisionObstructionActive)
331  {
332  HideWidget();
333  return;
334  }
335 
336  GetTarget();
337  GetActions();
338 
340  bool showTarget = (m_Target && !m_Hidden) || m_Interact || m_ContinuousInteract;
341  if (!showTarget)
342  {
343  if (m_Single)
344  showTarget = m_Single.HasTarget();
345 
346  if (m_Continuous)
347  showTarget = showTarget || m_Continuous.HasTarget();
348  }
349 
350  if (showTarget)
351  {
353  if (m_Target.GetObject() == null && (m_Interact || m_ContinuousInteract || m_Single || m_Continuous))
354  {
355  //Print(">> fixed widget");
356  m_CachedObject.Invalidate();
357  BuildFixedCursor();
358  m_Root.Show(true);
359  m_FixedOnPosition = false;
360  m_Hidden = false;
361  return;
362  }
363  else if (m_Target.GetObject() != null && !m_Target.GetObject().IsHologram() && (!m_Target.GetParent() || m_Target.GetParent() && !m_Target.GetParent().IsHologram()))
364  {
365  CheckRefresherFlagVisibility(m_Target.GetObject());
367  if (m_Target.GetObject() != m_CachedObject.Get())
368  {
369  if (!m_FixedOnPosition)
370  {
371  //Print(">> non-cached widget");
372  m_CachedObject.Invalidate();
373  BuildFloatingCursor(true);
374  m_Root.Show(true);
375  m_Hidden = false;
376  return;
377  }
378  else
379  {
380  //Print(">> non-cached widget (fixed)");
381  m_CachedObject.Invalidate();
382  BuildFixedCursor();
383  m_Root.Show(true);
384  m_FixedOnPosition = false;
385  m_Hidden = false;
386  return;
387  }
388  }
390  else if (m_Target.GetObject() == m_CachedObject.Get())
391  {
392  if (!m_FixedOnPosition)
393  {
394  //Print(">> cached widget");
395  BuildFloatingCursor(false);
396  m_Root.Show(true);
397  m_Hidden = false;
398  return;
399  }
400  else
401  {
402  //Print(">> cached widget (fixed)");
403  m_CachedObject.Invalidate();
404  BuildFixedCursor();
405  m_Root.Show(true);
406  m_FixedOnPosition = false;
407  m_Hidden = false;
408  return;
409  }
410  }
411  }
412  else
413  {
414  if (m_Root.IsVisible())
415  {
416  m_CachedObject.Invalidate();
417  m_Root.Show(false);
418  m_Hidden = false;
419 
420  // remove previous backlit
421  GetDayZGame().GetBacklit().HintClear();
422  }
423  }
424  }
425  else
426  {
427  if (m_Root.IsVisible())
428  {
429  m_CachedObject.Invalidate();
430  m_Root.Show(false);
431  m_FixedOnPosition = false;
432 
433  // remove previous backlit
434  GetDayZGame().GetBacklit().HintClear();
435  }
436 
437  m_Hidden = false;
438  }
439 
440  m_MaxWidthChild = 350;
441  }
442 
443  protected void ShowXboxHidePCIcons(string widget, bool show_xbox_icon)
444  {
445  m_Root.FindAnyWidget(widget + "_btn_icon_xbox").Show(show_xbox_icon);
446  m_Root.FindAnyWidget(widget + "_btn_icon").Show(!show_xbox_icon);
447  }
448 
449 
451  protected vector TransformToScreenPos(vector pWorldPos)
452  {
453  float parent_width, parent_height;
454  vector transformed_pos, screen_pos;
455 
457  screen_pos = GetGame().GetScreenPosRelative(pWorldPos);
459  m_Root.GetParent().GetScreenSize(parent_width, parent_height);
460 
462  transformed_pos[0] = screen_pos[0] * parent_width;
463  transformed_pos[1] = screen_pos[1] * parent_height;
464 
465  return transformed_pos;
466  }
467 
468  protected void GetOnScreenPosition(out float x, out float y)
469  {
470  const float DEFAULT_HANDLE_OFFSET = 0.2;
471  const string CE_CENTER_COMP_NAME = "ce_center";
472  const string MEM_LOD_NAME = LOD.NAME_MEMORY;
473 
474  int compIdx;
475  float pivotOffset = 0.0;
476  float memOffset = 0.0;
477  string compName;
478 
479  bool isTargetForced = false;
480 
481  vector worldPos;
482  vector modelPos;
483 
484  LOD lod;
485 
486  array<Selection> memSelections = new array<Selection>();
487  array<string> components = new array<string>; // for components with multiple selection
488 
489  Object object;
490 
491  if (m_Target)
492  {
493  object = m_Target.GetObject();
494  compIdx = m_Target.GetComponentIndex();
495 
496  if (m_Target.GetCursorHitPos() == vector.Zero)
497  isTargetForced = true;
498  }
499  else
500  {
501  return;
502  }
503 
504  if (object)
505  {
506  if (!isTargetForced)
507  {
508  compName = object.GetActionComponentName(compIdx);
509  object.GetActionComponentNameList(compIdx, components);
510 
511  if (!object.IsInventoryItem() && (object.HasFixedActionTargetCursorPosition() || object.GetActionComponentNameList(compIdx, components) == 0))
512  {
513  m_FixedOnPosition = true;
514  return;
515  }
516 
517  pivotOffset = object.ConfigGetFloat("actionTargetPivotOffsetY");
518  memOffset = object.ConfigGetFloat("actionTargetMemOffsetY");
519 
521  lod = object.GetLODByName(MEM_LOD_NAME);
522  if (lod != null)
523  {
525  lod.GetSelections(memSelections);
526 
527  // items with CE_Center mem point
528  if (MiscGameplayFunctions.IsComponentInSelection(memSelections, CE_CENTER_COMP_NAME))
529  {
530  for (int i2 = 0; i2 < memSelections.Count(); ++i2)
531  {
532  if (memSelections[i2].GetName() == CE_CENTER_COMP_NAME && memSelections[i2].GetVertexCount() == 1)
533  {
534  m_FixedOnPosition = false;
535  modelPos = object.GetSelectionPositionMS(CE_CENTER_COMP_NAME);
536  worldPos = object.ModelToWorld(modelPos);
537  if (memOffset != 0.0)
538  {
539  worldPos[1] = worldPos[1] + memOffset;
540  }
541  else
542  {
543  worldPos[1] = worldPos[1] + DEFAULT_HANDLE_OFFSET;
544  }
545  }
546  }
547 
549  m_CachedObject.Store(object, worldPos, compIdx);
550  }
552  else if (!compName.Contains("ladder") && IsComponentInSelection(memSelections, compName))
553  {
554  for (int i1 = 0; i1 < memSelections.Count(); ++i1)
555  {
557  if (memSelections[i1].GetName() == compName && memSelections[i1].GetVertexCount() == 1)
558  {
559  modelPos = object.GetSelectionPositionMS(compName);
560  worldPos = object.ModelToWorld(modelPos);
561 
562  m_FixedOnPosition = false;
563  if (object.GetType() == "Fence" || object.GetType() == "Watchttower" || object.GetType() == "GardenPlot")
564  m_FixedOnPosition = true;
565 
566  if (memOffset != 0.0)
567  {
568  worldPos[1] = worldPos[1] + memOffset;
569  }
570  else
571  {
572  worldPos[1] = worldPos[1] + DEFAULT_HANDLE_OFFSET;
573  }
574  }
575 
577  if (memSelections[i1].GetName() == compName && memSelections[i1].GetVertexCount() > 1)
578  {
579  for (int j = 0; j < components.Count(); ++j)
580  {
581  if (IsComponentInSelection(memSelections, components[j]))
582  {
583  modelPos = object.GetSelectionPositionMS(components[j]);
584  worldPos = object.ModelToWorld(modelPos);
585 
586  m_FixedOnPosition = false;
587  if (memOffset != 0.0)
588  {
589  worldPos[1] = worldPos[1] + memOffset;
590  }
591  else
592  {
593  worldPos[1] = worldPos[1] + DEFAULT_HANDLE_OFFSET;
594  }
595  }
596  }
597  }
598  }
599 
601  m_CachedObject.Store(object, worldPos, -1);
602  }
604  else if (compName.Contains("ladder") && IsComponentInSelection(memSelections, compName))
605  {
606  vector ladderHandlePointLS, ladderHandlePointWS;
607  vector closestHandlePos;
608  float lastDistance = 0;
609 
610  for (int i3 = 0; i3 < memSelections.Count(); ++i3)
611  {
612  if (memSelections[i3].GetName() == compName && memSelections[i3].GetVertexCount() > 1)
613  {
614  ladderHandlePointLS = memSelections[i3].GetVertexPosition(lod, 0);
615  ladderHandlePointWS = object.ModelToWorld(ladderHandlePointLS);
616  closestHandlePos = ladderHandlePointWS;
617  lastDistance = Math.AbsFloat(vector.DistanceSq(ladderHandlePointWS, m_Player.GetPosition()));
618 
619  for (int k = 1; k < memSelections[i3].GetVertexCount(); ++k)
620  {
621  ladderHandlePointLS = memSelections[i3].GetVertexPosition(lod, k);
622  ladderHandlePointWS = object.ModelToWorld(ladderHandlePointLS);
623 
624  if (lastDistance > Math.AbsFloat(vector.DistanceSq(ladderHandlePointWS, m_Player.GetPosition())))
625  {
626  lastDistance = Math.AbsFloat(vector.DistanceSq(ladderHandlePointWS, m_Player.GetPosition()));
627  closestHandlePos = ladderHandlePointWS;
628  }
629  }
630 
631  m_FixedOnPosition = false;
632  worldPos = closestHandlePos;
633  if (memOffset != 0.0)
634  {
635  worldPos[1] = worldPos[1] + memOffset;
636  }
637  else
638  {
639  worldPos[1] = worldPos[1] + DEFAULT_HANDLE_OFFSET;
640  }
641  }
642  }
643 
645  m_CachedObject.Store(object, worldPos, -1);
646  }
647  else
648  {
649  m_FixedOnPosition = true;
650  }
651  }
652  else
653  {
654  m_FixedOnPosition = true;
655  }
656  }
657  else
658  {
659  m_FixedOnPosition = true;
660  }
661 
662  vector pos = TransformToScreenPos(worldPos);
663 
664  x = pos[0];
665  y = pos[1];
666  }
667 
668  worldPos = vector.Zero;
669  isTargetForced = false;
670  }
671 
672  // kept for backward compatibility
673  protected bool IsComponentInSelection(array<Selection> selection, string compName)
674  {
675  return MiscGameplayFunctions.IsComponentInSelection(selection, compName);
676  }
677 
678  // getters
679 
680  protected void GetPlayer()
681  {
682  Class.CastTo(m_Player, GetGame().GetPlayer());
683  }
684 
685  protected void GetActionManager()
686  {
687  if (m_Player && m_Player.IsPlayerSelected())
688  {
689  Class.CastTo(m_AM, m_Player.GetActionManager());
690  }
691  else
692  {
693  m_AM = null;
694  }
695  }
696 
698  protected void GetActions()
699  {
700  m_Interact = null;
701  m_ContinuousInteract = null;
702  m_Single = null;
703  m_Continuous = null;
704 
705  if (!m_AM) return;
706  if (!m_Target) return;
707  if (m_Player.IsSprinting()) return;
708  if (m_Player.IsInVehicle()) return; // TODO: TMP: Car AM rework needed
709 
710  m_Interact = m_AM.GetPossibleAction(InteractActionInput);
711  m_ContinuousInteract = m_AM.GetPossibleAction(ContinuousInteractActionInput);
712  m_Single = m_AM.GetPossibleAction(DefaultActionInput);
713  m_Continuous = m_AM.GetPossibleAction(ContinuousDefaultActionInput);
714 
715  m_InteractActionsNum = m_AM.GetPossibleActionCount(InteractActionInput);
716  m_ContinuousInteractActionsNum = m_AM.GetPossibleActionCount(ContinuousInteractActionInput);
717  m_ItemActionsNum = m_AM.GetPossibleActionCount(DefaultActionInput);
718  m_ContinuousItemActionsNum = m_AM.GetPossibleActionCount(ContinuousDefaultActionInput);
719 
720  m_SelectedActionCategory = m_AM.GetSelectedActionCategory();
721 
722  if (m_Interact)
723  {
724  m_DisplayInteractTarget = m_Interact.GetDisplayInteractObject(m_Player, m_Target);
725  }
726  else if (m_Single)
727  {
728  m_DisplayInteractTarget = m_Single.GetDisplayInteractObject(m_Player, m_Target);
729  }
730  else if (m_ContinuousInteract)
731  {
732  m_DisplayInteractTarget = m_ContinuousInteract.GetDisplayInteractObject(m_Player, m_Target);
733  }
734  else
735  {
736  m_DisplayInteractTarget = null;
737  }
738  }
739 
740  protected void GetTarget()
741  {
742  if (!m_AM)
743  return;
744 
745  m_Target = m_AM.FindActionTarget();
746  if (m_Target && m_Target.GetObject() && m_Target.GetObject().IsItemBase())
747  {
748  ItemBase item = ItemBase.Cast(m_Target.GetObject());
749  InventoryLocation invLocation = new InventoryLocation();
750  item.GetInventory().GetCurrentInventoryLocation(invLocation);
751 
752  if (!item.IsTakeable() || (m_Player && m_Player.IsInVehicle()) || invLocation.GetType() != InventoryLocationType.GROUND)
753  m_Hidden = true;
754  }
755  }
756 
757  protected string GetActionDesc(ActionBase action)
758  {
759  string desc = "";
760  if (action && action.GetText())
761  desc = action.GetText();
762 
763  return desc;
764  }
765 
766  //Getting NAME of the entity
767  protected string GetItemDesc(ActionBase action)
768  {
769  string desc = "";
770  Object tgObject = m_DisplayInteractTarget;
771  if (!tgObject && m_Target)
772  {
773  tgObject = m_Target.GetObject();
774  }
775 
776  if (tgObject)
777  {
778  //BreakOut if item is ruined
779  Object tgParent = m_Target.GetParent();
780  if (!tgObject.IsAlive())
781  {
782  //Fetch parent item name if one is present
783  if (!tgParent || tgObject.DisplayNameRuinAttach())
784  desc = tgObject.GetDisplayName();
785  else
786  desc = tgParent.GetDisplayName();
787  return desc;
788  }
789 
790  EntityAI targetEntity;
791 
792  if (tgParent && (tgParent.IsItemBase() || tgParent.IsTransport()))
793  {
794  targetEntity = EntityAI.Cast(tgParent);
795  }
796 
797  if (tgObject.IsItemBase() || tgObject.IsTransport())
798  {
799  targetEntity = EntityAI.Cast(tgObject);
800  }
801 
802  if (targetEntity && targetEntity.ShowZonesHealth())
803  {
804  string zone = "";
805 
806  array<string> selections = new array<string>();
807 
808  //NOTE: relevant fire geometry and view geometry selection names MUST match in order to get a valid damage zone
809  if (targetEntity.IsInherited(TentBase) && TentBase.Cast(targetEntity).GetState() != TentBase.PACKED)
810  {
811  //This is really specific to tents, as they use proxies. Hence object must be used
812  if (DamageSystem.GetDamageZoneFromComponentName(targetEntity, tgObject.GetActionComponentName(m_Target.GetComponentIndex(), LOD.NAME_FIRE), zone))
813  {
814  desc = DamageSystem.GetDamageDisplayName(targetEntity, zone);
815  }
816  }
817  else
818  {
819  targetEntity.GetActionComponentNameList(m_Target.GetComponentIndex(), selections, LOD.NAME_VIEW);
820 
821  //Important to get display name from component tied to multiple selections
822  for (int s = 0; s < selections.Count(); s++)
823  {
824  if (DamageSystem.GetDamageZoneFromComponentName(targetEntity, selections[s], zone))
825  {
826  desc = DamageSystem.GetDamageDisplayName(targetEntity, zone);
827  }
828  }
829  }
830  }
831 
832  //Safety check to output something to widget
833  if (targetEntity && desc == "")
834  desc = targetEntity.GetDisplayName();
835  }
836 
837  return desc;
838  }
839 
840  protected int GetItemHealth()
841  {
842  int health = -1;
843 
844  if (m_Interact && !m_Interact.HasTarget())
845  {
846  return health;
847  }
848 
849  Object tgObject = m_DisplayInteractTarget;
850  if (!tgObject && m_Target)
851  {
852  tgObject = m_Target.GetObject();
853  }
854 
855  if (tgObject)
856  {
857  Object tgParent = m_Target.GetParent();
858  EntityAI targetEntity;
859 
860  //Return specific part health, even if display name is from parent
861  if (!tgObject.IsAlive())
862  {
863  health = tgObject.GetHealthLevel();
864  return health;
865  }
866 
867  if (tgParent && (tgParent.IsItemBase() || tgParent.IsTransport()))
868  {
869  targetEntity = EntityAI.Cast(tgParent);
870  }
871 
872  if (tgObject.IsItemBase() || tgObject.IsTransport())
873  {
874  targetEntity = EntityAI.Cast(tgObject);
875  }
876 
877  if (targetEntity)
878  {
879  if (!targetEntity.IsDamageDestroyed())
880  {
881  string zone = "";
882  array<string> selections = new array<string>();
883 
884  if (targetEntity.IsInherited(TentBase) && TentBase.Cast(targetEntity).GetState() != TentBase.PACKED)
885  {
886  //This is really specific to tents, as they use proxies. Hence object must be used
887  if (DamageSystem.GetDamageZoneFromComponentName(targetEntity, tgObject.GetActionComponentName(m_Target.GetComponentIndex(), LOD.NAME_FIRE), zone))
888  {
889  health = targetEntity.GetHealthLevel(zone);
890  }
891  }
892  else
893  {
894  //NOTE: relevant view geometry and view geometry selection names MUST match in order to get a valid damage zone
895  targetEntity.GetActionComponentNameList(m_Target.GetComponentIndex(), selections, LOD.NAME_VIEW);
896 
897  for (int s = 0; s < selections.Count(); s++)
898  {
899  if (DamageSystem.GetDamageZoneFromComponentName(targetEntity , selections[s], zone))
900  {
901  health = targetEntity.GetHealthLevel(zone);
902  break;
903  }
904  }
905  }
906 
907  if (zone == "")
908  health = targetEntity.GetHealthLevel();
909  }
910  }
911  else
912  {
913  health = tgObject.GetHealthLevel();
914  }
915  }
916 
917  return health;
918  }
919 
920  protected void GetItemQuantity(out int q_type, out float q_cur, out int q_min, out int q_max)
921  {
922  InventoryItem item = null;
923 
924  if (m_Interact && !m_Interact.HasTarget())
925  {
926  return;
927  }
928 
929  Object tgObject = m_DisplayInteractTarget;
930  if (!tgObject && m_Target)
931  {
932  tgObject = m_Target.GetObject();
933  }
934 
935  if (Class.CastTo(item, tgObject))
936  {
937  q_type = QuantityConversions.HasItemQuantity(item);
938  if (q_type > 0)
939  QuantityConversions.GetItemQuantity(item, q_cur, q_min, q_max);
940  }
941  }
942 
944  protected void GetItemCargoCount(out int cargoCount)
945  {
946  EntityAI entity = null;
947 
948  Object tgObject = m_DisplayInteractTarget;
949  if (!tgObject && m_Target)
950  {
951  tgObject = m_Target.GetObject();
952  }
953 
954  if (Class.CastTo(entity, tgObject))
955  {
956 
957  GameInventory inventory = entity.GetInventory();
958  if (inventory)
959  {
960  cargoCount = AttachmentsWithInventoryOrCargoCount(inventory);
961  return;
962  }
963 
965  cargoCount = 0;
966  }
967  }
968 
969  // setters
970  protected void SetItemDesc(string descText, int cargoCount, string itemWidget, string descWidget)
971  {
972  Widget widget;
973  widget = m_Root.FindAnyWidget(itemWidget);
974 
976  PlayerBase playerT = PlayerBase.Cast(m_Target.GetObject());
977  if (playerT)
978  string msg = playerT.GetLastUAMessage();
979 
980  if (descText.Length() == 0 && msg.Length() == 0)
981  {
982  widget.Show(false);
983  return;
984  }
985 
986  descText.ToUpper();
987  TextWidget itemName;
988  Class.CastTo(itemName, widget.FindAnyWidget(descWidget));
989 
991  if (cargoCount > 0)
992  descText = string.Format("[+] %1 %2", descText, msg);
993  else
994  descText = string.Format("%1 %2", descText, msg);
995 
996  itemName.SetText(descText);
997  widget.Show(true);
998  }
999 
1000  protected void SetItemHealth(int health, string itemWidget, string healthWidget, bool enabled)
1001  {
1002  Widget widget = m_Root.FindAnyWidget(itemWidget);
1003 
1004  if (enabled)
1005  {
1006  ImageWidget healthMark;
1007  Class.CastTo(healthMark, widget.FindAnyWidget(healthWidget));
1008  int color = 0x00FFFFFF;
1009 
1010  if (health == -1)
1011  {
1012  healthMark.GetParent().Show(false);
1013  widget.Show(enabled);
1014  return;
1015  }
1016 
1017  healthMark.SetColor(ItemManager.GetItemHealthColor(health));
1018  healthMark.SetAlpha(0.5);
1019  healthMark.GetParent().Show(true);
1020  }
1021 
1022  widget.Show(enabled);
1023  }
1024 
1025  protected void SetItemQuantity(int type, float current, int min, int max, string itemWidget, string quantityPBWidget, string quantityTextWidget, bool enabled)
1026  {
1027  Widget widget;
1028 
1029  widget = m_Root.FindAnyWidget(itemWidget);
1030 
1031  if (enabled)
1032  {
1033  ProgressBarWidget progressBar;
1034  TextWidget textWidget;
1035  Class.CastTo(progressBar, widget.FindAnyWidget(quantityPBWidget));
1036  Class.CastTo(textWidget, widget.FindAnyWidget(quantityTextWidget));
1037 
1038  //check for volume vs. count and display progressbar or "bubble" with exact count/max text
1039  switch (type)
1040  {
1041  case QUANTITY_HIDDEN :
1042  progressBar.Show(false);
1043  textWidget.Show(false);
1044  textWidget.GetParent().Show(false);
1045  break;
1046  case QUANTITY_COUNT :
1047  if (max > 1 || current > 1)
1048  {
1049  string qty_text = string.Format("%1/%2", Math.Round(current).ToString(), max.ToString());
1050  progressBar.Show(false);
1051  textWidget.SetText(qty_text);
1052  textWidget.Show(true);
1053  textWidget.GetParent().Show(true);
1054  }
1055  else
1056  {
1057  progressBar.Show(false);
1058  textWidget.Show(false);
1059  textWidget.GetParent().Show(false);
1060  }
1061  break;
1062  case QUANTITY_PROGRESS :
1063  float qty_num = Math.Round((current / max) * 100);
1064 
1065  textWidget.Show(false);
1066  progressBar.SetCurrent(qty_num);
1067  progressBar.Show(true);
1068  textWidget.GetParent().Show(true);
1069  break;
1070  }
1071  widget.Show(true);
1072  }
1073  else
1074  widget.Show(false);
1075  }
1076 
1077  protected void SetActionWidget(ActionBase action, string descText, string actionWidget, string descWidget)
1078  {
1079  Widget widget = m_Root.FindAnyWidget(actionWidget);
1080 
1081  if (action)
1082  {
1083  if (action.HasTarget() && m_AM.GetActionState() < 1) // targeted & action not performing
1084  {
1085  TextWidget actionName;
1086  Class.CastTo(actionName, widget.FindAnyWidget(descWidget));
1087 
1088  if (action.GetInput().GetInputType() == ActionInputType.AIT_CONTINUOUS)
1089  {
1090  descText = descText + " " + "#action_target_cursor_hold";
1091  actionName.SetText(descText);
1092  }
1093  else
1094  {
1095  actionName.SetText(descText);
1096  }
1097 
1098  widget.Show(true);
1099 
1100  int x, y;
1101  actionName.GetTextSize(x, y);
1102  if (x > m_MaxWidthChild);
1103  m_MaxWidthChild = x;
1104  }
1105  else
1106  {
1107  widget.Show(false);
1108  }
1109  }
1110  else
1111  {
1112  widget.Show(false);
1113  }
1114  }
1115 
1117  protected void SetMultipleInteractAction(string multiActionsWidget, string multiActionsWidget_NotSelect)
1118  {
1119  Widget widget, widget_not_select;
1120 
1121  widget = m_Root.FindAnyWidget(multiActionsWidget);
1122  widget_not_select = m_Root.FindAnyWidget(multiActionsWidget_NotSelect);
1123 
1124  if (m_InteractActionsNum > 1)
1125  {
1126  if (m_SelectedActionCategory == InteractActionInput)
1127  {
1128  widget.Show(true);
1129  widget_not_select.Show(false);
1130  }
1131  else
1132  {
1133  widget.Show(false);
1134  widget_not_select.Show(true);
1135  }
1136  }
1137  else
1138  {
1139  widget.Show(false);
1140  widget_not_select.Show(false);
1141  }
1142  }
1143 
1144  protected void SetMultipleContinuousInteractAction(string multiActionsWidget, string multiActionsWidget_NotSelect)
1145  {
1146  Widget widget, widget_not_select;
1147 
1148  widget = m_Root.FindAnyWidget(multiActionsWidget);
1149  widget_not_select = m_Root.FindAnyWidget(multiActionsWidget_NotSelect);
1150 
1151  if (m_ContinuousInteractActionsNum > 1)
1152  {
1153  if (m_SelectedActionCategory == ContinuousInteractActionInput)
1154  {
1155  widget.Show(true);
1156  widget_not_select.Show(false);
1157  }
1158  else
1159  {
1160  widget.Show(false);
1161  widget_not_select.Show(true);
1162  }
1163  }
1164  else
1165  {
1166  widget.Show(false);
1167  widget_not_select.Show(false);
1168  }
1169 
1170  }
1171 
1172  protected void SetMultipleItemAction(string multiActionsWidget, string multiActionsWidget_NotSelect)
1173  {
1174  Widget widget, widget_not_select;
1175 
1176  widget = m_Root.FindAnyWidget(multiActionsWidget);
1177  widget_not_select = m_Root.FindAnyWidget(multiActionsWidget_NotSelect);
1178 
1179  if (m_ItemActionsNum > 1)
1180  {
1181  if (m_SelectedActionCategory == DefaultActionInput)
1182  {
1183  widget.Show(true);
1184  widget_not_select.Show(false);
1185  }
1186  else
1187  {
1188  widget.Show(false);
1189  widget_not_select.Show(true);
1190  }
1191  }
1192  else
1193  {
1194  widget.Show(false);
1195  widget_not_select.Show(false);
1196  }
1197  }
1198 
1199  protected void SetMultipleContinuousItemAction(string multiActionsWidget, string multiActionsWidget_NotSelect)
1200  {
1201  Widget widget, widget_not_select;
1202 
1203  widget = m_Root.FindAnyWidget(multiActionsWidget);
1204  widget_not_select = m_Root.FindAnyWidget(multiActionsWidget_NotSelect);
1205 
1206  if (m_ContinuousItemActionsNum > 1)
1207  {
1208  if (m_SelectedActionCategory == ContinuousDefaultActionInput)
1209  {
1210  widget.Show(true);
1211  widget_not_select.Show(false);
1212  }
1213  else
1214  {
1215  widget.Show(false);
1216  widget_not_select.Show(true);
1217  }
1218  }
1219  else
1220  {
1221  widget.Show(false);
1222  widget_not_select.Show(false);
1223  }
1224  }
1225 
1226  protected void SetInteractActionIcon(string actionWidget, string actionIconFrameWidget, string actionIconWidget, string actionIconTextWidget)
1227  {
1228  Widget widget;
1229  ImageWidget iconWidget;
1230  TextWidget textWidget;
1231 
1232  widget = m_Root.FindAnyWidget(actionWidget);
1233  Class.CastTo(iconWidget, widget.FindAnyWidget(actionIconWidget));
1234  Class.CastTo(textWidget, widget.FindAnyWidget(actionIconTextWidget));
1235 
1236  GetDayZGame().GetBacklit().HintShow(m_UseActionWrapper.InputP());
1237 
1238  // uses text in floating widget
1239  iconWidget.Show(false);
1240  textWidget.SetText(InputUtils.GetButtonNameFromInput("UAAction", EInputDeviceType.MOUSE_AND_KEYBOARD));
1241  textWidget.Show(true);
1242  }
1243 
1244  protected void CheckRefresherFlagVisibility(Object object)
1245  {
1246  EntityAI entity;
1247  Widget w = m_Root.FindAnyWidget("item_flag_icon");
1248  if (Class.CastTo(entity,object) && w)
1249  {
1250  w.Show(entity.IsRefresherSignalingViable() && m_Player.IsTargetInActiveRefresherRange(entity));
1251  }
1252  }
1253 
1254  protected int AttachmentsWithInventoryOrCargoCount(notnull GameInventory inventory)
1255  {
1256  int attachmentsWithInventory = 0;
1257 
1258  CargoBase cargo = inventory.GetCargo();
1259  if (cargo && cargo.GetItemCount() > 0)
1260  {
1261  return 1;
1262  }
1263 
1264  for (int i = 0; i < inventory.AttachmentCount(); i++)
1265  {
1266  EntityAI attachment = inventory.GetAttachmentFromIndex(i);
1267  int attachmentSlotId = attachment.GetInventory().GetSlotId(0);
1268 
1269  if (attachment.GetInventory())
1270  {
1271  attachmentsWithInventory += 1;
1272  }
1273  }
1274 
1275  return attachmentsWithInventory;
1276  }
1277 
1278  protected IngameHud GetHud()
1279  {
1280  Mission mission = GetGame().GetMission();
1281  if (mission)
1282  {
1283  IngameHud hud = IngameHud.Cast(mission.GetHud());
1284  return hud;
1285  }
1286 
1287  return null;
1288  }
1289 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
QUANTITY_PROGRESS
const int QUANTITY_PROGRESS
Definition: constants.c:484
UAIDWrapper
Definition: uainput.c:14
m_Target
ref ActionTarget m_Target
Definition: actionbase.c:17
QUANTITY_COUNT
const int QUANTITY_COUNT
Definition: constants.c:483
mission
Mission mission
Definition: displaystatus.c:28
EDayZProfilesOptions
EDayZProfilesOptions
Definition: edayzprofilesoptions.c:1
m_Hud
Hud m_Hud
Definition: displaystatus.c:29
InputUtils
Definition: inpututils.c:1
QuantityConversions
Definition: quantityconversions.c:1
Mission
Mission class.
Definition: gameplay.c:670
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
ContinuousInteractActionInput
Definition: actioninput.c:521
ActionTargetsCursor
Definition: actiontargetscursor.c:53
GetScreenSize
proto void GetScreenSize(out int x, out int y)
GetName
proto native owned string GetName()
Definition: syncedvalue.c:117
ActionInputType
ActionInputType
Definition: actioninput.c:1
y
Icon y
QUANTITY_HIDDEN
const int QUANTITY_HIDDEN
Definition: constants.c:482
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
DefaultActionInput
Definition: actioninput.c:630
LOD
LOD class.
Definition: gameplay.c:202
InventoryItem
Definition: itembase.c:13
EInputDeviceType
EInputDeviceType
Definition: input.c:2
PPEManagerStatic
Static component of PPE manager, used to hold the instance.
Definition: ppemanager.c:2
RichTextWidget
Definition: gameplay.c:315
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
ActionTarget
class ActionTargets ActionTarget
TextWidget
Definition: enwidgets.c:219
InteractActionInput
Definition: actioninput.c:534
m_AM
protected ActionManagerBase m_AM
Definition: crosshairselector.c:57
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
CargoBase
represents base for cargo storage for entities
Definition: cargo.c:6
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
Object
Definition: objecttyped.c:1
ATCCachedObject
Definition: actiontargetscursor.c:1
TentBase
Definition: cartent.c:1
ItemManager
Definition: itemmanager.c:1
ActionManagerClient
Definition: actionmanagerclient.c:4
array< typename >
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
ActionBase
void ActionBase()
Definition: actionbase.c:73
x
Icon x
Widget
Definition: enwidgets.c:189
GetUApi
proto native UAInputAPI GetUApi()
Math
Definition: enmath.c:6
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
EntityAI
Definition: building.c:5
HasFixedActionTargetCursorPosition
override bool HasFixedActionTargetCursorPosition()
Definition: dayzanimal.c:115
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650
GetType
override int GetType()
Definition: huddebugwincharagents.c:49
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78
ContinuousDefaultActionInput
void ContinuousDefaultActionInput(PlayerBase player)
Definition: actioninput.c:606