itemdropwarningmenu.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. class WarningMenuBase : UIScriptedMenu
  2. {
  3. protected ButtonWidget m_OkButton;
  4. protected MultilineTextWidget m_Description;
  5. void WarningMenuBase()
  6. {
  7. if (GetGame().GetMission())
  8. {
  9. GetGame().GetMission().AddActiveInputExcludes({"menu"});
  10. GetGame().GetMission().GetHud().ShowHudUI(false);
  11. GetGame().GetMission().GetHud().ShowQuickbarUI(false);
  12. }
  13. }
  14. void ~WarningMenuBase()
  15. {
  16. if (GetGame() && GetGame().GetMission())
  17. {
  18. GetGame().GetMission().RemoveActiveInputExcludes({"menu"},true);
  19. GetGame().GetMission().GetHud().ShowHudUI(true);
  20. GetGame().GetMission().GetHud().ShowQuickbarUI(true);
  21. GetGame().GetMission().GetOnInputPresetChanged().Remove(OnInputPresetChanged);
  22. GetGame().GetMission().GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
  23. }
  24. }
  25. override Widget Init()
  26. {
  27. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_dropped_items.layout");
  28. m_OkButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("bOK"));
  29. m_Description = MultilineTextWidget.Cast(layoutRoot.FindAnyWidget("txtDescription"));
  30. m_Description.Show(true);
  31. string text = Widget.TranslateString(GetText());
  32. m_Description.SetText(text);
  33. if (GetGame().GetMission())
  34. {
  35. GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
  36. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  37. }
  38. OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
  39. return layoutRoot;
  40. }
  41. string GetText()
  42. {
  43. return "";
  44. }
  45. override bool OnClick(Widget w, int x, int y, int button)
  46. {
  47. super.OnClick(w, x, y, button);
  48. if (w.GetUserID() == IDC_OK)
  49. {
  50. Close();
  51. return true;
  52. }
  53. return false;
  54. }
  55. override void Update(float timeslice)
  56. {
  57. super.Update(timeslice);
  58. #ifdef PLATFORM_CONSOLE
  59. if (GetUApi().GetInputByID(UAUISelect).LocalPress())
  60. Close();
  61. #endif
  62. }
  63. protected void OnInputPresetChanged()
  64. {
  65. #ifdef PLATFORM_CONSOLE
  66. UpdateControlsElements();
  67. #endif
  68. }
  69. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  70. {
  71. UpdateControlsElements();
  72. UpdateControlsElementVisibility();
  73. }
  74. protected void UpdateControlsElements()
  75. {
  76. RichTextWidget toolbarText = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
  77. string context = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", "#early_access_alpha_understand", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  78. toolbarText.SetText(context);
  79. }
  80. protected void UpdateControlsElementVisibility()
  81. {
  82. bool toolbarShow = false;
  83. #ifdef PLATFORM_CONSOLE
  84. toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
  85. #endif
  86. layoutRoot.FindAnyWidget("BottomConsoleToolbar").Show(toolbarShow);
  87. m_OkButton.Show(!toolbarShow);
  88. }
  89. }
  90. class ItemDropWarningMenu : WarningMenuBase
  91. {
  92. override string GetText()
  93. {
  94. return "#str_item_drop_notification";
  95. }
  96. }
  97. class PlayerRepositionWarningMenu : WarningMenuBase
  98. {
  99. override string GetText()
  100. {
  101. return "#str_position_change_notification";
  102. }
  103. }