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