summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scenes/GUI/Leaderboard.cs62
-rw-r--r--scenes/GUI/Leaderboard.cs.uid1
-rw-r--r--scenes/GUI/Leaderboard.tscn51
-rw-r--r--scenes/GUI/leaderboard_item.tscn35
-rw-r--r--scenes/GUI/main_menu.tscn15
-rw-r--r--scripts/GUI/LeaderboardItem.cs41
-rw-r--r--scripts/GUI/LeaderboardItem.cs.uid1
-rw-r--r--scripts/GUI/MainMenu.cs12
-rw-r--r--scripts/GameManager.cs8
9 files changed, 225 insertions, 1 deletions
diff --git a/scenes/GUI/Leaderboard.cs b/scenes/GUI/Leaderboard.cs
new file mode 100644
index 0000000..cf126c9
--- /dev/null
+++ b/scenes/GUI/Leaderboard.cs
@@ -0,0 +1,62 @@
+using System;
+using Godot;
+using Godot.Collections;
+using TheLegendOfGustav.Utils;
+
+namespace TheLegendOfGustav.GUI;
+public partial class Leaderboard : Control
+{
+ [Signal]
+ public delegate void MenuRequestedEventHandler();
+ private static readonly PackedScene LeaderboardItemScene = GD.Load<PackedScene>("res://scenes/GUI/leaderboard_item.tscn");
+
+ private VBoxContainer leaderboard;
+ private Button BackButton;
+ // Called when the node enters the scene tree for the first time.
+ public override void _Ready()
+ {
+ leaderboard = GetNode<VBoxContainer>("VBoxContainer/VBoxContainer");
+ BackButton = GetNode<Button>("VBoxContainer/exit");
+
+ BackButton.Pressed += () => EmitSignal(SignalName.MenuRequested);
+
+ bool hasLeaderboardFile = FileAccess.FileExists("user://placar.json");
+ if (hasLeaderboardFile)
+ {
+ using var leaderboardFile = FileAccess.Open("user://placar.json", FileAccess.ModeFlags.Read);
+ string boardString = leaderboardFile.GetLine();
+
+ Dictionary<string, Variant> leaderBoardData;
+
+ try
+ {
+ var parseResult = Json.ParseString(boardString);
+ if (parseResult.VariantType == Variant.Type.Nil)
+ {
+ throw new Exception();
+ }
+ leaderBoardData = (Dictionary<string, Variant>)parseResult;
+ }
+ catch (Exception)
+ {
+ // Arquivo inválido.
+ return;
+ }
+
+ Array<Dictionary<string, Variant>> players = (Array<Dictionary<string, Variant>>)leaderBoardData["placar"];
+
+ foreach (Dictionary<string, Variant> player in players)
+ {
+ LeaderboardItem item = LeaderboardItemScene.Instantiate<LeaderboardItem>();
+
+ item.PlayerName = (string)player["jogador"];
+ item.Floor = (string)player["andar_mais_fundo"];
+ item.Kills = (string)player["inimigos_mortos"];
+ item.Damage = (string)player["dano_tomado"];
+
+ leaderboard.AddChild(item);
+ }
+
+ }
+ }
+}
diff --git a/scenes/GUI/Leaderboard.cs.uid b/scenes/GUI/Leaderboard.cs.uid
new file mode 100644
index 0000000..4681d98
--- /dev/null
+++ b/scenes/GUI/Leaderboard.cs.uid
@@ -0,0 +1 @@
+uid://bj6r5oalajbmc
diff --git a/scenes/GUI/Leaderboard.tscn b/scenes/GUI/Leaderboard.tscn
new file mode 100644
index 0000000..05471f3
--- /dev/null
+++ b/scenes/GUI/Leaderboard.tscn
@@ -0,0 +1,51 @@
+[gd_scene load_steps=6 format=3 uid="uid://ddxrecok5ctss"]
+
+[ext_resource type="Script" uid="uid://bj6r5oalajbmc" path="res://scenes/GUI/Leaderboard.cs" id="1_8w6tf"]
+[ext_resource type="Texture2D" uid="uid://bxjwbucke02gl" path="res://assets/bg.png" id="1_dlctp"]
+[ext_resource type="PackedScene" uid="uid://w4oy340d3ugn" path="res://scenes/GUI/leaderboard_item.tscn" id="2_8w6tf"]
+
+[sub_resource type="InputEventKey" id="InputEventKey_8w6tf"]
+device = -1
+keycode = 86
+unicode = 118
+
+[sub_resource type="Shortcut" id="Shortcut_kxih3"]
+events = [SubResource("InputEventKey_8w6tf")]
+
+[node name="Control" type="Control"]
+layout_mode = 3
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+script = ExtResource("1_8w6tf")
+
+[node name="TextureRect" type="TextureRect" parent="."]
+layout_mode = 1
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+texture = ExtResource("1_dlctp")
+expand_mode = 3
+
+[node name="VBoxContainer" type="VBoxContainer" parent="."]
+layout_mode = 1
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+
+[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer"]
+layout_mode = 2
+
+[node name="Header" parent="VBoxContainer/VBoxContainer" instance=ExtResource("2_8w6tf")]
+layout_mode = 2
+
+[node name="exit" type="Button" parent="VBoxContainer"]
+layout_mode = 2
+shortcut = SubResource("Shortcut_kxih3")
+text = "[V] Voltar"
diff --git a/scenes/GUI/leaderboard_item.tscn b/scenes/GUI/leaderboard_item.tscn
new file mode 100644
index 0000000..4cee6d3
--- /dev/null
+++ b/scenes/GUI/leaderboard_item.tscn
@@ -0,0 +1,35 @@
+[gd_scene load_steps=2 format=3 uid="uid://w4oy340d3ugn"]
+
+[ext_resource type="Script" uid="uid://cbjltiujfsw4v" path="res://scripts/GUI/LeaderboardItem.cs" id="1_ilpit"]
+
+[node name="HBoxContainer" type="HBoxContainer"]
+script = ExtResource("1_ilpit")
+
+[node name="hdNome" type="Label" parent="."]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "Nome"
+
+[node name="VSeparator" type="VSeparator" parent="."]
+layout_mode = 2
+
+[node name="hdAndar" type="Label" parent="."]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "Maior Andar"
+
+[node name="VSeparator2" type="VSeparator" parent="."]
+layout_mode = 2
+
+[node name="hdkills" type="Label" parent="."]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "Inimigos Mortos"
+
+[node name="VSeparator3" type="VSeparator" parent="."]
+layout_mode = 2
+
+[node name="hddamage" type="Label" parent="."]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "Dano tomado"
diff --git a/scenes/GUI/main_menu.tscn b/scenes/GUI/main_menu.tscn
index 2794830..f2ed0ae 100644
--- a/scenes/GUI/main_menu.tscn
+++ b/scenes/GUI/main_menu.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=10 format=3 uid="uid://cppjdsdfkkxtm"]
+[gd_scene load_steps=12 format=3 uid="uid://cppjdsdfkkxtm"]
[ext_resource type="Script" uid="uid://dx0fxht2oadb6" path="res://scripts/GUI/MainMenu.cs" id="1_b4h60"]
[ext_resource type="Texture2D" uid="uid://bxjwbucke02gl" path="res://assets/bg.png" id="1_tbt31"]
@@ -22,6 +22,14 @@ unicode = 99
[sub_resource type="Shortcut" id="Shortcut_1ei6q"]
events = [SubResource("InputEventKey_kebck")]
+[sub_resource type="InputEventKey" id="InputEventKey_b4h60"]
+device = -1
+keycode = 80
+unicode = 112
+
+[sub_resource type="Shortcut" id="Shortcut_kebck"]
+events = [SubResource("InputEventKey_b4h60")]
+
[sub_resource type="InputEventKey" id="InputEventKey_xm7ak"]
device = -1
keycode = 83
@@ -81,6 +89,11 @@ shortcut = SubResource("Shortcut_1ei6q")
shortcut_feedback = false
text = "[C] Continuar"
+[node name="leaderboard" type="Button" parent="VBoxContainer/CenterContainer/VBoxContainer"]
+layout_mode = 2
+shortcut = SubResource("Shortcut_kebck")
+text = "[P] Placar"
+
[node name="quit" type="Button" parent="VBoxContainer/CenterContainer/VBoxContainer"]
layout_mode = 2
shortcut = SubResource("Shortcut_h03jd")
diff --git a/scripts/GUI/LeaderboardItem.cs b/scripts/GUI/LeaderboardItem.cs
new file mode 100644
index 0000000..c05bf58
--- /dev/null
+++ b/scripts/GUI/LeaderboardItem.cs
@@ -0,0 +1,41 @@
+using Godot;
+
+namespace TheLegendOfGustav.GUI;
+
+public partial class LeaderboardItem : HBoxContainer
+{
+ [Export]
+ public string PlayerName { get; set; } = "Jogador";
+ [Export]
+ public string Floor { get; set; } = "Andar Máximo";
+ [Export]
+ public string Kills { get; set; } = "Inimigos Mortos";
+ [Export]
+ public string Damage { get; set; } = "Dano tomado";
+
+ private Label nameLabel;
+ private Label floorLabel;
+ private Label killsLabel;
+ private Label damageLabel;
+
+
+ // Called when the node enters the scene tree for the first time.
+ public override void _Ready()
+ {
+ nameLabel = GetNode<Label>("hdNome");
+ floorLabel = GetNode<Label>("hdAndar");
+ killsLabel = GetNode<Label>("hdkills");
+ damageLabel = GetNode<Label>("hddamage");
+
+
+ UpdateLabels();
+ }
+
+ public void UpdateLabels()
+ {
+ nameLabel.Text = PlayerName;
+ floorLabel.Text = Floor;
+ killsLabel.Text = Kills;
+ damageLabel.Text = Damage;
+ }
+}
diff --git a/scripts/GUI/LeaderboardItem.cs.uid b/scripts/GUI/LeaderboardItem.cs.uid
new file mode 100644
index 0000000..ddac2bd
--- /dev/null
+++ b/scripts/GUI/LeaderboardItem.cs.uid
@@ -0,0 +1 @@
+uid://cbjltiujfsw4v
diff --git a/scripts/GUI/MainMenu.cs b/scripts/GUI/MainMenu.cs
index fc46cd2..0d6c8c6 100644
--- a/scripts/GUI/MainMenu.cs
+++ b/scripts/GUI/MainMenu.cs
@@ -7,9 +7,12 @@ public partial class MainMenu : Control
private Button newGameButton;
private Button loadGameButton;
private Button quitButton;
+ private Button leaderboardButton;
[Signal]
public delegate void GameRequestEventHandler(bool load);
+ [Signal]
+ public delegate void LeaderboardRequestEventHandler();
public override void _Ready()
{
@@ -18,14 +21,18 @@ public partial class MainMenu : Control
newGameButton = GetNode<Button>("VBoxContainer/CenterContainer/VBoxContainer/neogame");
loadGameButton = GetNode<Button>("VBoxContainer/CenterContainer/VBoxContainer/continue");
quitButton = GetNode<Button>("VBoxContainer/CenterContainer/VBoxContainer/quit");
+ leaderboardButton = GetNode<Button>("VBoxContainer/CenterContainer/VBoxContainer/leaderboard");
newGameButton.Pressed += OnNewGameButtonPressed;
loadGameButton.Pressed += OnLoadGameButtonPressed;
quitButton.Pressed += OnQuitButtonPressed;
+ leaderboardButton.Pressed += OnLeaderBoardRequest;
newGameButton.GrabFocus();
bool hasSaveFile = FileAccess.FileExists("user://save_game.json");
+ bool hasLeaderboard = FileAccess.FileExists("user://placar.json");
loadGameButton.Disabled = !hasSaveFile;
+ leaderboardButton.Disabled = !hasLeaderboard;
}
private void OnNewGameButtonPressed()
@@ -38,6 +45,11 @@ public partial class MainMenu : Control
EmitSignal(SignalName.GameRequest, true);
}
+ private void OnLeaderBoardRequest()
+ {
+ EmitSignal(SignalName.LeaderboardRequest);
+ }
+
private void OnQuitButtonPressed()
{
GetTree().Quit();
diff --git a/scripts/GameManager.cs b/scripts/GameManager.cs
index df93954..4215475 100644
--- a/scripts/GameManager.cs
+++ b/scripts/GameManager.cs
@@ -10,6 +10,7 @@ public partial class GameManager : Node
private PackedScene mainMenuScene = GD.Load<PackedScene>("res://scenes/GUI/main_menu.tscn");
private PackedScene gameScene = GD.Load<PackedScene>("res://scenes/Game.tscn");
private PackedScene nameScene = GD.Load<PackedScene>("res://scenes/name_thyself.tscn");
+ private PackedScene leaderboardScene = GD.Load<PackedScene>("res://scenes/GUI/Leaderboard.tscn");
private Node currentScene;
@@ -44,6 +45,7 @@ public partial class GameManager : Node
MainMenu menu = (MainMenu)SwitchToScene(mainMenuScene);
Stats.Instance.Clear();
menu.GameRequest += OnGameRequest;
+ menu.LeaderboardRequest += OnLeaderboardRequest;
}
private void LoadGame()
@@ -88,4 +90,10 @@ public partial class GameManager : Node
LoadGame();
}
}
+
+ private void OnLeaderboardRequest()
+ {
+ Leaderboard scene = (Leaderboard)SwitchToScene(leaderboardScene);
+ scene.MenuRequested += LoadMainMenu;
+ }
}