5 protected KeybindingsMenu
m_Menu;
8 protected int m_CurrentSettingKeyIndex = -1;
9 protected int m_CurrentSettingAlternateKeyIndex = -1;
11 protected ref DropdownPrefab m_KBDropdown;
13 void KeybindingsGroup(
int index,
Input input,
Widget parent, KeybindingsMenu menu )
19 input.GetActionGroupName( index, group_name );
21 m_Root =
GetGame().GetWorkspace().CreateWidgets( GetLayoutName(), parent );
22 Widget subgroup =
m_Root.FindAnyWidget(
"group_content" );
26 AddSubgroup( subgroup, input );
29 InitPresets( index,
m_Root.FindAnyWidget(
"group_header" ), input );
36 string GetLayoutName()
38 return "gui/layouts/new_ui/options/keybindings_selectors/keybinding_group.layout";
41 void InitPresets(
int index,
Widget parent,
Input input )
43 Widget kb_root = parent.FindAnyWidget(
"keyboard_dropown" );
46 input.GetProfileName( input.GetCurrentProfile(), profile_text );
48 m_KBDropdown =
new DropdownPrefab( kb_root, profile_text );
50 m_KBDropdown.m_OnSelectItem.Insert( OnSelectKBPreset );
52 for(
int i = 0; i < input.GetProfilesCount(); i++ )
54 input.GetProfileName( i, profile_text );
55 m_KBDropdown.AddElement( profile_text );
61 void OnSelectKBPreset(
int index )
64 GetGame().GetInput().GetProfileName( index, profile_text );
65 m_KBDropdown.SetText( profile_text );
66 GetGame().GetInput().SetProfile( index );
71 void OnSelectConsolePreset(
int index )
74 GetGame().GetInput().GetProfileName( index, profile_text );
75 GetGame().GetInput().SetProfile( index );
81 foreach(
int index, KeybindingElement element : m_KeyWidgets )
89 Widget subgroup =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/new_ui/options/keybindings_selectors/keybinding_subgroup.layout", parent );
92 subgroup_name.SetText(
"TestSubgroup" );
93 Widget subgroup_content = subgroup.FindAnyWidget(
"subgroup_content" );
96 GetUApi().GetActiveInputs(actions);
97 for(
int i = 0; i < actions.Count(); i++ )
99 AddAction( actions.Get( i ), subgroup_content, input );
102 subgroup_content.Update();
107 m_KeyWidgets.Insert( index,
new KeybindingElement( index, parent,
this ) );
110 void ReloadAction(
int index )
112 if( m_KeyWidgets.Contains( index ) )
114 m_KeyWidgets.Get( index ).Reload();
118 bool IsEnteringKeyBind()
120 return ( m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1 );
123 void ClearKeybind(
int key_index )
125 m_Menu.ClearKeybind( key_index );
128 void ClearAlternativeKeybind(
int key_index )
130 m_Menu.ClearAlternativeKeybind( key_index );
133 void StartEnteringKeybind(
int key_index )
135 m_CurrentSettingAlternateKeyIndex = -1;
136 m_CurrentSettingKeyIndex = key_index;
137 m_Menu.StartEnteringKeybind( key_index );
140 void CancelEnteringKeybind()
142 if( m_CurrentSettingKeyIndex != -1 )
144 m_KeyWidgets.Get( m_CurrentSettingKeyIndex ).CancelEnteringKeybind();
145 m_CurrentSettingKeyIndex = -1;
149 void StartEnteringAlternateKeybind(
int key_index )
151 m_CurrentSettingKeyIndex = -1;
152 m_CurrentSettingAlternateKeyIndex = key_index;
153 m_Menu.StartEnteringAlternateKeybind( key_index );
156 void CancelEnteringAlternateKeybind()
158 if( m_CurrentSettingAlternateKeyIndex != -1 )
160 m_KeyWidgets.Get( m_CurrentSettingAlternateKeyIndex ).CancelEnteringAlternateKeybind();
161 m_CurrentSettingAlternateKeyIndex = -1;
167 foreach(
int index, KeybindingElement element : m_KeyWidgets )
169 if( element.IsChanged() || element.IsAlternateChanged() )
180 foreach(
int index, KeybindingElement element : m_KeyWidgets )
182 UAInput input = ua_api.GetInputByID( index );
184 if( element.IsChanged() )
186 array<int> new_keys = element.GetChangedBinds();
194 input.ClearDeviceBind(EUAINPUT_DEVICE_KEYBOARDMOUSE);
199 if( new_keys.Count() > 0 )
201 input.BindComboByHash( new_keys.Get( 0 ) );
202 for( i = 1; i < new_keys.Count(); i++ )
204 input.BindComboByHash( new_keys.Get( i ) );
209 if( element.IsAlternateChanged() )
211 array<int> new_alt_keys = element.GetChangedAlternateBinds();
213 if( input.AlternativeCount() == 0 )
215 input.AddAlternative();
224 input.ClearDeviceBind(EUAINPUT_DEVICE_CONTROLLER);
229 if( new_alt_keys.Count() > 0 )
231 input.BindComboByHash( new_alt_keys.Get( 0 ) );
232 for( i = 1; i < new_alt_keys.Count(); i++ )
234 input.BindComboByHash( new_alt_keys.Get( i ) );
248 void ResetEx(
bool forced =
false)
250 foreach(
int index, KeybindingElement element : m_KeyWidgets )
252 if( element.IsChanged() || element.IsAlternateChanged() || forced )
259 void Update(
float timeslice )
261 if( m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1 )
264 if( ua_api.DeterminePressedButton() != 0 )
273 for(
int i = 0; i < ua_api.DeterminedCount(); ++i )
275 int kb_id = ua_api.GetDetermined( i );
276 new_keybinds.Insert( kb_id );
282 if( m_CurrentSettingKeyIndex != -1 )
284 m_Menu.ConfirmKeybindEntry( new_keybinds );
285 m_KeyWidgets.Get( m_CurrentSettingKeyIndex ).Reload( new_keybinds,
false );
286 m_CurrentSettingKeyIndex = -1;
288 else if( m_CurrentSettingAlternateKeyIndex != -1 )
290 m_Menu.ConfirmAlternateKeybindEntry( new_keybinds );
291 m_KeyWidgets.Get( m_CurrentSettingAlternateKeyIndex ).Reload( new_keybinds,
true );
292 m_CurrentSettingAlternateKeyIndex = -1;
300 if( !ButtonWidget.Cast( w ) )
302 m_KBDropdown.Close();