DayZ 1.24
Loading...
Searching...
No Matches
KeybindingsContainer.c
Go to the documentation of this file.
1//container for various subgroups and their elements
2class KeybindingsContainer extends ScriptedWidgetEventHandler
3{
4 protected const int NO_SORTING = -1;
5 protected Widget m_Root;
8
9 protected ref map<int, ref ElementArray> m_KeyWidgetElements; //<input_action_id,<KeybindingElementNew>>
10 protected int m_CurrentSettingKeyIndex = -1;
11 protected int m_CurrentSettingAlternateKeyIndex = -1;
12
14
16 {
17 m_KeyWidgetElements = new map<int, ref ElementArray>;
18 m_Menu = menu;
19
20 m_Root = GetGame().GetWorkspace().CreateWidgets(GetLayoutName(), parent);
21 m_Scroll = ScrollWidget.Cast(m_Root.FindAnyWidget("group_scroll"));
22 Widget container = m_Root.FindAnyWidget("group_scroll");
23
24 CreateSubgroups(container, input);
25
26 container.Update();
27
28 m_Root.SetHandler(this);
29 }
30
32 {
33 return "gui/layouts/new_ui/options/keybindings_selectors/keybinding_container.layout";
34 }
35
37 {
38 GetUApi().PresetSelect(index);
39 ReloadElements();
40 GetUApi().Export();
41 GetUApi().SaveInputPresetMiscData();
42 }
43
45 {
46 foreach (ElementArray elements : m_KeyWidgetElements)
47 {
48 foreach (KeybindingElementNew element : elements)
49 element.Reload();
50 }
51 }
52
54 {
55 Widget subgroup = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/options/keybindings_selectors/keybinding_subgroup.layout", parent);
56 Widget subgroup_content = subgroup.FindAnyWidget("subgroup_content");
57
59 if (sort_index != NO_SORTING)
61 else
63
64 for (int i = 0; i < input_actions.Count(); i++)
66
67 m_Subgroups.Insert(subgroup);
68
69 subgroup_content.Update();
70 }
71
73 {
74 m_Subgroups = new array<Widget>;
75
77 for (int i = 0; i < sort_count; i++)
78 {
79 if (InputUtils.GetInputActionSortingMap().GetElement(i) && InputUtils.GetInputActionSortingMap().GetElement(i).Count() > 0)
81 }
82
83 //any unssorted inputs go here
85 AddSubgroup(NO_SORTING, parent, input);
86 }
87
88 void AddElement(int index, Widget parent, Input input)
89 {
90 //create array if needed
91 if (!m_KeyWidgetElements.Get(index))
92 {
94 m_KeyWidgetElements.Insert(index, elements);
95 }
96
97 KeybindingElementNew element = new KeybindingElementNew(index, parent, this);
98 m_KeyWidgetElements.Get(index).Insert(element);
99 }
100
102 {
103 return (m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1);
104 }
105
107 {
108 m_Menu.ClearKeybind(key_index);
109 }
110
112 {
113 m_Menu.ClearAlternativeKeybind(key_index);
114 }
115
117 {
118 m_CurrentSettingAlternateKeyIndex = -1;
119 m_CurrentSettingKeyIndex = key_index;
120 m_Menu.StartEnteringKeybind(key_index);
121 }
122
124 {
125 if (m_CurrentSettingKeyIndex != -1)
126 {
127 foreach (KeybindingElementNew element : m_KeyWidgetElements.Get(m_CurrentSettingKeyIndex))
128 element.CancelEnteringKeybind();
129 m_CurrentSettingKeyIndex = -1;
130 }
131 }
132
134 {
135 m_CurrentSettingKeyIndex = -1;
136 m_CurrentSettingAlternateKeyIndex = key_index;
137 m_Menu.StartEnteringAlternateKeybind(key_index);
138 }
139
141 {
142 if (m_CurrentSettingAlternateKeyIndex != -1)
143 {
144 foreach (KeybindingElementNew element : m_KeyWidgetElements.Get(m_CurrentSettingAlternateKeyIndex))
145 element.CancelEnteringKeybind();
146 m_CurrentSettingAlternateKeyIndex = -1;
147 }
148 }
149
152 {
153 foreach (ElementArray elements : m_KeyWidgetElements)
154 {
155 foreach (KeybindingElementNew element : elements)
156 {
157 if (element.IsChanged() || element.IsAlternateChanged())
158 return true;
159 }
160 }
161 return false;
162 }
163
164 void Apply()
165 {
167 int input_index = 0;
168
169 foreach (ElementArray elements : m_KeyWidgetElements)
170 {
171 foreach (int element_index, KeybindingElementNew element : elements)
172 {
173 if (element_index == 0)
174 {
175 UAInput input = ua_api.GetInputByID(m_KeyWidgetElements.GetKey(input_index));
176 int i;
177 if (element.IsChanged())
178 {
179 array<int> new_keys = element.GetChangedBinds();
180 input.ClearDeviceBind(EUAINPUT_DEVICE_KEYBOARDMOUSE);
181 if (new_keys.Count() > 0)
182 {
183 input.BindComboByHash(new_keys.Get(0));
184 for (i = 1; i < new_keys.Count(); i++)
185 input.BindComboByHash(new_keys.Get(i));
186 }
187 }
188
189 if (element.IsAlternateChanged())
190 {
191 array<int> new_alt_keys = element.GetChangedAlternateBinds();
192
193 if (input.AlternativeCount() == 0)
194 input.AddAlternative();
195
196 input.ClearDeviceBind(EUAINPUT_DEVICE_CONTROLLER);
197
198 if (new_alt_keys.Count() > 0)
199 {
200 input.BindComboByHash(new_alt_keys.Get(0));
201 for (i = 1; i < new_alt_keys.Count(); i++)
202 input.BindComboByHash(new_alt_keys.Get(i));
203 }
204 }
205 }
206 element.Reload();
207 }
208 input_index++;
209 }
210 }
211
212 void Reset(bool forced = false)
213 {
214 foreach (ElementArray elements : m_KeyWidgetElements)
215 {
216 foreach (KeybindingElementNew element : elements)
217 {
218 if (element.IsChanged() || element.IsAlternateChanged() || forced)
219 element.Reload();
220 }
221 }
222 }
223
224 void Update(float timeslice)
225 {
226 if (m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1)
227 {
229 if (ua_api.DeterminePressedButton() != 0)
230 {
231 string name;
232 string text;
234
235 // remove previous backlit
236 GetDayZGame().GetBacklit().KeybindingClear();
237
238 for (int i = 0; i < ua_api.DeterminedCount(); ++i)
239 {
240 int kb_id = ua_api.GetDetermined(i);
241 new_keybinds.Insert(kb_id);
242
243 // light up specific key
244 GetDayZGame().GetBacklit().KeybindingShow(kb_id);
245 }
246
247 if (m_CurrentSettingKeyIndex != -1)
248 {
249 m_Menu.ConfirmKeybindEntry(new_keybinds);
250 foreach (KeybindingElementNew element : m_KeyWidgetElements.Get(m_CurrentSettingKeyIndex))
251 element.Reload(new_keybinds, false);
252 m_CurrentSettingKeyIndex = -1;
253 }
254 else if (m_CurrentSettingAlternateKeyIndex != -1)
255 {
256 m_Menu.ConfirmAlternateKeybindEntry(new_keybinds);
257 foreach (KeybindingElementNew elementAlternate : m_KeyWidgetElements.Get(m_CurrentSettingAlternateKeyIndex))
258 elementAlternate.Reload(new_keybinds, true);
259 m_CurrentSettingAlternateKeyIndex = -1;
260 }
261 }
262 }
263 }
264
266 {
267 Widget w;
268 for (int i = 0; i < m_Subgroups.Count(); i++)
269 {
270 w = m_Subgroups[i];
271 w.Show(index == i);
272 }
273
274 m_Scroll.VScrollToPos01(0);
275 }
276}
277
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
DayZGame GetDayZGame()
Definition DayZGame.c:3530
ServerBrowserMenuNew m_Menu
Widget m_Root
Definition SizeToChild.c:85
proto native UAInputAPI GetUApi()
Definition input.c:11
static map< int, ref array< int > > GetInputActionSortingMap()
Definition InputUtils.c:203
static array< int > GetUnsortedInputActions()
Definition InputUtils.c:208
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void AddSubgroup(Widget parent, Input input)
int AddElement(string text, Widget content=null)
void KeybindingElementNew(int key_index, Widget parent, KeybindingsContainer group)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
void SwitchSubgroup(int index)
void ClearAlternativeKeybind(int key_index)
void ReloadElements()
void Reset(bool forced=false)
ScrollWidget m_Scroll
bool IsEnteringKeyBind()
void CreateSubgroups(Widget parent, Input input)
void OnSelectKBPreset(int index)
void StartEnteringAlternateKeybind(int key_index)
ref array< Widget > m_Subgroups
void AddElement(int index, Widget parent, Input input)
bool IsChanged()
is anything changed?
void AddSubgroup(int sort_index, Widget parent, Input input)
string GetLayoutName()
void StartEnteringKeybind(int key_index)
void Update(float timeslice)
KeybindingsMenu m_Menu
void ClearKeybind(int key_index)
void KeybindingsContainer(int index, Input input, Widget parent, KeybindingsMenu menu)
void CancelEnteringAlternateKeybind()
void CancelEnteringKeybind()
ref map< int, ref ElementArray > m_KeyWidgetElements
proto native CGame GetGame()