DayZ 1.24
Loading...
Searching...
No Matches
InputDeviceDisconnectWarningMenu.c
Go to the documentation of this file.
1class InputDeviceDisconnectWarningMenu extends UIScriptedMenu
2{
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
16
18 {
19 g_Game.GetMission().AddActiveInputExcludes({"gamepaddisconnect"});
20
21 m_DisconnectedDevices = new array<int>;
22 m_CanClose = false;
23
25 }
26
28 {
29 if (g_Game)
30 {
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
50 if (g_Game.GetUIManager() && g_Game.GetUIManager().IsDialogVisible())
51 g_Game.GetUIManager().CloseDialog();
52
54
55 return layoutRoot;
56 }
57
58 private void BuildMessages()
59 {
60 m_DeviceMessages = new map<int, string>;
61 m_DeviceMessages.Insert(EUAINPUT_DEVICE_CONTROLLER, string.Format("<image set=\"dayz_gui\" name=\"icon_Gamepad\" />"));
62 m_DeviceMessages.Insert(EUAINPUT_DEVICE_MOUSE, string.Format("<image set=\"dayz_gui\" name=\"icon_Mouse\" />"));
63 m_DeviceMessages.Insert(EUAINPUT_DEVICE_KEYBOARD, string.Format("<image set=\"dayz_gui\" name=\"icon_Keyboard\" />"));
64 }
65
67 private void UpdateDisconnectTexts()
68 {
69 int deviceCount = m_DisconnectedDevices.Count();
70 int count = m_DeviceOrder.Count();
71 int idx;
72 int device;
73 bool gamepadInactive = false;
74
75 m_DevicesText = string.Empty;
76 for (int i = 0; i < count; i++)
77 {
78 device = m_DeviceOrder[i];
79 idx = m_DisconnectedDevices.Find(device);
80 if (idx != -1) //is disconnected and relevant
81 {
82 m_DevicesText += m_DeviceMessages.Get(device) + " ";
84 {
85 gamepadInactive = true;
86 if (deviceCount > 1)
87 m_DevicesText += "| ";
88 }
89 }
90 }
91
92 if (deviceCount > 1)
93 {
94 m_CaptionText = "#str_inputdevice_notification_header_multiple";
95 m_ConfirmationText = "#str_inputdevice_notification_prompt_multiple";
96 }
97 else
98 {
99 m_CaptionText = "#str_inputdevice_notification_header_single";
100 m_ConfirmationText = "#str_inputdevice_notification_prompt_single";
101 }
102 }
103
104 private void SetDisconnectTexts()
105 {
106 m_CaptionWidget.SetText(m_CaptionText);
107 m_DeviceListWidget.SetText(m_DevicesText);
108 m_ActionTextWidget.SetText(m_ConfirmationText);
109
110 m_WrapperWidget.Update();
111 }
112
113 private void UpdateDisconnectedDevices(int device = -1)
114 {
115 m_DisconnectedDevices.Clear();
116 m_CanClose = g_Game.GetInput().AreAllAllowedInputDevicesActive(m_DisconnectedDevices);
118 m_Initialized = true;
119 }
120
121 private void UpdateWarningMenu(int device)
122 {
123 if (m_CanClose)
124 Close();
125 else if (layoutRoot)
126 {
129 }
130 }
131
132 //back-up close handling
133 override bool OnMouseButtonUp(Widget w, int x, int y, int button)
134 {
135 bool ret = super.OnMouseButtonUp(w, x, y, button);
136
137 if (m_CanClose)
138 Close();
139 return ret | m_CanClose;
140 }
141
142 //back-up close handling
143 override bool OnKeyUp(Widget w, int x, int y, int key)
144 {
145 bool ret = super.OnKeyUp(w, x, y, key);
146
147 if (m_CanClose)
148 Close();
149 return ret | m_CanClose;
150 }
151}
DayZGame g_Game
Definition DayZGame.c:3528
Icon x
Icon y
void Close()
bool m_Initialized
void UpdateDisconnectTexts()
Composes message depending on context.
ref array< int > m_DisconnectedDevices
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
ref map< int, string > m_DeviceMessages
override bool OnKeyUp(Widget w, int x, int y, int key)
void UpdateDisconnectedDevices(int device=-1)
static const string Empty
Definition EnString.c:7