mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 10:25:54 +00:00
Item Notifications
This commit is contained in:
parent
fc35baeaba
commit
0438ed4a04
8 changed files with 98 additions and 25 deletions
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=22 format=3 uid="uid://dkwi1hu1bixoe"]
|
||||
[gd_scene load_steps=23 format=3 uid="uid://dkwi1hu1bixoe"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://baf6pxbvhqmjk" path="res://Scripts/Hud.cs" id="1_m0hb0"]
|
||||
[ext_resource type="FontFile" uid="uid://ccm3u37q1hvux" path="res://fonts/Xolonium-Regular.ttf" id="2_0xmx2"]
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
[ext_resource type="LabelSettings" uid="uid://buk3e7bbwmnv1" path="res://Resources/Styles/Hud_Text_Style.tres" id="2_x7kl7"]
|
||||
[ext_resource type="Texture2D" uid="uid://dde36pgb8fbwc" path="res://Sprites/selector_big.png" id="3_hee3i"]
|
||||
[ext_resource type="PackedScene" uid="uid://bybd38ivpb2ly" path="res://Scenes/HUD/pause_menu.tscn" id="3_hxmxt"]
|
||||
[ext_resource type="PackedScene" uid="uid://cq342rj7ibnqy" path="res://Scenes/HUD/ItemNotification.tscn" id="3_mw35l"]
|
||||
[ext_resource type="PackedScene" uid="uid://bemu3l6b1e84y" path="res://Scenes/HUD/debug_menu.tscn" id="4_gd1k6"]
|
||||
[ext_resource type="PackedScene" uid="uid://bwlstkdibs7oc" path="res://Scenes/HUD/BossHud.tscn" id="5_vmict"]
|
||||
[ext_resource type="FontFile" uid="uid://coek1e2q257pq" path="res://fonts/at01.ttf" id="6_sk1eq"]
|
||||
|
|
@ -70,6 +71,7 @@ anti_aliasing = false
|
|||
process_mode = 3
|
||||
script = ExtResource("1_m0hb0")
|
||||
WeaponContainerTemplate = ExtResource("2_mattb")
|
||||
ItemNotificationTemplate = ExtResource("3_mw35l")
|
||||
_healthLabel = NodePath("VBoxContainer/HealthBarContainer/HealthLabel")
|
||||
_healthBar = NodePath("VBoxContainer/HealthBarContainer/HealthBar")
|
||||
_shieldLabel = NodePath("VBoxContainer/ShieldBarContainer/ShieldLabel")
|
||||
|
|
@ -167,6 +169,7 @@ label_settings = ExtResource("2_x7kl7")
|
|||
|
||||
[node name="ItemsContainer" type="VBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/separation = 0
|
||||
|
||||
[node name="BossHud" parent="." instance=ExtResource("5_vmict")]
|
||||
|
|
|
|||
|
|
@ -5,39 +5,30 @@
|
|||
[ext_resource type="LabelSettings" uid="uid://buk3e7bbwmnv1" path="res://Resources/Styles/Hud_Text_Style.tres" id="3_a6rek"]
|
||||
[ext_resource type="Texture2D" uid="uid://c5g0qg6u2gm6f" path="res://Sprites/Items/Ammo1.png" id="4_kbanm"]
|
||||
|
||||
[node name="HudItemContainer" type="Control" node_paths=PackedStringArray("Icon", "AmmoIcon", "TotalAmmoLabel", "LoadedAmmoLabel")]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_pwei3")
|
||||
Icon = NodePath("HBoxContainer/WeaponIcon")
|
||||
AmmoIcon = NodePath("HBoxContainer/Ammo Icon")
|
||||
TotalAmmoLabel = NodePath("HBoxContainer/TotalAmmo")
|
||||
LoadedAmmoLabel = NodePath("HBoxContainer/LoadedAmmo")
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
offset_right = 16.0
|
||||
[node name="HudItemContainer" type="HBoxContainer" node_paths=PackedStringArray("Icon", "AmmoIcon", "TotalAmmoLabel", "LoadedAmmoLabel")]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 16.0
|
||||
theme_override_constants/separation = 0
|
||||
script = ExtResource("1_pwei3")
|
||||
Icon = NodePath("WeaponIcon")
|
||||
AmmoIcon = NodePath("Ammo Icon")
|
||||
TotalAmmoLabel = NodePath("TotalAmmo")
|
||||
LoadedAmmoLabel = NodePath("LoadedAmmo")
|
||||
|
||||
[node name="WeaponIcon" type="TextureRect" parent="HBoxContainer"]
|
||||
[node name="WeaponIcon" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("2_pqw4t")
|
||||
|
||||
[node name="LoadedAmmo" type="Label" parent="HBoxContainer"]
|
||||
[node name="LoadedAmmo" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "0"
|
||||
label_settings = ExtResource("3_a6rek")
|
||||
|
||||
[node name="Ammo Icon" type="TextureRect" parent="HBoxContainer"]
|
||||
[node name="Ammo Icon" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("4_kbanm")
|
||||
|
||||
[node name="TotalAmmo" type="Label" parent="HBoxContainer"]
|
||||
[node name="TotalAmmo" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "0"
|
||||
label_settings = ExtResource("3_a6rek")
|
||||
|
|
|
|||
22
Scenes/HUD/ItemNotification.tscn
Normal file
22
Scenes/HUD/ItemNotification.tscn
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://cq342rj7ibnqy"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bysbukjjv8nc2" path="res://Scripts/UI/ItemNotification.cs" id="1_g1ix0"]
|
||||
[ext_resource type="Texture2D" uid="uid://duwiasewxvcb5" path="res://Sprites/Items/Icicle_Gun.png" id="2_5xd0r"]
|
||||
[ext_resource type="LabelSettings" uid="uid://buk3e7bbwmnv1" path="res://Resources/Styles/Hud_Text_Style.tres" id="3_lpbqr"]
|
||||
|
||||
[node name="ItemNotification" type="HBoxContainer" node_paths=PackedStringArray("Icon", "DescriptionLabel")]
|
||||
offset_right = 35.0
|
||||
offset_bottom = 16.0
|
||||
theme_override_constants/separation = 0
|
||||
script = ExtResource("1_g1ix0")
|
||||
Icon = NodePath("ItemIcon")
|
||||
DescriptionLabel = NodePath("Label")
|
||||
|
||||
[node name="ItemIcon" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("2_5xd0r")
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Asdfg"
|
||||
label_settings = ExtResource("3_lpbqr")
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -19,7 +19,12 @@ public partial class Hud : CanvasLayer
|
|||
|
||||
[Export]
|
||||
public PackedScene WeaponContainerTemplate { get; private set; }
|
||||
|
||||
[Export]
|
||||
public PackedScene ItemNotificationTemplate { get; private set; }
|
||||
|
||||
[Export] public float ItemsNotificationTimeout { get; private set; } = 3f;
|
||||
|
||||
[Export]
|
||||
private Node2D _selector;
|
||||
|
||||
|
|
@ -60,8 +65,19 @@ public partial class Hud : CanvasLayer
|
|||
// Assuming the HUD has a Label node named "HealthLabel"
|
||||
//_healthLabel = GetNode<Label>("HealthLabel");
|
||||
_gameOverPanel.Hide();
|
||||
|
||||
InventoryManager.Instance.ItemAdded += OnItemAdded;
|
||||
}
|
||||
|
||||
|
||||
private void OnItemAdded(LootItem item, int currentamount)
|
||||
{
|
||||
var instance = ItemNotificationTemplate.Instantiate<ItemNotification>();
|
||||
|
||||
_itemsContainer.CallDeferred("add_child", instance);
|
||||
|
||||
instance.Init(item, currentamount, ItemsNotificationTimeout);
|
||||
}
|
||||
|
||||
public void ShowMessage(string text)
|
||||
{
|
||||
var message = GetNode<Label>("Message");
|
||||
|
|
|
|||
40
Scripts/UI/ItemNotification.cs
Normal file
40
Scripts/UI/ItemNotification.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.UI;
|
||||
|
||||
public partial class ItemNotification : Container
|
||||
{
|
||||
public LootItem Item { get; private set; }
|
||||
[Export]
|
||||
public TextureRect Icon { get; private set; }
|
||||
[Export]
|
||||
public Label DescriptionLabel { get; private set; }
|
||||
|
||||
private double _counter = 0;
|
||||
private double _timeout = 0;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
_counter += delta;
|
||||
if (_counter >= _timeout)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
public void Init(LootItem item, int total, float timeout)
|
||||
{
|
||||
_timeout = timeout;
|
||||
_counter = 0;
|
||||
Item = item;
|
||||
|
||||
UpdateCounter(item, total);
|
||||
}
|
||||
|
||||
private void UpdateCounter(LootItem item, int total)
|
||||
{
|
||||
DescriptionLabel.Text = $"{item.ItemName} +{item.Amount} ({total})";
|
||||
Icon.Texture = item.InventorySprite;
|
||||
}
|
||||
}
|
||||
1
Scripts/UI/ItemNotification.cs.uid
Normal file
1
Scripts/UI/ItemNotification.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bysbukjjv8nc2
|
||||
|
|
@ -3,7 +3,7 @@ using Godot;
|
|||
|
||||
namespace Cirno.Scripts.UI;
|
||||
|
||||
public partial class WeaponAmmoCounter : Control
|
||||
public partial class WeaponAmmoCounter : Container
|
||||
{
|
||||
public LootItem Item { get; private set; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue