From f2482e4e38306688f6f1366620f6e7e7f8dbb8b8 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 16 Feb 2025 17:36:33 +0100 Subject: [PATCH] Changed UI sprites to use sprite in resource --- Resources/Items/Blue_Keycard.tres | 8 +++++++- Resources/Items/Cheat_Gun_Item.tres | 4 +++- Resources/Items/Green_Keycard.tres | 8 +++++++- Resources/Items/IceShotgun.tres | 4 +++- Resources/Items/IcicleGun.tres | 4 +++- Scenes/HUD/Items/icicle_gun.tscn | 2 ++ Scripts/Hud.cs | 7 ++++++- Scripts/PlayerMovement.cs | 10 +++++----- Scripts/Resources/LootItem.cs | 2 +- Scripts/Selector.cs | 11 ++++++++++- 10 files changed, 47 insertions(+), 13 deletions(-) diff --git a/Resources/Items/Blue_Keycard.tres b/Resources/Items/Blue_Keycard.tres index 57538c4d..12f1ab05 100644 --- a/Resources/Items/Blue_Keycard.tres +++ b/Resources/Items/Blue_Keycard.tres @@ -1,6 +1,11 @@ -[gd_resource type="Resource" script_class="LootItem" load_steps=2 format=3 uid="uid://cj5aa7btaw6q0"] +[gd_resource type="Resource" script_class="LootItem" load_steps=4 format=3 uid="uid://cj5aa7btaw6q0"] [ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="1_k8cnp"] +[ext_resource type="Texture2D" uid="uid://bvybqletsvqgk" path="res://Sprites/Items/BlueKeycard_Small.png" id="1_sgsjd"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_ebbst"] +atlas = ExtResource("1_sgsjd") +region = Rect2(0, 0, 16, 16) [resource] script = ExtResource("1_k8cnp") @@ -12,3 +17,4 @@ Max = 1 PickupIfMaxed = false ConsumeOnUse = false UiType = 1 +InventorySprite = SubResource("AtlasTexture_ebbst") diff --git a/Resources/Items/Cheat_Gun_Item.tres b/Resources/Items/Cheat_Gun_Item.tres index 4d50e2b8..54b57deb 100644 --- a/Resources/Items/Cheat_Gun_Item.tres +++ b/Resources/Items/Cheat_Gun_Item.tres @@ -1,7 +1,8 @@ -[gd_resource type="Resource" script_class="LootItem" load_steps=4 format=3 uid="uid://cfq121rs3bsu8"] +[gd_resource type="Resource" script_class="LootItem" load_steps=5 format=3 uid="uid://cfq121rs3bsu8"] [ext_resource type="PackedScene" uid="uid://pemr2lrv3ylk" path="res://Scenes/HUD/Items/ying_yang_gun_huditem.tscn" id="1_i6xgq"] [ext_resource type="Resource" uid="uid://ckppo2seg313h" path="res://Resources/Weapons/Cheat_Gun.tres" id="2_0na1t"] +[ext_resource type="Texture2D" uid="uid://61kfxc7k3do" path="res://Sprites/Items/Ying_Yang_Gun.png" id="2_5g5j1"] [ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="3_i0e51"] [resource] @@ -15,4 +16,5 @@ Max = 1 PickupIfMaxed = true ConsumeOnUse = false UiType = 1 +InventorySprite = ExtResource("2_5g5j1") HudItemScene = ExtResource("1_i6xgq") diff --git a/Resources/Items/Green_Keycard.tres b/Resources/Items/Green_Keycard.tres index afee081e..f4eeb7b5 100644 --- a/Resources/Items/Green_Keycard.tres +++ b/Resources/Items/Green_Keycard.tres @@ -1,7 +1,12 @@ -[gd_resource type="Resource" script_class="LootItem" load_steps=2 format=3 uid="uid://cspcgkr0tane2"] +[gd_resource type="Resource" script_class="LootItem" load_steps=4 format=3 uid="uid://cspcgkr0tane2"] +[ext_resource type="Texture2D" uid="uid://bvkjnc3ggp7ba" path="res://Sprites/Items/GreenKeycard_Small.png" id="1_eyk8n"] [ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="1_t0s5w"] +[sub_resource type="AtlasTexture" id="AtlasTexture_iasoh"] +atlas = ExtResource("1_eyk8n") +region = Rect2(0, 0, 16, 16) + [resource] script = ExtResource("1_t0s5w") ItemName = "Green Keycard" @@ -12,3 +17,4 @@ Max = 1 PickupIfMaxed = false ConsumeOnUse = false UiType = 1 +InventorySprite = SubResource("AtlasTexture_iasoh") diff --git a/Resources/Items/IceShotgun.tres b/Resources/Items/IceShotgun.tres index a4d00203..c39756ce 100644 --- a/Resources/Items/IceShotgun.tres +++ b/Resources/Items/IceShotgun.tres @@ -1,7 +1,8 @@ -[gd_resource type="Resource" script_class="LootItem" load_steps=4 format=3 uid="uid://dau0s8ob7qnpc"] +[gd_resource type="Resource" script_class="LootItem" load_steps=5 format=3 uid="uid://dau0s8ob7qnpc"] [ext_resource type="PackedScene" uid="uid://bqb3gbnrkqewt" path="res://Scenes/HUD/Items/ice_shotgun_huditem.tscn" id="1_13ven"] [ext_resource type="Resource" uid="uid://cyntngidhcbkc" path="res://Resources/Weapons/Ice_Shotgun_Weapon.tres" id="2_3le6e"] +[ext_resource type="Texture2D" uid="uid://b46usr10jhmev" path="res://Sprites/Items/Ice_Shotgun.png" id="2_4ibag"] [ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="3_cjfxs"] [resource] @@ -15,4 +16,5 @@ Max = 1 PickupIfMaxed = false ConsumeOnUse = false UiType = 1 +InventorySprite = ExtResource("2_4ibag") HudItemScene = ExtResource("1_13ven") diff --git a/Resources/Items/IcicleGun.tres b/Resources/Items/IcicleGun.tres index ee925646..4706822a 100644 --- a/Resources/Items/IcicleGun.tres +++ b/Resources/Items/IcicleGun.tres @@ -1,7 +1,8 @@ -[gd_resource type="Resource" script_class="LootItem" load_steps=4 format=3 uid="uid://cs3ihltcn2166"] +[gd_resource type="Resource" script_class="LootItem" load_steps=5 format=3 uid="uid://cs3ihltcn2166"] [ext_resource type="Resource" uid="uid://b8apu0l5fm4k" path="res://Resources/Weapons/IcicleGun.tres" id="1_itajb"] [ext_resource type="PackedScene" uid="uid://cicthr1v5v4s2" path="res://Scenes/HUD/Items/icicle_gun.tscn" id="1_lfbsh"] +[ext_resource type="Texture2D" uid="uid://duwiasewxvcb5" path="res://Sprites/Items/Icicle_Gun.png" id="2_eaoas"] [ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="2_hy2hk"] [resource] @@ -15,4 +16,5 @@ Max = 1 PickupIfMaxed = false ConsumeOnUse = false UiType = 1 +InventorySprite = ExtResource("2_eaoas") HudItemScene = ExtResource("1_lfbsh") diff --git a/Scenes/HUD/Items/icicle_gun.tscn b/Scenes/HUD/Items/icicle_gun.tscn index 2251f798..aa124151 100644 --- a/Scenes/HUD/Items/icicle_gun.tscn +++ b/Scenes/HUD/Items/icicle_gun.tscn @@ -3,5 +3,7 @@ [ext_resource type="Texture2D" uid="uid://duwiasewxvcb5" path="res://Sprites/Items/Icicle_Gun.png" id="1_ebd3h"] [node name="IcicleGun" type="TextureRect"] +offset_right = 16.0 +offset_bottom = 16.0 texture = ExtResource("1_ebd3h") stretch_mode = 2 diff --git a/Scripts/Hud.cs b/Scripts/Hud.cs index c0346992..956d945c 100644 --- a/Scripts/Hud.cs +++ b/Scripts/Hud.cs @@ -92,7 +92,12 @@ public partial class Hud : CanvasLayer var hbox = new HBoxContainer(); _itemsContainer.AddChild(hbox); - var instance = item.HudItemScene.Instantiate(); + var instance = new TextureRect(); + instance.Texture = item.InventorySprite; + instance.StretchMode = TextureRect.StretchModeEnum.Keep; + // change transform size? + + //var instance = item.HudItemScene.Instantiate(); //_in.CallDeferred("add_child", instance); hbox.AddChild(instance); diff --git a/Scripts/PlayerMovement.cs b/Scripts/PlayerMovement.cs index 23c2cbac..0d827581 100644 --- a/Scripts/PlayerMovement.cs +++ b/Scripts/PlayerMovement.cs @@ -348,11 +348,11 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible EmitSignal(nameof(InteractableAreaEntered), interactable); if (_selector == null) return; - //_selector.Position = interactable.Position; - _selector.SelectedInteractable = interactable; - //_selector.AddInteractable(interactable); - //_selector.Visible = true; - //_lastInteractable = interactable; + + _selector.AddInteractable(interactable); + + //_selector.SelectedInteractable = interactable; + } } diff --git a/Scripts/Resources/LootItem.cs b/Scripts/Resources/LootItem.cs index e4bf7481..a2af2466 100644 --- a/Scripts/Resources/LootItem.cs +++ b/Scripts/Resources/LootItem.cs @@ -15,7 +15,7 @@ public partial class LootItem : Resource [Export] public bool ConsumeOnUse; [Export] public UiItemType UiType; - [Export] public AtlasTexture InventorySprite; + [Export] public Texture2D InventorySprite; [Export] public SpriteFrames WorldSprite; [Export] public PackedScene HudItemScene; diff --git a/Scripts/Selector.cs b/Scripts/Selector.cs index 103258e3..7ba564c4 100644 --- a/Scripts/Selector.cs +++ b/Scripts/Selector.cs @@ -47,7 +47,15 @@ public partial class Selector : Node2D if (Input.IsActionJustPressed("scan")) { SelectNext(); - + } + + if (SelectedInteractable != null) { + this.Visible = true; + this.GlobalPosition = SelectedInteractable.GlobalPosition; + } + else + { + this.Visible = false; } } @@ -107,6 +115,7 @@ public partial class Selector : Node2D public void UpdatePosition() { + return; if (SelectedInteractable != null) { this.Position = SelectedInteractable.Position;