DayZ 1.24
Loading...
Searching...
No Matches
KeybindingElementNew.c
Go to the documentation of this file.
1class KeybindingElementNew extends ScriptedWidgetEventHandler
2{
3 protected KeybindingsContainer m_Container;
4
5 protected Widget m_Root;
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 {
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
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
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 m_ElementModifier.SetText("#keybind_press");
132 if (input.IsReleaseLimit())
133 m_ElementModifier.SetText("#keybind_release");
134 if (input.IsHoldLimit())
135 m_ElementModifier.SetText("#keybind_hold");
136 if (input.IsHoldBeginLimit())
137 m_ElementModifier.SetText("#keybind_holdbegin");
138 if (input.IsClickLimit())
139 m_ElementModifier.SetText("#keybind_click");
140 if (input.IsDoubleClickLimit())
141 m_ElementModifier.SetText("#keybind_doubletap");
142 }
143 else
144 m_ElementModifier.SetText("");
145
146 string option_text;
147 string name;
148
149 GetGame().GetInput().GetActionDesc(m_ElementIndex, option_text);
150 m_ElementName.SetText(option_text);
151
152 // column #1 :: keyboard + mouse
154
155 // column #2 :: controller
156 SetElementTitle(m_AlternativeBindButton, input, EUAINPUT_DEVICE_CONTROLLER);
157 }
158
160 {
161 string output;
162 if (custom_binds.Count() > 1)
163 {
164 if (custom_binds.Get(0) != 0)
165 output = GetUApi().GetButtonName(custom_binds.Get(0));
166 for (int i = 1; i < custom_binds.Count(); i++)
167 {
168 if (custom_binds.Get(i) != 0)
169 output += " + " + GetUApi().GetButtonName(custom_binds.Get(i));
170 }
171 }
172 else if (custom_binds.Count() > 0)
173 {
174 if (custom_binds.Get(0) != 0)
175 output = GetUApi().GetButtonName(custom_binds.Get(0));
176 }
177
178 if (is_alternate)
179 {
180 m_CustomAlternateBind = custom_binds;
181 m_IsAlternateEdited = true;
182 m_AlternativeBindButton.SetText(output);
183 }
184 else
185 {
186 m_CustomBind = custom_binds;
187 m_IsEdited = true;
188 m_PrimaryBindButton.SetText(output);
189 }
190 }
191
193 {
194 m_Container.StartEnteringKeybind(m_ElementIndex);
195 m_PrimaryBindButton.SetText("#layout_keybinding_new_keybind");
196 }
197
199 {
200 Reload();
201 }
202
204 {
205 m_Container.StartEnteringAlternateKeybind(m_ElementIndex);
206 m_AlternativeBindButton.SetText("#layout_keybinding_new_keybind");
207 }
208
210 {
211 Reload();
212 }
213
214 override bool OnClick(Widget w, int x, int y, int button)
215 {
216 if (!m_Container.IsEnteringKeyBind())
217 {
218 if (w == m_PrimaryBindButton)
219 m_EntryTimer.Run(0.01, this, "StartEnteringKeybind");
220 if (w == m_AlternativeBindButton)
221 m_EntryTimer.Run(0.01, this, "StartEnteringAlternateKeybind");
222 }
223 return false;
224 }
225
226 override bool OnMouseButtonUp(Widget w, int x, int y, int button)
227 {
228 if (w == m_PrimaryClear)
229 {
230 m_IsEdited = true;
231 m_CustomBind = new array<int>;
232 m_PrimaryBindButton.SetText("");
233 m_Container.ClearKeybind(m_ElementIndex);
234 }
235 if (w == m_AlternativeClear)
236 {
237 m_IsAlternateEdited = true;
238 m_CustomAlternateBind = new array<int>;
239 m_AlternativeBindButton.SetText("");
240 m_Container.ClearAlternativeKeybind(m_ElementIndex);
241 }
242 return false;
243 }
244
245 override bool OnMouseEnter(Widget w, int x, int y)
246 {
247 if (w == m_PrimaryBindButton || w == m_PrimaryClear)
248 {
249 m_PrimaryBindButton.SetColor(ARGBF(1, 1, 0, 0));
250 m_PrimaryClear.Show(true);
251 m_PrimaryClear.Update();
252 m_AlternativeClear.Show(false);
253 return true;
254 }
255 else if (w == m_AlternativeBindButton || w == m_AlternativeClear)
256 {
257 m_AlternativeBindButton.SetColor(ARGBF(1, 1, 0, 0));
258 m_PrimaryClear.Show(false);
259 m_AlternativeClear.Show(true);
260 m_AlternativeClear.Update();
261 return true;
262 }
263 else
264 {
265 m_PrimaryBindButton.SetColor(ARGBF(0, 0, 0, 0));
266 m_AlternativeBindButton.SetColor(ARGBF(1, 0, 0, 0));
267 m_PrimaryClear.Show(false);
268 m_AlternativeClear.Show(false);
269 }
270 return false;
271 }
272
273 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
274 {
275 if (w == m_PrimaryClear || w == m_PrimaryBindButton)
276 {
277 if (enterW != m_PrimaryClear && enterW != m_PrimaryBindButton)
278 {
279 m_PrimaryClear.Show(false);
280 m_PrimaryBindButton.SetColor(ARGBF(1, 0, 0, 0));
281 }
282 }
283 if (w == m_AlternativeClear || w == m_AlternativeBindButton)
284 {
285 if (enterW != m_AlternativeClear && enterW != m_AlternativeBindButton)
286 {
287 m_AlternativeClear.Show(false);
288 m_AlternativeBindButton.SetColor(ARGBF(1, 0, 0, 0));
289 }
290 }
291 return false;
292 }
293}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Icon x
Icon y
Widget m_Root
Definition SizeToChild.c:85
proto native UAInputAPI GetUApi()
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void Reload(array< int > custom_binds, bool is_alternate)
void SetElementTitle(ButtonWidget btnWidget, UAInput pInput, int iDeviceFlags)
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
ref array< int > m_CustomAlternateBind
bool SetElementTitle(UAInput pInput, int iDeviceFlags, out string output)
assemble all active bindings at widget element
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
override bool OnClick(Widget w, int x, int y, int button)
KeybindingsContainer m_Container
override bool OnMouseEnter(Widget w, int x, int y)
void KeybindingElementNew(int key_index, Widget parent, KeybindingsContainer group)
proto native CGame GetGame()
const int CALL_CATEGORY_GUI
Definition tools.c:9
int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.
Definition proto.c:332