using System; using System.Diagnostics; using System.Threading.Tasks; using Godot; public partial class UIHandler : Control { [Export] CodingWindow codingWindow; [Export] RobotList robotList; [Export] Camera3D mainCam; [Export] Map map; [Export] RichTextLabel FPS; [Export] RichTextLabel RAM; [Export] PanelContainer options; [Export] Control uiContent; [Export] PanelContainer menu; public override void _Ready() { } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { robotList.OnRobotJumpTo += (robot) => { mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z + 3f); ShowCodingWindow(robot); }; if (Input.IsActionJustPressed("map")) { map.Visible = !map.Visible; if (map.Visible) { map.ShowMap(); } } if (Input.IsActionJustPressed("menu")) { HandleMenu(); } DisplayStats(); } public void HandleMenu() { bool shouldMenuOpen = true; foreach (PanelContainer element in uiContent.GetChildren()) { if (element.Visible) { element.Visible = false; shouldMenuOpen = false; } } if (shouldMenuOpen) { menu.Visible = true; } } public void ChangeColor(Color color) { GameData.lightColor = color; LightHandler.RedrawLights(color); } public void ShowCodingWindow(Robot robot) { codingWindow.ShowWindow(robot); } public void DisplayStats() { FPS.Text = Engine.GetFramesPerSecond().ToString() + " FPS"; double memory = Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024); string memoryDisplay = memory > 1024 ? Math.Round(memory / 1024, 2).ToString() + " GB" : memory.ToString() + " MB"; RAM.Text = memoryDisplay; } public void ShowOptions() { options.Visible = true; } public void ExitGame() { GetTree().ChangeSceneToFile("res://Scenes/MainMenu.tscn"); } }