DayZ 1.24
Loading...
Searching...
No Matches
ItemActionsWidget.c
Go to the documentation of this file.
1class ItemActionsWidget extends ScriptedWidgetEventHandler
2{
3 protected PlayerBase m_Player;
5 protected ActionBase m_Interact;
6 protected ActionBase m_ContinuousInteract;
7 protected ActionBase m_Single;
8 protected ActionBase m_Continuous;
10 protected IngameHud m_Hud;
11
13
14 protected int m_InteractActionsNum;
16 protected int m_ItemActionsNum;
18 protected bool m_HealthEnabled;
19 protected bool m_QuantityEnabled;
20
21 protected ref WidgetFadeTimer m_FadeTimer;
22 protected bool m_Faded;
23 protected bool m_Hidden;
24
25 protected Widget m_Root;
26 protected Widget m_ItemLeft;
27
29 protected float m_MaxWidthChild;
30 protected float m_RootWidth;
31 protected float m_RootHeight;
32
34 {
35 m_Interact = null;
36 m_ContinuousInteract = null;
37 m_Single = null;
38 m_Continuous = null;
39 m_AM = null;
40
41 m_FadeTimer = new WidgetFadeTimer;
42 m_Faded = true;
43
44 m_HealthEnabled = true;
45 m_QuantityEnabled = true;
46
47 m_Hud = GetHud();
48 m_Hidden = true;
49
50 m_UseActionWrapper = GetUApi().GetInputByID(UAAction).GetPersistentWrapper();
51
52 GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(Update);
53 GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
54 GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
55 }
56
58 {
59 GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Remove(Update);
60 }
61
67 protected void SetXboxIcon(string name, string imageset_name, string image_name) {};
69
70 protected void SetControllerIcon(string pWidgetName, string pInputName)
71 {
72 RichTextWidget w = RichTextWidget.Cast(m_Root.FindAnyWidget(pWidgetName + "_btn_icon_xbox"));
74 }
75
76 protected void ShowXboxHidePCIcons(string widget, bool show_xbox_icon)
77 {
78 m_Root.FindAnyWidget(widget + "_btn_icon_xbox").Show(show_xbox_icon);
79 m_Root.FindAnyWidget(widget + "_btn_icon").Show(!show_xbox_icon);
80 }
81
82 protected void OnWidgetScriptInit(Widget w)
83 {
84 m_Root = w;
85 m_Root.SetHandler(this);
86 m_Root.Show(false);
87
88 m_ItemLeft = w.FindAnyWidget("ia_item_left");
89
93 }
94
95 protected void OnInputPresetChanged()
96 {
97#ifdef PLATFORM_CONSOLE
99#endif
100 }
101
106
109 {
110 SetControllerIcon("ia_interact", "UAAction");
111 SetControllerIcon("ia_continuous_interact", "UAAction");
112 SetControllerIcon("ia_single", "UADefaultAction");
113 SetControllerIcon("ia_continuous", "UADefaultAction");
114 }
115
118 {
119 bool showConsoleIcons = false;
120#ifdef PLATFORM_CONSOLE
121 showConsoleIcons = GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER || !GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
122#endif
123
125 ShowXboxHidePCIcons("ia_continuous_interact", showConsoleIcons);
127 ShowXboxHidePCIcons("ia_continuous", showConsoleIcons);
128 }
129
130 protected void BuildCursor()
131 {
132 int health = -1;
133 int quantityType = 0;
134 int quantityMin = -1;
135 int quantityMax = -1;
136 float quantityCurrent = -1.0;
137
138 // item health
140 SetItemHealth(health, "ia_item", "ia_item_health_mark", m_HealthEnabled);
141
142 // quantity
144 if (m_EntityInHands && m_EntityInHands.IsWeapon())
145 {
146 SetWeaponQuantity(0, 0, "ia_item", "ia_item_quantity_pb", "ia_item_quantity_text", m_QuantityEnabled);
147 SetWeaponModeAndZeroing("ia_item_subdesc", "ia_item_subdesc_up", "ia_item_subdesc_down", true);
148 }
150 else if (m_EntityInHands && m_EntityInHands.IsTransmitter())
151 {
152 SetRadioFrequency(GetRadioFrequency(), "ia_item_subdesc", "ia_item_subdesc_up", "ia_item_subdesc_down", m_QuantityEnabled);
154 SetItemQuantity(quantityType, quantityCurrent, quantityMin, quantityMax, "ia_item", "ia_item_quantity_pb", "ia_item_quantity_text", true);
155 }
156 else
157 {
159 SetItemQuantity(quantityType, quantityCurrent, quantityMin, quantityMax, "ia_item", "ia_item_quantity_pb", "ia_item_quantity_text", m_QuantityEnabled);
160 SetWeaponModeAndZeroing("ia_item_subdesc", "", "", false);
161 }
162
163 SetItemDesc(m_EntityInHands, GetItemDesc(m_EntityInHands), "ia_item", "ia_item_desc");
164 SetInteractActionIcon("ia_interact", "ia_interact_icon_frame", "ia_interact_btn_inner_icon", "ia_interact_btn_text");
165 SetActionWidget(m_Interact, GetActionDesc(m_Interact), "ia_interact", "ia_interact_action_name");
166
167 SetInteractActionIcon("ia_continuous_interact", "ia_continuous_interact_icon_frame", "ia_continuous_interact_btn_inner_icon", "ia_continuous_interact_btn_text");
168 SetActionWidget(m_ContinuousInteract, GetActionDesc(m_ContinuousInteract), "ia_continuous_interact", "ia_continuous_interact_action_name");
169
170 SetActionWidget(m_Single, GetActionDesc(m_Single), "ia_single", "ia_single_action_name");
171 SetActionWidget(m_Continuous, GetActionDesc(m_Continuous), "ia_continuous", "ia_continuous_action_name");
172 SetMultipleInteractAction("ia_interact_mlt_wrapper");
173 SetMultipleContinuousInteractAction("ia_continuous_interact_mlt_wrapper");
174 SetMultipleItemAction("ia_single_mlt_wrapper");
175 SetMultipleContinuousItemAction("ia_continuous_mlt_wrapper");
176 }
177
178 protected void Update()
179 {
181 if (!g_Game.GetProfileOption(EDayZProfilesOptions.HUD) || !m_Hud.IsHudVisible())
182 {
183 m_Root.Show(false);
184 return;
185 }
186
187 if (m_Player && !m_Player.IsAlive()) // handle respawn
188 {
189 m_Player = null;
190 m_AM = null;
191 }
192
193 if (!m_Player)
194 GetPlayer();
195
196 if (!m_AM)
198
199 GetActions();
201
202 if ((m_EntityInHands || !m_Hidden) && GetGame().GetUIManager().GetMenu() == null)
203 {
205 BuildCursor();
207 m_Root.Show(true);
208 }
209 else
210 m_Root.Show(false);
211
212 m_MaxWidthChild = 200;
213 }
214
215 // getters
216 protected void GetPlayer()
217 {
219 }
220
221 protected void GetActionManager()
222 {
224 ActionManagerClient.CastTo(m_AM, m_Player.GetActionManager());
225 else
226 m_AM = null;
227 }
228
229 protected void GetActions()
230 {
231 m_Interact = null;
232 m_ContinuousInteract = null;
233 m_Single = null;
234 m_Continuous = null;
235
236 if (!m_AM)
237 return;
238
239 if (m_Player.IsSprinting())
240 return;
241
242 m_Interact = m_AM.GetPossibleAction(InteractActionInput);
243 m_ContinuousInteract = m_AM.GetPossibleAction(ContinuousInteractActionInput);
244 m_Single = m_AM.GetPossibleAction(DefaultActionInput);
245 m_Continuous = m_AM.GetPossibleAction(ContinuousDefaultActionInput);
246
247 if (!m_Interact && !m_ContinuousInteract && !m_Continuous && !m_Single)
248 m_Hidden = false;
249
250 m_InteractActionsNum = m_AM.GetPossibleActionCount(InteractActionInput);
251 m_ContinuousInteractActionsNum = m_AM.GetPossibleActionCount(ContinuousInteractActionInput);
252 m_ItemActionsNum = m_AM.GetPossibleActionCount(DefaultActionInput);
253 m_ContinuousItemActionsNum = m_AM.GetPossibleActionCount(ContinuousDefaultActionInput);
254 }
255
256 protected void GetEntityInHands()
257 {
258 if (!m_Player) return;
259
260 EntityAI eai = m_Player.GetHumanInventory().GetEntityInHands();
261
262 if (eai && !eai.IsInherited(DummyItem))
263 m_EntityInHands = eai;
264 else
265 m_EntityInHands = null;
266 }
267
268 protected string GetActionDesc(ActionBase action)
269 {
270 if (action && action.GetText())
271 return action.GetText();
272
273 return string.Empty;
274 }
275
276 protected string GetItemDesc(EntityAI entity)
277 {
278 if (m_EntityInHands)
279 return m_EntityInHands.GetDisplayName();
280
281 return string.Empty;
282 }
283
284 protected int GetItemHealth()
285 {
286 if (m_EntityInHands)
287 return m_EntityInHands.GetHealthLevel();
288
289 return -1;
290 }
291
292 protected void GetItemQuantity(out int q_type, out float q_cur, out int q_min, out int q_max)
293 {
294 if (m_EntityInHands)
295 {
296 InventoryItem item = InventoryItem.Cast(m_EntityInHands);
297 q_type = QuantityConversions.HasItemQuantity(m_EntityInHands);
298 if (q_type > 0)
299 {
301 {
303
304 q_cur = (q_cur / q_max);
305 // to percents
306 q_min = 0;
307 q_cur = q_cur * 100;
308 q_max = 100;
309 }
310 else
312 }
313 }
314 }
315
316 protected string GetRadioFrequency()
317 {
319 if (Class.CastTo(trans, m_EntityInHands))
320 return trans.GetTunedFrequency().ToString();
321
322 return string.Empty;
323 }
324
325 // setters
326 protected void SetItemDesc(EntityAI entity, string descText, string itemWidget, string descWidget)
327 {
329
330 widget = m_Root.FindAnyWidget(itemWidget);
331
332 if (entity && m_Player && !m_Player.GetItemAccessor().IsItemInHandsHidden())
333 {
334 descText.ToUpper();
336 Class.CastTo(itemName, widget.FindAnyWidget(descWidget));
337 itemName.SetText(descText);
338 widget.Show(true);
339 }
340 else
341 widget.Show(false);
342 }
343
344 protected void SetItemHealth(int health, string itemWidget, string healthWidget, bool enabled)
345 {
347
348 widget = m_Root.FindAnyWidget(itemWidget);
349
350 if (enabled)
351 {
353 Class.CastTo(healthMark, widget.FindAnyWidget(healthWidget));
354
355 switch (health)
356 {
357 case -1 :
358 healthMark.GetParent().Show(false);
359 break;
362 healthMark.SetAlpha(0.5);
363 healthMark.GetParent().Show(true);
364 break;
366 healthMark.SetColor(Colors.COLOR_WORN);
367 healthMark.SetAlpha(0.5);
368 healthMark.GetParent().Show(true);
369 break;
372 healthMark.SetAlpha(0.5);
373 healthMark.GetParent().Show(true);
374 break;
377 healthMark.SetAlpha(0.5);
378 healthMark.GetParent().Show(true);
379 break;
382 healthMark.SetAlpha(0.5);
383 healthMark.GetParent().Show(true);
384 break;
385 default :
386 healthMark.SetColor(0x00FFFFFF);
387 healthMark.SetAlpha(0.5);
388 healthMark.GetParent().Show(true);
389 break;
390 }
391
392 widget.Show(true);
393 }
394 else
395 widget.Show(false);
396 }
397
398 protected void SetItemQuantity(int type, float current, int min, int max, string itemWidget, string quantityPBWidget, string quantityTextWidget, bool enabled)
399 {
401
402 widget = m_Root.FindAnyWidget(itemWidget);
403
404 if (enabled)
405 {
410
411 //check for volume vs. count and display progressbar or "bubble" with exact count/max text
412 switch (type)
413 {
414 case QUANTITY_HIDDEN :
415 progressBar.Show(false);
416 textWidget.Show(false);
417 textWidget.GetParent().Show(false);
418 break;
419 case QUANTITY_COUNT :
420 if (max > 1 || current > 1)
421 {
422 string qty_text = string.Format("%1/%2", Math.Round(current).ToString(), max.ToString());
423 progressBar.Show(false);
424 textWidget.SetText(qty_text);
425 textWidget.Show(true);
426 textWidget.GetParent().Show(true);
427 break;
428 }
429 else
430 {
431 progressBar.Show(false);
432 textWidget.Show(false);
433 textWidget.GetParent().Show(false);
434 break;
435 }
436 case QUANTITY_PROGRESS :
437 textWidget.Show(false);
438 progressBar.SetCurrent(current);
439 progressBar.Show(true);
440 textWidget.GetParent().Show(true);
441 break;
442 }
443 widget.Show(true);
444 }
445 else
446 widget.Show(false);
447 }
448
449 protected void SetWeaponQuantity(int chamber, int mag, string itemWidget, string quantityPBWidget, string quantityTextWidget, bool enabled)
450 {
452
453 widget = m_Root.FindAnyWidget(itemWidget);
454
455 if (enabled)
456 {
457 string wpn_qty = "";
458
463
466 int mag_quantity = -1;
467
468 if (Class.CastTo(wpn, m_EntityInHands))
469 {
470 if (Magnum_Base.Cast(wpn))
471 {
472 mag_quantity = 0;
473 for (int j = 0; j < wpn.GetMuzzleCount(); j++)
474 {
475 if (wpn.IsChamberFull(j) && !wpn.IsChamberFiredOut(j))
476 mag_quantity++;
477 }
478 wpn_qty = mag_quantity.ToString();
479 }
480 else
481 {
482 for (int i = 0; i < wpn.GetMuzzleCount(); i++)
483 {
484 if (i > 0 && (wpn.GetMuzzleCount() < 3 || i % 2 == 0))
485 wpn_qty = wpn_qty + " ";
486 if (wpn.IsChamberEmpty(i))
487 wpn_qty = wpn_qty + "0";
488 else if (wpn.IsChamberFiredOut(i))
489 wpn_qty = wpn_qty + "F";
490 else
491 wpn_qty = wpn_qty + "1";
492
493 maga = wpn.GetMagazine(i);
494 if (maga)
495 mag_quantity = maga.GetAmmoCount();
496 else if (wpn.GetInternalMagazineMaxCartridgeCount(i) > 0)
497 mag_quantity = wpn.GetInternalMagazineCartridgeCount(i);
498
499 }
500
501 if (wpn.IsJammed())
502 {
503 if (mag_quantity != -1)
504 wpn_qty = string.Format("X (+%1)", mag_quantity);
505 else
506 wpn_qty = "X";
507 }
508 else
509 {
510 if (mag_quantity != -1)
511 wpn_qty = wpn_qty + " (" + mag_quantity.ToString() + ")";
512 }
513 }
514 }
515
516 progressBar.Show(false);
517 textWidget.SetText(wpn_qty);
518 textWidget.Show(true);
519 textWidget.GetParent().Show(true);
520 }
521 else
522 widget.Show(false);
523 }
524
525 protected void SetWeaponModeAndZeroing(string itemWidget, string upWidget, string downWidget, bool enabled)
526 {
528
529 widget = m_Root.FindAnyWidget(itemWidget);
530
531 if (enabled && m_Player)
532 {
535
536 Class.CastTo(txtModeWidget, widget.FindAnyWidget(upWidget));
538
539 Weapon w = Weapon.Cast(m_Player.GetHumanInventory().GetEntityInHands());
540 string zeroing = string.Empty;
541 if (w)
542 zeroing = string.Format("%1 m", w.GetCurrentZeroing(w.GetCurrentMuzzle()));
543
545 txtZeroingWidget.SetText(zeroing);
546 widget.Show(true);
547 }
548 else
549 widget.Show(false);
550 }
551
552 // not used instead of this is used confing parameter for fire mode
553 protected string WeaponModeTextTemp()
554 {
555 return "unused";
556 }
557
558 protected void SetRadioFrequency(string freq, string itemWidget, string upWidget, string downWidget, bool enabled)
559 {
561
562 widget = m_Root.FindAnyWidget(itemWidget);
563
564 if (enabled)
565 {
568 Class.CastTo(txtUpWidget, widget.FindAnyWidget(upWidget));
569 Class.CastTo(txtDownWidget, widget.FindAnyWidget(downWidget));
570
571 txtUpWidget.SetText(freq);
572 txtDownWidget.SetText("MHz");
573 widget.Show(true);
574 }
575 else
576 widget.Show(false);
577 }
578
579 protected void SetActionWidget(ActionBase action, string descText, string actionWidget, string descWidget)
580 {
581 Widget widget = m_Root.FindAnyWidget(actionWidget);
582
583 if (action && (!action.HasTarget() || (m_Player && m_Player.GetCommand_Vehicle())))
584 {
586 Class.CastTo(actionName, widget.FindAnyWidget(descWidget));
587
588
589 if (action.GetInput().GetInputType() == ActionInputType.AIT_CONTINUOUS)
590 {
591 descText = descText + " " + "#action_target_cursor_hold";
592 actionName.SetText(descText);
593 }
594 else
595 actionName.SetText(descText);
596
597 widget.Show(true);
598 }
599 else
600 widget.Show(false);
601 }
602
605 {
607
608 widget = m_Root.FindAnyWidget(multiActionsWidget);
609 widget.Show(m_InteractActionsNum > 1);
610 }
611
614 {
616
617 widget = m_Root.FindAnyWidget(multiActionsWidget);
618 widget.Show(m_ContinuousInteractActionsNum > 1);
619 }
620
622 {
624
625 widget = m_Root.FindAnyWidget(multiActionsWidget);
626 widget.Show(m_ItemActionsNum > 1);
627 }
628
631 {
633
634 widget = m_Root.FindAnyWidget(multiActionsWidget);
635 widget.Show(m_ContinuousItemActionsNum > 1);
636 }
637
639 {
640 string keyName = string.Empty;
644
645 widget = m_Root.FindAnyWidget(actionWidget);
649
650 m_UseActionWrapper.InputP().SelectAlternative(0);
651 for (int c = 0; c < m_UseActionWrapper.InputP().BindKeyCount(); c++)
652 {
653 int _hc = m_UseActionWrapper.InputP().GetBindKey(0);
654 keyName = GetUApi().GetButtonName(_hc);
655 }
656
657 // uses text in floating widget
658 iconWidget.Show(false);
659 textWidget.SetText(keyName);
660 textWidget.Show(true);
661 }
662
664 {
665 Widget w = m_Root.FindAnyWidget("ia_item_flag_icon");
666 if (m_Player && m_Player.GetHologramLocal())
667 {
668 EntityAI entity = m_Player.GetHologramLocal().GetProjectionEntity();
669 w.Show(entity.IsRefresherSignalingViable() && m_Player.IsTargetInActiveRefresherRange(entity));
670 }
671 else if (w.IsVisible())
672 w.Show(false);
673 }
674
676 {
678 typename actionName;
679 if (Class.CastTo(item, m_EntityInHands) && item.GetActionWidgetOverride(actionName))
680 {
681 ActionBase action = ActionManagerBase.GetAction(actionName);
682 if (action)
683 m_Single = action;
684 }
685 }
686
687 protected IngameHud GetHud()
688 {
689 Mission mission = GetGame().GetMission();
690 if (mission)
691 {
692 IngameHud hud = IngameHud.Cast(mission.GetHud());
693 return hud;
694 }
695
696 return null;
697 }
698}
void OnInputPresetChanged()
Definition Inventory.c:160
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition Inventory.c:167
ActionInputType
Definition ActionInput.c:2
float quantityMax
float quantityMin
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
ActionManagerBase m_AM
DayZGame g_Game
Definition DayZGame.c:3528
Hud m_Hud
Mission mission
EDayZProfilesOptions
DayZPlayer m_Player
Definition Hand_Events.c:42
Widget m_Root
Definition SizeToChild.c:85
proto native UAInputAPI GetUApi()
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition Colors.c:4
const int COLOR_DAMAGED
Definition Colors.c:22
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_RUINED
Definition Colors.c:20
WeaponManager GetWeaponManager()
bool IsHudVisible()
Definition IngameHud.c:1037
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Definition InputUtils.c:151
Definition EnMath.c:7
Mission class.
Definition gameplay.c:668
Hud GetHud()
Definition gameplay.c:701
static float GetItemQuantity(InventoryItem item)
static int HasItemQuantity(notnull EntityAI item)
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void SetControllerIcon(string pWidgetName, string pInputName)
void ShowXboxHidePCIcons(string widget, bool show_xbox_icon)
void SetSingleXboxIcon(string imageset_name, string image_name)
void SetActionWidget(ActionBase action, string descText, string actionWidget, string descWidget)
void SetContinuousXboxIcon(string imageset_name, string image_name)
void SetMultipleContinuousItemAction(string multiActionsWidget)
shows arrows near the interact action if there are more than one available
void UpdatePCIconsVisibility()
Contains logic for icon set switching (Gamepad/M&K)
void SetContinuousInteractXboxIcon(string imageset_name, string image_name)
void SetWeaponQuantity(int chamber, int mag, string itemWidget, string quantityPBWidget, string quantityTextWidget, bool enabled)
void SetRadioFrequency(string freq, string itemWidget, string upWidget, string downWidget, bool enabled)
void SetMultipleContinuousInteractAction(string multiActionsWidget)
shows arrows near the interact action if there are more than one available
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
float GetItemQuantity(InventoryItem item)
void SetInteractActionIcon(string actionWidget, string actionIconFrameWidget, string actionIconWidget, string actionIconTextWidget)
void SetItemDesc(EntityAI entity, string descText, string itemWidget, string descWidget)
void SetXboxIcon(string name, string imageset_name, string image_name)
void SetItemHealth(int health, string itemWidget, string healthWidget, bool enabled)
void SetWeaponModeAndZeroing(string itemWidget, string upWidget, string downWidget, bool enabled)
void SetItemQuantity(int type, float current, int min, int max, string itemWidget, string quantityPBWidget, string quantityTextWidget, bool enabled)
string GetActionDesc(ActionBase action)
void GetItemQuantity(out int q_type, out float q_cur, out int q_min, out int q_max)
void UpdateControllerInputIcons()
Loads icons from the latest keybinds.
float m_MaxWidthChild
widget width
void SetMultipleItemAction(string multiActionsWidget)
void SetMultipleInteractAction(string multiActionsWidget)
shows arrows near the interact action if there are more than one available
string GetItemDesc(EntityAI entity)
void SetInteractXboxIcon(string imageset_name, string image_name)
DEPRECATED.
proto native UAInput InputP()
script counterpart to engine's class Weapon
string GetCurrentModeName()
proto native CGame GetGame()
const int QUANTITY_PROGRESS
Definition constants.c:484
const int QUANTITY_COUNT
Definition constants.c:483
const int QUANTITY_HIDDEN
Definition constants.c:482
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:757
const int STATE_WORN
Definition constants.c:760
const int STATE_DAMAGED
Definition constants.c:759
const int STATE_BADLY_DAMAGED
Definition constants.c:758
const int STATE_PRISTINE
Definition constants.c:761
static proto float Round(float f)
Returns mathematical round of value.
const int CALL_CATEGORY_GUI
Definition tools.c:9
proto native volatile void Update()
EInputDeviceType
Definition input.c:3