Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
keybindingsgroup.c
Go to the documentation of this file.
1 class KeybindingsGroup extends ScriptedWidgetEventHandler
3 {
4  protected Widget m_Root;
5  protected KeybindingsMenu m_Menu;
6 
7  protected ref map<int, ref KeybindingElement> m_KeyWidgets;
8  protected int m_CurrentSettingKeyIndex = -1;
9  protected int m_CurrentSettingAlternateKeyIndex = -1;
10 
11  protected ref DropdownPrefab m_KBDropdown;
12 
13  void KeybindingsGroup( int index, Input input, Widget parent, KeybindingsMenu menu )
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 
36  string GetLayoutName()
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 
61  void OnSelectKBPreset( int index )
62  {
63  string profile_text;
64  GetGame().GetInput().GetProfileName( index, profile_text );
65  m_KBDropdown.SetText( profile_text );
66  GetGame().GetInput().SetProfile( index );
67  ReloadProfiles();
68  m_KBDropdown.Close();
69  }
70 
71  void OnSelectConsolePreset( int index )
72  {
73  string profile_text;
74  GetGame().GetInput().GetProfileName( index, profile_text );
75  GetGame().GetInput().SetProfile( index );
76  ReloadProfiles();
77  }
78 
79  void ReloadProfiles()
80  {
81  foreach( int index, KeybindingElement element : m_KeyWidgets )
82  {
83  element.Reload();
84  }
85  }
86 
87  void AddSubgroup( /*int index, */Widget parent, Input input )
88  {
89  Widget subgroup = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/new_ui/options/keybindings_selectors/keybinding_subgroup.layout", parent );
90  TextWidget subgroup_name = TextWidget.Cast( subgroup.FindAnyWidget( "subgroup_text" ) );
91 
92  subgroup_name.SetText( "TestSubgroup" );
93  Widget subgroup_content = subgroup.FindAnyWidget( "subgroup_content" );
94 
95  TIntArray actions = new TIntArray;
96  GetUApi().GetActiveInputs(actions);
97  for( int i = 0; i < actions.Count(); i++ )
98  {
99  AddAction( actions.Get( i ), subgroup_content, input );
100  }
101 
102  subgroup_content.Update();
103  }
104 
105  void AddAction( int index, Widget parent, Input input )
106  {
107  m_KeyWidgets.Insert( index, new KeybindingElement( index, parent, this ) );
108  }
109 
110  void ReloadAction( int index )
111  {
112  if( m_KeyWidgets.Contains( index ) )
113  {
114  m_KeyWidgets.Get( index ).Reload();
115  }
116  }
117 
118  bool IsEnteringKeyBind()
119  {
120  return ( m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1 );
121  }
122 
123  void ClearKeybind( int key_index )
124  {
125  m_Menu.ClearKeybind( key_index );
126  }
127 
128  void ClearAlternativeKeybind( int key_index )
129  {
130  m_Menu.ClearAlternativeKeybind( key_index );
131  }
132 
133  void StartEnteringKeybind( int key_index )
134  {
135  m_CurrentSettingAlternateKeyIndex = -1;
136  m_CurrentSettingKeyIndex = key_index;
137  m_Menu.StartEnteringKeybind( key_index );
138  }
139 
140  void CancelEnteringKeybind()
141  {
142  if( m_CurrentSettingKeyIndex != -1 )
143  {
144  m_KeyWidgets.Get( m_CurrentSettingKeyIndex ).CancelEnteringKeybind();
145  m_CurrentSettingKeyIndex = -1;
146  }
147  }
148 
149  void StartEnteringAlternateKeybind( int key_index )
150  {
151  m_CurrentSettingKeyIndex = -1;
152  m_CurrentSettingAlternateKeyIndex = key_index;
153  m_Menu.StartEnteringAlternateKeybind( key_index );
154  }
155 
156  void CancelEnteringAlternateKeybind()
157  {
158  if( m_CurrentSettingAlternateKeyIndex != -1 )
159  {
160  m_KeyWidgets.Get( m_CurrentSettingAlternateKeyIndex ).CancelEnteringAlternateKeybind();
161  m_CurrentSettingAlternateKeyIndex = -1;
162  }
163  }
164 
165  bool IsChanged()
166  {
167  foreach( int index, KeybindingElement element : m_KeyWidgets )
168  {
169  if( element.IsChanged() || element.IsAlternateChanged() )
170  {
171  return true;
172  }
173  }
174  return false;
175  }
176 
177  void Apply()
178  {
179  UAInputAPI ua_api = GetUApi();
180  foreach( int index, KeybindingElement element : m_KeyWidgets )
181  {
182  UAInput input = ua_api.GetInputByID( index );
183  int i;
184  if( element.IsChanged() )
185  {
186  array<int> new_keys = element.GetChangedBinds();
187 
188 /* if( input.AlternativeCount() == 0 )
189  {
190  input.AddAlternative();
191  }
192  else*/
193  {
194  input.ClearDeviceBind(EUAINPUT_DEVICE_KEYBOARDMOUSE);
195 // input.SelectAlternative( 0 );
196 // input.ClearAlternative( 0 );
197  }
198 
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 /* if( input.AlternativeCount() < 2 )
219  {
220  input.AddAlternative();
221  }
222  else*/
223  {
224  input.ClearDeviceBind(EUAINPUT_DEVICE_CONTROLLER);
225 // input.SelectAlternative( 1 );
226 // input.ClearAlternative( 1 );
227  }
228 
229  if( new_alt_keys.Count() > 0 )
230  {
231  input.BindComboByHash( new_alt_keys.Get( 0 ) );
232  for( i = 1; i < new_alt_keys.Count(); i++ )
233  {
234  input.BindComboByHash( new_alt_keys.Get( i ) );
235  }
236  }
237  }
238  element.Reload();
239  }
240  }
241 
242  //DEPRECATED
243  void Reset()
244  {
245  ResetEx();
246  }
247 
248  void ResetEx(bool forced = false)
249  {
250  foreach( int index, KeybindingElement element : m_KeyWidgets )
251  {
252  if( element.IsChanged() || element.IsAlternateChanged() || forced )
253  {
254  element.Reload();
255  }
256  }
257  }
258 
259  void Update( float timeslice )
260  {
261  if( m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1 )
262  {
263  UAInputAPI ua_api = GetUApi();
264  if( ua_api.DeterminePressedButton() != 0 )
265  {
266  string name;
267  string text;
268  ref array<int> new_keybinds = new array<int>;
269 
270  // remove previous backlit
271  GetDayZGame().GetBacklit().KeybindingClear();
272 
273  for( int i = 0; i < ua_api.DeterminedCount(); ++i )
274  {
275  int kb_id = ua_api.GetDetermined( i );
276  new_keybinds.Insert( kb_id );
277 
278  // light up specific key
279  GetDayZGame().GetBacklit().KeybindingShow(kb_id);
280  }
281 
282  if( m_CurrentSettingKeyIndex != -1 )
283  {
284  m_Menu.ConfirmKeybindEntry( new_keybinds );
285  m_KeyWidgets.Get( m_CurrentSettingKeyIndex ).Reload( new_keybinds, false );
286  m_CurrentSettingKeyIndex = -1;
287  }
288  else if( m_CurrentSettingAlternateKeyIndex != -1 )
289  {
290  m_Menu.ConfirmAlternateKeybindEntry( new_keybinds );
291  m_KeyWidgets.Get( m_CurrentSettingAlternateKeyIndex ).Reload( new_keybinds, true );
292  m_CurrentSettingAlternateKeyIndex = -1;
293  }
294  }
295  }
296  }
297 
298  override bool OnMouseButtonDown( Widget w, int x, int y, int button )
299  {
300  if( !ButtonWidget.Cast( w ) )
301  {
302  m_KBDropdown.Close();
303  }
304  return false;
305  }
306 }
GetGame
proto native CGame GetGame()
UAInput
Definition: uainput.c:23
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
y
Icon y
m_Menu
protected ServerBrowserMenuNew m_Menu
Definition: serverbrowsertab.c:30
TIntArray
array< int > TIntArray
Definition: enscript.c:687
map
map
Definition: controlsxboxnew.c:3
TextWidget
Definition: enwidgets.c:219
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
Input
Definition: input.c:10
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
OnMouseButtonDown
bool OnMouseButtonDown(Widget w, int x, int y, int button)
Definition: pluginitemdiagnostic.c:117
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