DayZ 1.24
Loading...
Searching...
No Matches
InputUtils.c
Go to the documentation of this file.
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>>
13
14 static const float ICON_SCALE_NORMAL = 1.21;
15 static const float ICON_SCALE_TOOLBAR = 1.81;
16
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 return GetUApi().GetButtonName(inp.GetBindKey(0));
25 }
26
27 return "";
28 }
29
31 static map<int, ref TStringArray> GetComboButtonNamesFromInput(string pInputName, int pInputDeviceType) //TODO: revisit to include same input device alternatives too?
32 {
33 UAInput inp = GetUApi().GetInputByName(pInputName);
35 map<int, ref TStringArray> output; //<alternativeIDX<button_array>>
36 for (int i = 0; i < inp.AlternativeCount(); i++)
37 {
38 inp.SelectAlternative(i);
39 if (inp.BindingCount() > 0 && inp.Binding(0) != 0 && inp.CheckBindDevice(0, pInputDeviceType))
40 {
42 if (inp.IsCombo())
43 {
44 buttons.Insert(GetUApi().GetButtonName(inp.Binding(0)));
45
46 for (int j = 1; j < inp.BindingCount(); j++)
47 {
48 if (inp.Binding(j) != 0 && inp.CheckBindDevice(j, pInputDeviceType))
49 buttons.Insert(GetUApi().GetButtonName(inp.Binding(j)));
50 }
51 //return buttons;
52 }
53 else
54 {
55 buttons.Insert(GetUApi().GetButtonName(inp.GetBindKey(0)));
56 //return buttons;
57 }
58
59 if (buttons.Count() > 0)
60 {
61 if (!output)
63 output.Insert(i, buttons);
64 }
65 }
66 }
67
68 return output;
69 }
70
72 {
74
75 for (int i = 0; i < pInput.AlternativeCount(); i++)
76 {
77 pInput.SelectAlternative(i);
78 bool done = false;
79 for (int bk = 0; bk < pInput.BindKeyCount(); bk++)
80 {
81 if (pInput.CheckBindDevice(0, pInputDeviceType))
82 {
83 buttonIcons.Insert(GetUApi().GetButtonIcon(pInput.Binding(bk)));
84
85 if (bk == pInput.BindKeyCount() - 1)
86 done = true;
87 }
88 }
89
90 if (done)
91 {
92 buttonIcons.Invert();
93 return buttonIcons;
94 }
95 }
96
97 return buttonIcons;
98 }
99
109
111 {
113 if (buttons.Count() == 0)
114 return;
115
116 for (int i = 0; i < buttons.Count(); i++)
117 {
119 buttons.Get(i).Split(":", parts);
120
121 if (parts.Count() < 2)
122 return;
123
124 pImageSet.Insert(parts[1].SubstringInverted(parts[1], parts[1].Length() - 6, parts[1].Length()));
125
127#ifdef PLATFORM_PS4
128 if (GetGame().GetInput().GetEnterButton() == GamepadButton.B)
129 {
131 if (parts[2] == "cross")
132 parts[2] = "circle";
133
135 if (parts[2] == "circle")
136 parts[2] = "cross";
137 }
138#endif
139
140 pIconName.Insert(parts[2]);
141 }
142 }
143
150
152 {
156
157 if (imageSets.Count() == 0)
158 return "";
159
160 string result = string.Format("<image set=\"%1\" name=\"%2\" scale=\"%3\" />", imageSets.Get(0), iconNames.Get(0), pScale);
161
162 string divider = " ";
163 if (pVertical)
164 divider = string.Format("\n%1\n", divider);
165
166 if (imageSets.Count() > 1)
167 {
169 for (int i = 1; i < imageSets.Count(); i++)
170 result = string.Format("%1%2<image set=\"%3\" name=\"%4\" scale=\"%5\" />", result, divider, imageSets.Get(i), iconNames.Get(i), pScale);
171 }
172
173 return string.Format("%1 %2", result, pLocalizedDescription);
174 }
175
186
188 {
189 string profile_name;
190 GetGame().GetInput().GetProfileName(GetUApi().PresetCurrent(), profile_name);
191
194 else
196 }
197
199 {
201 }
202
207
212
213 static bool InitInputMetadata()
214 {
216 {
218
222 GetUApi().GetActiveInputs(m_UnsortedInputActions);
223
224 UAInput inp;
225
226 for (int i = 0; i < GetUApi().SortingCount(); i++)
227 {
228 int input_id;
230 for (int j = 0; j < m_UnsortedInputActions.Count(); j++)
231 {
233 inp = GetUApi().GetInputByID(input_id);
234 if (inp.HasSorting(i))
235 {
237 sorted_actions.Insert(input_id);
238 }
239 }
240
241 if (sorting_content.Count() > 0)
242 {
243 sorting_content.Sort();
245 }
246 }
247
248 //remove sorted used inputs
249 int count = sorted_actions.Count();
250 for (i = 0; i < count; i++)
252 return true;
253 }
254 return false;
255 }
256}
ActionInput GetInput()
Definition ActionBase.c:989
proto native UAInputAPI GetUApi()
static map< int, ref array< int > > GetInputActionSortingMap()
Definition InputUtils.c:203
static const int VARIANT_NEW
Definition InputUtils.c:7
ref map< int, ref array< int > > m_InputActionSortingMap
Definition InputUtils.c:11
static bool InitInputMetadata()
Definition InputUtils.c:213
static const string PRESET_NEW
Definition InputUtils.c:5
static const string PRESET_OLD
Definition InputUtils.c:4
static const float ICON_SCALE_NORMAL
Definition InputUtils.c:14
static int m_CurrentPresetIDConsole
Definition InputUtils.c:8
static int GetConsolePresetID()
Definition InputUtils.c:198
static string GetRichtextButtonIconFromInputAction(string pInputAction, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Definition InputUtils.c:176
static string GetButtonNameFromInput(string pInputName, int pInputDeviceType)
Definition InputUtils.c:17
static void GetImagesetAndIconFromInputAction(string pInputAction, int pInputDeviceType, out array< string > pImageSet, out array< string > pIconName)
Definition InputUtils.c:144
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Definition InputUtils.c:151
ref array< int > m_UnsortedInputActions
Definition InputUtils.c:12
static array< int > GetUnsortedInputActions()
Definition InputUtils.c:208
static array< string > GetButtonIconPathFromInput(notnull UAInput pInput, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER)
Definition InputUtils.c:71
static map< int, ref TStringArray > GetComboButtonNamesFromInput(string pInputName, int pInputDeviceType)
returns a map of button names, combo or not
Definition InputUtils.c:31
static void UpdateConsolePresetID()
Definition InputUtils.c:187
static const float ICON_SCALE_TOOLBAR
Definition InputUtils.c:15
static array< string > GetButtonIconPathFromInput(string pInputName, int pInputDeviceType)
Definition InputUtils.c:100
static const int VARIANT_OLD
Definition InputUtils.c:6
static void GetImagesetAndIconFromInputAction(notnull UAInput pInput, int pInputDeviceType, out array< string > pImageSet, out array< string > pIconName)
Definition InputUtils.c:110
proto native CGame GetGame()
array< string > TStringArray
Definition EnScript.c:666
array< int > TIntArray
Definition EnScript.c:668
GamepadButton
Definition EnSystem.c:341