4 protected const int NO_SORTING = -1;
6 protected KeybindingsMenu
m_Menu;
7 protected ScrollWidget m_Scroll;
10 protected int m_CurrentSettingKeyIndex = -1;
11 protected int m_CurrentSettingAlternateKeyIndex = -1;
15 void KeybindingsContainer(
int index,
Input input,
Widget parent, KeybindingsMenu menu )
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" );
24 CreateSubgroups(container,input);
31 string GetLayoutName()
33 return "gui/layouts/new_ui/options/keybindings_selectors/keybinding_container.layout";
36 void OnSelectKBPreset(
int index )
38 GetUApi().PresetSelect( index );
41 GetUApi().SaveInputPresetMiscData();
46 foreach ( ElementArray elements : m_KeyWidgetElements )
48 foreach (KeybindingElementNew element : elements)
55 void AddSubgroup(
int sort_index,
Widget parent,
Input input )
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" );
61 if (sort_index != NO_SORTING)
63 input_actions =
InputUtils.GetInputActionSortingMap().Get(sort_index);
67 input_actions =
InputUtils.GetUnsortedInputActions();
70 for (
int i = 0; i < input_actions.Count(); i++)
72 AddElement( input_actions[i], subgroup_content, input );
75 m_Subgroups.Insert(subgroup);
77 subgroup_content.Update();
84 int sort_count =
InputUtils.GetInputActionSortingMap().Count();
85 for (
int i = 0; i < sort_count; i++)
87 if (
InputUtils.GetInputActionSortingMap().GetElement(i) &&
InputUtils.GetInputActionSortingMap().GetElement(i).Count() > 0)
89 AddSubgroup(
InputUtils.GetInputActionSortingMap().GetKey(i),parent,input);
96 AddSubgroup(NO_SORTING,parent,input);
100 void AddElement(
int index,
Widget parent,
Input input )
103 if (!m_KeyWidgetElements.Get(index))
105 ElementArray elements =
new ElementArray;
106 m_KeyWidgetElements.Insert( index, elements );
109 KeybindingElementNew element =
new KeybindingElementNew( index, parent,
this );
110 m_KeyWidgetElements.Get(index).Insert(element);
113 bool IsEnteringKeyBind()
115 return ( m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1 );
118 void ClearKeybind(
int key_index )
120 m_Menu.ClearKeybind( key_index );
123 void ClearAlternativeKeybind(
int key_index )
125 m_Menu.ClearAlternativeKeybind( key_index );
128 void StartEnteringKeybind(
int key_index )
130 m_CurrentSettingAlternateKeyIndex = -1;
131 m_CurrentSettingKeyIndex = key_index;
132 m_Menu.StartEnteringKeybind( key_index );
135 void CancelEnteringKeybind()
137 if ( m_CurrentSettingKeyIndex != -1 )
139 foreach (KeybindingElementNew element : m_KeyWidgetElements.Get( m_CurrentSettingKeyIndex ))
141 element.CancelEnteringKeybind();
143 m_CurrentSettingKeyIndex = -1;
147 void StartEnteringAlternateKeybind(
int key_index )
149 m_CurrentSettingKeyIndex = -1;
150 m_CurrentSettingAlternateKeyIndex = key_index;
151 m_Menu.StartEnteringAlternateKeybind( key_index );
154 void CancelEnteringAlternateKeybind()
156 if ( m_CurrentSettingAlternateKeyIndex != -1 )
158 foreach (KeybindingElementNew element : m_KeyWidgetElements.Get( m_CurrentSettingAlternateKeyIndex ))
160 element.CancelEnteringKeybind();
162 m_CurrentSettingAlternateKeyIndex = -1;
169 foreach (ElementArray elements : m_KeyWidgetElements)
171 foreach (KeybindingElementNew element : elements)
173 if (element.IsChanged() || element.IsAlternateChanged())
187 foreach (ElementArray elements : m_KeyWidgetElements)
189 foreach (
int element_index, KeybindingElementNew element : elements)
191 if (element_index == 0)
193 UAInput input = ua_api.GetInputByID( m_KeyWidgetElements.GetKey(input_index) );
195 if ( element.IsChanged() )
197 array<int> new_keys = element.GetChangedBinds();
198 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();
218 input.ClearDeviceBind(EUAINPUT_DEVICE_CONTROLLER);
220 if ( new_alt_keys.Count() > 0 )
222 input.BindComboByHash( new_alt_keys.Get( 0 ) );
223 for( i = 1; i < new_alt_keys.Count(); i++ )
225 input.BindComboByHash( new_alt_keys.Get( i ) );
236 void Reset(
bool forced =
false)
238 foreach ( ElementArray elements : m_KeyWidgetElements )
240 foreach (KeybindingElementNew element : elements)
242 if ( element.IsChanged() || element.IsAlternateChanged() || forced )
250 void Update(
float timeslice )
252 if ( m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1 )
255 if ( ua_api.DeterminePressedButton() != 0 )
264 for(
int i = 0; i < ua_api.DeterminedCount(); ++i )
266 int kb_id = ua_api.GetDetermined( i );
267 new_keybinds.Insert( kb_id );
273 if ( m_CurrentSettingKeyIndex != -1 )
275 m_Menu.ConfirmKeybindEntry( new_keybinds );
276 foreach (KeybindingElementNew element : m_KeyWidgetElements.Get( m_CurrentSettingKeyIndex ))
278 element.Reload( new_keybinds,
false );
280 m_CurrentSettingKeyIndex = -1;
282 else if ( m_CurrentSettingAlternateKeyIndex != -1 )
284 m_Menu.ConfirmAlternateKeybindEntry( new_keybinds );
285 foreach (KeybindingElementNew elementAlternate : m_KeyWidgetElements.Get( m_CurrentSettingAlternateKeyIndex ))
287 elementAlternate.Reload( new_keybinds,
true );
289 m_CurrentSettingAlternateKeyIndex = -1;
295 void SwitchSubgroup(
int index)
298 for (
int i = 0; i < m_Subgroups.Count(); i++)
304 m_Scroll.VScrollToPos01(0);