Dayz Explorer 1.28.160049
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;
6 protected KeybindingsMenu m_Menu;
7 protected ScrollWidget m_Scroll;
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
15 void KeybindingsContainer( int index, Input input, Widget parent, KeybindingsMenu menu )
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
36 void OnSelectKBPreset( int index )
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 {
50 element.Reload();
51 }
52 }
53 }
54
55 void AddSubgroup( int sort_index, Widget parent, Input input )
56 {
57 Widget subgroup = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/new_ui/options/keybindings_selectors/keybinding_subgroup.layout", parent );
58 Widget subgroup_content = subgroup.FindAnyWidget( "subgroup_content" );
59
60 TIntArray input_actions;
61 if (sort_index != NO_SORTING)
62 {
63 input_actions = InputUtils.GetInputActionSortingMap().Get(sort_index);
64 }
65 else
66 {
67 input_actions = InputUtils.GetUnsortedInputActions();
68 }
69
70 for (int i = 0; i < input_actions.Count(); i++)
71 {
72 AddElement( input_actions[i], subgroup_content, input );
73 }
74
75 m_Subgroups.Insert(subgroup);
76
77 subgroup_content.Update();
78 }
79
80 void CreateSubgroups( Widget parent, Input input )
81 {
82 m_Subgroups = new array<Widget>;
83
84 int sort_count = InputUtils.GetInputActionSortingMap().Count();
85 for (int i = 0; i < sort_count; i++)
86 {
87 if (InputUtils.GetInputActionSortingMap().GetElement(i) && InputUtils.GetInputActionSortingMap().GetElement(i).Count() > 0)
88 {
89 AddSubgroup(InputUtils.GetInputActionSortingMap().GetKey(i),parent,input);
90 }
91 }
92
93 //any unssorted inputs go here
95 {
96 AddSubgroup(NO_SORTING,parent,input);
97 }
98 }
99
100 void AddElement( int index, Widget parent, Input input )
101 {
102 //create array if needed
103 if (!m_KeyWidgetElements.Get(index))
104 {
105 ElementArray elements = new ElementArray;
106 m_KeyWidgetElements.Insert( index, elements );
107 }
108
109 KeybindingElementNew element = new KeybindingElementNew( index, parent, this );
110 m_KeyWidgetElements.Get(index).Insert(element);
111 }
112
114 {
115 return ( m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1 );
116 }
117
118 void ClearKeybind( int key_index )
119 {
120 m_Menu.ClearKeybind( key_index );
121 }
122
123 void ClearAlternativeKeybind( int key_index )
124 {
125 m_Menu.ClearAlternativeKeybind( key_index );
126 }
127
128 void StartEnteringKeybind( int key_index )
129 {
130 m_CurrentSettingAlternateKeyIndex = -1;
131 m_CurrentSettingKeyIndex = key_index;
132 m_Menu.StartEnteringKeybind( key_index );
133 }
134
136 {
137 if ( m_CurrentSettingKeyIndex != -1 )
138 {
139 foreach (KeybindingElementNew element : m_KeyWidgetElements.Get( m_CurrentSettingKeyIndex ))
140 {
141 element.CancelEnteringKeybind();
142 }
143 m_CurrentSettingKeyIndex = -1;
144 }
145 }
146
147 void StartEnteringAlternateKeybind( int key_index )
148 {
149 m_CurrentSettingKeyIndex = -1;
150 m_CurrentSettingAlternateKeyIndex = key_index;
151 m_Menu.StartEnteringAlternateKeybind( key_index );
152 }
153
155 {
156 if ( m_CurrentSettingAlternateKeyIndex != -1 )
157 {
158 foreach (KeybindingElementNew element : m_KeyWidgetElements.Get( m_CurrentSettingAlternateKeyIndex ))
159 {
160 element.CancelEnteringKeybind();
161 }
162 m_CurrentSettingAlternateKeyIndex = -1;
163 }
164 }
165
168 {
169 foreach (ElementArray elements : m_KeyWidgetElements)
170 {
171 foreach (KeybindingElementNew element : elements)
172 {
173 if (element.IsChanged() || element.IsAlternateChanged())
174 {
175 return true;
176 }
177 }
178 }
179 return false;
180 }
181
182 void Apply()
183 {
184 UAInputAPI ua_api = GetUApi();
185 int input_index = 0;
186
187 foreach (ElementArray elements : m_KeyWidgetElements)
188 {
189 foreach (int element_index, KeybindingElementNew element : elements)
190 {
191 if (element_index == 0)
192 {
193 UAInput input = ua_api.GetInputByID( m_KeyWidgetElements.GetKey(input_index) );
194 int i;
195 if ( element.IsChanged() )
196 {
197 array<int> new_keys = element.GetChangedBinds();
198 input.ClearDeviceBind(EUAINPUT_DEVICE_KEYBOARDMOUSE);
199 if ( new_keys.Count() > 0 )
200 {
201 input.BindComboByHash( new_keys.Get( 0 ) );
202 for( i = 1; i < new_keys.Count(); i++ )
203 {
204 input.BindComboByHash( new_keys.Get( i ) );
205 }
206 }
207 }
208
209 if ( element.IsAlternateChanged() )
210 {
211 array<int> new_alt_keys = element.GetChangedAlternateBinds();
212
213 if ( input.AlternativeCount() == 0 )
214 {
215 input.AddAlternative();
216 }
217
218 input.ClearDeviceBind(EUAINPUT_DEVICE_CONTROLLER);
219
220 if ( new_alt_keys.Count() > 0 )
221 {
222 input.BindComboByHash( new_alt_keys.Get( 0 ) );
223 for( i = 1; i < new_alt_keys.Count(); i++ )
224 {
225 input.BindComboByHash( new_alt_keys.Get( i ) );
226 }
227 }
228 }
229 }
230 element.Reload();
231 }
232 input_index++;
233 }
234 }
235
236 void Reset(bool forced = false)
237 {
238 foreach ( ElementArray elements : m_KeyWidgetElements )
239 {
240 foreach (KeybindingElementNew element : elements)
241 {
242 if ( element.IsChanged() || element.IsAlternateChanged() || forced )
243 {
244 element.Reload();
245 }
246 }
247 }
248 }
249
250 void Update( float timeslice )
251 {
252 if ( m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1 )
253 {
254 UAInputAPI ua_api = GetUApi();
255 if ( ua_api.DeterminePressedButton() != 0 )
256 {
257 string name;
258 string text;
259 ref array<int> new_keybinds = new array<int>;
260
261 // remove previous backlit
262 GetDayZGame().GetBacklit().KeybindingClear();
263
264 for( int i = 0; i < ua_api.DeterminedCount(); ++i )
265 {
266 int kb_id = ua_api.GetDetermined( i );
267 new_keybinds.Insert( kb_id );
268
269 // light up specific key
270 GetDayZGame().GetBacklit().KeybindingShow(kb_id);
271 }
272
273 if ( m_CurrentSettingKeyIndex != -1 )
274 {
275 m_Menu.ConfirmKeybindEntry( new_keybinds );
276 foreach (KeybindingElementNew element : m_KeyWidgetElements.Get( m_CurrentSettingKeyIndex ))
277 {
278 element.Reload( new_keybinds, false );
279 }
280 m_CurrentSettingKeyIndex = -1;
281 }
282 else if ( m_CurrentSettingAlternateKeyIndex != -1 )
283 {
284 m_Menu.ConfirmAlternateKeybindEntry( new_keybinds );
285 foreach (KeybindingElementNew elementAlternate : m_KeyWidgetElements.Get( m_CurrentSettingAlternateKeyIndex ))
286 {
287 elementAlternate.Reload( new_keybinds, true );
288 }
289 m_CurrentSettingAlternateKeyIndex = -1;
290 }
291 }
292 }
293 }
294
295 void SwitchSubgroup(int index)
296 {
297 Widget w;
298 for (int i = 0; i < m_Subgroups.Count(); i++)
299 {
300 w = m_Subgroups[i];
301 w.Show(index == i);
302 }
303
304 m_Scroll.VScrollToPos01(0);
305 }
306}
307
308typedef array<ref KeybindingElementNew> ElementArray;
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Definition input.c:11
static map< int, ref array< int > > GetInputActionSortingMap()
Definition inpututils.c:229
static array< int > GetUnsortedInputActions()
Definition inpututils.c:234
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
DayZGame GetDayZGame()
Definition dayzgame.c:3870
proto native CGame GetGame()
ServerBrowserMenuNew m_Menu
Widget m_Root
Definition sizetochild.c:91
proto native UAInputAPI GetUApi()