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