2023-07-12 15:27:27 +08:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Security;
|
2023-06-29 01:01:52 +08:00
|
|
|
using Godot;
|
|
|
|
using BITKit;
|
|
|
|
|
|
|
|
namespace BITFactory;
|
|
|
|
public partial class CourseElement : Node
|
|
|
|
{
|
|
|
|
private static Node CurrentScene;
|
2023-07-17 04:10:14 +08:00
|
|
|
private static string CurrentScenePath=string.Empty;
|
2023-06-29 01:01:52 +08:00
|
|
|
[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;
|
|
|
|
}
|
2023-07-04 04:08:18 +08:00
|
|
|
|
2023-07-12 15:27:27 +08:00
|
|
|
Stopwatch stopwatch = new();
|
|
|
|
stopwatch.Start();
|
2023-07-17 04:10:14 +08:00
|
|
|
if (CurrentScenePath == CourseScene?.ResourcePath)
|
2023-07-04 04:08:18 +08:00
|
|
|
{
|
|
|
|
BIT4Log.Log<CourseElement>($"已返回当前课程");
|
|
|
|
UXService.Open(CurrentScene as Control);
|
|
|
|
return;
|
|
|
|
}
|
2023-06-29 01:01:52 +08:00
|
|
|
if (CurrentScene is not null)
|
|
|
|
{
|
|
|
|
BIT4Log.Log<CourseElement>($"正在释放课程:\t{CurrentScene.Name}");
|
|
|
|
CurrentScene.QueueFree();
|
|
|
|
BIT4Log.Log<CourseElement>($"已释放当前课程:\t{CurrentScene.Name}");
|
|
|
|
}
|
2023-07-04 04:08:18 +08:00
|
|
|
CurrentScene = CourseScene!.Instantiate();
|
2023-07-17 04:10:14 +08:00
|
|
|
CurrentScenePath = CourseScene.ResourcePath;
|
2023-06-29 01:01:52 +08:00
|
|
|
GetTree().Root.AddChild(CurrentScene);
|
|
|
|
UXService.Open(CurrentScene as Control);
|
2023-07-12 15:27:27 +08:00
|
|
|
BIT4Log.Log<CourseElement>($"已加载新的课程:\t{CourseScene.ResourceName}");
|
|
|
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
BIT4Log.Log<CourseElement>($"加载课程耗时:\t{stopwatch.ElapsedMilliseconds}ms");
|
2023-06-29 01:01:52 +08:00
|
|
|
}
|
|
|
|
}
|