itemactionswidget.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. class ItemActionsWidget extends ScriptedWidgetEventHandler
  2. {
  3. protected PlayerBase m_Player;
  4. protected EntityAI m_EntityInHands;
  5. protected ActionBase m_Interact;
  6. protected ActionBase m_ContinuousInteract;
  7. protected ActionBase m_Single;
  8. protected ActionBase m_Continuous;
  9. protected ActionManagerClient m_AM;
  10. protected IngameHud m_Hud;
  11. protected UAIDWrapper m_UseActionWrapper;
  12. protected int m_InteractActionsNum;
  13. protected int m_ContinuousInteractActionsNum;
  14. protected int m_ItemActionsNum;
  15. protected int m_ContinuousItemActionsNum;
  16. protected bool m_HealthEnabled;
  17. protected bool m_QuantityEnabled;
  18. protected ref WidgetFadeTimer m_FadeTimer;
  19. protected bool m_Faded;
  20. protected bool m_Hidden;
  21. protected bool m_ItemFrozen;
  22. protected Widget m_Root;
  23. protected Widget m_ItemLeft;
  24. //! widget width
  25. protected float m_MaxWidthChild;
  26. protected float m_RootWidth;
  27. protected float m_RootHeight;
  28. void ItemActionsWidget()
  29. {
  30. m_Interact = null;
  31. m_ContinuousInteract = null;
  32. m_Single = null;
  33. m_Continuous = null;
  34. m_AM = null;
  35. m_FadeTimer = new WidgetFadeTimer;
  36. m_Faded = true;
  37. m_HealthEnabled = true;
  38. m_QuantityEnabled = true;
  39. m_Hud = GetHud();
  40. m_Hidden = true;
  41. m_ItemFrozen = false;
  42. m_UseActionWrapper = GetUApi().GetInputByID(UAAction).GetPersistentWrapper();
  43. GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(Update);
  44. GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
  45. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  46. }
  47. void ~ItemActionsWidget()
  48. {
  49. GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Remove(Update);
  50. }
  51. //! DEPRECATED
  52. void SetInteractXboxIcon(string imageset_name, string image_name) {};
  53. void SetContinuousInteractXboxIcon(string imageset_name, string image_name) {};
  54. void SetSingleXboxIcon(string imageset_name, string image_name) {};
  55. void SetContinuousXboxIcon(string imageset_name, string image_name) {};
  56. protected void SetXboxIcon(string name, string imageset_name, string image_name) {};
  57. //! ----------
  58. protected void SetControllerIcon(string pWidgetName, string pInputName)
  59. {
  60. RichTextWidget w = RichTextWidget.Cast(m_Root.FindAnyWidget(pWidgetName + "_btn_icon_xbox"));
  61. w.SetText(InputUtils.GetRichtextButtonIconFromInputAction(pInputName, "", EUAINPUT_DEVICE_CONTROLLER));
  62. }
  63. protected void ShowXboxHidePCIcons(string widget, bool show_xbox_icon)
  64. {
  65. m_Root.FindAnyWidget(widget + "_btn_icon_xbox").Show(show_xbox_icon);
  66. m_Root.FindAnyWidget(widget + "_btn_icon").Show(!show_xbox_icon);
  67. }
  68. protected void OnWidgetScriptInit(Widget w)
  69. {
  70. m_Root = w;
  71. m_Root.SetHandler(this);
  72. m_Root.Show(false);
  73. m_ItemLeft = w.FindAnyWidget("ia_item_left");
  74. //! UA -> widget icon
  75. UpdateControllerInputIcons();
  76. UpdatePCIconsVisibility();
  77. }
  78. protected void OnInputPresetChanged()
  79. {
  80. #ifdef PLATFORM_CONSOLE
  81. UpdateControllerInputIcons();
  82. #endif
  83. }
  84. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  85. {
  86. UpdatePCIconsVisibility();
  87. }
  88. //! Loads icons from the latest keybinds
  89. private void UpdateControllerInputIcons()
  90. {
  91. SetControllerIcon("ia_interact", "UAAction");
  92. SetControllerIcon("ia_continuous_interact", "UAAction");
  93. SetControllerIcon("ia_single", "UADefaultAction");
  94. SetControllerIcon("ia_continuous", "UADefaultAction");
  95. }
  96. //! Contains logic for icon set switching (Gamepad/M&K)
  97. private void UpdatePCIconsVisibility()
  98. {
  99. bool showConsoleIcons = false;
  100. #ifdef PLATFORM_CONSOLE
  101. showConsoleIcons = GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER || !GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
  102. #endif
  103. ShowXboxHidePCIcons("ia_interact", showConsoleIcons);
  104. ShowXboxHidePCIcons("ia_continuous_interact", showConsoleIcons);
  105. ShowXboxHidePCIcons("ia_single", showConsoleIcons);
  106. ShowXboxHidePCIcons("ia_continuous", showConsoleIcons);
  107. }
  108. protected void BuildCursor()
  109. {
  110. m_ItemFrozen = false;
  111. int health = -1;
  112. int quantityType = 0;
  113. int quantityMin = -1;
  114. int quantityMax = -1;
  115. float quantityCurrent = -1.0;
  116. // item health
  117. health = GetItemHealth();
  118. m_ItemFrozen = GetItemFrozen();
  119. SetItemHealth(health, "ia_item", "ia_item_health_mark", m_HealthEnabled);
  120. // quantity
  121. //! weapon specific
  122. if (m_EntityInHands && m_EntityInHands.IsWeapon())
  123. {
  124. SetWeaponQuantity(0, 0, "ia_item", "ia_item_quantity_pb", "ia_item_quantity_text", m_QuantityEnabled);
  125. SetWeaponModeAndZeroing("ia_item_subdesc", "ia_item_subdesc_up", "ia_item_subdesc_down", true);
  126. }
  127. //! transmitter/PAS specific
  128. else if (m_EntityInHands && m_EntityInHands.IsTransmitter())
  129. {
  130. SetRadioFrequency(GetRadioFrequency(), "ia_item_subdesc", "ia_item_subdesc_up", "ia_item_subdesc_down", m_QuantityEnabled);
  131. GetItemQuantity(quantityType, quantityCurrent, quantityMin, quantityMax);
  132. SetItemQuantity(quantityType, quantityCurrent, quantityMin, quantityMax, "ia_item", "ia_item_quantity_pb", "ia_item_quantity_text", true);
  133. }
  134. else
  135. {
  136. GetItemQuantity(quantityType, quantityCurrent, quantityMin, quantityMax);
  137. SetItemQuantity(quantityType, quantityCurrent, quantityMin, quantityMax, "ia_item", "ia_item_quantity_pb", "ia_item_quantity_text", m_QuantityEnabled);
  138. SetWeaponModeAndZeroing("ia_item_subdesc", "", "", false);
  139. }
  140. SetItemDesc(m_EntityInHands, GetItemDesc(m_EntityInHands), "ia_item", "ia_item_desc");
  141. SetInteractActionIcon("ia_interact", "ia_interact_icon_frame", "ia_interact_btn_inner_icon", "ia_interact_btn_text");
  142. SetActionWidget(m_Interact, GetActionDesc(m_Interact), "ia_interact", "ia_interact_action_name");
  143. SetInteractActionIcon("ia_continuous_interact", "ia_continuous_interact_icon_frame", "ia_continuous_interact_btn_inner_icon", "ia_continuous_interact_btn_text");
  144. SetActionWidget(m_ContinuousInteract, GetActionDesc(m_ContinuousInteract), "ia_continuous_interact", "ia_continuous_interact_action_name");
  145. SetActionWidget(m_Single, GetActionDesc(m_Single), "ia_single", "ia_single_action_name");
  146. SetActionWidget(m_Continuous, GetActionDesc(m_Continuous), "ia_continuous", "ia_continuous_action_name");
  147. SetMultipleInteractAction("ia_interact_mlt_wrapper");
  148. SetMultipleContinuousInteractAction("ia_continuous_interact_mlt_wrapper");
  149. SetMultipleItemAction("ia_single_mlt_wrapper");
  150. SetMultipleContinuousItemAction("ia_continuous_mlt_wrapper");
  151. }
  152. protected void Update()
  153. {
  154. //! don't show when disabled in profile
  155. if (!g_Game.GetProfileOption(EDayZProfilesOptions.HUD) || !m_Hud.IsHudVisible())
  156. {
  157. m_Root.Show(false);
  158. return;
  159. }
  160. if (m_Player && !m_Player.IsAlive()) // handle respawn
  161. {
  162. m_Player = null;
  163. m_AM = null;
  164. }
  165. if (!m_Player)
  166. GetPlayer();
  167. if (!m_AM)
  168. GetActionManager();
  169. GetActions();
  170. GetEntityInHands();
  171. if ((m_EntityInHands || !m_Hidden) && GetGame().GetUIManager().GetMenu() == null)
  172. {
  173. CheckForActionWidgetOverrides();
  174. BuildCursor();
  175. CheckRefresherFlagVisibility();
  176. m_Root.Show(true);
  177. }
  178. else
  179. m_Root.Show(false);
  180. m_MaxWidthChild = 200;
  181. }
  182. // getters
  183. protected void GetPlayer()
  184. {
  185. Class.CastTo(m_Player, GetGame().GetPlayer());
  186. }
  187. protected void GetActionManager()
  188. {
  189. if (m_Player && m_Player.IsPlayerSelected())
  190. ActionManagerClient.CastTo(m_AM, m_Player.GetActionManager());
  191. else
  192. m_AM = null;
  193. }
  194. protected void GetActions()
  195. {
  196. m_Interact = null;
  197. m_ContinuousInteract = null;
  198. m_Single = null;
  199. m_Continuous = null;
  200. if (!m_AM)
  201. return;
  202. if (m_Player.IsSprinting())
  203. return;
  204. m_Interact = m_AM.GetPossibleAction(InteractActionInput);
  205. m_ContinuousInteract = m_AM.GetPossibleAction(ContinuousInteractActionInput);
  206. m_Single = m_AM.GetPossibleAction(DefaultActionInput);
  207. m_Continuous = m_AM.GetPossibleAction(ContinuousDefaultActionInput);
  208. if (!m_Interact && !m_ContinuousInteract && !m_Continuous && !m_Single)
  209. m_Hidden = false;
  210. m_InteractActionsNum = m_AM.GetPossibleActionCount(InteractActionInput);
  211. m_ContinuousInteractActionsNum = m_AM.GetPossibleActionCount(ContinuousInteractActionInput);
  212. m_ItemActionsNum = m_AM.GetPossibleActionCount(DefaultActionInput);
  213. m_ContinuousItemActionsNum = m_AM.GetPossibleActionCount(ContinuousDefaultActionInput);
  214. }
  215. protected void GetEntityInHands()
  216. {
  217. if (!m_Player) return;
  218. EntityAI eai = m_Player.GetHumanInventory().GetEntityInHands();
  219. if (eai && !eai.IsInherited(DummyItem))
  220. {
  221. m_EntityInHands = eai;
  222. }
  223. else
  224. {
  225. m_EntityInHands = null;
  226. }
  227. }
  228. protected string GetActionDesc(ActionBase action)
  229. {
  230. if (action && action.GetText())
  231. return action.GetText();
  232. return string.Empty;
  233. }
  234. protected string GetItemDesc(EntityAI entity)
  235. {
  236. if (m_EntityInHands)
  237. return m_EntityInHands.GetDisplayName();
  238. return string.Empty;
  239. }
  240. protected bool GetItemFrozen()
  241. {
  242. return m_EntityInHands && m_EntityInHands.GetIsFrozen();
  243. }
  244. protected int GetItemHealth()
  245. {
  246. if (m_EntityInHands)
  247. return m_EntityInHands.GetHealthLevel();
  248. return -1;
  249. }
  250. protected void GetItemQuantity(out int q_type, out float q_cur, out int q_min, out int q_max)
  251. {
  252. if (m_EntityInHands)
  253. {
  254. InventoryItem item = InventoryItem.Cast(m_EntityInHands);
  255. q_type = QuantityConversions.HasItemQuantity(m_EntityInHands);
  256. if (q_type > 0)
  257. {
  258. if (q_type == QUANTITY_PROGRESS)
  259. {
  260. QuantityConversions.GetItemQuantity(item, q_cur, q_min, q_max);
  261. q_cur = (q_cur / q_max);
  262. // to percents
  263. q_min = 0;
  264. q_cur = q_cur * 100;
  265. q_max = 100;
  266. }
  267. else
  268. {
  269. QuantityConversions.GetItemQuantity(item, q_cur, q_min, q_max);
  270. }
  271. }
  272. }
  273. }
  274. protected string GetRadioFrequency()
  275. {
  276. TransmitterBase trans;
  277. if (Class.CastTo(trans, m_EntityInHands))
  278. {
  279. return trans.GetTunedFrequency().ToString();
  280. }
  281. return string.Empty;
  282. }
  283. // setters
  284. protected void SetItemDesc(EntityAI entity, string descText, string itemWidget, string descWidget)
  285. {
  286. Widget widget;
  287. widget = m_Root.FindAnyWidget(itemWidget);
  288. if (entity && m_Player && !m_Player.GetItemAccessor().IsItemInHandsHidden())
  289. {
  290. descText.ToUpper();
  291. TextWidget itemName;
  292. Class.CastTo(itemName, widget.FindAnyWidget(descWidget));
  293. itemName.SetText(descText);
  294. widget.Show(true);
  295. }
  296. else
  297. widget.Show(false);
  298. }
  299. protected void SetItemHealth(int health, string itemWidget, string healthWidget, bool enabled)
  300. {
  301. Widget widget;
  302. widget = m_Root.FindAnyWidget(itemWidget);
  303. if (enabled)
  304. {
  305. ImageWidget healthMark;
  306. Class.CastTo(healthMark, widget.FindAnyWidget(healthWidget));
  307. if (m_ItemFrozen && health != GameConstants.STATE_RUINED)
  308. {
  309. healthMark.SetColor(Colors.COLOR_FROZEN);
  310. healthMark.SetAlpha(0.5);
  311. healthMark.GetParent().Show(true);
  312. }
  313. else
  314. {
  315. switch (health)
  316. {
  317. case -1 :
  318. healthMark.GetParent().Show(false);
  319. break;
  320. case GameConstants.STATE_PRISTINE :
  321. healthMark.SetColor(Colors.COLOR_PRISTINE);
  322. healthMark.SetAlpha(0.5);
  323. healthMark.GetParent().Show(true);
  324. break;
  325. case GameConstants.STATE_WORN :
  326. healthMark.SetColor(Colors.COLOR_WORN);
  327. healthMark.SetAlpha(0.5);
  328. healthMark.GetParent().Show(true);
  329. break;
  330. case GameConstants.STATE_DAMAGED :
  331. healthMark.SetColor(Colors.COLOR_DAMAGED);
  332. healthMark.SetAlpha(0.5);
  333. healthMark.GetParent().Show(true);
  334. break;
  335. case GameConstants.STATE_BADLY_DAMAGED:
  336. healthMark.SetColor(Colors.COLOR_BADLY_DAMAGED);
  337. healthMark.SetAlpha(0.5);
  338. healthMark.GetParent().Show(true);
  339. break;
  340. case GameConstants.STATE_RUINED :
  341. healthMark.SetColor(Colors.COLOR_RUINED);
  342. healthMark.SetAlpha(0.5);
  343. healthMark.GetParent().Show(true);
  344. break;
  345. default :
  346. healthMark.SetColor(0x00FFFFFF);
  347. healthMark.SetAlpha(0.5);
  348. healthMark.GetParent().Show(true);
  349. break;
  350. }
  351. }
  352. widget.Show(true);
  353. }
  354. else
  355. widget.Show(false);
  356. }
  357. protected void SetItemQuantity(int type, float current, int min, int max, string itemWidget, string quantityPBWidget, string quantityTextWidget, bool enabled)
  358. {
  359. Widget widget;
  360. widget = m_Root.FindAnyWidget(itemWidget);
  361. if (enabled)
  362. {
  363. ProgressBarWidget progressBar;
  364. TextWidget textWidget;
  365. Class.CastTo(progressBar, widget.FindAnyWidget(quantityPBWidget));
  366. Class.CastTo(textWidget, widget.FindAnyWidget(quantityTextWidget));
  367. //check for volume vs. count and display progressbar or "bubble" with exact count/max text
  368. switch (type)
  369. {
  370. case QUANTITY_HIDDEN :
  371. progressBar.Show(false);
  372. textWidget.Show(false);
  373. textWidget.GetParent().Show(false);
  374. break;
  375. case QUANTITY_COUNT :
  376. if (max > 1 || current > 1)
  377. {
  378. string qty_text = string.Format("%1/%2", Math.Round(current).ToString(), max.ToString());
  379. progressBar.Show(false);
  380. textWidget.SetText(qty_text);
  381. textWidget.Show(true);
  382. textWidget.GetParent().Show(true);
  383. break;
  384. }
  385. else
  386. {
  387. progressBar.Show(false);
  388. textWidget.Show(false);
  389. textWidget.GetParent().Show(false);
  390. break;
  391. }
  392. case QUANTITY_PROGRESS :
  393. textWidget.Show(false);
  394. progressBar.SetCurrent(current);
  395. progressBar.Show(true);
  396. textWidget.GetParent().Show(true);
  397. break;
  398. }
  399. widget.Show(true);
  400. }
  401. else
  402. widget.Show(false);
  403. }
  404. protected void SetWeaponQuantity(int chamber, int mag, string itemWidget, string quantityPBWidget, string quantityTextWidget, bool enabled)
  405. {
  406. Widget widget;
  407. widget = m_Root.FindAnyWidget(itemWidget);
  408. if (enabled)
  409. {
  410. string wpn_qty = "";
  411. ProgressBarWidget progressBar;
  412. TextWidget textWidget;
  413. Class.CastTo(progressBar, widget.FindAnyWidget(quantityPBWidget));
  414. Class.CastTo(textWidget, widget.FindAnyWidget(quantityTextWidget));
  415. Weapon_Base wpn;
  416. Magazine maga;
  417. int mag_quantity = -1;
  418. if (Class.CastTo(wpn, m_EntityInHands))
  419. {
  420. if (Magnum_Base.Cast(wpn))
  421. {
  422. mag_quantity = 0;
  423. for (int j = 0; j < wpn.GetMuzzleCount(); j++)
  424. {
  425. if (wpn.IsChamberFull(j)&& !wpn.IsChamberFiredOut(j))
  426. mag_quantity++;
  427. }
  428. wpn_qty = mag_quantity.ToString();
  429. }
  430. else
  431. {
  432. for (int i = 0; i < wpn.GetMuzzleCount(); i++)
  433. {
  434. if (i > 0 && (wpn.GetMuzzleCount() < 3 || i%2 == 0))
  435. {
  436. wpn_qty = wpn_qty + " ";
  437. }
  438. if (wpn.IsChamberEmpty(i))
  439. {
  440. wpn_qty = wpn_qty + "0";
  441. }
  442. else if (wpn.IsChamberFiredOut(i))
  443. {
  444. wpn_qty = wpn_qty + "F";
  445. }
  446. else
  447. {
  448. wpn_qty = wpn_qty + "1";
  449. }
  450. maga = wpn.GetMagazine(i);
  451. if (maga)
  452. {
  453. mag_quantity = maga.GetAmmoCount();
  454. }
  455. else if (wpn.GetInternalMagazineMaxCartridgeCount(i) > 0)
  456. {
  457. mag_quantity = wpn.GetInternalMagazineCartridgeCount(i);
  458. }
  459. }
  460. if (wpn.IsJammed())
  461. {
  462. if (mag_quantity != -1)
  463. wpn_qty = string.Format("X (+%1)", mag_quantity);
  464. else
  465. wpn_qty = "X";
  466. }
  467. else
  468. {
  469. if (mag_quantity != -1)
  470. {
  471. wpn_qty = wpn_qty + " (" + mag_quantity.ToString() + ")";
  472. }
  473. }
  474. }
  475. }
  476. progressBar.Show(false);
  477. textWidget.SetText(wpn_qty);
  478. textWidget.Show(true);
  479. textWidget.GetParent().Show(true);
  480. }
  481. else
  482. widget.Show(false);
  483. }
  484. protected void SetWeaponModeAndZeroing(string itemWidget, string upWidget, string downWidget, bool enabled)
  485. {
  486. Widget widget;
  487. widget = m_Root.FindAnyWidget(itemWidget);
  488. if (enabled && m_Player)
  489. {
  490. TextWidget txtModeWidget;
  491. TextWidget txtZeroingWidget;
  492. Class.CastTo(txtModeWidget, widget.FindAnyWidget(upWidget));
  493. Class.CastTo(txtZeroingWidget, widget.FindAnyWidget(downWidget));
  494. Weapon w = Weapon.Cast(m_Player.GetHumanInventory().GetEntityInHands());
  495. string zeroing = string.Empty;
  496. if (w)
  497. zeroing = string.Format("%1 m", w.GetCurrentZeroing(w.GetCurrentMuzzle()));
  498. txtModeWidget.SetText(m_Player.GetWeaponManager().GetCurrentModeName());
  499. txtZeroingWidget.SetText(zeroing);
  500. widget.Show(true);
  501. }
  502. else
  503. widget.Show(false);
  504. }
  505. // not used instead of this is used confing parameter for fire mode
  506. protected string WeaponModeTextTemp()
  507. {
  508. return "unused";
  509. }
  510. protected void SetRadioFrequency(string freq, string itemWidget, string upWidget, string downWidget, bool enabled)
  511. {
  512. Widget widget;
  513. widget = m_Root.FindAnyWidget(itemWidget);
  514. if (enabled)
  515. {
  516. TextWidget txtUpWidget;
  517. TextWidget txtDownWidget;
  518. Class.CastTo(txtUpWidget, widget.FindAnyWidget(upWidget));
  519. Class.CastTo(txtDownWidget, widget.FindAnyWidget(downWidget));
  520. txtUpWidget.SetText(freq);
  521. txtDownWidget.SetText("MHz");
  522. widget.Show(true);
  523. }
  524. else
  525. widget.Show(false);
  526. }
  527. protected void SetActionWidget(ActionBase action, string descText, string actionWidget, string descWidget)
  528. {
  529. Widget widget = m_Root.FindAnyWidget(actionWidget);
  530. if (action && (!action.HasTarget() || (m_Player && m_Player.GetCommand_Vehicle())))
  531. {
  532. TextWidget actionName;
  533. Class.CastTo(actionName, widget.FindAnyWidget(descWidget));
  534. if (action.GetInput().GetInputType() == ActionInputType.AIT_CONTINUOUS)
  535. {
  536. descText = descText + " " + "#action_target_cursor_hold";
  537. actionName.SetText(descText);
  538. }
  539. else
  540. {
  541. actionName.SetText(descText);
  542. }
  543. widget.Show(true);
  544. }
  545. else
  546. {
  547. widget.Show(false);
  548. }
  549. }
  550. //! shows arrows near the interact action if there are more than one available
  551. protected void SetMultipleInteractAction(string multiActionsWidget)
  552. {
  553. Widget widget;
  554. widget = m_Root.FindAnyWidget(multiActionsWidget);
  555. widget.Show(m_InteractActionsNum > 1);
  556. }
  557. //! shows arrows near the interact action if there are more than one available
  558. protected void SetMultipleContinuousInteractAction(string multiActionsWidget)
  559. {
  560. Widget widget;
  561. widget = m_Root.FindAnyWidget(multiActionsWidget);
  562. widget.Show(m_ContinuousInteractActionsNum > 1);
  563. }
  564. protected void SetMultipleItemAction(string multiActionsWidget)
  565. {
  566. Widget widget;
  567. widget = m_Root.FindAnyWidget(multiActionsWidget);
  568. widget.Show(m_ItemActionsNum > 1);
  569. }
  570. //! shows arrows near the interact action if there are more than one available
  571. protected void SetMultipleContinuousItemAction(string multiActionsWidget)
  572. {
  573. Widget widget;
  574. widget = m_Root.FindAnyWidget(multiActionsWidget);
  575. widget.Show(m_ContinuousItemActionsNum > 1);
  576. }
  577. protected void SetInteractActionIcon(string actionWidget, string actionIconFrameWidget, string actionIconWidget, string actionIconTextWidget)
  578. {
  579. string keyName = string.Empty;
  580. Widget widget, frameWidget;
  581. ImageWidget iconWidget;
  582. TextWidget textWidget;
  583. widget = m_Root.FindAnyWidget(actionWidget);
  584. Class.CastTo(frameWidget, widget.FindAnyWidget(actionIconFrameWidget));
  585. Class.CastTo(iconWidget, widget.FindAnyWidget(actionIconWidget));
  586. Class.CastTo(textWidget, widget.FindAnyWidget(actionIconTextWidget));
  587. m_UseActionWrapper.InputP().SelectAlternative(0); //! select first alternative (which is the primary bind)
  588. for (int c = 0; c < m_UseActionWrapper.InputP().BindKeyCount(); c++)
  589. {
  590. int _hc = m_UseActionWrapper.InputP().GetBindKey(0);
  591. keyName = GetUApi().GetButtonName(_hc);
  592. }
  593. // uses text in floating widget
  594. iconWidget.Show(false);
  595. textWidget.SetText(keyName);
  596. textWidget.Show(true);
  597. }
  598. protected void CheckRefresherFlagVisibility()
  599. {
  600. Widget w = m_Root.FindAnyWidget("ia_item_flag_icon");
  601. if (m_Player && m_Player.GetHologramLocal())
  602. {
  603. EntityAI entity = m_Player.GetHologramLocal().GetProjectionEntity();
  604. w.Show(entity.IsRefresherSignalingViable() && m_Player.IsTargetInActiveRefresherRange(entity));
  605. }
  606. else if (w.IsVisible())
  607. {
  608. w.Show(false);
  609. }
  610. }
  611. protected void CheckForActionWidgetOverrides()
  612. {
  613. ItemBase item;
  614. typename actionName;
  615. if (Class.CastTo(item, m_EntityInHands) && item.GetActionWidgetOverride(actionName))
  616. {
  617. ActionBase action = ActionManagerBase.GetAction(actionName);
  618. if (action)
  619. {
  620. m_Single = action;
  621. }
  622. }
  623. }
  624. protected IngameHud GetHud()
  625. {
  626. Mission mission = GetGame().GetMission();
  627. if (mission)
  628. {
  629. IngameHud hud = IngameHud.Cast(mission.GetHud());
  630. return hud;
  631. }
  632. return null;
  633. }
  634. }