1class TabberUI
extends ScriptedWidgetEventHandler
3 protected bool m_FirstInit =
true;
5 protected Widget m_TabControlsRoot;
7 protected int m_TabsCount;
11 protected int m_SelectedIndex;
12 protected float m_ResolutionMultiplier;
13 protected bool m_CanSwitch;
17 ref
Timer m_InitTimer;
21 #ifdef PLATFORM_CONSOLE
28 switch (pInputDeviceType)
32 m_TabControlsRoot.FindAnyWidget(
"ConsoleControls").Show(
true);
36 if (
GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
38 m_TabControlsRoot.FindAnyWidget(
"ConsoleControls").Show(
false);
48 m_ResolutionMultiplier =
y / 1080;
52 Widget tab_controls =
m_Root.FindAnyWidget(
"Tab_Control_Container");
55 Widget tab_child = tab_controls.GetChildren();
60 tab_child = tab_child.GetSibling();
63 for (
int i = 0; i < m_TabsCount; i++ )
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)
69 tab_control.SetHandler(
this);
70 m_TabControls.Insert(i, tab_control);
71 m_Tabs.Insert(i, tab_widget);
75 Error(
"Tabber could not find correctly named tab or control at index " + i);
80 #ifdef PLATFORM_CONSOLE
86 m_InitTimer.Run(0.01,
this,
"AlignTabbers");
102 m_InitTimer =
new Timer();
103 m_TabControlsRoot =
m_Root.FindAnyWidget(
"TabControls");
113 Widget tab_controls_container = m_TabControlsRoot.FindAnyWidget(
"Tab_Control_Container" );
114 Widget tab_controls_scroller = m_TabControlsRoot.FindAnyWidget(
"Tab_Control_Scroller" );
116 m_TabControlsRoot.Update();
117 tab_controls_container.Update();
119 Widget tab_child = tab_controls_container.GetChildren();
122 if ( tab_child.IsVisible() )
124 TextWidget tab_text = TextWidget.Cast( tab_child.FindAnyWidget( tab_child.GetName() +
"_Title" ) );
127 tab_text.GetTextSize( t_x, t_y );
128 tab_child.SetSize( t_x + 10 * m_ResolutionMultiplier, 1 );
129 tab_controls_container.Update();
131 total_size += ( t_x + 10 * m_ResolutionMultiplier );
134 tab_child = tab_child.GetSibling();
137 tab_child = tab_controls_container.GetChildren();
140 tab_controls_container.GetScreenPos( x_f_c, y_f_c );
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 );
149 tab_child = tab_child.GetSibling();
152 m_TabControlsRoot.GetSize(
x,
y );
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();
161 int AddTab(
string name )
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" ) );
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" );
173 control_text.SetText(
name );
175 control.SetHandler(
this );
176 m_TabControls.Insert( new_index, control );
177 m_Tabs.Insert( new_index, tab );
184 void RemoveTab(
int index )
190 Widget GetTab(
int index )
192 return m_Tabs.Get( index );
197 return m_Tabs.Count();
205 void SetCanSwitch(
bool value)
210 void PerformSwitchTab(
int index)
212 DeselectTabControl( m_SelectedIndex );
213 DeselectTabPanel( m_SelectedIndex );
215 SelectTabControl( index );
216 SelectTabPanel( index );
218 m_SelectedIndex = index;
219 m_OnTabSwitch.Invoke( m_SelectedIndex );
230 int index = m_TabControls.GetKeyByValue( w );
231 if ( m_SelectedIndex == index )
236 Widget tab_control = m_TabControls.Get( index );
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) );
247 override bool OnMouseLeave( Widget w, Widget enterW,
int x,
int y )
249 int index = m_TabControls.GetKeyByValue( w );
250 if ( m_SelectedIndex == index )
255 Widget tab_control = m_TabControls.Get( index );
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) );
269 int index = m_TabControls.GetKeyByValue( w );
270 if ( m_SelectedIndex != index )
272 m_OnAttemptTabSwitch.Invoke( m_SelectedIndex, index );
273 if ( CanSwitchTab() )
275 PerformSwitchTab(index);
285 override bool OnChildAdd( Widget w, Widget child )
287 if ( w ==
m_Root.FindAnyWidget(
"Tab_Control_Container" ) )
295 override bool OnChildRemove( Widget w, Widget child )
297 if ( w ==
m_Root.FindAnyWidget(
"Tab_Control_Container" ) )
305 void EnableTabControl(
int index,
bool enable )
307 Widget tab_control =
m_Root.FindAnyWidget(
"Tab_Control_" + index );
309 tab_control.Show( enable );
313 void SelectTabControl(
int index )
315 Widget tab_control = m_TabControls.Get( index );
326 Widget tab_title = TextWidget.Cast(tab_control.FindAnyWidget( tab_control.GetName() +
"_Title" ));
328 int color_title =
ARGB(255, 255, 0, 0);
329 int color_backg =
ARGB(255, 0, 0 ,0);
331 #ifdef PLATFORM_CONSOLE
332 color_title =
ARGB(255, 255, 255, 255);
333 color_backg =
ARGB(255, 200, 0 ,0);
336 tab_title.SetColor( color_title );
337 tab_control.SetColor( color_backg );
341 void SelectTabPanel(
int index )
343 Widget tab = m_Tabs.Get( index );
350 void DeselectTabControl(
int index )
352 Widget tab_control = m_TabControls.Get( index );
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) );
368 void DeselectTabPanel(
int index )
370 Widget tab = m_Tabs.Get( index );
379 for (
int i = 0; i < m_TabControls.Count(); i++)
381 DeselectTabControl(i);
388 int next_index = m_SelectedIndex + 1;
390 while ( next_index < m_Tabs.Count() && !m_TabControls[next_index].IsVisible() )
395 if ( next_index >= m_Tabs.Count() )
400 if ( m_SelectedIndex != next_index )
402 m_OnAttemptTabSwitch.Invoke( m_SelectedIndex, next_index );
403 if ( CanSwitchTab() )
405 PerformSwitchTab(next_index);
418 int next_index = m_SelectedIndex - 1;
420 if ( next_index < 0 )
422 next_index = m_TabControls.Count() - 1;
425 while ( next_index > 0 && !m_TabControls[next_index].IsVisible() )
430 if ( m_SelectedIndex != next_index )
432 m_OnAttemptTabSwitch.Invoke( m_SelectedIndex, next_index );
433 if ( CanSwitchTab() )
435 PerformSwitchTab(next_index);
446 int GetSelectedIndex()
448 return m_SelectedIndex;
451 void RefreshTab(
bool performInitAlignment =
false)
453 m_FirstInit = performInitAlignment;
455 PerformSwitchTab(m_SelectedIndex);
460 Widget xbControls =
m_Root.FindAnyWidget(
"ConsoleControls");
463 xbControls.Show(m_TabsCount > 1);
480 void DisableTabs(
bool disable)
482 foreach (Widget w : m_Tabs)
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void OnInputPresetChanged()
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
ScriptInvoker Class provide list of callbacks usage:
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
proto void GetScreenSize(out int x, out int y)
int ARGB(int a, int r, int g, int b)
void OnWidgetScriptInit(Widget w)