DayZ 1.24
Loading...
Searching...
No Matches
KeybindingElement.c
Go to the documentation of this file.
1
2class KeybindingElement extends ScriptedWidgetEventHandler
3{
4 protected KeybindingsGroup m_Group;
5
6 protected Widget m_Root;
13
14 protected int m_ElementIndex;
15 protected bool m_IsEdited;
16 protected bool m_IsAlternateEdited;
17
20
21 protected ref Timer m_EntryTimer = new Timer(CALL_CATEGORY_GUI);
22
23 void KeybindingElement(int key_index, Widget parent, KeybindingsGroup group)
24 {
25 m_Root = GetGame().GetWorkspace().CreateWidgets(GetLayoutName(), parent);
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
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 {
124 UAInput input = GetUApi().GetInputByID(m_ElementIndex);
125 m_IsEdited = false;
126 m_IsAlternateEdited = false;
127 m_CustomBind = null;
128 m_CustomAlternateBind = null;
129
130 if (input.IsLimited())
131 {
132 if (input.IsPressLimit())
133 m_ElementModifier.SetText("#keybind_press");
134 if (input.IsReleaseLimit())
135 m_ElementModifier.SetText("#keybind_release");
136 if (input.IsHoldLimit())
137 m_ElementModifier.SetText("#keybind_hold");
138 if (input.IsHoldBeginLimit())
139 m_ElementModifier.SetText("#keybind_holdbegin");
140 if (input.IsClickLimit())
141 m_ElementModifier.SetText("#keybind_click");
142 if (input.IsDoubleClickLimit())
143 m_ElementModifier.SetText("#keybind_doubletap");
144 }
145 else
146 m_ElementModifier.SetText("");
147
148 string option_text;
149 string name;
150
151 GetGame().GetInput().GetActionDesc(m_ElementIndex, option_text);
152 m_ElementName.SetText(option_text);
153
154 // column #1 :: keyboard + mouse
156
157 // column #2 :: controller
158 SetElementTitle(m_AlternativeBindButton, input, EUAINPUT_DEVICE_CONTROLLER);
159 }
160
162 {
163 string output;
164 if (custom_binds.Count() > 1)
165 {
166 if (custom_binds.Get(0) != 0)
167 output = GetUApi().GetButtonName(custom_binds.Get(0));
168 for (int i = 1; i < custom_binds.Count(); i++)
169 {
170 if (custom_binds.Get(i) != 0)
171 output += " + " + GetUApi().GetButtonName(custom_binds.Get(i));
172 }
173 }
174 else if (custom_binds.Count() > 0)
175 {
176 if (custom_binds.Get(0) != 0)
177 output = GetUApi().GetButtonName(custom_binds.Get(0));
178 }
179
180 if (is_alternate)
181 {
182 m_CustomAlternateBind = custom_binds;
183 m_IsAlternateEdited = true;
184 m_AlternativeBindButton.SetText(output);
185 }
186 else
187 {
188 m_CustomBind = custom_binds;
189 m_IsEdited = true;
190 m_PrimaryBindButton.SetText(output);
191 }
192 }
193
195 {
196 m_Group.StartEnteringKeybind(m_ElementIndex);
197 m_PrimaryBindButton.SetText("#layout_keybinding_new_keybind");
198 }
199
201 {
202 Reload();
203 }
204
206 {
207 m_Group.StartEnteringAlternateKeybind(m_ElementIndex);
208 m_AlternativeBindButton.SetText("#layout_keybinding_new_keybind");
209 }
210
212 {
213 Reload();
214 }
215
216 override bool OnClick(Widget w, int x, int y, int button)
217 {
218 if (!m_Group.IsEnteringKeyBind())
219 {
220 if (w == m_PrimaryBindButton)
221 m_EntryTimer.Run(0.01, this, "StartEnteringKeybind");
222 if (w == m_AlternativeBindButton)
223 m_EntryTimer.Run(0.01, this, "StartEnteringAlternateKeybind");
224 }
225 return false;
226 }
227
228 override bool OnMouseButtonUp(Widget w, int x, int y, int button)
229 {
230 if (w == m_PrimaryClear)
231 {
232 m_IsEdited = true;
233 m_CustomBind = new array<int>;
234 m_PrimaryBindButton.SetText("");
235 m_Group.ClearKeybind(m_ElementIndex);
236 }
237 if (w == m_AlternativeClear)
238 {
239 m_IsAlternateEdited = true;
240 m_CustomAlternateBind = new array<int>;
241 m_AlternativeBindButton.SetText("");
242 m_Group.ClearAlternativeKeybind(m_ElementIndex);
243 }
244 return false;
245 }
246
247 override bool OnMouseEnter(Widget w, int x, int y)
248 {
249 if (w == m_PrimaryBindButton || w == m_PrimaryClear)
250 {
251 m_PrimaryBindButton.SetColor(ARGBF(1, 1, 0, 0));
252 m_PrimaryClear.Show(true);
253 m_PrimaryClear.Update();
254 m_AlternativeClear.Show(false);
255 return true;
256 }
257 else if (w == m_AlternativeBindButton || w == m_AlternativeClear)
258 {
259 m_AlternativeBindButton.SetColor(ARGBF(1, 1, 0, 0));
260 m_PrimaryClear.Show(false);
261 m_AlternativeClear.Show(true);
262 m_AlternativeClear.Update();
263 return true;
264 }
265 else
266 {
267 m_PrimaryBindButton.SetColor(ARGBF(0, 0, 0, 0));
268 m_AlternativeBindButton.SetColor(ARGBF(1, 0, 0, 0));
269 m_PrimaryClear.Show(false);
270 m_AlternativeClear.Show(false);
271 }
272 return false;
273 }
274
275 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
276 {
277 if (w == m_PrimaryClear || w == m_PrimaryBindButton)
278 {
279 if (enterW != m_PrimaryClear && enterW != m_PrimaryBindButton)
280 {
281 m_PrimaryClear.Show(false);
282 m_PrimaryBindButton.SetColor(ARGBF(1, 0, 0, 0));
283 }
284 }
285 if (w == m_AlternativeClear || w == m_AlternativeBindButton)
286 {
287 if (enterW != m_AlternativeClear && enterW != m_AlternativeBindButton)
288 {
289 m_AlternativeClear.Show(false);
290 m_AlternativeBindButton.SetColor(ARGBF(1, 0, 0, 0));
291 }
292 }
293 return false;
294 }
295}
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
array< int > GetChangedAlternateBinds()
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
override bool OnClick(Widget w, int x, int y, int button)
void KeybindingElement(int key_index, Widget parent, KeybindingsGroup group)
override bool OnMouseEnter(Widget w, int x, int y)
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