Item HUD management

This commit is contained in:
Marco 2025-01-31 13:03:38 +01:00
commit 13c4489017
17 changed files with 215 additions and 44 deletions

View file

@ -0,0 +1,14 @@
[gd_resource type="Resource" script_class="LootItem" load_steps=3 format=3 uid="uid://ct1fa2huvy34n"]
[ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="1_31o2l"]
[ext_resource type="SpriteFrames" uid="uid://pmwatoyt2ase" path="res://Resources/Sprites/Ammo_Inventory_Sprite.tres" id="1_fubhk"]
[resource]
script = ExtResource("1_31o2l")
Item = 3
Amount = 100
Max = 800
PickupIfMaxed = false
ConsumeOnUse = false
InventorySprite = ExtResource("1_fubhk")
WorldSprite = ExtResource("1_fubhk")

View file

@ -0,0 +1,11 @@
[gd_scene load_steps=4 format=3 uid="uid://j1pbuvw2kduo"]
[ext_resource type="PackedScene" uid="uid://dxs3ks2ucaxl4" path="res://Scenes/Items/Red_Keycard.tscn" id="1_v0ux4"]
[ext_resource type="Resource" uid="uid://ct1fa2huvy34n" path="res://Resources/Items/Ammo1.tres" id="2_2eoli"]
[ext_resource type="SpriteFrames" uid="uid://pmwatoyt2ase" path="res://Resources/Sprites/Ammo_Inventory_Sprite.tres" id="2_8g7mw"]
[node name="Ammo1" instance=ExtResource("1_v0ux4")]
LootTable = [ExtResource("2_2eoli")]
[node name="AnimatedSprite2D" parent="." index="1"]
sprite_frames = ExtResource("2_8g7mw")

View file

@ -1,5 +1,7 @@
[gd_resource type="Resource" script_class="LootItem" load_steps=2 format=3 uid="uid://dibquna7fww7t"]
[gd_resource type="Resource" script_class="LootItem" load_steps=4 format=3 uid="uid://dibquna7fww7t"]
[ext_resource type="SpriteFrames" uid="uid://cikw4v6n0folb" path="res://Resources/Sprites/Red_Keycard_Overworld_Sprite.tres" id="1_1j6xs"]
[ext_resource type="Texture2D" uid="uid://bao53hesxreoh" path="res://Resources/Sprites/Red_Keycard_Inventory_Texture.tres" id="1_glhfu"]
[ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="1_istlt"]
[resource]
@ -7,3 +9,7 @@ script = ExtResource("1_istlt")
Item = 0
Amount = 1
Max = 1
PickupIfMaxed = false
ConsumeOnUse = false
InventorySprite = ExtResource("1_glhfu")
WorldSprite = ExtResource("1_1j6xs")

View file

@ -0,0 +1,18 @@
[gd_resource type="SpriteFrames" load_steps=3 format=3 uid="uid://pmwatoyt2ase"]
[ext_resource type="Texture2D" uid="uid://c5g0qg6u2gm6f" path="res://Sprites/Items/Ammo1.png" id="1_opgo2"]
[sub_resource type="AtlasTexture" id="AtlasTexture_0k673"]
atlas = ExtResource("1_opgo2")
region = Rect2(0, 0, 16, 16)
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_0k673")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]

View file

@ -0,0 +1,18 @@
[gd_resource type="SpriteFrames" load_steps=3 format=3 uid="uid://bnvusxrrd2351"]
[ext_resource type="Texture2D" uid="uid://c53bchw2krocb" path="res://Sprites/Red_Keycard.png" id="1_l8v2c"]
[sub_resource type="AtlasTexture" id="AtlasTexture_us62y"]
atlas = ExtResource("1_l8v2c")
region = Rect2(0, 0, 16, 16)
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_us62y")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]

View file

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://bao53hesxreoh"]
[ext_resource type="Texture2D" uid="uid://bad6gbl2gity3" path="res://Sprites/Items/RedKeycard_Small.png" id="1_eer7d"]
[resource]
atlas = ExtResource("1_eer7d")
region = Rect2(0, 0, 16.0056, 16)

View file

@ -0,0 +1,25 @@
[gd_resource type="SpriteFrames" load_steps=4 format=3 uid="uid://cikw4v6n0folb"]
[ext_resource type="Texture2D" uid="uid://bad6gbl2gity3" path="res://Sprites/Items/RedKeycard_Small.png" id="1_shn5c"]
[sub_resource type="AtlasTexture" id="AtlasTexture_o0au0"]
atlas = ExtResource("1_shn5c")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_fx6tu"]
atlas = ExtResource("1_shn5c")
region = Rect2(16, 0, 16, 16)
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_o0au0")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_fx6tu")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]

View file

@ -26,21 +26,10 @@ animations = [{
"speed": 5.0
}]
[node name="HUD" type="CanvasLayer"]
[node name="HUD" type="CanvasLayer" node_paths=PackedStringArray("_healthLabel", "_itemsContainer")]
script = ExtResource("1_m0hb0")
[node name="HealthLabel" type="Label" parent="."]
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 1.0
offset_top = -160.0
offset_right = 306.0
offset_bottom = -82.0
grow_vertical = 0
theme_override_fonts/font = ExtResource("2_0xmx2")
theme_override_font_sizes/font_size = 12
text = "100/100"
_healthLabel = NodePath("VBoxContainer/HealthLabel")
_itemsContainer = NodePath("VBoxContainer/ItemsContainer")
[node name="GameOver" type="Label" parent="."]
visible = false
@ -69,3 +58,24 @@ position = Vector2(67, 47)
sprite_frames = SubResource("SpriteFrames_78fwv")
frame = 1
frame_progress = 0.8514
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="HealthLabel" type="Label" parent="VBoxContainer"]
layout_mode = 2
theme_override_fonts/font = ExtResource("2_0xmx2")
theme_override_font_sizes/font_size = 12
text = "100/100"
[node name="ItemsContainer" type="VBoxContainer" parent="VBoxContainer"]
layout_mode = 2
[node name="TextureRect" type="TextureRect" parent="VBoxContainer/ItemsContainer"]
layout_mode = 2

11
Scenes/Items/Ammo1.tscn Normal file
View file

@ -0,0 +1,11 @@
[gd_scene load_steps=4 format=3 uid="uid://cmr6fclttrpkb"]
[ext_resource type="PackedScene" uid="uid://dxs3ks2ucaxl4" path="res://Scenes/Items/Red_Keycard.tscn" id="1_i3l7m"]
[ext_resource type="Resource" uid="uid://ct1fa2huvy34n" path="res://Resources/Items/Ammo1.tres" id="2_j10i4"]
[ext_resource type="SpriteFrames" uid="uid://pmwatoyt2ase" path="res://Resources/Sprites/Ammo_Inventory_Sprite.tres" id="3_6n103"]
[node name="Ammo1" instance=ExtResource("1_i3l7m")]
LootTable = [ExtResource("2_j10i4")]
[node name="AnimatedSprite2D" parent="." index="1"]
sprite_frames = ExtResource("3_6n103")

View file

@ -1,33 +1,11 @@
[gd_scene load_steps=8 format=3 uid="uid://dxs3ks2ucaxl4"]
[gd_scene load_steps=5 format=3 uid="uid://dxs3ks2ucaxl4"]
[ext_resource type="Script" path="res://Scripts/Interactables/ItemPickup.cs" id="1_cvvxn"]
[ext_resource type="SpriteFrames" uid="uid://cikw4v6n0folb" path="res://Resources/Sprites/Red_Keycard_Overworld_Sprite.tres" id="3_htu4x"]
[ext_resource type="Resource" uid="uid://dibquna7fww7t" path="res://Resources/Items/Red_Keycard.tres" id="4_84krq"]
[ext_resource type="Texture2D" uid="uid://bad6gbl2gity3" path="res://Sprites/Items/RedKeycard_Small.png" id="4_k5oc1"]
[sub_resource type="CircleShape2D" id="CircleShape2D_6vv2s"]
[sub_resource type="AtlasTexture" id="AtlasTexture_o0au0"]
atlas = ExtResource("4_k5oc1")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_fx6tu"]
atlas = ExtResource("4_k5oc1")
region = Rect2(16, 0, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_vi6i0"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_o0au0")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_fx6tu")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]
[node name="RedKeyCard" type="Area2D" groups=["Interactable"]]
collision_layer = 4
collision_mask = 2
@ -38,4 +16,4 @@ LootTable = [ExtResource("4_84krq")]
shape = SubResource("CircleShape2D_6vv2s")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_vi6i0")
sprite_frames = ExtResource("3_htu4x")

View file

@ -41,7 +41,10 @@ public partial class GameManager : Node2D
_player.HealthChanged += (newHealth, maxHealth) => _hud.UpdateHealth(newHealth, maxHealth);
_player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable);
Inventory.ItemAdded += (item) => _hud.AddInventoryItem(item);
Inventory.ItemRemoved += (item) => _hud.RemoveInventoryItem(item);
//_player.Connect(nameof(_player.HealthChanged), _hud, nameof(_hud.UpdateHealth));
}

View file

@ -1,12 +1,13 @@
using Godot;
using System;
using Cirno.Scripts.Resources;
public partial class Hud : CanvasLayer
{
[Signal]
public delegate void StartGameEventHandler();
private Label _healthLabel;
//private Label _healthLabel;
[Export]
public PackedScene SelectorScene { get; set; }
@ -14,10 +15,13 @@ public partial class Hud : CanvasLayer
[Export]
private Node2D _selector;
[Export] private Label _healthLabel;
[Export] private Container _itemsContainer;
public override void _Ready()
{
// Assuming the HUD has a Label node named "HealthLabel"
_healthLabel = GetNode<Label>("HealthLabel");
//_healthLabel = GetNode<Label>("HealthLabel");
}
public void ShowMessage(string text)
@ -56,4 +60,17 @@ public partial class Hud : CanvasLayer
//_selector.Position = _selector.tolo
}
public void AddInventoryItem(LootItem item)
{
TextureRect texture = new TextureRect();
texture.Texture = item.InventorySprite;
_itemsContainer.AddChild(texture);
}
public void RemoveInventoryItem(LootItem item)
{
}
}

View file

@ -10,6 +10,12 @@ public partial class InventoryManager : Node2D
public bool RedKeycard { get; set; }
private List<LootItem> _items = new List<LootItem>();
[Signal]
public delegate void ItemAddedEventHandler(LootItem item);
[Signal]
public delegate void ItemRemovedEventHandler(LootItem item);
// Called when the node enters the scene tree for the first time.
public override void _Ready()
@ -33,8 +39,10 @@ public partial class InventoryManager : Node2D
public bool AddItem(ItemTypes type, int amount = 1)
{
_items.Add(new LootItem() { Item = type, Amount = amount });
var item = new LootItem() { Item = type, Amount = amount };
_items.Add(item);
GD.Print($"Added {type} x{amount}");
EmitSignal(nameof(ItemAdded), item);
// switch (type)
// {
// // case ItemTypes.KeycardRed:

View file

@ -8,4 +8,9 @@ public partial class LootItem : Resource
[Export] public ItemTypes Item;
[Export] public int Amount;
[Export] public int Max;
[Export] public bool PickupIfMaxed;
[Export] public bool ConsumeOnUse;
[Export] public AtlasTexture InventorySprite;
[Export] public SpriteFrames WorldSprite;
}

BIN
Sprites/Items/Ammo1.aseprite (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Sprites/Items/Ammo1.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c5g0qg6u2gm6f"
path="res://.godot/imported/Ammo1.png-05d86b462dc0f5b4fb8cd16192981dcd.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/Items/Ammo1.png"
dest_files=["res://.godot/imported/Ammo1.png-05d86b462dc0f5b4fb8cd16192981dcd.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1