Cleaned up project with better structure.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Godot;
|
||||
using static GameData;
|
||||
|
||||
public partial class Camera3d : Camera3D
|
||||
{
|
||||
[Export] public float Speed = 7.5f;
|
||||
[Export] public float MouseSensitivity = 0.2f;
|
||||
[Export] public float ScrollStrength = 5.0f;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Position = new Vector3(0, 0, tileWidth / 2);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (canMove) MoveCamera(delta);
|
||||
}
|
||||
|
||||
public void MoveCamera(double delta)
|
||||
{
|
||||
float d = (float)delta;
|
||||
|
||||
Vector3 rotation = RotationDegrees;
|
||||
rotation.X = Mathf.Clamp(rotation.X, -90f, 90f);
|
||||
RotationDegrees = rotation;
|
||||
|
||||
Vector3 direction = Vector3.Zero;
|
||||
if (Input.IsActionPressed("move_forward") && Position.Z > 0) direction += Transform.Basis.Z;
|
||||
if (Input.IsActionPressed("move_backward") && Position.Z < layerSize * 6) direction -= Transform.Basis.Z;
|
||||
if (Input.IsActionPressed("move_left") && Position.X > 0) direction -= Transform.Basis.X;
|
||||
if (Input.IsActionPressed("move_right") && Position.X < layerSize * 6) direction += Transform.Basis.X;
|
||||
|
||||
if (direction != Vector3.Zero)
|
||||
{
|
||||
direction = direction.Normalized() * Speed * (Input.IsActionPressed("sprint") ? 2.5f : 1) * d;
|
||||
Translate(direction);
|
||||
}
|
||||
|
||||
if (Position.Y != 10 - visibleLayer * 4)
|
||||
{
|
||||
Position = new Vector3(Position.X, 10 - visibleLayer * 4, Position.Z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://c7khr6oist3ku
|
||||
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
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;
|
||||
[Export] PanelContainer inventory;
|
||||
[Export] ResearchList researchList;
|
||||
[Export] TextureRect robotAlarm;
|
||||
|
||||
private bool receivedRobotJumpSignal = false;
|
||||
public override void _Ready()
|
||||
{
|
||||
robotList.OnRobotJumpTo += OnRobotJumpTo;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
robotList.OnRobotJumpTo -= OnRobotJumpTo;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
DisplayStats();
|
||||
DisplayRobotAlarm();
|
||||
|
||||
Control focused = GetViewport().GuiGetFocusOwner();
|
||||
|
||||
if (focused is LineEdit || focused is TextEdit)
|
||||
return;
|
||||
|
||||
if (Input.IsActionJustPressed("map")) HandleMapButton();
|
||||
if (Input.IsActionJustPressed("menu")) HandleMenuButton();
|
||||
if (Input.IsActionJustPressed("robot_list")) HandleRobotListButton();
|
||||
if (Input.IsActionJustPressed("inventory")) HandleInventoryButton();
|
||||
if (Input.IsActionJustPressed("research")) HandleResearchButton();
|
||||
}
|
||||
|
||||
public void HandleMenuButton()
|
||||
{
|
||||
OpenUIElement(menu);
|
||||
}
|
||||
|
||||
public void HandleMenu()
|
||||
{
|
||||
HandleMenuButton();
|
||||
}
|
||||
|
||||
public void ShowOptions()
|
||||
{
|
||||
OpenUIElement(options);
|
||||
}
|
||||
|
||||
public void HandleMapButton()
|
||||
{
|
||||
OpenUIElement(map);
|
||||
if (map.Visible) map.ShowMap();
|
||||
}
|
||||
|
||||
public void HandleRobotListButton()
|
||||
{
|
||||
receivedRobotJumpSignal = false;
|
||||
OpenUIElement(robotList);
|
||||
}
|
||||
|
||||
public void HandleInventoryButton()
|
||||
{
|
||||
OpenUIElement(inventory);
|
||||
}
|
||||
|
||||
public void HandleResearchButton()
|
||||
{
|
||||
OpenUIElement(researchList);
|
||||
if (researchList.Visible) researchList.SetupGraph();
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
if (child == element) continue;
|
||||
child.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayRobotAlarm()
|
||||
{
|
||||
string messages = "";
|
||||
foreach (Robot robot in GameData.robots)
|
||||
{
|
||||
if (robot.currentMessage.Length > 0)
|
||||
{
|
||||
messages += $"{robot.Name}: {robot.currentMessage}\r";
|
||||
}
|
||||
}
|
||||
robotAlarm.Visible = messages.Length > 0;
|
||||
robotAlarm.TooltipText = messages;
|
||||
}
|
||||
|
||||
private void OnRobotJumpTo(Robot 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bm7knir4552j5
|
||||
Reference in New Issue
Block a user