Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit 2a9d397

Browse files
Remove all static from GameConsole
1 parent 82b8169 commit 2a9d397

6 files changed

Lines changed: 64 additions & 21 deletions

File tree

Scenes/Main.tscn

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
[gd_scene load_steps=9 format=2]
1+
[gd_scene load_steps=14 format=2]
22

33
[ext_resource path="res://Scripts/Scenes/Main/GameManager.cs" type="Script" id=1]
44
[ext_resource path="res://Scripts/Scenes/Main/MusicManager.cs" type="Script" id=2]
55
[ext_resource path="res://Scripts/Scenes/Main/Debug.cs" type="Script" id=3]
66
[ext_resource path="res://Scripts/Netcode/Common/Utils/NetworkManager.cs" type="Script" id=4]
77
[ext_resource path="res://Scripts/Scenes/Main/SceneManager.cs" type="Script" id=5]
8-
[ext_resource path="res://Scenes/Prefabs/Debugger.tscn" type="PackedScene" id=6]
8+
[ext_resource path="res://Themes/Main.tres" type="Theme" id=6]
99
[ext_resource path="res://Scripts/Scenes/Main/ErrorNotifier.cs" type="Script" id=7]
10+
[ext_resource path="res://Scripts/Msc/UIGameConsole.cs" type="Script" id=8]
1011
[ext_resource path="res://Scenes/Prefabs/ServerSimulation.tscn" type="PackedScene" id=9]
1112

13+
[sub_resource type="StyleBoxEmpty" id=1]
14+
15+
[sub_resource type="StyleBoxEmpty" id=7]
16+
17+
[sub_resource type="StyleBoxEmpty" id=6]
18+
19+
[sub_resource type="StyleBoxFlat" id=8]
20+
bg_color = Color( 0, 0, 0, 0.784314 )
21+
1222
[node name="Main" type="Node"]
1323
script = ExtResource( 1 )
24+
NodePathGameConsole = NodePath("CanvasLayer/Game Console")
1425

1526
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
1627
volume_db = -10.0
@@ -54,5 +65,37 @@ gui_disable_input = true
5465
[node name="Camera2D" type="Camera2D" parent="CanvasLayer/Server Simulation/ViewportContainer/Viewport"]
5566
current = true
5667

57-
[node name="Debugger" parent="CanvasLayer" instance=ExtResource( 6 )]
68+
[node name="Game Console" type="PanelContainer" parent="CanvasLayer"]
5869
visible = false
70+
anchor_right = 1.0
71+
anchor_bottom = 1.0
72+
theme = ExtResource( 6 )
73+
custom_styles/panel = SubResource( 1 )
74+
script = ExtResource( 8 )
75+
NodePathLogs = NodePath("VBoxContainer/TextEdit")
76+
NodePathConsole = NodePath("VBoxContainer/Console")
77+
78+
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/Game Console"]
79+
margin_right = 1024.0
80+
margin_bottom = 600.0
81+
82+
[node name="TextEdit" type="TextEdit" parent="CanvasLayer/Game Console/VBoxContainer"]
83+
margin_right = 1024.0
84+
margin_bottom = 580.0
85+
size_flags_vertical = 3
86+
custom_styles/read_only = SubResource( 7 )
87+
custom_styles/focus = SubResource( 6 )
88+
custom_styles/normal = SubResource( 8 )
89+
readonly = true
90+
syntax_highlighting = true
91+
show_line_numbers = true
92+
highlight_all_occurrences = true
93+
smooth_scrolling = true
94+
wrap_enabled = true
95+
96+
[node name="Console" type="LineEdit" parent="CanvasLayer/Game Console/VBoxContainer"]
97+
margin_top = 584.0
98+
margin_right = 1024.0
99+
margin_bottom = 600.0
100+
101+
[connection signal="text_entered" from="CanvasLayer/Game Console/VBoxContainer/Console" to="CanvasLayer/Game Console" method="_on_Console_text_entered"]

Scenes/Prefabs/Debugger.tscn

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[gd_scene load_steps=7 format=2]
22

33
[ext_resource path="res://Themes/Main.tres" type="Theme" id=1]
4-
[ext_resource path="res://Scripts/Msc/UIDebugger.cs" type="Script" id=2]
4+
[ext_resource path="res://Scripts/Msc/UIGameConsole.cs" type="Script" id=2]
55

66
[sub_resource type="StyleBoxEmpty" id=1]
77

@@ -18,8 +18,6 @@ anchor_bottom = 1.0
1818
theme = ExtResource( 1 )
1919
custom_styles/panel = SubResource( 1 )
2020
script = ExtResource( 2 )
21-
NodePathLogs = NodePath("VBoxContainer/TextEdit")
22-
NodePathConsole = NodePath("VBoxContainer/Console")
2321

2422
[node name="VBoxContainer" type="VBoxContainer" parent="."]
2523
margin_right = 1024.0
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,37 @@
44
namespace GodotModules
55
{
66
// This is the in game console which appears on pressing F12
7-
public class UIDebugger : Control
7+
public class UIGameConsole : PanelContainer
88
{
99
[Export] public readonly NodePath NodePathLogs;
1010
[Export] public readonly NodePath NodePathConsole;
1111

12-
public static UIDebugger Instance { get; set; }
13-
private static TextEdit Logs { get; set; }
12+
private TextEdit Logs { get; set; }
1413

1514
private LineEdit Console { get; set; } // the console input
1615

1716
public override void _Ready()
1817
{
19-
Instance = this;
2018
Logs = GetNode<TextEdit>(NodePathLogs);
2119
Console = GetNode<LineEdit>(NodePathConsole);
2220
}
2321

24-
public static void AddException(Exception e) => AddMessage($"{e.Message}\n{e.StackTrace}");
22+
public void AddException(Exception e) => AddMessage($"{e.Message}\n{e.StackTrace}");
2523

26-
public static void AddMessage(string message)
24+
public void AddMessage(string message)
2725
{
2826
Logs.Text += $"{message}\n";
2927
ScrollToBottom();
3028
}
3129

32-
public static void ToggleVisibility()
30+
public void ToggleVisibility()
3331
{
34-
Instance.Visible = !Instance.Visible;
35-
Instance.Console.GrabFocus();
32+
Visible = !Visible;
33+
Console.GrabFocus();
3634
ScrollToBottom();
3735
}
3836

39-
private static void ScrollToBottom() => Logs.ScrollVertical = Mathf.Inf;
37+
private void ScrollToBottom() => Logs.ScrollVertical = Mathf.Inf;
4038

4139
private void _on_Console_text_entered(string text)
4240
{

Scripts/Netcode/Common/Utils/Logger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static void Dequeue()
7575
Console.ResetColor();
7676

7777
#if CLIENT
78-
UIDebugger.AddMessage(text);
78+
GameManager.GameConsole.AddMessage(text);
7979
#endif
8080
break;
8181
case LoggerOpcode.LogError:
@@ -91,7 +91,7 @@ public static void Dequeue()
9191

9292
#if CLIENT
9393
ErrorNotifier.IncrementErrorCount();
94-
UIDebugger.AddMessage(errorText);
94+
GameManager.GameConsole.AddMessage(errorText);
9595
#endif
9696
break;
9797
}

Scripts/Scenes/Main/GameManager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ namespace GodotModules
77
{
88
public class GameManager : Node
99
{
10+
[Export] public readonly NodePath NodePathGameConsole;
11+
public static UIGameConsole GameConsole { get; set; }
12+
1013
public static string GameName = "Godot Modules";
1114
public static OptionsData Options { get; set; }
1215
public static SceneTree GameTree { get; set; }
1316

1417
public override void _Ready()
1518
{
1619
GameTree = GetTree();
20+
GameConsole = GetNode<UIGameConsole>(NodePathGameConsole);
1721
}
1822

1923
public override async void _Process(float delta)
@@ -27,7 +31,7 @@ public override void _Input(InputEvent @event)
2731
{
2832
if (Input.IsActionJustPressed("ui_debug"))
2933
{
30-
UIDebugger.ToggleVisibility();
34+
GameConsole.ToggleVisibility();
3135
}
3236

3337
if (Input.IsActionJustPressed("ui_fullscreen"))

Scripts/Scenes/Main/SceneManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public static void EscapePressed(Action action)
6161
{
6262
if (Input.IsActionJustPressed("ui_cancel"))
6363
{
64-
if (UIDebugger.Instance.Visible)
64+
if (GameManager.GameConsole.Visible)
6565
{
66-
UIDebugger.ToggleVisibility();
66+
GameManager.GameConsole.ToggleVisibility();
6767
return;
6868
}
6969

0 commit comments

Comments
 (0)