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