Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
inputdevicedisconnectwarningmenu.c
Go to the documentation of this file.
1 class InputDeviceDisconnectWarningMenu extends UIScriptedMenu
2 {
3  private ref array<int> m_DisconnectedDevices;
4  private ref array<int> m_DeviceOrder = {EUAINPUT_DEVICE_CONTROLLER,EUAINPUT_DEVICE_MOUSE,EUAINPUT_DEVICE_KEYBOARD};
5  private ref map<int,string> m_DeviceMessages;
6  private bool m_CanClose;
7  private bool m_Initialized;
8  private string m_DevicesText;
9  private string m_CaptionText;
10  private string m_ConfirmationText;
11 
12  private WrapSpacerWidget m_WrapperWidget;
13  private TextWidget m_CaptionWidget;
14  private RichTextWidget m_DeviceListWidget;
15  private RichTextWidget m_ActionTextWidget;
16 
17  void InputDeviceDisconnectWarningMenu()
18  {
19  g_Game.GetMission().AddActiveInputExcludes({"gamepaddisconnect"});
20 
21  m_DisconnectedDevices = new array<int>;
22  m_CanClose = false;
23 
24  BuildMessages();
25  }
26 
27  void ~InputDeviceDisconnectWarningMenu()
28  {
29  if (g_Game)
30  {
31  PPERequesterBank.GetRequester(PPERequester_ControllerDisconnectBlur).Stop();
32  g_Game.DeleteTitleScreen(); // Removes any outstanding gamepad identification propmt; the gamepad is already recognized by now
33  if (g_Game.GetMission())
34  g_Game.GetMission().RemoveActiveInputExcludes({"gamepaddisconnect"},true);
35  }
36  }
37 
38  override Widget Init()
39  {
40  layoutRoot = g_Game.GetWorkspace().CreateWidgets("gui/layouts/new_ui/notifications/day_z_input_device_warning.layout");
41  m_WrapperWidget = WrapSpacerWidget.Cast(layoutRoot.FindAnyWidget("Wrapper"));
42  m_CaptionWidget = TextWidget.Cast(layoutRoot.FindAnyWidget("Caption"));
43  m_DeviceListWidget = RichTextWidget.Cast(layoutRoot.FindAnyWidget("DeviceList"));
44  m_ActionTextWidget = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ActionText"));
45 
46  g_Game.GetMission().GetOnInputDeviceConnected().Insert(UpdateDisconnectedDevices);
47  g_Game.GetMission().GetOnInputDeviceDisconnected().Insert(UpdateDisconnectedDevices);
48 
49  UpdateDisconnectedDevices();
50  if (g_Game.GetUIManager() && g_Game.GetUIManager().IsDialogVisible())
51  {
52  g_Game.GetUIManager().CloseDialog();
53  }
54 
55  PPERequesterBank.GetRequester(PPERequester_ControllerDisconnectBlur).Start();
56 
57  return layoutRoot;
58  }
59 
60  private void BuildMessages()
61  {
62  m_DeviceMessages = new map<int,string>;
63  m_DeviceMessages.Insert(EUAINPUT_DEVICE_CONTROLLER,string.Format("<image set=\"dayz_gui\" name=\"icon_Gamepad\" />"));
64  m_DeviceMessages.Insert(EUAINPUT_DEVICE_MOUSE,string.Format("<image set=\"dayz_gui\" name=\"icon_Mouse\" />"));
65  m_DeviceMessages.Insert(EUAINPUT_DEVICE_KEYBOARD,string.Format("<image set=\"dayz_gui\" name=\"icon_Keyboard\" />"));
66  }
67 
69  private void UpdateDisconnectTexts()
70  {
71  int deviceCount = m_DisconnectedDevices.Count();
72  int count = m_DeviceOrder.Count();
73  int idx;
74  int device;
75  bool gamepadInactive = false;
76 
77  m_DevicesText = string.Empty;
78  for (int i = 0; i < count; i++)
79  {
80  device = m_DeviceOrder[i];
81  idx = m_DisconnectedDevices.Find(device);
82  if (idx != -1) //is disconnected and relevant
83  {
84  m_DevicesText += m_DeviceMessages.Get(device) + " ";
85  if (device == EUAINPUT_DEVICE_CONTROLLER)
86  {
87  gamepadInactive = true;
88  if (deviceCount > 1)
89  {
90  m_DevicesText += "| ";
91  }
92  }
93  }
94  }
95 
96  if (deviceCount > 1)
97  {
98  m_CaptionText = "#str_inputdevice_notification_header_multiple";
99  m_ConfirmationText = "#str_inputdevice_notification_prompt_multiple";
100  }
101  else
102  {
103  m_CaptionText = "#str_inputdevice_notification_header_single";
104  m_ConfirmationText = "#str_inputdevice_notification_prompt_single";
105  }
106  }
107 
108  private void SetDisconnectTexts()
109  {
110  m_CaptionWidget.SetText(m_CaptionText);
111  m_DeviceListWidget.SetText(m_DevicesText);
112  m_ActionTextWidget.SetText(m_ConfirmationText);
113 
114  m_WrapperWidget.Update();
115  }
116 
117  private void UpdateDisconnectedDevices(int device = -1)
118  {
119  m_DisconnectedDevices.Clear();
120  m_CanClose = g_Game.GetInput().AreAllAllowedInputDevicesActive(m_DisconnectedDevices);
121  UpdateWarningMenu(device);
122  m_Initialized = true;
123  }
124 
125  private void UpdateWarningMenu(int device)
126  {
127  if (m_CanClose)
128  {
129  Close();
130  }
131  else if (layoutRoot)
132  {
133  UpdateDisconnectTexts();
134  SetDisconnectTexts();
135  }
136  }
137 
138  //back-up close handling
139  override bool OnMouseButtonUp(Widget w, int x, int y, int button)
140  {
141  bool ret = super.OnMouseButtonUp(w,x,y,button);
142 
143  if (m_CanClose)
144  {
145  Close();
146  }
147  return ret | m_CanClose;
148  }
149 
150  //back-up close handling
151  override bool OnKeyUp(Widget w, int x, int y, int key)
152  {
153  bool ret = super.OnKeyUp(w,x,y,key);
154 
155  if (m_CanClose)
156  {
157  Close();
158  }
159  return ret | m_CanClose;
160  }
161 }
UIScriptedMenu
Definition: dayzgame.c:63
Close
void Close()
y
Icon y
OnMouseButtonUp
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Definition: radialmenu.c:668
RichTextWidget
Definition: gameplay.c:315
map
map
Definition: controlsxboxnew.c:3
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
TextWidget
Definition: enwidgets.c:219
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
x
Icon x
m_Initialized
protected bool m_Initialized
Definition: uihintpanel.c:23
Widget
Definition: enwidgets.c:189