1class KeybindingElementNew
extends ScriptedWidgetEventHandler
3 protected KeybindingsContainer m_Container;
6 protected TextWidget m_ElementName;
7 protected TextWidget m_ElementModifier;
8 protected ButtonWidget m_PrimaryBindButton;
9 protected ButtonWidget m_AlternativeBindButton;
10 protected Widget m_PrimaryClear;
11 protected Widget m_AlternativeClear;
13 protected int m_ElementIndex;
14 protected bool m_IsEdited;
15 protected bool m_IsAlternateEdited;
18 protected ref
array<int> m_CustomAlternateBind;
22 void KeybindingElementNew(
int key_index, Widget parent, KeybindingsContainer group )
24 m_Root =
GetGame().GetWorkspace().CreateWidgets( GetLayoutName(), parent );
25 m_ElementName = TextWidget.Cast(
m_Root.FindAnyWidget(
"setting_label" ) );
26 m_ElementModifier = TextWidget.Cast(
m_Root.FindAnyWidget(
"modifier_label" ) );
27 m_PrimaryBindButton = ButtonWidget.Cast(
m_Root.FindAnyWidget(
"primary_bind" ) );
28 m_AlternativeBindButton = ButtonWidget.Cast(
m_Root.FindAnyWidget(
"alternative_bind" ) );
29 m_PrimaryClear =
m_Root.FindAnyWidget(
"primary_clear" );
30 m_AlternativeClear =
m_Root.FindAnyWidget(
"alternative_clear" );
33 m_ElementIndex = key_index;
39 string GetLayoutName()
41 return "gui/layouts/new_ui/options/keybindings_selectors/keybinding_option.layout";
49 bool IsAlternateChanged()
51 return m_IsAlternateEdited;
61 return m_CustomAlternateBind;
65 void SetElementTitle( ButtonWidget btnWidget,
UAInput pInput,
int iDeviceFlags )
68 int a, i, countbind = 0;
70 for( a = 0; a < pInput.AlternativeCount(); a++ )
72 pInput.SelectAlternative(a);
73 if( pInput.IsCombo() )
75 if( pInput.BindingCount() > 0 )
77 if( pInput.Binding(0) != 0 && pInput.CheckBindDevice(0,iDeviceFlags) )
82 output +=
GetUApi().GetButtonName( pInput.Binding(0) );
85 for( i = 1; i < pInput.BindingCount(); i++ )
87 if( pInput.Binding(i) != 0 )
89 output +=
" + " +
GetUApi().GetButtonName( pInput.Binding(i) );
99 if( pInput.BindingCount() > 0 )
101 if( pInput.Binding(0) != 0 && pInput.CheckBindDevice(0,iDeviceFlags) )
106 output +=
GetUApi().GetButtonName( pInput.Binding(0) );
115 btnWidget.SetText(output);
117 btnWidget.SetText(
"");
124 m_IsAlternateEdited =
false;
126 m_CustomAlternateBind = null;
128 if( input.IsLimited() )
130 if( input.IsPressLimit() )
132 m_ElementModifier.SetText(
"#keybind_press" );
134 if( input.IsReleaseLimit() )
136 m_ElementModifier.SetText(
"#keybind_release" );
138 if( input.IsHoldLimit() )
140 m_ElementModifier.SetText(
"#keybind_hold" );
142 if( input.IsHoldBeginLimit() )
144 m_ElementModifier.SetText(
"#keybind_holdbegin" );
146 if( input.IsClickLimit() )
148 m_ElementModifier.SetText(
"#keybind_click" );
150 if( input.IsDoubleClickLimit() )
152 m_ElementModifier.SetText(
"#keybind_doubletap" );
157 m_ElementModifier.SetText(
"" );
163 GetGame().GetInput().GetActionDesc( m_ElementIndex, option_text );
164 m_ElementName.SetText( option_text );
167 SetElementTitle(m_PrimaryBindButton, input, EUAINPUT_DEVICE_KEYBOARDMOUSE);
170 SetElementTitle(m_AlternativeBindButton, input, EUAINPUT_DEVICE_CONTROLLER);
173 void Reload(
array<int> custom_binds,
bool is_alternate )
176 if( custom_binds.Count() > 1 )
178 if( custom_binds.Get( 0 ) != 0 )
179 output =
GetUApi().GetButtonName( custom_binds.Get( 0 ) );
180 for(
int i = 1; i < custom_binds.Count(); i++ )
182 if( custom_binds.Get( i ) != 0 )
183 output +=
" + " +
GetUApi().GetButtonName( custom_binds.Get( i ) );
186 else if( custom_binds.Count() > 0 )
188 if( custom_binds.Get( 0 ) != 0 )
189 output =
GetUApi().GetButtonName( custom_binds.Get( 0 ) );
194 m_CustomAlternateBind = custom_binds;
195 m_IsAlternateEdited =
true;
196 m_AlternativeBindButton.SetText( output );
200 m_CustomBind = custom_binds;
202 m_PrimaryBindButton.SetText( output );
206 void StartEnteringKeybind()
208 m_Container.StartEnteringKeybind( m_ElementIndex );
209 m_PrimaryBindButton.SetText(
"#layout_keybinding_new_keybind" );
212 void CancelEnteringKeybind()
217 void StartEnteringAlternateKeybind()
219 m_Container.StartEnteringAlternateKeybind( m_ElementIndex );
220 m_AlternativeBindButton.SetText(
"#layout_keybinding_new_keybind" );
223 void CancelEnteringAlternateKeybind()
228 override bool OnClick( Widget w,
int x,
int y,
int button )
230 if( !m_Container.IsEnteringKeyBind() )
232 if( w == m_PrimaryBindButton )
234 m_EntryTimer.Run( 0.01,
this,
"StartEnteringKeybind" );
236 if( w == m_AlternativeBindButton )
238 m_EntryTimer.Run( 0.01,
this,
"StartEnteringAlternateKeybind" );
246 if( w == m_PrimaryClear )
250 m_PrimaryBindButton.SetText(
"" );
253 if( w == m_AlternativeClear )
255 m_IsAlternateEdited =
true;
257 m_AlternativeBindButton.SetText(
"" );
265 if( w == m_PrimaryBindButton || w == m_PrimaryClear )
267 m_PrimaryBindButton.SetColor(
ARGBF( 1, 1, 0, 0 ) );
268 m_PrimaryClear.Show(
true );
269 m_PrimaryClear.Update();
270 m_AlternativeClear.Show(
false );
273 else if( w == m_AlternativeBindButton || w == m_AlternativeClear )
275 m_AlternativeBindButton.SetColor(
ARGBF( 1, 1, 0, 0 ) );
276 m_PrimaryClear.Show(
false );
277 m_AlternativeClear.Show(
true );
278 m_AlternativeClear.Update();
283 m_PrimaryBindButton.SetColor(
ARGBF( 0, 0, 0, 0 ) );
284 m_AlternativeBindButton.SetColor(
ARGBF( 1, 0, 0, 0 ) );
285 m_PrimaryClear.Show(
false );
286 m_AlternativeClear.Show(
false );
291 override bool OnMouseLeave( Widget w, Widget enterW,
int x,
int y )
293 if( w == m_PrimaryClear || w == m_PrimaryBindButton )
295 if( enterW != m_PrimaryClear && enterW != m_PrimaryBindButton )
297 m_PrimaryClear.Show(
false );
298 m_PrimaryBindButton.SetColor(
ARGBF( 1, 0, 0, 0 ) );
301 if( w == m_AlternativeClear || w == m_AlternativeBindButton )
303 if( enterW != m_AlternativeClear && enterW != m_AlternativeBindButton )
305 m_AlternativeClear.Show(
false );
306 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.