diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-11-10 12:56:00 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-11-10 12:56:00 -0300 |
| commit | 0f3c49b7743f7c7fabf41fdf4cb3ffe1a4ac3bf4 (patch) | |
| tree | df940efb7502899441295acd5039311b9e6e4927 /scenes | |
| parent | c4f5404211ef654944d5615e9055c714441f8234 (diff) | |
Placar.
Diffstat (limited to 'scenes')
| -rw-r--r-- | scenes/GUI/Leaderboard.cs | 62 | ||||
| -rw-r--r-- | scenes/GUI/Leaderboard.cs.uid | 1 | ||||
| -rw-r--r-- | scenes/GUI/Leaderboard.tscn | 51 | ||||
| -rw-r--r-- | scenes/GUI/leaderboard_item.tscn | 35 | ||||
| -rw-r--r-- | scenes/GUI/main_menu.tscn | 15 |
5 files changed, 163 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") |
