DayZ 1.24
Loading...
Searching...
No Matches
TabberUI.c
Go to the documentation of this file.
2{
3 protected bool m_FirstInit = true;
4 protected Widget m_Root;
6
7 protected int m_TabsCount;
10
11 protected int m_SelectedIndex;
12 protected float m_ResolutionMultiplier;
13 protected bool m_CanSwitch;
14
15 ref ScriptInvoker m_OnTabSwitch = new ScriptInvoker();
16 ref ScriptInvoker m_OnAttemptTabSwitch = new ScriptInvoker();
18
19 protected void OnInputPresetChanged()
20 {
21#ifdef PLATFORM_CONSOLE
23#endif
24 }
25
27 {
28 switch (pInputDeviceType)
29 {
30 case EInputDeviceType.CONTROLLER:
32 m_TabControlsRoot.FindAnyWidget("ConsoleControls").Show(true);
33 break;
34
35 default:
36 if (GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
37 m_TabControlsRoot.FindAnyWidget("ConsoleControls").Show(false);
38 break;
39 }
40 }
41
42 void Init()
43 {
44 int x, y;
46 m_ResolutionMultiplier = y / 1080;
47 m_CanSwitch = true;
48 m_TabsCount = 0;
49
50 Widget tab_controls = m_Root.FindAnyWidget("Tab_Control_Container");
51 if (tab_controls)
52 {
53 Widget tab_child = tab_controls.GetChildren();
54
55 while (tab_child)
56 {
57 m_TabsCount++;
58 tab_child = tab_child.GetSibling();
59 }
60
61 for (int i = 0; i < m_TabsCount; i++)
62 {
63 Widget tab_control = tab_controls.FindAnyWidget("Tab_Control_" + i);
64 Widget tab_widget = m_Root.FindAnyWidget("Tab_" + i);
66 {
67 tab_control.SetHandler(this);
68 m_TabControls.Insert(i, tab_control);
69 m_Tabs.Insert(i, tab_widget);
70 }
71 else
72 Error("Tabber could not find correctly named tab or control at index " + i);
73 }
74
75 AlignTabbers();
76#ifdef PLATFORM_CONSOLE
78#endif
79
80 SelectTabControl(0);
81
82 m_InitTimer.Run(0.01, this, "AlignTabbers");
83 }
84
85 GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
86 GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
87
88 OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
89 }
90
92 {
93 m_TabsCount = 0;
94 m_TabControls = new map<int, Widget>;
95 m_Tabs = new map<int, Widget>;
96
97 m_Root = w;
98 m_InitTimer = new Timer();
99 m_TabControlsRoot = m_Root.FindAnyWidget("TabControls");
100
101 Init();
102 }
103
105 {
106 float total_size;
107 float x, y;
108
109 Widget tab_controls_container = m_TabControlsRoot.FindAnyWidget("Tab_Control_Container");
110 Widget tab_controls_scroller = m_TabControlsRoot.FindAnyWidget("Tab_Control_Scroller");
111
112 m_TabControlsRoot.Update();
113 tab_controls_container.Update();
114
116 while (tab_child)
117 {
118 if (tab_child.IsVisible())
119 {
120 TextWidget tab_text = TextWidget.Cast(tab_child.FindAnyWidget(tab_child.GetName() + "_Title"));
121 int t_x, t_y;
122 tab_text.Update();
123 tab_text.GetTextSize(t_x, t_y);
124 tab_child.SetSize(t_x + 10 * m_ResolutionMultiplier, 1);
125 tab_controls_container.Update();
126
127 total_size += (t_x + 10 * m_ResolutionMultiplier);
128 }
129
130 tab_child = tab_child.GetSibling();
131 }
132
133 tab_child = tab_controls_container.GetChildren();
134
135 float x_f_c, y_f_c;
136 tab_controls_container.GetScreenPos(x_f_c, y_f_c);
137
138 while (tab_child)
139 {
140 Widget tab_bg = tab_child.FindAnyWidget(tab_child.GetName() + "_Background");
141 tab_child.GetScreenPos(x, y);
142 tab_bg.SetPos((x_f_c - x), 0);
143 tab_bg.SetSize(total_size, 1);
144
145 tab_child = tab_child.GetSibling();
146 }
147
148 m_TabControlsRoot.GetSize(x, y);
149
150 m_TabControlsRoot.SetSize(total_size, y);
151 tab_controls_container.Update();
153 tab_controls_scroller.Update();
154 m_TabControlsRoot.Update();
155 }
156
157 int AddTab(string name)
158 {
159 int new_index = m_Tabs.Count();
160 Widget tab = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/tabber_prefab/tab.layout", m_Root);
161 Widget control = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/tabber_prefab/tab_control.layout", m_Root.FindAnyWidget("Tab_Control_Container"));
162 TextWidget control_text = TextWidget.Cast(control.FindAnyWidget("Tab_Control_x_Title"));
163
164 tab.SetName("Tab_" + new_index);
165 control.SetName("Tab_Control_" + new_index);
166 control_text.SetName("Tab_Control_" + new_index + "_Title");
167 control.FindAnyWidget("Tab_Control_x_Background").SetName("Tab_Control_" + new_index + "_Background");
168
169 control_text.SetText(name);
170
171 control.SetHandler(this);
172 m_TabControls.Insert(new_index, control);
173 m_Tabs.Insert(new_index, tab);
174
175 AlignTabbers();
176
177 return new_index;
178 }
179
180 void RemoveTab(int index)
181 {
182
183 }
184
185
187 {
188 return m_Tabs.Get(index);
189 }
190
192 {
193 return m_Tabs.Count();
194 }
195
197 {
198 return m_CanSwitch;
199 }
200
202 {
203 m_CanSwitch = value;
204 }
205
207 {
208 DeselectTabControl(m_SelectedIndex);
209 DeselectTabPanel(m_SelectedIndex);
210
211 SelectTabControl(index);
212 SelectTabPanel(index);
213
214 m_SelectedIndex = index;
215 m_OnTabSwitch.Invoke(m_SelectedIndex);
216
217 if (m_FirstInit)
218 {
219 AlignTabbers();
220 m_FirstInit = false;
221 }
222 }
223
224 override bool OnMouseEnter(Widget w, int x, int y)
225 {
226 int index = m_TabControls.GetKeyByValue(w);
227 if (m_SelectedIndex == index)
228 return false;
229
230 Widget tab_control = m_TabControls.Get(index);
231 if (tab_control)
232 {
233 Widget tab_title = TextWidget.Cast(tab_control.FindAnyWidget(tab_control.GetName() + "_Title"));
234 tab_title.SetColor(ARGB(255, 255, 0, 0));
235 tab_control.SetColor(ARGB(255, 0, 0, 0));
236 }
237
238 return false;
239 }
240
241 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
242 {
243 int index = m_TabControls.GetKeyByValue(w);
244 if (m_SelectedIndex == index)
245 return false;
246
247 Widget tab_control = m_TabControls.Get(index);
248 if (tab_control)
249 {
250 Widget tab_title = TextWidget.Cast(tab_control.FindAnyWidget(tab_control.GetName() + "_Title"));
251 tab_title.SetColor(ARGB(255, 255, 255, 255));
252 tab_control.SetColor(ARGB(0, 0, 0, 0));
253 }
254 return false;
255 }
256
257 override bool OnMouseButtonUp(Widget w, int x, int y, int button)
258 {
259 if (button == MouseState.LEFT)
260 {
261 int index = m_TabControls.GetKeyByValue(w);
262 if (m_SelectedIndex != index)
263 {
264 m_OnAttemptTabSwitch.Invoke(m_SelectedIndex, index);
265 if (CanSwitchTab())
266 {
267 PerformSwitchTab(index);
268
269 return true;
270 }
271 }
272 }
273
274 return false;
275 }
276
278 {
279 if (w == m_Root.FindAnyWidget("Tab_Control_Container"))
280 {
281 AlignTabbers();
282 return true;
283 }
284 return false;
285 }
286
288 {
289 if (w == m_Root.FindAnyWidget("Tab_Control_Container"))
290 {
291 AlignTabbers();
292 return true;
293 }
294 return false;
295 }
296
298 {
299 Widget tab_control = m_Root.FindAnyWidget("Tab_Control_" + index);
300 if (tab_control)
301 tab_control.Show(enable);
302 AlignTabbers();
303 }
304
306 {
307 Widget tab_control = m_TabControls.Get(index);
308 if (tab_control)
309 {
310 /*
311 Widget tab_bg = tab_control.FindAnyWidget( tab_control.GetName() + "_Background" );
312 if( tab_bg )
313 {
314 tab_bg.Show( true );
315 }
316 */
317
318 Widget tab_title = TextWidget.Cast(tab_control.FindAnyWidget(tab_control.GetName() + "_Title"));
319
320 int color_title = ARGB(255, 255, 0, 0);
321 int color_backg = ARGB(255, 0, 0, 0);
322
323#ifdef PLATFORM_CONSOLE
324 color_title = ARGB(255, 255, 255, 255);
325 color_backg = ARGB(255, 200, 0, 0);
326#endif
327
328 tab_title.SetColor(color_title);
329 tab_control.SetColor(color_backg);
330 }
331 }
332
334 {
335 Widget tab = m_Tabs.Get(index);
336 if (tab)
337 tab.Show(true);
338 }
339
341 {
342 Widget tab_control = m_TabControls.Get(index);
343 if (tab_control)
344 {
345 /*
346 Widget tab_bg = tab_control.FindAnyWidget( tab_control.GetName() + "_Background" );
347 if( tab_bg )
348 {
349 tab_bg.Show( false );
350 }
351 */
352 Widget tab_title = TextWidget.Cast(tab_control.FindAnyWidget(tab_control.GetName() + "_Title"));
353 tab_title.SetColor(ARGB(255, 255, 255, 255));
354 tab_control.SetColor(ARGB(0, 0, 0, 0));
355 }
356 }
357
359 {
360 Widget tab = m_Tabs.Get(index);
361 if (tab)
362 tab.Show(false);
363 }
364
366 {
367 for (int i = 0; i < m_TabControls.Count(); i++)
368 {
369 DeselectTabControl(i);
370 DeselectTabPanel(i);
371 }
372 }
373
374 void NextTab()
375 {
376 int next_index = m_SelectedIndex + 1;
377
378 while (next_index < m_Tabs.Count() && !m_TabControls[next_index].IsVisible())
379 next_index++;
380
381 if (next_index >= m_Tabs.Count())
382 next_index = 0;
383
384 if (m_SelectedIndex != next_index)
385 {
386 m_OnAttemptTabSwitch.Invoke(m_SelectedIndex, next_index);
387 if (CanSwitchTab())
388 PerformSwitchTab(next_index);
389 }
390
391 if (m_FirstInit)
392 {
393 AlignTabbers();
394 m_FirstInit = false;
395 }
396 }
397
399 {
400 int next_index = m_SelectedIndex - 1;
401
402 if (next_index < 0)
403 next_index = m_TabControls.Count() - 1;
404
405 while (next_index > 0 && !m_TabControls[next_index].IsVisible())
406 next_index--;
407
408 if (m_SelectedIndex != next_index)
409 {
410 m_OnAttemptTabSwitch.Invoke(m_SelectedIndex, next_index);
411 if (CanSwitchTab())
412 PerformSwitchTab(next_index);
413 }
414
415 if (m_FirstInit)
416 {
417 AlignTabbers();
418 m_FirstInit = false;
419 }
420 }
421
423 {
424 return m_SelectedIndex;
425 }
426
428 {
429 m_FirstInit = performInitAlignment;
430 DeselectAll();
431 PerformSwitchTab(m_SelectedIndex);
432 }
433
434 protected void UpdateControlsElements()
435 {
436 Widget xbControls = m_Root.FindAnyWidget("ConsoleControls");
437 if (xbControls)
438 {
439 xbControls.Show(m_TabsCount > 1);
440
441 RichTextWidget toolbar_lb = RichTextWidget.Cast(xbControls.FindAnyWidget("TabLeftControl"));
442 RichTextWidget toolbar_rb = RichTextWidget.Cast(xbControls.FindAnyWidget("TabRightControl"));
443 if (toolbar_lb)
445
446 if (toolbar_rb)
448 }
449 }
450
453 {
454 foreach (Widget w : m_Tabs)
455 {
456 if (disable)
457 w.SetFlags(WidgetFlags.IGNOREPOINTER);
458 else
459 w.ClearFlags(WidgetFlags.IGNOREPOINTER);
460 w.Enable(!disable);
461 }
462 }
463}
void OnInputPresetChanged()
Definition Inventory.c:160
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition Inventory.c:167
ActionInput GetInput()
Definition ActionBase.c:989
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
override Widget Init()
Definition DayZGame.c:120
Icon x
Icon y
void UpdateControlsElements()
Widget m_Root
Definition SizeToChild.c:85
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Definition InputUtils.c:151
static const float ICON_SCALE_TOOLBAR
Definition InputUtils.c:15
ScriptInvoker Class provide list of callbacks usage:
Definition tools.c:116
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void PerformSwitchTab(int index)
Definition TabberUI.c:206
void DeselectTabControl(int index)
Definition TabberUI.c:340
void EnableTabControl(int index, bool enable)
Definition TabberUI.c:297
void OnWidgetScriptInit(Widget w)
Definition TabberUI.c:91
void RemoveTab(int index)
Definition TabberUI.c:180
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Definition TabberUI.c:257
override bool OnChildRemove(Widget w, Widget child)
Definition TabberUI.c:287
void DisableTabs(bool disable)
useful if we want to disable actual tabs for whatever reason
Definition TabberUI.c:452
ref map< int, Widget > m_Tabs
Definition TabberUI.c:9
override bool OnChildAdd(Widget w, Widget child)
Definition TabberUI.c:277
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition TabberUI.c:26
int AddTab(string name)
Definition TabberUI.c:157
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition TabberUI.c:241
void SelectTabPanel(int index)
Definition TabberUI.c:333
void DeselectTabPanel(int index)
Definition TabberUI.c:358
void SetCanSwitch(bool value)
Definition TabberUI.c:201
override bool OnMouseEnter(Widget w, int x, int y)
Definition TabberUI.c:224
ref map< int, Widget > m_TabControls
Definition TabberUI.c:8
void SelectTabControl(int index)
Definition TabberUI.c:305
Widget GetTab(int index)
Definition TabberUI.c:186
void RefreshTab(bool performInitAlignment=false)
Definition TabberUI.c:427
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
MouseState
Definition EnSystem.c:311
proto void GetScreenSize(out int x, out int y)
WidgetFlags
Definition EnWidgets.c:58
proto native bool IsVisible()
EInputDeviceType
Definition input.c:3
int ARGB(int a, int r, int g, int b)
Definition proto.c:322