iFactory.Godot/Mods/教育平台/Scripts/CourseElement.cs

52 lines
1.1 KiB
C#
Raw Normal View History

2023-06-29 01:01:52 +08:00
using Godot;
using System;
using BITKit;
namespace BITFactory;
public partial class CourseElement : Node
{
private static Node CurrentScene;
[Export]
public PackedScene CourseScene;
[Export] private Label courseLabel;
[Export] private Button entryButton;
[Export]
public string CourseName
{
get => _courseName;
2023-07-03 02:34:01 +08:00
set
{
if (courseLabel is not null)
courseLabel.Text = _courseName = value;
}
2023-06-29 01:01:52 +08:00
}
private string _courseName;
public override void _Ready()
{
//entryButton.Connect(nameof(Button.press))
entryButton.Pressed += EntryCourse;
}
private void EntryCourse()
{
if (CourseScene is null)
{
return;
}
if (CurrentScene is not null)
{
BIT4Log.Log<CourseElement>($"正在释放课程:\t{CurrentScene.Name}");
CurrentScene.QueueFree();
BIT4Log.Log<CourseElement>($"已释放当前课程:\t{CurrentScene.Name}");
}
CurrentScene = CourseScene.Instantiate();
GetTree().Root.AddChild(CurrentScene);
UXService.Open(CurrentScene as Control);
BIT4Log.Log<CourseElement>($"已加载新的课程:\t{CurrentScene.Name}");
}
}