DayZ 1.24
Loading...
Searching...
No Matches
KeybindingsGroup.c
Go to the documentation of this file.
1
2class KeybindingsGroup extends ScriptedWidgetEventHandler
3{
4 protected Widget m_Root;
6
8 protected int m_CurrentSettingKeyIndex = -1;
9 protected int m_CurrentSettingAlternateKeyIndex = -1;
10
11 protected ref DropdownPrefab m_KBDropdown;
12
14 {
15 m_KeyWidgets = new map<int, ref KeybindingElement>;
16 m_Menu = menu;
17
18 string group_name;
19 input.GetActionGroupName(index, group_name);
20
21 m_Root = GetGame().GetWorkspace().CreateWidgets(GetLayoutName(), parent);
22 Widget subgroup = m_Root.FindAnyWidget("group_content");
23
24 // for( int i = 0; i < 1; i++ )
25 // {
26 AddSubgroup(/*index, */subgroup, input);
27 // }
28
29 InitPresets(index, m_Root.FindAnyWidget("group_header"), input);
30
31 subgroup.Update();
32
33 m_Root.SetHandler(this);
34 }
35
37 {
38 return "gui/layouts/new_ui/options/keybindings_selectors/keybinding_group.layout";
39 }
40
41 void InitPresets(int index, Widget parent, Input input)
42 {
43 Widget kb_root = parent.FindAnyWidget("keyboard_dropown");
44
45 string profile_text;
46 input.GetProfileName(input.GetCurrentProfile(), profile_text);
47
48 m_KBDropdown = new DropdownPrefab(kb_root, profile_text);
49
50 m_KBDropdown.m_OnSelectItem.Insert(OnSelectKBPreset);
51
52 for (int i = 0; i < input.GetProfilesCount(); i++)
53 {
54 input.GetProfileName(i, profile_text);
55 m_KBDropdown.AddElement(profile_text);
56 }
57
58 kb_root.Update();
59 }
60
62 {
63 string profile_text;
64 GetGame().GetInput().GetProfileName(index, profile_text);
65 m_KBDropdown.SetText(profile_text);
66 GetGame().GetInput().SetProfile(index);
68 m_KBDropdown.Close();
69 }
70
72 {
73 string profile_text;
74 GetGame().GetInput().GetProfileName(index, profile_text);
75 GetGame().GetInput().SetProfile(index);
77 }
78
80 {
81 foreach (int index, KeybindingElement element : m_KeyWidgets)
82 element.Reload();
83 }
84
85 void AddSubgroup(/*int index, */Widget parent, Input input)
86 {
87 Widget subgroup = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/options/keybindings_selectors/keybinding_subgroup.layout", parent);
88 TextWidget subgroup_name = TextWidget.Cast(subgroup.FindAnyWidget("subgroup_text"));
89
90 subgroup_name.SetText("TestSubgroup");
91 Widget subgroup_content = subgroup.FindAnyWidget("subgroup_content");
92
94 GetUApi().GetActiveInputs(actions);
95 for (int i = 0; i < actions.Count(); i++)
97
98 subgroup_content.Update();
99 }
100
101 void AddAction(int index, Widget parent, Input input)
102 {
103 m_KeyWidgets.Insert(index, new KeybindingElement(index, parent, this));
104 }
105
107 {
108 if (m_KeyWidgets.Contains(index))
109 m_KeyWidgets.Get(index).Reload();
110 }
111
113 {
114 return (m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1);
115 }
116
118 {
119 m_Menu.ClearKeybind(key_index);
120 }
121
123 {
124 m_Menu.ClearAlternativeKeybind(key_index);
125 }
126
128 {
129 m_CurrentSettingAlternateKeyIndex = -1;
130 m_CurrentSettingKeyIndex = key_index;
131 m_Menu.StartEnteringKeybind(key_index);
132 }
133
135 {
136 if (m_CurrentSettingKeyIndex != -1)
137 {
138 m_KeyWidgets.Get(m_CurrentSettingKeyIndex).CancelEnteringKeybind();
139 m_CurrentSettingKeyIndex = -1;
140 }
141 }
142
144 {
145 m_CurrentSettingKeyIndex = -1;
146 m_CurrentSettingAlternateKeyIndex = key_index;
147 m_Menu.StartEnteringAlternateKeybind(key_index);
148 }
149
151 {
152 if (m_CurrentSettingAlternateKeyIndex != -1)
153 {
154 m_KeyWidgets.Get(m_CurrentSettingAlternateKeyIndex).CancelEnteringAlternateKeybind();
155 m_CurrentSettingAlternateKeyIndex = -1;
156 }
157 }
158
160 {
161 foreach (int index, KeybindingElement element : m_KeyWidgets)
162 {
163 if (element.IsChanged() || element.IsAlternateChanged())
164 return true;
165 }
166 return false;
167 }
168
169 void Apply()
170 {
172 foreach (int index, KeybindingElement element : m_KeyWidgets)
173 {
174 UAInput input = ua_api.GetInputByID(index);
175 int i;
176 if (element.IsChanged())
177 {
178 array<int> new_keys = element.GetChangedBinds();
179
180 /* if( input.AlternativeCount() == 0 )
181 {
182 input.AddAlternative();
183 }
184 else*/
185 {
186 input.ClearDeviceBind(EUAINPUT_DEVICE_KEYBOARDMOUSE);
187 // input.SelectAlternative( 0 );
188 // input.ClearAlternative( 0 );
189 }
190
191 if (new_keys.Count() > 0)
192 {
193 input.BindComboByHash(new_keys.Get(0));
194 for (i = 1; i < new_keys.Count(); i++)
195 input.BindComboByHash(new_keys.Get(i));
196 }
197 }
198
199 if (element.IsAlternateChanged())
200 {
201 array<int> new_alt_keys = element.GetChangedAlternateBinds();
202
203 if (input.AlternativeCount() == 0)
204 input.AddAlternative();
205
206 /* if( input.AlternativeCount() < 2 )
207 {
208 input.AddAlternative();
209 }
210 else*/
211 {
212 input.ClearDeviceBind(EUAINPUT_DEVICE_CONTROLLER);
213 // input.SelectAlternative( 1 );
214 // input.ClearAlternative( 1 );
215 }
216
217 if (new_alt_keys.Count() > 0)
218 {
219 input.BindComboByHash(new_alt_keys.Get(0));
220 for (i = 1; i < new_alt_keys.Count(); i++)
221 input.BindComboByHash(new_alt_keys.Get(i));
222 }
223 }
224 element.Reload();
225 }
226 }
227
228 //DEPRECATED
229 void Reset()
230 {
231 ResetEx();
232 }
233
234 void ResetEx(bool forced = false)
235 {
236 foreach (int index, KeybindingElement element : m_KeyWidgets)
237 {
238 if (element.IsChanged() || element.IsAlternateChanged() || forced)
239 element.Reload();
240 }
241 }
242
243 void Update(float timeslice)
244 {
245 if (m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1)
246 {
248 if (ua_api.DeterminePressedButton() != 0)
249 {
250 string name;
251 string text;
253
254 // remove previous backlit
255 GetDayZGame().GetBacklit().KeybindingClear();
256
257 for (int i = 0; i < ua_api.DeterminedCount(); ++i)
258 {
259 int kb_id = ua_api.GetDetermined(i);
260 new_keybinds.Insert(kb_id);
261
262 // light up specific key
263 GetDayZGame().GetBacklit().KeybindingShow(kb_id);
264 }
265
266 if (m_CurrentSettingKeyIndex != -1)
267 {
268 m_Menu.ConfirmKeybindEntry(new_keybinds);
269 m_KeyWidgets.Get(m_CurrentSettingKeyIndex).Reload(new_keybinds, false);
270 m_CurrentSettingKeyIndex = -1;
271 }
272 else if (m_CurrentSettingAlternateKeyIndex != -1)
273 {
274 m_Menu.ConfirmAlternateKeybindEntry(new_keybinds);
275 m_KeyWidgets.Get(m_CurrentSettingAlternateKeyIndex).Reload(new_keybinds, true);
276 m_CurrentSettingAlternateKeyIndex = -1;
277 }
278 }
279 }
280 }
281
282 override bool OnMouseButtonDown(Widget w, int x, int y, int button)
283 {
284 if (!ButtonWidget.Cast(w))
285 m_KBDropdown.Close();
286 return false;
287 }
288}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
DayZGame GetDayZGame()
Definition DayZGame.c:3530
Icon x
Icon y
ServerBrowserMenuNew m_Menu
Widget m_Root
Definition SizeToChild.c:85
proto native UAInputAPI GetUApi()
Definition input.c:11
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void KeybindingsGroup(int index, Input input, Widget parent, KeybindingsMenu menu)
void ClearAlternativeKeybind(int key_index)
void Update(float timeslice)
void DropdownPrefab(Widget root, string text="")
void OnSelectConsolePreset(int index)
ref DropdownPrefab m_KBDropdown
void InitPresets(int index, Widget parent, Input input)
void AddSubgroup(Widget parent, Input input)
ref map< int, ref KeybindingElement > m_KeyWidgets
void AddAction(int index, Widget parent, Input input)
void ClearKeybind(int key_index)
void KeybindingElement(int key_index, Widget parent, KeybindingsGroup group)
void ResetEx(bool forced=false)
void StartEnteringAlternateKeybind(int key_index)
void StartEnteringKeybind(int key_index)
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
array< int > TIntArray
Definition EnScript.c:668