Big project cleanup with overhaul of file responsibilities (KISS) and code (DRY, YAGNI)
This commit is contained in:
@@ -17,8 +17,7 @@ public partial class Camera3d : Camera3D
|
||||
{
|
||||
Control focused = GetViewport().GuiGetFocusOwner();
|
||||
|
||||
if (focused is LineEdit || focused is TextEdit)
|
||||
return;
|
||||
if (focused is LineEdit || focused is TextEdit) return;
|
||||
if (canMove) MoveCamera(delta);
|
||||
}
|
||||
|
||||
@@ -38,17 +37,13 @@ public partial class Camera3d : Camera3D
|
||||
|
||||
if (direction != Vector3.Zero)
|
||||
{
|
||||
if(robot != null) robot = null;
|
||||
robot = null;
|
||||
direction = direction.Normalized() * Speed * (Input.IsActionPressed("sprint") ? 2.5f : 1) * d;
|
||||
Translate(direction);
|
||||
}
|
||||
else
|
||||
else if (robot != null)
|
||||
{
|
||||
if(robot != null)
|
||||
{
|
||||
Position = new Vector3(robot.Position.X, 10 - visibleLayer * 4, robot.Position.Z + 4f);
|
||||
}
|
||||
|
||||
Position = new Vector3(robot.Position.X, 10 - visibleLayer * 4, robot.Position.Z + 4f);
|
||||
}
|
||||
|
||||
if (Position.Y != 10 - visibleLayer * 4)
|
||||
|
||||
+20
-103
@@ -1,5 +1,3 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Godot;
|
||||
|
||||
public partial class UIHandler : Control
|
||||
@@ -46,10 +44,7 @@ public partial class UIHandler : Control
|
||||
DisplayStats();
|
||||
DisplayRobotAlarm();
|
||||
|
||||
Control focused = GetViewport().GuiGetFocusOwner();
|
||||
|
||||
if (focused is LineEdit || focused is TextEdit)
|
||||
return;
|
||||
if (IsTextInputFocused()) return;
|
||||
|
||||
if (Input.IsActionJustPressed("map")) HandleMapButton();
|
||||
if (Input.IsActionJustPressed("menu")) HandleMenuButton();
|
||||
@@ -58,22 +53,29 @@ public partial class UIHandler : Control
|
||||
if (Input.IsActionJustPressed("research")) HandleResearchButton();
|
||||
}
|
||||
|
||||
private bool IsTextInputFocused()
|
||||
{
|
||||
Control focused = GetViewport().GuiGetFocusOwner();
|
||||
return focused is LineEdit || focused is TextEdit;
|
||||
}
|
||||
|
||||
public void HandleMenuButton()
|
||||
{
|
||||
if(GameData.survival.isDead) return;
|
||||
if (GameData.survival.isDead) return;
|
||||
|
||||
OpenUIElement(menu);
|
||||
GameData.isPaused = menu.Visible || options.Visible;
|
||||
}
|
||||
|
||||
public void HandleMenu()
|
||||
{
|
||||
if(GameData.survival.isDead) return;
|
||||
HandleMenuButton();
|
||||
}
|
||||
|
||||
public void ShowOptions()
|
||||
{
|
||||
if(GameData.survival.isDead) return;
|
||||
if (GameData.survival.isDead) return;
|
||||
|
||||
menu.Hide();
|
||||
OpenUIElement(options);
|
||||
GameData.isPaused = options.Visible;
|
||||
@@ -81,14 +83,16 @@ public partial class UIHandler : Control
|
||||
|
||||
public void HandleMapButton()
|
||||
{
|
||||
if(GameData.survival.isDead) return;
|
||||
if (GameData.survival.isDead) return;
|
||||
|
||||
OpenUIElement(map);
|
||||
if (map.Visible) map.ShowMap();
|
||||
}
|
||||
|
||||
public void HandleRobotListButton()
|
||||
{
|
||||
if(GameData.survival.isDead) return;
|
||||
if (GameData.survival.isDead) return;
|
||||
|
||||
receivedRobotFollowSignal = false;
|
||||
receivedRobotJumpSignal = false;
|
||||
OpenUIElement(robotList);
|
||||
@@ -96,28 +100,19 @@ public partial class UIHandler : Control
|
||||
|
||||
public void HandleInventoryButton()
|
||||
{
|
||||
if(GameData.survival.isDead) return;
|
||||
if (GameData.survival.isDead) return;
|
||||
|
||||
OpenUIElement(inventory);
|
||||
}
|
||||
|
||||
public void HandleResearchButton()
|
||||
{
|
||||
if(GameData.survival.isDead) return;
|
||||
if (GameData.survival.isDead) return;
|
||||
|
||||
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;
|
||||
DisplaySurvivalStats();
|
||||
DisplayWorldStats();
|
||||
DisplayLoseCondition();
|
||||
}
|
||||
|
||||
public void ExitGame()
|
||||
{
|
||||
GetTree().ChangeSceneToFile("res://Scenes/MainMenu.tscn");
|
||||
@@ -139,14 +134,7 @@ public partial class UIHandler : Control
|
||||
public void OpenUIElement(Control element)
|
||||
{
|
||||
SoundManager.PlayButton();
|
||||
if (element.Visible)
|
||||
{
|
||||
element.Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
element.Show();
|
||||
}
|
||||
element.Visible = !element.Visible;
|
||||
HideUIElements(element);
|
||||
}
|
||||
|
||||
@@ -164,25 +152,6 @@ public partial class UIHandler : Control
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayRobotAlarm()
|
||||
{
|
||||
string messages = "";
|
||||
if (GameData.survival.isDead)
|
||||
{
|
||||
messages += GameData.survival.currentStatus + "\r";
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -201,42 +170,6 @@ public partial class UIHandler : Control
|
||||
mainCam.Follow(robot);
|
||||
}
|
||||
|
||||
private void DisplaySurvivalStats()
|
||||
{
|
||||
energyLabel.Text = $"Energy: {GameData.survival.energy:0}/{GameData.survival.maxEnergy:0}";
|
||||
waterLabel.Text = $"Water: {GameData.survival.thirst:0}/{GameData.survival.maxThirst:0}";
|
||||
hungerLabel.Text = $"Food: {GameData.survival.hunger:0}/{GameData.survival.maxHunger:0}";
|
||||
survivalStatus.Text = GameData.survival.currentStatus;
|
||||
survivalStatus.Modulate = GameData.survival.currentStatus.Contains("critical")
|
||||
? UIStyle.GetWarningColor()
|
||||
: Colors.White;
|
||||
|
||||
if (GameData.survival.isDead)
|
||||
{
|
||||
ShowGameOver();
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayWorldStats()
|
||||
{
|
||||
currentLayer.Text = $"Layer: {GameData.currentLayer + 1}/{GameData.ruinSize}";
|
||||
deepestLayer.Text = $"Gate depth: {GameData.lowestLayer}";
|
||||
if (GameData.lowestLayer == GameData.ruinSize)
|
||||
{
|
||||
unlockLayer.Visible = false;
|
||||
return;
|
||||
}
|
||||
unlockLayer.TooltipText = "Gate requirements:\r" + GameData.map[GameData.lowestLayer].DisplayGateIngredients();
|
||||
unlockLayer.Disabled = !GameData.inventory.CanCraft(GameData.map[GameData.lowestLayer].gateIngredients, 1);
|
||||
}
|
||||
|
||||
private void DisplayLoseCondition()
|
||||
{
|
||||
if (!GameData.HasNoRobotRecovery()) return;
|
||||
|
||||
ShowGameOver("No robots remain and no robot can be spawned from inventory.");
|
||||
}
|
||||
|
||||
public void UnlockLayer()
|
||||
{
|
||||
if (GameData.inventory.CanCraft(GameData.map[GameData.lowestLayer].gateIngredients, 1))
|
||||
@@ -259,20 +192,4 @@ public partial class UIHandler : Control
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowGameOver()
|
||||
{
|
||||
ShowGameOver($"You died!\rReason: {GameData.survival.deathReason}\rBetter luck next time.");
|
||||
}
|
||||
|
||||
public void ShowGameOver(string message)
|
||||
{
|
||||
if (gameOver.Visible) return;
|
||||
gameOver.GetNode<RichTextLabel>("./VBoxContainer/Content").Text = $"[font_size=32]{message}\r";
|
||||
gameOver.Show();
|
||||
}
|
||||
|
||||
public void HideGameOver()
|
||||
{
|
||||
gameOver.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Godot;
|
||||
|
||||
public partial class UIHandler
|
||||
{
|
||||
public void DisplayStats()
|
||||
{
|
||||
FPS.Text = Engine.GetFramesPerSecond().ToString() + " FPS";
|
||||
RAM.Text = GetMemoryDisplay();
|
||||
DisplaySurvivalStats();
|
||||
DisplayWorldStats();
|
||||
DisplayLoseCondition();
|
||||
}
|
||||
|
||||
private string GetMemoryDisplay()
|
||||
{
|
||||
double memory = Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024);
|
||||
if (memory > 1024)
|
||||
{
|
||||
return Math.Round(memory / 1024, 2).ToString() + " GB";
|
||||
}
|
||||
|
||||
return memory.ToString() + " MB";
|
||||
}
|
||||
|
||||
private void DisplayRobotAlarm()
|
||||
{
|
||||
string messages = "";
|
||||
if (GameData.survival.isDead)
|
||||
{
|
||||
messages += GameData.survival.currentStatus + "\r";
|
||||
}
|
||||
|
||||
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 DisplaySurvivalStats()
|
||||
{
|
||||
energyLabel.Text = $"Energy: {GameData.survival.energy:0}/{GameData.survival.maxEnergy:0}";
|
||||
waterLabel.Text = $"Water: {GameData.survival.thirst:0}/{GameData.survival.maxThirst:0}";
|
||||
hungerLabel.Text = $"Food: {GameData.survival.hunger:0}/{GameData.survival.maxHunger:0}";
|
||||
survivalStatus.Text = GameData.survival.currentStatus;
|
||||
survivalStatus.Modulate = GameData.survival.currentStatus.Contains("critical")
|
||||
? UIStyle.GetWarningColor()
|
||||
: Colors.White;
|
||||
|
||||
if (GameData.survival.isDead)
|
||||
{
|
||||
ShowGameOver();
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayWorldStats()
|
||||
{
|
||||
currentLayer.Text = $"Layer: {GameData.currentLayer + 1}/{GameData.ruinSize}";
|
||||
deepestLayer.Text = $"Gate depth: {GameData.lowestLayer}";
|
||||
if (GameData.lowestLayer == GameData.ruinSize)
|
||||
{
|
||||
unlockLayer.Visible = false;
|
||||
return;
|
||||
}
|
||||
unlockLayer.TooltipText = "Gate requirements:\r" + GameData.map[GameData.lowestLayer].DisplayGateIngredients();
|
||||
unlockLayer.Disabled = !GameData.inventory.CanCraft(GameData.map[GameData.lowestLayer].gateIngredients, 1);
|
||||
}
|
||||
|
||||
private void DisplayLoseCondition()
|
||||
{
|
||||
if (!GameData.HasNoRobotRecovery()) return;
|
||||
|
||||
ShowGameOver("No robots remain and no robot can be spawned from inventory.");
|
||||
}
|
||||
|
||||
public void ShowGameOver()
|
||||
{
|
||||
ShowGameOver($"You died!\rReason: {GameData.survival.deathReason}\rBetter luck next time.");
|
||||
}
|
||||
|
||||
public void ShowGameOver(string message)
|
||||
{
|
||||
if (gameOver.Visible) return;
|
||||
gameOver.GetNode<RichTextLabel>("./VBoxContainer/Content").Text = $"[font_size=32]{message}\r";
|
||||
gameOver.Show();
|
||||
}
|
||||
|
||||
public void HideGameOver()
|
||||
{
|
||||
gameOver.Hide();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b2q7e88lokg3l
|
||||
Reference in New Issue
Block a user