DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
KeybindingElement.c
См. документацию.
1
2class KeybindingElement extends ScriptedWidgetEventHandler
3{
5
6 protected Widget m_Root;
9 protected ButtonWidget m_PrimaryBindButton;
10 protected ButtonWidget m_AlternativeBindButton;
13
14 protected int m_ElementIndex;
15 protected bool m_IsEdited;
16 protected bool m_IsAlternateEdited;
17
18 protected ref array<int> m_CustomBind;
20
21 protected ref Timer m_EntryTimer = new Timer( CALL_CATEGORY_GUI );
22
23 void KeybindingElement( int key_index, Widget parent, KeybindingsGroup group )
24 {
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
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
51 {
53 }
54
56 {
57 return m_CustomBind;
58 }
59
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 {
125 m_IsEdited = false;
126 m_IsAlternateEdited = false;
127 m_CustomBind = 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 GetGame().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
209 {
210 m_Group.StartEnteringKeybind( m_ElementIndex );
211 m_PrimaryBindButton.SetText( "#layout_keybinding_new_keybind" );
212 }
213
215 {
216 Reload();
217 }
218
220 {
221 m_Group.StartEnteringAlternateKeybind( m_ElementIndex );
222 m_AlternativeBindButton.SetText( "#layout_keybinding_new_keybind" );
223 }
224
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;
252 m_PrimaryBindButton.SetText( "" );
253 m_Group.ClearKeybind( m_ElementIndex );
254 }
255 if( w == m_AlternativeClear )
256 {
257 m_IsAlternateEdited = true;
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 }
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
Icon x
Icon y
proto native UAInputAPI GetUApi()
proto native WorkspaceWidget GetWorkspace()
proto native Input GetInput()
proto int GetActionDesc(int action_index, out string desc)
void KeybindingsGroup(int index, Input input, Widget parent, KeybindingsMenu menu)
Определения KeybindingsGroup.c:13
void Reload(array< int > custom_binds, bool is_alternate)
Определения KeybindingElement.c:175
TextWidget m_ElementName
Определения KeybindingElement.c:7
ref array< int > m_CustomBind
Определения KeybindingElement.c:18
Widget m_PrimaryClear
Определения KeybindingElement.c:11
void SetElementTitle(ButtonWidget btnWidget, UAInput pInput, int iDeviceFlags)
Определения KeybindingElement.c:66
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Определения KeybindingElement.c:246
Widget m_Root
Определения SizeToChild.c:9
void StartEnteringKeybind()
Определения KeybindingElement.c:208
ButtonWidget m_AlternativeBindButton
Определения KeybindingElement.c:10
ref array< int > m_CustomAlternateBind
Определения KeybindingElement.c:19
TextWidget m_ElementModifier
Определения KeybindingElement.c:8
ref Timer m_EntryTimer
Определения KeybindingElement.c:21
void StartEnteringAlternateKeybind()
Определения KeybindingElement.c:219
array< int > GetChangedBinds()
Определения KeybindingElement.c:55
ButtonWidget m_PrimaryBindButton
Определения KeybindingElement.c:9
bool SetElementTitle(UAInput pInput, int iDeviceFlags, out string output)
assemble all active bindings at widget element
Определения ControlMappingKeybinds.c:74
array< int > GetChangedAlternateBinds()
Определения KeybindingElement.c:60
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Определения KeybindingElement.c:293
override bool OnClick(Widget w, int x, int y, int button)
Определения KeybindingElement.c:230
void KeybindingElement(int key_index, Widget parent, KeybindingsGroup group)
Определения KeybindingElement.c:23
Widget m_AlternativeClear
Определения KeybindingElement.c:12
void CancelEnteringKeybind()
Определения KeybindingElement.c:214
bool m_IsAlternateEdited
Определения KeybindingElement.c:16
override bool OnMouseEnter(Widget w, int x, int y)
Определения KeybindingElement.c:265
KeybindingsGroup m_Group
Определения KeybindingElement.c:4
void CancelEnteringAlternateKeybind()
Определения KeybindingElement.c:225
bool IsAlternateChanged()
Определения KeybindingElement.c:50
map: item x vector(index, width, height)
Определения EnWidgets.c:651
Определения EnWidgets.c:220
Определения DayZPlayerImplement.c:63
proto native bool IsHoldLimit()
proto native int Binding(int iIndex)
proto native bool IsClickLimit()
proto native int BindingCount()
proto native int AlternativeCount()
proto native UAInput GetInputByID(int iID)
returns list of all bindable (i.e. visible) inputs from the active group ('core' by default)
proto native owned string GetButtonName(int iHash)
proto native void SelectAlternative(int iIndex)
proto native bool IsReleaseLimit()
proto native bool IsCombo()
proto native bool IsHoldBeginLimit()
proto native bool IsPressLimit()
proto native bool IsLimited()
proto native bool IsDoubleClickLimit()
proto native bool CheckBindDevice(int iIndex, int iDeviceFlags)
Определения UAInput.c:24
Определения EnWidgets.c:190
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
const int CALL_CATEGORY_GUI
Определения tools.c:9
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.
int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.
Определения proto.c:332