supervisor-simulator/scenes/CampusController.cs
2025-12-15 22:44:41 +08:00

64 lines
1.5 KiB
C#

using Godot;
using System;
public partial class CampusController : Node2D
{
private Control _taskContainer;
private Control _logContainer;
private Button _taskToggle;
private Button _logToggle;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_taskContainer = GetNode<Control>("Task");
_logContainer = GetNode<Control>("Log");
// Path to buttons based on scene structure
_taskToggle = GetNode<Button>("TopBar/HBox/CC1/TaskToggle");
_logToggle = GetNode<Button>("TopBar/HBox/CC2/LogToggle");
// Sync initial state
_taskToggle.ButtonPressed = _taskContainer.Visible;
_logToggle.ButtonPressed = _logContainer.Visible;
_taskToggle.Toggled += OnTaskToggled;
_logToggle.Toggled += OnLogToggled;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
private void OnTaskToggled(bool pressed)
{
AnimateVisibility(_taskContainer, pressed);
}
private void OnLogToggled(bool pressed)
{
AnimateVisibility(_logContainer, pressed);
}
private void AnimateVisibility(Control container, bool visible)
{
var tween = CreateTween();
if (visible)
{
if (!container.Visible)
{
var col = container.Modulate;
col.A = 0;
container.Modulate = col;
container.Visible = true;
}
tween.TweenProperty(container, "modulate:a", 1.0f, 0.2f);
}
else
{
tween.TweenProperty(container, "modulate:a", 0.0f, 0.2f);
tween.TweenCallback(Callable.From(() => container.Visible = false));
}
}
}