Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
inpututils.c
Go to the documentation of this file.
1 class InputUtils
2 {
3  //useful for console preset differentiation
4  static const string PRESET_OLD = "#STR_UAPRESET_0";
5  static const string PRESET_NEW = "#STR_UAPRESET_1";
6  static const int VARIANT_OLD = 0;
7  static const int VARIANT_NEW = 1;
8  static int m_CurrentPresetIDConsole = -1;
9  //
10 
11  static protected ref map<int, ref array<int>> m_InputActionSortingMap; //<sorting_idx,<input_ID>>
12  static protected ref array<int> m_UnsortedInputActions;
13 
14  static const float ICON_SCALE_NORMAL = 1.21;
15  static const float ICON_SCALE_TOOLBAR = 1.81;
16 
17  static string GetButtonNameFromInput(string pInputName, int pInputDeviceType)
18  {
19  UAInput inp = GetUApi().GetInputByName(pInputName);
20  for (int i = 0; i < inp.AlternativeCount(); i++)
21  {
22  inp.SelectAlternative(i);
23  if (inp.CheckBindDevice(0, pInputDeviceType))
24  {
25  return GetUApi().GetButtonName(inp.GetBindKey(0));
26  }
27  }
28 
29  return "";
30  }
31 
33  static map<int,ref TStringArray> GetComboButtonNamesFromInput(string pInputName, int pInputDeviceType) //TODO: revisit to include same input device alternatives too?
34  {
35  UAInput inp = GetUApi().GetInputByName(pInputName);
36  TStringArray buttons;
37  map<int,ref TStringArray> output;//<alternativeIDX<button_array>>
38  for (int i = 0; i < inp.AlternativeCount(); i++)
39  {
40  inp.SelectAlternative(i);
41  if (inp.BindingCount() > 0 && inp.Binding(0) != 0 && inp.CheckBindDevice(0,pInputDeviceType))
42  {
43  buttons = new TStringArray;
44  if (inp.IsCombo())
45  {
46  buttons.Insert(GetUApi().GetButtonName( inp.Binding(0) ));
47 
48  for (int j = 1; j < inp.BindingCount(); j++)
49  {
50  if (inp.Binding(j) != 0 && inp.CheckBindDevice(j,pInputDeviceType))
51  {
52  buttons.Insert(GetUApi().GetButtonName( inp.Binding(j) ));
53  }
54  }
55  //return buttons;
56  }
57  else
58  {
59  buttons.Insert(GetUApi().GetButtonName(inp.GetBindKey(0)));
60  //return buttons;
61  }
62 
63  if (buttons.Count() > 0)
64  {
65  if (!output)
66  {
67  output = new map<int,ref TStringArray>;
68  }
69  output.Insert(i,buttons);
70  }
71  }
72  }
73 
74  return output;
75  }
76 
77  static array<string> GetButtonIconPathFromInput(notnull UAInput pInput, int pInputDeviceType = EUAINPUT_DEVICE_CONTROLLER)
78  {
79  array<string> buttonIcons = new array<string>();
80 
81  for (int i = 0; i < pInput.AlternativeCount(); i++)
82  {
83  pInput.SelectAlternative(i);
84  bool done = false;
85  for (int bk = 0; bk < pInput.BindKeyCount(); bk++)
86  {
87  if (pInput.CheckBindDevice(0, pInputDeviceType))
88  {
89  buttonIcons.Insert(GetUApi().GetButtonIcon(pInput.Binding(bk)));
90 
91  if (bk == pInput.BindKeyCount() - 1)
92  {
93  done = true;
94  }
95  }
96  }
97 
98  if (done)
99  {
100  buttonIcons.Invert();
101  return buttonIcons;
102  }
103  }
104 
105  return buttonIcons;
106  }
107 
108  static array<string> GetButtonIconPathFromInput(string pInputName, int pInputDeviceType)
109  {
110  UAInput inp = GetUApi().GetInputByName(pInputName);
111 
112  array<string> buttonIcons = new array<string>();
113  buttonIcons = InputUtils.GetButtonIconPathFromInput(inp, pInputDeviceType);
114 
115  return buttonIcons;
116  }
117 
118  static void GetImagesetAndIconFromInputAction(notnull UAInput pInput, int pInputDeviceType, out array<string> pImageSet, out array<string> pIconName)
119  {
120  array<string> buttons = InputUtils.GetButtonIconPathFromInput(pInput, pInputDeviceType);
121  if (buttons.Count() == 0 )
122  {
123  return;
124  }
125 
126  for (int i = 0; i < buttons.Count(); i++)
127  {
128  array<string> parts = new array<string>;
129  buttons.Get(i).Split(":", parts);
130 
131  if (parts.Count() < 2)
132  {
133  return;
134  }
135 
136  pImageSet.Insert(parts[1].SubstringInverted(parts[1], parts[1].Length() - 6, parts[1].Length()));
137 
139  #ifdef PLATFORM_PS4
140  if (GetGame().GetInput().GetEnterButton() == GamepadButton.B)
141  {
143  if (parts[2] == "cross")
144  {
145  parts[2] = "circle";
146  }
147 
149  if (parts[2] == "circle")
150  {
151  parts[2] = "cross";
152  }
153  }
154  #endif
155 
156  pIconName.Insert(parts[2]);
157  }
158  }
159 
160  static void GetImagesetAndIconFromInputAction(string pInputAction, int pInputDeviceType, out array<string> pImageSet, out array<string> pIconName)
161  {
162  UAInput inp = GetUApi().GetInputByName(pInputAction);
163 
164  InputUtils.GetImagesetAndIconFromInputAction(inp, pInputDeviceType, pImageSet, pIconName);
165  }
166 
167  static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType = EUAINPUT_DEVICE_CONTROLLER, float pScale = ICON_SCALE_NORMAL, bool pVertical = false)
168  {
169  array<string> imageSets = new array<string>();
170  array<string> iconNames = new array<string>();
171  InputUtils.GetImagesetAndIconFromInputAction(pInput, pInputDeviceType, imageSets, iconNames);
172 
173  if (imageSets.Count() == 0)
174  {
175  return "";
176  }
177 
178  string result = string.Format("<image set=\"%1\" name=\"%2\" scale=\"%3\" />", imageSets.Get(0), iconNames.Get(0), pScale);
179 
180  string divider = " ";
181  if (pVertical)
182  {
183  divider = string.Format("\n%1\n", divider);
184  }
185 
186  if (imageSets.Count() > 1)
187  {
189  for (int i = 1; i < imageSets.Count(); i++)
190  {
191  result = string.Format("%1%2<image set=\"%3\" name=\"%4\" scale=\"%5\" />", result, divider, imageSets.Get(i), iconNames.Get(i), pScale);
192  }
193  }
194 
195  return string.Format("%1 %2", result, pLocalizedDescription);
196  }
197 
198  static string GetRichtextButtonIconFromInputAction(string pInputAction, string pLocalizedDescription, int pInputDeviceType = EUAINPUT_DEVICE_CONTROLLER, float pScale = ICON_SCALE_NORMAL, bool pVertical = false)
199  {
200  UAInput inp = GetUApi().GetInputByName(pInputAction);
201 
202  array<string> imageSets = new array<string>();
203  array<string> iconNames = new array<string>();
204  InputUtils.GetImagesetAndIconFromInputAction(inp, pInputDeviceType, imageSets, iconNames);
205 
206  return InputUtils.GetRichtextButtonIconFromInputAction(inp, pLocalizedDescription, pInputDeviceType, pScale, pVertical);
207  }
208 
209  static void UpdateConsolePresetID()
210  {
211  string profile_name;
212  GetGame().GetInput().GetProfileName(GetUApi().PresetCurrent(), profile_name);
213 
214  if (profile_name == PRESET_OLD)
215  {
216  m_CurrentPresetIDConsole = VARIANT_OLD;
217  }
218  else
219  {
220  m_CurrentPresetIDConsole = VARIANT_NEW;
221  }
222  }
223 
224  static int GetConsolePresetID()
225  {
226  return m_CurrentPresetIDConsole;
227  }
228 
229  static map<int, ref array<int>> GetInputActionSortingMap()
230  {
231  return m_InputActionSortingMap;
232  }
233 
234  static array<int> GetUnsortedInputActions()
235  {
236  return m_UnsortedInputActions;
237  }
238 
239  static bool InitInputMetadata()
240  {
241  if (!m_InputActionSortingMap)
242  {
243  m_InputActionSortingMap = new map<int, ref array<int>>;
244 
245  TIntArray sorted_actions = new TIntArray;
246  if (!m_UnsortedInputActions)
247  {
248  m_UnsortedInputActions = new array<int>;
249  }
250  GetUApi().GetActiveInputs(m_UnsortedInputActions);
251 
252  UAInput inp;
253 
254  for (int i = 0; i < GetUApi().SortingCount(); i++)
255  {
256  int input_id;
257  array<int> sorting_content = new array<int>;
258  for (int j = 0; j < m_UnsortedInputActions.Count(); j++)
259  {
260  input_id = m_UnsortedInputActions[j];
261  inp = GetUApi().GetInputByID(input_id);
262  if (inp.HasSorting(i))
263  {
264  sorting_content.Insert(input_id);
265  sorted_actions.Insert(input_id);
266  }
267  }
268 
269  if (sorting_content.Count() > 0)
270  {
271  sorting_content.Sort();
272  m_InputActionSortingMap.Insert(i,sorting_content);
273  }
274  }
275 
276  //remove sorted used inputs
277  int count = sorted_actions.Count();
278  for (i = 0; i < count; i++)
279  {
280  m_UnsortedInputActions.RemoveItem(sorted_actions[i]);
281  }
282  return true;
283  }
284  return false;
285  }
286 }
GetGame
proto native CGame GetGame()
InputUtils
Definition: inpututils.c:1
UAInput
Definition: uainput.c:23
TStringArray
array< string > TStringArray
Definition: enscript.c:685
TIntArray
array< int > TIntArray
Definition: enscript.c:687
map
map
Definition: controlsxboxnew.c:3
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
GamepadButton
GamepadButton
Definition: ensystem.c:340
GetUApi
proto native UAInputAPI GetUApi()
GetInput
ActionInput GetInput()
Definition: actionbase.c:1066