95 lines
2.1 KiB
C#
95 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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;
|
|
|
|
bool receivedRobotJumpSignal = false;
|
|
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) =>
|
|
{
|
|
if(receivedRobotJumpSignal) return;
|
|
receivedRobotJumpSignal = true;
|
|
mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z + 3f);
|
|
codingWindow.SetRobot(robot);
|
|
OpenUIElement(codingWindow);
|
|
};
|
|
|
|
if (Input.IsActionJustPressed("map")) HandleMapButton();
|
|
if (Input.IsActionJustPressed("menu")) HandleMenuButton();
|
|
if (Input.IsActionJustPressed("robot_list")) HandleRobotListButton();
|
|
DisplayStats();
|
|
}
|
|
|
|
public void HandleMenuButton()
|
|
{
|
|
OpenUIElement(menu);
|
|
}
|
|
|
|
public void HandleMapButton()
|
|
{
|
|
OpenUIElement(map);
|
|
}
|
|
|
|
public void HandleRobotListButton()
|
|
{
|
|
receivedRobotJumpSignal = false;
|
|
OpenUIElement(robotList);
|
|
}
|
|
|
|
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 ExitGame()
|
|
{
|
|
GetTree().ChangeSceneToFile("res://Scenes/MainMenu.tscn");
|
|
}
|
|
|
|
public void OpenUIElement(Control element)
|
|
{
|
|
if (element.Visible)
|
|
{
|
|
element.Hide();
|
|
}
|
|
else
|
|
{
|
|
element.Show();
|
|
}
|
|
HideUIElements(element);
|
|
}
|
|
|
|
private void HideUIElements(Control element)
|
|
{
|
|
foreach (PanelContainer child in uiContent.GetChildren())
|
|
{
|
|
GD.Print(child == element);
|
|
if (child == element) continue;
|
|
child.Visible = false;
|
|
}
|
|
}
|
|
}
|