Move files to UI.Inventory namespace

pull/37/head
John Montagu, the 4th Earl of Sandvich 2024-05-29 14:55:23 -07:00
parent b13eb48b99
commit 71f14c5121
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
9 changed files with 208 additions and 42 deletions

View File

@ -1,19 +1,18 @@
using Godot;
using SupaLidlGame.Items;
namespace SupaLidlGame.UI;
namespace SupaLidlGame.UI.Inventory;
public partial class Hotbar : GridContainer
{
[Export]
private Godot.Collections.Array<InventorySlot> _slots;
private Godot.Collections.Array<HotbarSlot> _slots;
public override void _Ready()
{
Events.EventBus.Instance.PlayerInventoryUpdate += OnInventoryUpdate;
}
public void OnInventoryUpdate(Inventory inventory)
public void OnInventoryUpdate(Items.Inventory inventory)
{
GD.Print($"UPDATE: {inventory.SelectedIndex} is selected index.");
for (int i = 0; i < 3; i++)

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://sfs8dpfitpdu"]
[ext_resource type="Script" path="res://UI/Hotbar.cs" id="1_2sak2"]
[ext_resource type="PackedScene" uid="uid://ctad0dkoyw8ad" path="res://UI/InventorySlot.tscn" id="1_ct3cn"]
[ext_resource type="Script" path="res://UI/Inventory/Hotbar.cs" id="1_2sak2"]
[ext_resource type="PackedScene" uid="uid://ctad0dkoyw8ad" path="res://UI/Inventory/InventorySlot.tscn" id="2_upggg"]
[node name="Hotbar" type="GridContainer" node_paths=PackedStringArray("_slots")]
anchors_preset = 1
@ -15,11 +15,11 @@ columns = 3
script = ExtResource("1_2sak2")
_slots = [NodePath("InventorySlot"), NodePath("InventorySlot2"), NodePath("InventorySlot3")]
[node name="InventorySlot" parent="." instance=ExtResource("1_ct3cn")]
[node name="InventorySlot" parent="." instance=ExtResource("2_upggg")]
layout_mode = 2
[node name="InventorySlot2" parent="." instance=ExtResource("1_ct3cn")]
[node name="InventorySlot2" parent="." instance=ExtResource("2_upggg")]
layout_mode = 2
[node name="InventorySlot3" parent="." instance=ExtResource("1_ct3cn")]
[node name="InventorySlot3" parent="." instance=ExtResource("2_upggg")]
layout_mode = 2

View File

@ -0,0 +1,32 @@
using Godot;
using GodotUtilities;
using GodotUtilities.SourceGenerators;
namespace SupaLidlGame.UI.Inventory;
[Scene]
public partial class HotbarSlot : InventorySlot
{
[Node("TextureRect")]
private TextureRect _textureRect;
[Node("Selected")]
private NinePatchRect _selected;
private static Texture2D _placeholderTexture;
private Items.ItemMetadata _item;
private bool _isSelected = false;
public bool IsSelected
{
get => _isSelected;
set
{
_isSelected = value;
_selected.Visible = _isSelected;
_frame.Visible = !_isSelected;
}
}
}

View File

@ -0,0 +1,28 @@
using Godot;
using SupaLidlGame.Items;
namespace SupaLidlGame.UI.Inventory;
public partial class InventoryGrid : GridContainer
{
private SupaLidlGame.Items.Inventory _inventorySource;
public SupaLidlGame.Items.Inventory InventorySource
{
set
{
_inventorySource = value;
}
get => _inventorySource;
}
public override void _Ready()
{
}
public void Redraw()
{
}
}

View File

@ -0,0 +1,8 @@
[gd_scene format=3 uid="uid://chmokkxsy5vas"]
[node name="InventoryGrid" type="GridContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

View File

@ -2,21 +2,18 @@ using Godot;
using GodotUtilities;
using GodotUtilities.SourceGenerators;
namespace SupaLidlGame.UI;
namespace SupaLidlGame.UI.Inventory;
[Scene]
public partial class InventorySlot : ColorRect
{
[Node("TextureRect")]
private TextureRect _textureRect;
protected TextureRect _textureRect;
[Node("Selected")]
private NinePatchRect _selected;
protected NinePatchRect _frame;
[Node("Unselected")]
private NinePatchRect _unselected;
private static Texture2D _placeholderTexture;
protected static Texture2D _placeholderTexture;
private Items.ItemMetadata _item;
@ -29,7 +26,6 @@ public partial class InventorySlot : ColorRect
if (_item is null)
{
//_textureRect.Texture = _placeholderTexture;
_textureRect.Texture = null;
}
else
@ -39,19 +35,6 @@ public partial class InventorySlot : ColorRect
}
}
private bool _isSelected = false;
public bool IsSelected
{
get => _isSelected;
set
{
_isSelected = value;
_selected.Visible = _isSelected;
_unselected.Visible = !_isSelected;
}
}
static InventorySlot()
{
_placeholderTexture = ResourceLoader.Load<Texture2D>(
@ -66,9 +49,4 @@ public partial class InventorySlot : ColorRect
}
base._Notification(what);
}
public override void _Ready()
{
}
}

View File

@ -1,13 +1,12 @@
[gd_scene load_steps=4 format=3 uid="uid://ctad0dkoyw8ad"]
[gd_scene load_steps=3 format=3 uid="uid://ctad0dkoyw8ad"]
[ext_resource type="Script" path="res://UI/InventorySlot.cs" id="1_llonk"]
[ext_resource type="Texture2D" uid="uid://bd81g8aivb2ql" path="res://Assets/Sprites/UI/menu-rect-no-bg-32.png" id="2_vvog5"]
[ext_resource type="Texture2D" uid="uid://b16461tjso0j7" path="res://Assets/Sprites/UI/hotbar-inactive.png" id="3_jr23q"]
[ext_resource type="Script" path="res://UI/Inventory/InventorySlot.cs" id="1_tj1me"]
[ext_resource type="Texture2D" uid="uid://dc1gcsbhkchvg" path="res://Assets/Sprites/UI/hotbar-active.png" id="2_m56j3"]
[node name="InventorySlot" type="ColorRect"]
custom_minimum_size = Vector2(32, 32)
color = Color(1, 1, 1, 0)
script = ExtResource("1_llonk")
script = ExtResource("1_tj1me")
[node name="TextureRect" type="TextureRect" parent="."]
layout_mode = 1
@ -26,7 +25,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("2_vvog5")
texture = ExtResource("2_m56j3")
[node name="Unselected" type="NinePatchRect" parent="."]
self_modulate = Color(1, 1, 1, 0.5)
@ -36,4 +35,4 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("3_jr23q")
texture = ExtResource("2_m56j3")

View File

@ -0,0 +1,44 @@
[gd_scene load_steps=4 format=3 uid="uid://bsheehtfcdwhh"]
[ext_resource type="Theme" uid="uid://cksjbu3vrup5" path="res://UI/Themes/supalidl.tres" id="1_elbte"]
[ext_resource type="Texture2D" uid="uid://dp7osg05ip5oo" path="res://Assets/Sprites/sword.png" id="2_5jpi0"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_idehr"]
bg_color = Color(0.976471, 0.956863, 0.956863, 1)
[node name="ShopItem" type="BoxContainer"]
offset_right = 67.0
offset_bottom = 16.0
theme = ExtResource("1_elbte")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 2
theme_override_constants/separation = 0
[node name="Item Margin" type="MarginContainer" parent="VBoxContainer"]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Item Margin"]
layout_mode = 2
[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Item Margin/HBoxContainer"]
layout_mode = 2
texture = ExtResource("2_5jpi0")
[node name="Label" type="Label" parent="VBoxContainer/Item Margin/HBoxContainer"]
layout_mode = 2
text = "Your mom's Item"
[node name="PanelContainer2" type="PanelContainer" parent="VBoxContainer"]
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_idehr")
[node name="DescriptionMargin" type="MarginContainer" parent="VBoxContainer/PanelContainer2"]
layout_mode = 2
theme_override_constants/margin_top = 2
theme_override_constants/margin_bottom = 2
[node name="Label" type="Label" parent="VBoxContainer/PanelContainer2/DescriptionMargin"]
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "250 Shillings"

View File

@ -0,0 +1,78 @@
[gd_scene load_steps=6 format=3 uid="uid://cyggkyqosjk36"]
[ext_resource type="Texture2D" uid="uid://uhmowtsi3wfh" path="res://Assets/Sprites/UI/menu-rect-no-bg-white.png" id="2_puklu"]
[ext_resource type="FontFile" uid="uid://cgwa8bjiyv534" path="res://Assets/Fonts/alagard.ttf" id="3_aj4jx"]
[ext_resource type="PackedScene" uid="uid://ctad0dkoyw8ad" path="res://UI/Inventory/InventorySlot.tscn" id="4_wawb8"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_gm1xk"]
bg_color = Color(0, 0, 0, 0.752941)
border_width_left = 16
border_width_top = 16
border_width_right = 16
border_width_bottom = 16
border_color = Color(0, 0, 0, 0)
border_blend = true
corner_radius_top_left = 16
corner_radius_top_right = 16
corner_radius_bottom_right = 16
corner_radius_bottom_left = 16
[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_bvu21"]
texture = ExtResource("2_puklu")
texture_margin_left = 32.0
texture_margin_top = 32.0
texture_margin_right = 32.0
texture_margin_bottom = 32.0
[node name="Panel" type="PanelContainer"]
anchors_preset = 6
anchor_left = 1.0
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
offset_left = -236.0
offset_top = -175.5
offset_bottom = 175.5
grow_horizontal = 0
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_gm1xk")
[node name="PanelContainer" type="PanelContainer" parent="."]
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxTexture_bvu21")
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="PanelContainer/VBoxContainer"]
layout_mode = 2
theme_override_fonts/font = ExtResource("3_aj4jx")
text = "Snus Dealer"
[node name="GridContainer" type="GridContainer" parent="PanelContainer/VBoxContainer"]
layout_mode = 2
columns = 4
[node name="InventorySlot" parent="PanelContainer/VBoxContainer/GridContainer" instance=ExtResource("4_wawb8")]
layout_mode = 2
[node name="InventorySlot2" parent="PanelContainer/VBoxContainer/GridContainer" instance=ExtResource("4_wawb8")]
layout_mode = 2
[node name="InventorySlot3" parent="PanelContainer/VBoxContainer/GridContainer" instance=ExtResource("4_wawb8")]
layout_mode = 2
[node name="InventorySlot4" parent="PanelContainer/VBoxContainer/GridContainer" instance=ExtResource("4_wawb8")]
layout_mode = 2
[node name="InventorySlot5" parent="PanelContainer/VBoxContainer/GridContainer" instance=ExtResource("4_wawb8")]
layout_mode = 2
[node name="InventorySlot6" parent="PanelContainer/VBoxContainer/GridContainer" instance=ExtResource("4_wawb8")]
layout_mode = 2
[node name="InventorySlot7" parent="PanelContainer/VBoxContainer/GridContainer" instance=ExtResource("4_wawb8")]
layout_mode = 2
[node name="InventorySlot8" parent="PanelContainer/VBoxContainer/GridContainer" instance=ExtResource("4_wawb8")]
layout_mode = 2