Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
keybindingscontainer.c
Go to the documentation of this file.
1 //container for various subgroups and their elements
2 class 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 
13  protected ref array<Widget> m_Subgroups;
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 
31  string GetLayoutName()
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 
44  void ReloadElements()
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
94  if (InputUtils.GetUnsortedInputActions() && InputUtils.GetUnsortedInputActions().Count() > 0)
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 
113  bool IsEnteringKeyBind()
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 
135  void CancelEnteringKeybind()
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 
154  void CancelEnteringAlternateKeybind()
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 
167  bool IsChanged()
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 
308 typedef array<ref KeybindingElementNew> ElementArray;
GetGame
proto native CGame GetGame()
InputUtils
Definition: inpututils.c:1
UAInput
Definition: uainput.c:23
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
m_Menu
protected ServerBrowserMenuNew m_Menu
Definition: serverbrowsertab.c:30
map
map
Definition: controlsxboxnew.c:3
array< Widget >
Input
Definition: input.c:10
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Reset
void Reset()
Definition: inventory.c:1106
Widget
Definition: enwidgets.c:189
UAInputAPI
Definition: uainput.c:164
GetUApi
proto native UAInputAPI GetUApi()
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650