DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
KeybindingElementNew.c
См. документацию.
1class KeybindingElementNew extends ScriptedWidgetEventHandler
2{
3 protected KeybindingsContainer m_Container;
4
5 protected Widget m_Root;
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;
19
20 protected ref Timer m_EntryTimer = new Timer( CALL_CATEGORY_GUI );
21
22 void KeybindingElementNew( int key_index, Widget parent, KeybindingsContainer group )
23 {
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
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
50 {
52 }
53
55 {
56 return m_CustomBind;
57 }
58
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 {
123 m_IsEdited = false;
124 m_IsAlternateEdited = false;
125 m_CustomBind = 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
207 {
208 m_Container.StartEnteringKeybind( m_ElementIndex );
209 m_PrimaryBindButton.SetText( "#layout_keybinding_new_keybind" );
210 }
211
213 {
214 Reload();
215 }
216
218 {
219 m_Container.StartEnteringAlternateKeybind( m_ElementIndex );
220 m_AlternativeBindButton.SetText( "#layout_keybinding_new_keybind" );
221 }
222
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;
250 m_PrimaryBindButton.SetText( "" );
251 m_Container.ClearKeybind( m_ElementIndex );
252 }
253 if( w == m_AlternativeClear )
254 {
255 m_IsAlternateEdited = true;
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 }
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}
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 Reload(array< int > custom_binds, bool is_alternate)
Определения KeybindingElementNew.c:173
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)
Определения KeybindingElementNew.c:65
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Определения KeybindingElementNew.c:244
Widget m_Root
Определения SizeToChild.c:9
void StartEnteringKeybind()
Определения KeybindingElementNew.c:206
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()
Определения KeybindingElementNew.c:217
array< int > GetChangedBinds()
Определения KeybindingElementNew.c:54
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()
Определения KeybindingElementNew.c:59
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Определения KeybindingElementNew.c:291
override bool OnClick(Widget w, int x, int y, int button)
Определения KeybindingElementNew.c:228
KeybindingsContainer m_Container
Определения KeybindingElementNew.c:3
Widget m_AlternativeClear
Определения KeybindingElement.c:12
void CancelEnteringKeybind()
Определения KeybindingElementNew.c:212
bool m_IsAlternateEdited
Определения KeybindingElement.c:16
override bool OnMouseEnter(Widget w, int x, int y)
Определения KeybindingElementNew.c:263
void CancelEnteringAlternateKeybind()
Определения KeybindingElementNew.c:223
bool IsAlternateChanged()
Определения KeybindingElementNew.c:49
void KeybindingElementNew(int key_index, Widget parent, KeybindingsContainer group)
Определения KeybindingElementNew.c:22
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