DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
InputUtils.c
См. документацию.
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
210 {
211 string profile_name;
212 GetGame().GetInput().GetProfileName(GetUApi().PresetCurrent(), profile_name);
213
214 if (profile_name == PRESET_OLD)
215 {
217 }
218 else
219 {
221 }
222 }
223
225 {
227 }
228
233
238
239 static bool InitInputMetadata()
240 {
242 {
244
245 TIntArray sorted_actions = new TIntArray;
247 {
249 }
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}
map
Определения ControlsXboxNew.c:4
proto native UAInputAPI GetUApi()
proto native Input GetInput()
proto int GetProfileName(int profile_index, out string name)
gets profile by index
static map< int, ref array< int > > GetInputActionSortingMap()
Определения InputUtils.c:229
static const int VARIANT_NEW
Определения InputUtils.c:7
ref map< int, ref array< int > > m_InputActionSortingMap
Определения InputUtils.c:11
static bool InitInputMetadata()
Определения InputUtils.c:239
static const string PRESET_NEW
Определения InputUtils.c:5
static const string PRESET_OLD
Определения InputUtils.c:4
static const float ICON_SCALE_NORMAL
Определения InputUtils.c:14
static int m_CurrentPresetIDConsole
Определения InputUtils.c:8
static int GetConsolePresetID()
Определения InputUtils.c:224
static string GetRichtextButtonIconFromInputAction(string pInputAction, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Определения InputUtils.c:198
static string GetButtonNameFromInput(string pInputName, int pInputDeviceType)
Определения InputUtils.c:17
static void GetImagesetAndIconFromInputAction(string pInputAction, int pInputDeviceType, out array< string > pImageSet, out array< string > pIconName)
Определения InputUtils.c:160
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Определения InputUtils.c:167
ref array< int > m_UnsortedInputActions
Определения InputUtils.c:12
static array< int > GetUnsortedInputActions()
Определения InputUtils.c:234
static array< string > GetButtonIconPathFromInput(notnull UAInput pInput, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER)
Определения InputUtils.c:77
static map< int, ref TStringArray > GetComboButtonNamesFromInput(string pInputName, int pInputDeviceType)
returns a map of button names, combo or not
Определения InputUtils.c:33
static void UpdateConsolePresetID()
Определения InputUtils.c:209
static const float ICON_SCALE_TOOLBAR
Определения InputUtils.c:15
static array< string > GetButtonIconPathFromInput(string pInputName, int pInputDeviceType)
Определения InputUtils.c:108
static const int VARIANT_OLD
Определения InputUtils.c:6
static void GetImagesetAndIconFromInputAction(notnull UAInput pInput, int pInputDeviceType, out array< string > pImageSet, out array< string > pIconName)
Определения InputUtils.c:118
Определения InputUtils.c:2
proto native int Binding(int iIndex)
proto native int BindingCount()
proto native int AlternativeCount()
proto native UAInput GetInputByID(int iID)
returns list of all bindable (i.e. visible) inputs from the active group ('core' by default)
proto native UAInput GetInputByName(string sInputName)
proto native owned string GetButtonName(int iHash)
proto native int SortingCount()
proto native void GetActiveInputs(out TIntArray items)
proto native void SelectAlternative(int iIndex)
proto native int GetBindKey(int iIndex)
proto native bool IsCombo()
proto native bool HasSorting(int iIndex)
proto native bool CheckBindDevice(int iIndex, int iDeviceFlags)
Определения UAInput.c:24
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
array< string > TStringArray
Определения EnScript.c:685
array< int > TIntArray
Определения EnScript.c:687
GamepadButton
Определения EnSystem.c:341
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.