diff options
Diffstat (limited to 'scenes/GUI')
| -rw-r--r-- | scenes/GUI/Leaderboard.cs | 62 | ||||
| -rw-r--r-- | scenes/GUI/Leaderboard.cs.uid | 1 | ||||
| -rw-r--r-- | scenes/GUI/Leaderboard.tscn | 53 | ||||
| -rw-r--r-- | scenes/GUI/button.tres | 10 | ||||
| -rw-r--r-- | scenes/GUI/leaderboard_item.tscn | 35 | ||||
| -rw-r--r-- | scenes/GUI/main_menu.tscn | 20 |
6 files changed, 180 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..5724e34 --- /dev/null +++ b/scenes/GUI/Leaderboard.tscn @@ -0,0 +1,53 @@ +[gd_scene load_steps=7 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"] +[ext_resource type="StyleBox" uid="uid://krfa04v10vwc" path="res://scenes/GUI/button.tres" id="4_kxih3"] + +[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 +theme_override_styles/normal = ExtResource("4_kxih3") +shortcut = SubResource("Shortcut_kxih3") +text = "[V] Voltar" diff --git a/scenes/GUI/button.tres b/scenes/GUI/button.tres new file mode 100644 index 0000000..601c8f7 --- /dev/null +++ b/scenes/GUI/button.tres @@ -0,0 +1,10 @@ +[gd_resource type="StyleBoxTexture" load_steps=2 format=3 uid="uid://krfa04v10vwc"] + +[ext_resource type="Texture2D" uid="uid://dwg5pwgld1xrr" path="res://assets/sprites/inter-face/button_texture.png" id="1_dju77"] + +[resource] +texture = ExtResource("1_dju77") +texture_margin_left = 2.0 +texture_margin_top = 2.0 +texture_margin_right = 2.0 +texture_margin_bottom = 2.0 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..95700a0 100644 --- a/scenes/GUI/main_menu.tscn +++ b/scenes/GUI/main_menu.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=10 format=3 uid="uid://cppjdsdfkkxtm"] +[gd_scene load_steps=13 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"] +[ext_resource type="StyleBox" uid="uid://krfa04v10vwc" path="res://scenes/GUI/button.tres" id="3_kebck"] [sub_resource type="LabelSettings" id="LabelSettings_b4h60"] font_size = 32 @@ -22,6 +23,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 @@ -71,18 +80,27 @@ label_settings = SubResource("LabelSettings_b4h60") [node name="neogame" type="Button" parent="VBoxContainer/CenterContainer/VBoxContainer"] layout_mode = 2 +theme_override_styles/normal = ExtResource("3_kebck") shortcut = SubResource("Shortcut_b4h60") shortcut_feedback = false text = "[N] Novo jogo" [node name="continue" type="Button" parent="VBoxContainer/CenterContainer/VBoxContainer"] layout_mode = 2 +theme_override_styles/normal = ExtResource("3_kebck") shortcut = SubResource("Shortcut_1ei6q") shortcut_feedback = false text = "[C] Continuar" +[node name="leaderboard" type="Button" parent="VBoxContainer/CenterContainer/VBoxContainer"] +layout_mode = 2 +theme_override_styles/normal = ExtResource("3_kebck") +shortcut = SubResource("Shortcut_kebck") +text = "[P] Placar" + [node name="quit" type="Button" parent="VBoxContainer/CenterContainer/VBoxContainer"] layout_mode = 2 +theme_override_styles/normal = ExtResource("3_kebck") shortcut = SubResource("Shortcut_h03jd") text = "[S] Sair" |
