DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
KeybindingsGroup.c
Go to the documentation of this file.
1
2class KeybindingsGroup extends ScriptedWidgetEventHandler
3{
4 protected Widget m_Root;
5 protected KeybindingsMenu m_Menu;
6
8 protected int m_CurrentSettingKeyIndex = -1;
9 protected int m_CurrentSettingAlternateKeyIndex = -1;
10
11 protected ref DropdownPrefab m_KBDropdown;
12
13 void KeybindingsGroup( int index, Input input, Widget parent, KeybindingsMenu menu )
14 {
15 m_KeyWidgets = new map<int, ref KeybindingElement>;
16 m_Menu = menu;
17
18 string group_name;
19 input.GetActionGroupName( index, group_name );
20
22 Widget subgroup = m_Root.FindAnyWidget( "group_content" );
23
24// for( int i = 0; i < 1; i++ )
25// {
26 AddSubgroup( /*index, */subgroup, input );
27// }
28
29 InitPresets( index, m_Root.FindAnyWidget( "group_header" ), input );
30
31 subgroup.Update();
32
33 m_Root.SetHandler( this );
34 }
35
37 {
38 return "gui/layouts/new_ui/options/keybindings_selectors/keybinding_group.layout";
39 }
40
41 void InitPresets( int index, Widget parent, Input input )
42 {
43 Widget kb_root = parent.FindAnyWidget( "keyboard_dropown" );
44
45 string profile_text;
46 input.GetProfileName( input.GetCurrentProfile(), profile_text );
47
48 m_KBDropdown = new DropdownPrefab( kb_root, profile_text );
49
50 m_KBDropdown.m_OnSelectItem.Insert( OnSelectKBPreset );
51
52 for( int i = 0; i < input.GetProfilesCount(); i++ )
53 {
54 input.GetProfileName( i, profile_text );
55 m_KBDropdown.AddElement( profile_text );
56 }
57
58 kb_root.Update();
59 }
60
61 void OnSelectKBPreset( int index )
62 {
63 string profile_text;
64 GetGame().GetInput().GetProfileName( index, profile_text );
65 m_KBDropdown.SetText( profile_text );
66 GetGame().GetInput().SetProfile( index );
68 m_KBDropdown.Close();
69 }
70
71 void OnSelectConsolePreset( int index )
72 {
73 string profile_text;
74 GetGame().GetInput().GetProfileName( index, profile_text );
75 GetGame().GetInput().SetProfile( index );
77 }
78
80 {
81 foreach( int index, KeybindingElement element : m_KeyWidgets )
82 {
83 element.Reload();
84 }
85 }
86
87 void AddSubgroup( /*int index, */Widget parent, Input input )
88 {
89 Widget subgroup = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/new_ui/options/keybindings_selectors/keybinding_subgroup.layout", parent );
90 TextWidget subgroup_name = TextWidget.Cast( subgroup.FindAnyWidget( "subgroup_text" ) );
91
92 subgroup_name.SetText( "TestSubgroup" );
93 Widget subgroup_content = subgroup.FindAnyWidget( "subgroup_content" );
94
95 TIntArray actions = new TIntArray;
96 GetUApi().GetActiveInputs(actions);
97 for( int i = 0; i < actions.Count(); i++ )
98 {
99 AddAction( actions.Get( i ), subgroup_content, input );
100 }
101
102 subgroup_content.Update();
103 }
104
105 void AddAction( int index, Widget parent, Input input )
106 {
107 m_KeyWidgets.Insert( index, new KeybindingElement( index, parent, this ) );
108 }
109
110 void ReloadAction( int index )
111 {
112 if( m_KeyWidgets.Contains( index ) )
113 {
114 m_KeyWidgets.Get( index ).Reload();
115 }
116 }
117
119 {
120 return ( m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1 );
121 }
122
123 void ClearKeybind( int key_index )
124 {
125 m_Menu.ClearKeybind( key_index );
126 }
127
128 void ClearAlternativeKeybind( int key_index )
129 {
130 m_Menu.ClearAlternativeKeybind( key_index );
131 }
132
133 void StartEnteringKeybind( int key_index )
134 {
135 m_CurrentSettingAlternateKeyIndex = -1;
136 m_CurrentSettingKeyIndex = key_index;
137 m_Menu.StartEnteringKeybind( key_index );
138 }
139
141 {
142 if( m_CurrentSettingKeyIndex != -1 )
143 {
144 m_KeyWidgets.Get( m_CurrentSettingKeyIndex ).CancelEnteringKeybind();
145 m_CurrentSettingKeyIndex = -1;
146 }
147 }
148
149 void StartEnteringAlternateKeybind( int key_index )
150 {
151 m_CurrentSettingKeyIndex = -1;
152 m_CurrentSettingAlternateKeyIndex = key_index;
153 m_Menu.StartEnteringAlternateKeybind( key_index );
154 }
155
157 {
158 if( m_CurrentSettingAlternateKeyIndex != -1 )
159 {
160 m_KeyWidgets.Get( m_CurrentSettingAlternateKeyIndex ).CancelEnteringAlternateKeybind();
161 m_CurrentSettingAlternateKeyIndex = -1;
162 }
163 }
164
166 {
167 foreach( int index, KeybindingElement element : m_KeyWidgets )
168 {
169 if( element.IsChanged() || element.IsAlternateChanged() )
170 {
171 return true;
172 }
173 }
174 return false;
175 }
176
177 void Apply()
178 {
179 UAInputAPI ua_api = GetUApi();
180 foreach( int index, KeybindingElement element : m_KeyWidgets )
181 {
182 UAInput input = ua_api.GetInputByID( index );
183 int i;
184 if( element.IsChanged() )
185 {
186 array<int> new_keys = element.GetChangedBinds();
187
188/* if( input.AlternativeCount() == 0 )
189 {
190 input.AddAlternative();
191 }
192 else*/
193 {
194 input.ClearDeviceBind(EUAINPUT_DEVICE_KEYBOARDMOUSE);
195// input.SelectAlternative( 0 );
196// input.ClearAlternative( 0 );
197 }
198
199 if( new_keys.Count() > 0 )
200 {
201 input.BindComboByHash( new_keys.Get( 0 ) );
202 for( i = 1; i < new_keys.Count(); i++ )
203 {
204 input.BindComboByHash( new_keys.Get( i ) );
205 }
206 }
207 }
208
209 if( element.IsAlternateChanged() )
210 {
211 array<int> new_alt_keys = element.GetChangedAlternateBinds();
212
213 if( input.AlternativeCount() == 0 )
214 {
215 input.AddAlternative();
216 }
217
218/* if( input.AlternativeCount() < 2 )
219 {
220 input.AddAlternative();
221 }
222 else*/
223 {
224 input.ClearDeviceBind(EUAINPUT_DEVICE_CONTROLLER);
225// input.SelectAlternative( 1 );
226// input.ClearAlternative( 1 );
227 }
228
229 if( new_alt_keys.Count() > 0 )
230 {
231 input.BindComboByHash( new_alt_keys.Get( 0 ) );
232 for( i = 1; i < new_alt_keys.Count(); i++ )
233 {
234 input.BindComboByHash( new_alt_keys.Get( i ) );
235 }
236 }
237 }
238 element.Reload();
239 }
240 }
241
242 //DEPRECATED
243 void Reset()
244 {
245 ResetEx();
246 }
247
248 void ResetEx(bool forced = false)
249 {
250 foreach( int index, KeybindingElement element : m_KeyWidgets )
251 {
252 if( element.IsChanged() || element.IsAlternateChanged() || forced )
253 {
254 element.Reload();
255 }
256 }
257 }
258
259 void Update( float timeslice )
260 {
261 if( m_CurrentSettingKeyIndex != -1 || m_CurrentSettingAlternateKeyIndex != -1 )
262 {
263 UAInputAPI ua_api = GetUApi();
264 if( ua_api.DeterminePressedButton() != 0 )
265 {
266 string name;
267 string text;
268 ref array<int> new_keybinds = new array<int>;
269
270 // remove previous backlit
271 GetDayZGame().GetBacklit().KeybindingClear();
272
273 for( int i = 0; i < ua_api.DeterminedCount(); ++i )
274 {
275 int kb_id = ua_api.GetDetermined( i );
276 new_keybinds.Insert( kb_id );
277
278 // light up specific key
279 GetDayZGame().GetBacklit().KeybindingShow(kb_id);
280 }
281
282 if( m_CurrentSettingKeyIndex != -1 )
283 {
284 m_Menu.ConfirmKeybindEntry( new_keybinds );
285 m_KeyWidgets.Get( m_CurrentSettingKeyIndex ).Reload( new_keybinds, false );
286 m_CurrentSettingKeyIndex = -1;
287 }
288 else if( m_CurrentSettingAlternateKeyIndex != -1 )
289 {
290 m_Menu.ConfirmAlternateKeybindEntry( new_keybinds );
291 m_KeyWidgets.Get( m_CurrentSettingAlternateKeyIndex ).Reload( new_keybinds, true );
292 m_CurrentSettingAlternateKeyIndex = -1;
293 }
294 }
295 }
296 }
297
298 override bool OnMouseButtonDown( Widget w, int x, int y, int button )
299 {
300 if( !ButtonWidget.Cast( w ) )
301 {
302 m_KBDropdown.Close();
303 }
304 return false;
305 }
306}
DayZGame GetDayZGame()
Definition DayZGame.c:3656
Icon x
Icon y
string name
protected ServerBrowserMenuNew m_Menu
protected Widget m_Root
Definition SizeToChild.c:91
proto native UAInputAPI GetUApi()
proto native Input GetInput()
proto native WorkspaceWidget GetWorkspace()
Definition input.c:11
proto native int GetCurrentProfile()
gets currently selected profile
proto int GetActionGroupName(int group_index, out string name)
proto int GetProfileName(int profile_index, out string name)
gets profile by index
proto native int GetProfilesCount()
gets profile by name
proto native int SetProfile(int index)
setting active profile
map: item x vector(index, width, height)
Definition EnWidgets.c:538
void OnSelectConsolePreset(int index)
void StartEnteringAlternateKeybind(int key_index)
protected ref DropdownPrefab m_KBDropdown
void AddSubgroup(Widget parent, Input input)
void ClearAlternativeKeybind(int key_index)
void Update(float timeslice)
void ResetEx(bool forced=false)
void KeybindingsGroup(int index, Input input, Widget parent, KeybindingsMenu menu)
void AddAction(int index, Widget parent, Input input)
void StartEnteringKeybind(int key_index)
protected ref map< int, ref KeybindingElement > m_KeyWidgets
protected KeybindingsMenu m_Menu
protected Widget m_Root
Definition SizeToChild.c:9
void InitPresets(int index, Widget parent, Input input)
void DropdownPrefab(Widget root, string text="")
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
void KeybindingElement(int key_index, Widget parent, KeybindingsGroup group)
void ClearKeybind(int key_index)
proto native int DeterminedCount()
proto native int DeterminePressedButton()
proto native UAInput GetInputByID(int iID)
returns list of all bindable (i.e. visible) inputs from the active group ('core' by default)
proto native int GetDetermined(int iIndex)
proto native void GetActiveInputs(out TIntArray items)
proto native void BindComboByHash(int iHash)
proto native int AlternativeCount()
proto native void AddAlternative()
proto native void ClearDeviceBind(int iDeviceFlags)
proto native CGame GetGame()
array< int > TIntArray
Definition EnScript.c:687
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.