Improved UI calls
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
@@ -14,6 +15,8 @@ public partial class UIHandler : Control
|
||||
[Export] PanelContainer options;
|
||||
[Export] Control uiContent;
|
||||
[Export] PanelContainer menu;
|
||||
|
||||
bool receivedRobotJumpSignal = false;
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
@@ -24,50 +27,33 @@ public partial class UIHandler : Control
|
||||
{
|
||||
robotList.OnRobotJumpTo += (robot) =>
|
||||
{
|
||||
if(receivedRobotJumpSignal) return;
|
||||
receivedRobotJumpSignal = true;
|
||||
mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z + 3f);
|
||||
ShowCodingWindow(robot);
|
||||
codingWindow.SetRobot(robot);
|
||||
OpenUIElement(codingWindow);
|
||||
};
|
||||
|
||||
if (Input.IsActionJustPressed("map"))
|
||||
{
|
||||
map.ShowMap(false);
|
||||
}
|
||||
|
||||
if (Input.IsActionJustPressed("menu"))
|
||||
{
|
||||
HandleMenu();
|
||||
}
|
||||
|
||||
if (Input.IsActionJustPressed("map")) HandleMapButton();
|
||||
if (Input.IsActionJustPressed("menu")) HandleMenuButton();
|
||||
if (Input.IsActionJustPressed("robot_list")) HandleRobotListButton();
|
||||
DisplayStats();
|
||||
}
|
||||
|
||||
public void HandleMenu()
|
||||
public void HandleMenuButton()
|
||||
{
|
||||
bool shouldMenuOpen = true;
|
||||
foreach (PanelContainer element in uiContent.GetChildren())
|
||||
{
|
||||
if (element.Visible)
|
||||
{
|
||||
element.Visible = false;
|
||||
shouldMenuOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldMenuOpen)
|
||||
{
|
||||
menu.Visible = true;
|
||||
}
|
||||
OpenUIElement(menu);
|
||||
}
|
||||
|
||||
public void ChangeColor(Color color)
|
||||
public void HandleMapButton()
|
||||
{
|
||||
GameData.lightColor = color;
|
||||
LightHandler.RedrawLights(color);
|
||||
OpenUIElement(map);
|
||||
}
|
||||
|
||||
public void ShowCodingWindow(Robot robot)
|
||||
public void HandleRobotListButton()
|
||||
{
|
||||
codingWindow.ShowWindow(robot);
|
||||
receivedRobotJumpSignal = false;
|
||||
OpenUIElement(robotList);
|
||||
}
|
||||
|
||||
public void DisplayStats()
|
||||
@@ -78,13 +64,31 @@ public partial class UIHandler : Control
|
||||
RAM.Text = memoryDisplay;
|
||||
}
|
||||
|
||||
public void ShowOptions()
|
||||
{
|
||||
options.Visible = true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user