46 lines
937 B
C#
46 lines
937 B
C#
using Godot;
|
|
using System;
|
|
using Godot.Collections;
|
|
|
|
namespace BITKit;
|
|
[Tool]
|
|
[Obsolete("see UXTabContainerService")]
|
|
public partial class UXWindowService : Control
|
|
{
|
|
[Export] private Array<Button> tabs;
|
|
[Export] private Array<Control> windows;
|
|
public override void _Ready()
|
|
{
|
|
if (Engine.IsEditorHint()) return;
|
|
if(tabs.Count != windows.Count) throw new Exception("tabs.Count != windows.Count");
|
|
ButtonGroup buttonGroup = new();
|
|
for (var i = 0; i < tabs.Count; i++)
|
|
{
|
|
var tab = tabs[i];
|
|
var window = windows[i];
|
|
tab.Pressed += () =>
|
|
{
|
|
ShowWindow(window);
|
|
};
|
|
}
|
|
if(tabs.Count>0)
|
|
{
|
|
ShowWindow(windows[0]);
|
|
}
|
|
}
|
|
private void ShowWindow(CanvasItem window)
|
|
{
|
|
foreach (var x in windows)
|
|
{
|
|
//if(window.Visible is true && window != x)
|
|
x.Hide();
|
|
}
|
|
var index = windows.IndexOf(window as Control);
|
|
if (index is not -1)
|
|
{
|
|
tabs[index].ButtonPressed = true;
|
|
}
|
|
window.Show();
|
|
}
|
|
}
|