breakpoint
This commit is contained in:
82
BITKit/Scripts/UX/UXTabViewService.cs
Normal file
82
BITKit/Scripts/UX/UXTabViewService.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
[Tool]
|
||||
public partial class UXTabViewService : Control
|
||||
{
|
||||
[ExportCategory(Constant.Header.Settings)]
|
||||
[Export(PropertyHint.Range, "0,100,1")]
|
||||
private int currentIndex
|
||||
{
|
||||
get=>_currentIndex;
|
||||
set => SetIndex(value);
|
||||
}
|
||||
[Export] private int initialIndex;
|
||||
[ExportCategory(Constant.Header.Components)]
|
||||
[Export] private Array<Button> tabs;
|
||||
[Export] private TabContainer tabContainer;
|
||||
private ButtonGroup _buttonGroup;
|
||||
|
||||
private int _currentIndex;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (_isReady is false) return;
|
||||
_buttonGroup = new ButtonGroup();
|
||||
|
||||
for (var i = 0; i < tabs.Count; i++)
|
||||
{
|
||||
var tab = tabs[i];
|
||||
var _i = i;
|
||||
tab.Pressed += () => { SetIndex(_i); };
|
||||
}
|
||||
|
||||
var index = (Engine.IsEditorHint(), currentIndex, initialIndex) switch
|
||||
{
|
||||
(true,_,_)=>currentIndex,
|
||||
(false,_,>-1)=>initialIndex,
|
||||
(_,_,-1)=>-1,
|
||||
_ => -1
|
||||
};
|
||||
SetIndex(index);
|
||||
}
|
||||
|
||||
private void SetIndex(int value)
|
||||
{
|
||||
if (_isReady is false) return;
|
||||
if (value < 0) return;
|
||||
|
||||
EnsureConfiguration();
|
||||
|
||||
value = Mathf.Clamp(value, 0, tabContainer.GetChildCount() -1 );
|
||||
|
||||
_currentIndex = value;
|
||||
tabContainer.CurrentTab = value;
|
||||
|
||||
foreach (var tab in tabs)
|
||||
{
|
||||
tab.ButtonPressed = false;
|
||||
}
|
||||
if (tabs.TryGetElementAt(value, out var button))
|
||||
{
|
||||
button.ButtonPressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureConfiguration()
|
||||
{
|
||||
if (_isReady is false) return;
|
||||
tabContainer.TabsVisible = false;
|
||||
|
||||
foreach (var tab in tabs)
|
||||
{
|
||||
tab.ButtonGroup = _buttonGroup;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isReady => IsNodeReady() && tabContainer is not null & tabs is not null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user