Dayz Explorer 1.29.162510
Loading...
Searching...
No Matches
keybindingelement.c
Go to the documentation of this file.
1
2class KeybindingElement extends ScriptedWidgetEventHandler
3{
4 protected KeybindingsGroup m_Group;
5
6 protected Widget m_Root;
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;
13
14 protected int m_ElementIndex;
15 protected bool m_IsEdited;
16 protected bool m_IsAlternateEdited;
17
18 protected ref array<int> m_CustomBind;
19 protected ref array<int> m_CustomAlternateBind;
20
21 protected ref Timer m_EntryTimer = new Timer( CALL_CATEGORY_GUI );
22
23 void KeybindingElement( int key_index, Widget parent, KeybindingsGroup group )
24 {
25 m_Root = g_Game.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" );
32
33 m_Group = group;
34 m_ElementIndex = key_index;
35
36 Reload();
37 m_Root.SetHandler( this );
38 }
39
40 string GetLayoutName()
41 {
42 return "gui/layouts/new_ui/options/keybindings_selectors/keybinding_option.layout";
43 }
44
45 bool IsChanged()
46 {
47 return m_IsEdited;
48 }
49
50 bool IsAlternateChanged()
51 {
52 return m_IsAlternateEdited;
53 }
54
55 array<int> GetChangedBinds()
56 {
57 return m_CustomBind;
58 }
59
60 array<int> GetChangedAlternateBinds()
61 {
62 return m_CustomAlternateBind;
63 }
64
65 // assembly all related binding at widget element
66 void SetElementTitle( ButtonWidget btnWidget, UAInput pInput, int iDeviceFlags )
67 {
68 string output;
69 int a, i, countbind = 0;
70
71 for( a = 0; a < pInput.AlternativeCount(); a++ )
72 {
73 pInput.SelectAlternative(a);
74 if( pInput.IsCombo() )
75 {
76 if( pInput.BindingCount() > 0 )
77 {
78 if( pInput.Binding(0) != 0 && pInput.CheckBindDevice(0,iDeviceFlags) )
79 {
80 if( countbind > 0 )
81 output += ", ";
82
83 output += GetUApi().GetButtonName( pInput.Binding(0) );
84 countbind++;
85
86 for( i = 1; i < pInput.BindingCount(); i++ )
87 {
88 if( pInput.Binding(i) != 0 )
89 {
90 output += " + " + GetUApi().GetButtonName( pInput.Binding(i) );
91 countbind++;
92 }
93 }
94
95 }
96 }
97 }
98 else
99 {
100 if( pInput.BindingCount() > 0 )
101 {
102 if( pInput.Binding(0) != 0 && pInput.CheckBindDevice(0,iDeviceFlags) )
103 {
104 if( countbind > 0 )
105 output += ", ";
106
107 output += GetUApi().GetButtonName( pInput.Binding(0) );
108 countbind++;
109 }
110 }
111 }
112
113 }
114
115 // nothing may be available - we do not want "null" or "0" in string
116 if( countbind > 0 )
117 btnWidget.SetText(output);
118 else
119 btnWidget.SetText("");
120 }
121
122 void Reload()
123 {
124 UAInput input = GetUApi().GetInputByID( m_ElementIndex );
125 m_IsEdited = false;
126 m_IsAlternateEdited = false;
127 m_CustomBind = null;
128 m_CustomAlternateBind = null;
129
130 if( input.IsLimited() )
131 {
132 if( input.IsPressLimit() )
133 {
134 m_ElementModifier.SetText( "#keybind_press" );
135 }
136 if( input.IsReleaseLimit() )
137 {
138 m_ElementModifier.SetText( "#keybind_release" );
139 }
140 if( input.IsHoldLimit() )
141 {
142 m_ElementModifier.SetText( "#keybind_hold" );
143 }
144 if( input.IsHoldBeginLimit() )
145 {
146 m_ElementModifier.SetText( "#keybind_holdbegin" );
147 }
148 if( input.IsClickLimit() )
149 {
150 m_ElementModifier.SetText( "#keybind_click" );
151 }
152 if( input.IsDoubleClickLimit() )
153 {
154 m_ElementModifier.SetText( "#keybind_doubletap" );
155 }
156 }
157 else
158 {
159 m_ElementModifier.SetText( "" );
160 }
161
162 string option_text;
163 string name;
164
165 g_Game.GetInput().GetActionDesc( m_ElementIndex, option_text );
166 m_ElementName.SetText( option_text );
167
168 // column #1 :: keyboard + mouse
169 SetElementTitle(m_PrimaryBindButton, input, EUAINPUT_DEVICE_KEYBOARDMOUSE);
170
171 // column #2 :: controller
172 SetElementTitle(m_AlternativeBindButton, input, EUAINPUT_DEVICE_CONTROLLER);
173 }
174
175 void Reload( array<int> custom_binds, bool is_alternate )
176 {
177 string output;
178 if( custom_binds.Count() > 1 )
179 {
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++ )
183 {
184 if( custom_binds.Get( i ) != 0 )
185 output += " + " + GetUApi().GetButtonName( custom_binds.Get( i ) );
186 }
187 }
188 else if( custom_binds.Count() > 0 )
189 {
190 if( custom_binds.Get( 0 ) != 0 )
191 output = GetUApi().GetButtonName( custom_binds.Get( 0 ) );
192 }
193
194 if( is_alternate )
195 {
196 m_CustomAlternateBind = custom_binds;
197 m_IsAlternateEdited = true;
198 m_AlternativeBindButton.SetText( output );
199 }
200 else
201 {
202 m_CustomBind = custom_binds;
203 m_IsEdited = true;
204 m_PrimaryBindButton.SetText( output );
205 }
206 }
207
208 void StartEnteringKeybind()
209 {
210 m_Group.StartEnteringKeybind( m_ElementIndex );
211 m_PrimaryBindButton.SetText( "#layout_keybinding_new_keybind" );
212 }
213
214 void CancelEnteringKeybind()
215 {
216 Reload();
217 }
218
219 void StartEnteringAlternateKeybind()
220 {
221 m_Group.StartEnteringAlternateKeybind( m_ElementIndex );
222 m_AlternativeBindButton.SetText( "#layout_keybinding_new_keybind" );
223 }
224
225 void CancelEnteringAlternateKeybind()
226 {
227 Reload();
228 }
229
230 override bool OnClick( Widget w, int x, int y, int button )
231 {
232 if( !m_Group.IsEnteringKeyBind() )
233 {
234 if( w == m_PrimaryBindButton )
235 {
236 m_EntryTimer.Run( 0.01, this, "StartEnteringKeybind" );
237 }
238 if( w == m_AlternativeBindButton )
239 {
240 m_EntryTimer.Run( 0.01, this, "StartEnteringAlternateKeybind" );
241 }
242 }
243 return false;
244 }
245
246 override bool OnMouseButtonUp( Widget w, int x, int y, int button )
247 {
248 if( w == m_PrimaryClear )
249 {
250 m_IsEdited = true;
251 m_CustomBind = new array<int>;
252 m_PrimaryBindButton.SetText( "" );
253 m_Group.ClearKeybind( m_ElementIndex );
254 }
255 if( w == m_AlternativeClear )
256 {
257 m_IsAlternateEdited = true;
258 m_CustomAlternateBind = new array<int>;
259 m_AlternativeBindButton.SetText( "" );
260 m_Group.ClearAlternativeKeybind( m_ElementIndex );
261 }
262 return false;
263 }
264
265 override bool OnMouseEnter( Widget w, int x, int y )
266 {
267 if( w == m_PrimaryBindButton || w == m_PrimaryClear )
268 {
269 m_PrimaryBindButton.SetColor( ARGBF( 1, 1, 0, 0 ) );
270 m_PrimaryClear.Show( true );
271 m_PrimaryClear.Update();
272 m_AlternativeClear.Show( false );
273 return true;
274 }
275 else if( w == m_AlternativeBindButton || w == m_AlternativeClear )
276 {
277 m_AlternativeBindButton.SetColor( ARGBF( 1, 1, 0, 0 ) );
278 m_PrimaryClear.Show( false );
279 m_AlternativeClear.Show( true );
280 m_AlternativeClear.Update();
281 return true;
282 }
283 else
284 {
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 );
289 }
290 return false;
291 }
292
293 override bool OnMouseLeave( Widget w, Widget enterW, int x, int y )
294 {
295 if( w == m_PrimaryClear || w == m_PrimaryBindButton )
296 {
297 if( enterW != m_PrimaryClear && enterW != m_PrimaryBindButton )
298 {
299 m_PrimaryClear.Show( false );
300 m_PrimaryBindButton.SetColor( ARGBF( 1, 0, 0, 0 ) );
301 }
302 }
303 if( w == m_AlternativeClear || w == m_AlternativeBindButton )
304 {
305 if( enterW != m_AlternativeClear && enterW != m_AlternativeBindButton )
306 {
307 m_AlternativeClear.Show( false );
308 m_AlternativeBindButton.SetColor( ARGBF( 1, 0, 0, 0 ) );
309 }
310 }
311 return false;
312 }
313}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
DayZGame g_Game
Definition dayzgame.c:3942
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition dayzgame.c:152
const int CALL_CATEGORY_GUI
Definition tools.c:9
Icon x
Icon y
int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.
Definition proto.c:332
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Definition radialmenu.c:669
Widget m_Root
Definition sizetochild.c:91
proto native UAInputAPI GetUApi()
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)