DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
TabberUI.c
См. документацию.
1class TabberUI extends ScriptedWidgetEventHandler
2{
3 protected bool m_FirstInit = true;
4 protected Widget m_Root;
6
7 protected int m_TabsCount;
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
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 );
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 {
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
80 #ifdef PLATFORM_CONSOLE
82 #endif
83
85
86 m_InitTimer.Run(0.01, this, "AlignTabbers");
87 }
88
91
92 OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
93 }
94
96 {
97 m_TabsCount = 0;
100
101 m_Root = w;
102 m_InitTimer = new Timer();
103 m_TabControlsRoot = m_Root.FindAnyWidget("TabControls");
104
105 Init();
106 }
107
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
196 {
197 return m_Tabs.Count();
198 }
199
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 {
214
215 SelectTabControl( index );
216 SelectTabPanel( index );
217
218 m_SelectedIndex = index;
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
378 {
379 for (int i = 0; i < m_TabControls.Count(); i++)
380 {
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
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
447 {
448 return m_SelectedIndex;
449 }
450
451 void RefreshTab(bool performInitAlignment = false)
452 {
453 m_FirstInit = performInitAlignment;
454 DeselectAll();
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}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
map
Определения ControlsXboxNew.c:4
Icon x
Icon y
proto native WorkspaceWidget GetWorkspace()
proto native Mission GetMission()
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Определения InputUtils.c:167
static const float ICON_SCALE_TOOLBAR
Определения InputUtils.c:15
Определения InputUtils.c:2
ScriptInvoker GetOnInputDeviceChanged()
Определения gameplay.c:851
ScriptInvoker GetOnInputPresetChanged()
Определения gameplay.c:859
Определения gameplay.c:317
proto bool Insert(func fn, int flags=EScriptInvokerInsertFlags.IMMEDIATE)
insert method to list
ScriptInvoker Class provide list of callbacks usage:
Определения tools.c:116
void PerformSwitchTab(int index)
Определения TabberUI.c:210
int GetSelectedIndex()
Определения TabberUI.c:446
void DeselectTabControl(int index)
Определения TabberUI.c:350
int m_TabsCount
Определения TabberUI.c:7
void EnableTabControl(int index, bool enable)
Определения TabberUI.c:305
Widget m_TabControlsRoot
Определения TabberUI.c:5
int m_SelectedIndex
Определения TabberUI.c:11
void PreviousTab()
Определения TabberUI.c:416
void OnWidgetScriptInit(Widget w)
Определения TabberUI.c:95
void RemoveTab(int index)
Определения TabberUI.c:184
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Определения TabberUI.c:265
void AlignTabbers()
Определения TabberUI.c:108
Widget m_Root
Определения SizeToChild.c:9
override bool OnChildRemove(Widget w, Widget child)
Определения TabberUI.c:295
bool m_FirstInit
Определения TabberUI.c:3
void DisableTabs(bool disable)
useful if we want to disable actual tabs for whatever reason
Определения TabberUI.c:480
ref map< int, Widget > m_Tabs
Определения TabberUI.c:9
override bool OnChildAdd(Widget w, Widget child)
Определения TabberUI.c:285
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Определения TabberUI.c:26
int AddTab(string name)
Определения TabberUI.c:161
void NextTab()
Определения TabberUI.c:386
bool m_CanSwitch
Определения TabberUI.c:13
void UpdateControlsElements()
Определения TabberUI.c:458
ref ScriptInvoker m_OnAttemptTabSwitch
Определения TabberUI.c:16
void DeselectAll()
Определения TabberUI.c:377
ref Timer m_InitTimer
Определения TabberUI.c:17
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Определения TabberUI.c:247
void SelectTabPanel(int index)
Определения TabberUI.c:341
bool CanSwitchTab()
Определения TabberUI.c:200
void DeselectTabPanel(int index)
Определения TabberUI.c:368
void Init()
Определения TabberUI.c:44
bool IsVisible()
Определения ContextMenu.c:134
void SetCanSwitch(bool value)
Определения TabberUI.c:205
void OnInputPresetChanged()
Определения TabberUI.c:19
override bool OnMouseEnter(Widget w, int x, int y)
Определения TabberUI.c:228
ref ScriptInvoker m_OnTabSwitch
Определения TabberUI.c:15
ref map< int, Widget > m_TabControls
Определения TabberUI.c:8
void SelectTabControl(int index)
Определения TabberUI.c:313
Widget GetTab(int index)
Определения TabberUI.c:190
void RefreshTab(bool performInitAlignment=false)
Определения TabberUI.c:451
int GetTabCount()
Определения TabberUI.c:195
float m_ResolutionMultiplier
Определения TabberUI.c:12
map: item x vector(index, width, height)
Определения EnWidgets.c:651
Определения EnWidgets.c:220
Определения DayZPlayerImplement.c:63
Определения EnWidgets.c:190
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Определения EnDebug.c:90
MouseState
Определения EnSystem.c:311
proto void GetScreenSize(out int x, out int y)
WidgetFlags
Определения EnWidgets.c:58
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.
EInputDeviceType
Определения input.c:3
int ARGB(int a, int r, int g, int b)
Определения proto.c:322