2class KeybindingElement
extends ScriptedWidgetEventHandler
4 protected KeybindingsGroup m_Group;
7 protected TextWidget m_ElementName;
8 protected TextWidget m_ElementModifier;
9 protected ButtonWidget m_PrimaryBindButton;
10 protected ButtonWidget m_AlternativeBindButton;
11 protected Widget m_PrimaryClear;
12 protected Widget m_AlternativeClear;
14 protected int m_ElementIndex;
15 protected bool m_IsEdited;
16 protected bool m_IsAlternateEdited;
19 protected ref
array<int> m_CustomAlternateBind;
23 void KeybindingElement(
int key_index, Widget parent, KeybindingsGroup group )
25 m_Root =
GetGame().GetWorkspace().CreateWidgets( GetLayoutName(), parent );
26 m_ElementName = TextWidget.Cast(
m_Root.FindAnyWidget(
"setting_label" ) );
27 m_ElementModifier = TextWidget.Cast(
m_Root.FindAnyWidget(
"modifier_label" ) );
28 m_PrimaryBindButton = ButtonWidget.Cast(
m_Root.FindAnyWidget(
"primary_bind" ) );
29 m_AlternativeBindButton = ButtonWidget.Cast(
m_Root.FindAnyWidget(
"alternative_bind" ) );
30 m_PrimaryClear =
m_Root.FindAnyWidget(
"primary_clear" );
31 m_AlternativeClear =
m_Root.FindAnyWidget(
"alternative_clear" );
34 m_ElementIndex = key_index;
40 string GetLayoutName()
42 return "gui/layouts/new_ui/options/keybindings_selectors/keybinding_option.layout";
50 bool IsAlternateChanged()
52 return m_IsAlternateEdited;
62 return m_CustomAlternateBind;
66 void SetElementTitle( ButtonWidget btnWidget,
UAInput pInput,
int iDeviceFlags )
69 int a, i, countbind = 0;
71 for( a = 0; a < pInput.AlternativeCount(); a++ )
73 pInput.SelectAlternative(a);
74 if( pInput.IsCombo() )
76 if( pInput.BindingCount() > 0 )
78 if( pInput.Binding(0) != 0 && pInput.CheckBindDevice(0,iDeviceFlags) )
83 output +=
GetUApi().GetButtonName( pInput.Binding(0) );
86 for( i = 1; i < pInput.BindingCount(); i++ )
88 if( pInput.Binding(i) != 0 )
90 output +=
" + " +
GetUApi().GetButtonName( pInput.Binding(i) );
100 if( pInput.BindingCount() > 0 )
102 if( pInput.Binding(0) != 0 && pInput.CheckBindDevice(0,iDeviceFlags) )
107 output +=
GetUApi().GetButtonName( pInput.Binding(0) );
117 btnWidget.SetText(output);
119 btnWidget.SetText(
"");
126 m_IsAlternateEdited =
false;
128 m_CustomAlternateBind = null;
130 if( input.IsLimited() )
132 if( input.IsPressLimit() )
134 m_ElementModifier.SetText(
"#keybind_press" );
136 if( input.IsReleaseLimit() )
138 m_ElementModifier.SetText(
"#keybind_release" );
140 if( input.IsHoldLimit() )
142 m_ElementModifier.SetText(
"#keybind_hold" );
144 if( input.IsHoldBeginLimit() )
146 m_ElementModifier.SetText(
"#keybind_holdbegin" );
148 if( input.IsClickLimit() )
150 m_ElementModifier.SetText(
"#keybind_click" );
152 if( input.IsDoubleClickLimit() )
154 m_ElementModifier.SetText(
"#keybind_doubletap" );
159 m_ElementModifier.SetText(
"" );
165 GetGame().GetInput().GetActionDesc( m_ElementIndex, option_text );
166 m_ElementName.SetText( option_text );
169 SetElementTitle(m_PrimaryBindButton, input, EUAINPUT_DEVICE_KEYBOARDMOUSE);
172 SetElementTitle(m_AlternativeBindButton, input, EUAINPUT_DEVICE_CONTROLLER);
175 void Reload(
array<int> custom_binds,
bool is_alternate )
178 if( custom_binds.Count() > 1 )
180 if( custom_binds.Get( 0 ) != 0 )
181 output =
GetUApi().GetButtonName( custom_binds.Get( 0 ) );
182 for(
int i = 1; i < custom_binds.Count(); i++ )
184 if( custom_binds.Get( i ) != 0 )
185 output +=
" + " +
GetUApi().GetButtonName( custom_binds.Get( i ) );
188 else if( custom_binds.Count() > 0 )
190 if( custom_binds.Get( 0 ) != 0 )
191 output =
GetUApi().GetButtonName( custom_binds.Get( 0 ) );
196 m_CustomAlternateBind = custom_binds;
197 m_IsAlternateEdited =
true;
198 m_AlternativeBindButton.SetText( output );
202 m_CustomBind = custom_binds;
204 m_PrimaryBindButton.SetText( output );
208 void StartEnteringKeybind()
210 m_Group.StartEnteringKeybind( m_ElementIndex );
211 m_PrimaryBindButton.SetText(
"#layout_keybinding_new_keybind" );
214 void CancelEnteringKeybind()
219 void StartEnteringAlternateKeybind()
221 m_Group.StartEnteringAlternateKeybind( m_ElementIndex );
222 m_AlternativeBindButton.SetText(
"#layout_keybinding_new_keybind" );
225 void CancelEnteringAlternateKeybind()
230 override bool OnClick( Widget w,
int x,
int y,
int button )
232 if( !m_Group.IsEnteringKeyBind() )
234 if( w == m_PrimaryBindButton )
236 m_EntryTimer.Run( 0.01,
this,
"StartEnteringKeybind" );
238 if( w == m_AlternativeBindButton )
240 m_EntryTimer.Run( 0.01,
this,
"StartEnteringAlternateKeybind" );
248 if( w == m_PrimaryClear )
252 m_PrimaryBindButton.SetText(
"" );
255 if( w == m_AlternativeClear )
257 m_IsAlternateEdited =
true;
259 m_AlternativeBindButton.SetText(
"" );
267 if( w == m_PrimaryBindButton || w == m_PrimaryClear )
269 m_PrimaryBindButton.SetColor(
ARGBF( 1, 1, 0, 0 ) );
270 m_PrimaryClear.Show(
true );
271 m_PrimaryClear.Update();
272 m_AlternativeClear.Show(
false );
275 else if( w == m_AlternativeBindButton || w == m_AlternativeClear )
277 m_AlternativeBindButton.SetColor(
ARGBF( 1, 1, 0, 0 ) );
278 m_PrimaryClear.Show(
false );
279 m_AlternativeClear.Show(
true );
280 m_AlternativeClear.Update();
285 m_PrimaryBindButton.SetColor(
ARGBF( 0, 0, 0, 0 ) );
286 m_AlternativeBindButton.SetColor(
ARGBF( 1, 0, 0, 0 ) );
287 m_PrimaryClear.Show(
false );
288 m_AlternativeClear.Show(
false );
293 override bool OnMouseLeave( Widget w, Widget enterW,
int x,
int y )
295 if( w == m_PrimaryClear || w == m_PrimaryBindButton )
297 if( enterW != m_PrimaryClear && enterW != m_PrimaryBindButton )
299 m_PrimaryClear.Show(
false );
300 m_PrimaryBindButton.SetColor(
ARGBF( 1, 0, 0, 0 ) );
303 if( w == m_AlternativeClear || w == m_AlternativeBindButton )
305 if( enterW != m_AlternativeClear && enterW != m_AlternativeBindButton )
307 m_AlternativeClear.Show(
false );
308 m_AlternativeBindButton.SetColor(
ARGBF( 1, 0, 0, 0 ) );
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
void ClearAlternativeKeybind(int key_index)
void ClearKeybind(int key_index)
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
proto native CGame GetGame()
int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.