Skip to content

Commit

Permalink
Add a temp item to the player's inventory to test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Makosai committed Sep 30, 2023
1 parent b1fcab6 commit d33e0d0
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 14 deletions.
8 changes: 8 additions & 0 deletions scripts/inventory/category_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ class_name CategoryData extends Resource

@export var name: String = ""
@export var slots: Array[SlotData]

func add_item(item: ItemData):
var new_slot = SlotData.new()
new_slot.item = item
new_slot.quantity = 1

slots.append(new_slot)
return self
20 changes: 20 additions & 0 deletions scripts/inventory/inventory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,23 @@ func add_category(name: String, slots: Array[SlotData] = []):

categories.append(new_category)
return self

func add_item(category_name: String, item: ItemData):
var category: CategoryData = get_category(category_name)
category.add_item(item)
return self

func get_category(category_name: String) -> CategoryData:
var filtered = categories.filter(func(elem): return elem.name == category_name)

# Category doesn't exist
if filtered.size() <= 0:
return

var category = filtered.front()

# Shouldn't happen, but be safe and end if null.
if category == null:
return

return category
19 changes: 18 additions & 1 deletion scripts/inventory/player_inventory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var current_tab = Tab.WEAPONS
# Resources
@export var ui_header_atlas: CompressedTexture2D
@export var header_tab: PackedScene
@export var inventory_item: PackedScene

# Cache
var header_tab_nodes: Array[Control]
Expand Down Expand Up @@ -58,9 +59,25 @@ func create_inventory():
.add_category(keys[Tab.EQUIPMENT])
.add_category(keys[Tab.MATERIALS]))

inventory.add_item(keys[Tab.WEAPONS], load("res://scripts/items/1000_wooden_sword.tres"))

func setup_ui():
setup_header_tabs()
update_inventory_items()

func update_inventory_items():
var keys = Tab.keys()
var items: Array[SlotData] = inventory.get_category(keys[current_tab]).slots

for slot in items:
var item = slot.item
var node = inventory_item.instantiate() as Control
var label = node.get_node("Label") as Label
label.text = item.name
var icon = node.get_node("Icon") as TextureRect
icon.texture

%CurrentItems.add_child(node)

class HeaderTab:
var name: String
Expand All @@ -86,7 +103,7 @@ func setup_header_tabs():

var node = header_tab.instantiate() as Control
node.name = tab.name
if tab.name == starting_tab:
if tab.name == keys[starting_tab]:
update_indicator_pos(i)

var btn: Button = node.get_node("Button") as Button
Expand Down
2 changes: 1 addition & 1 deletion scripts/inventory/slot_data.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class_name SlotData extends Resource

@export var item_data: ItemData
@export var item: ItemData
@export var quantity: int = 1
109 changes: 109 additions & 0 deletions scripts/inventory/ui/inventory_item.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
[gd_scene load_steps=6 format=3 uid="uid://mnb51x6xo73p"]

[ext_resource type="FontFile" uid="uid://csid2dfym77r7" path="res://fonts/Nunito/static/Nunito-Bold.ttf" id="1_r5ffr"]
[ext_resource type="Texture2D" uid="uid://d7eyaepxetvj" path="res://scripts/items/1000_wooden_sword_atlas.tres" id="2_aa0ph"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2aphv"]
bg_color = Color(0.0803, 0.448463, 0.73, 1)
corner_radius_top_left = 8
corner_radius_top_right = 8
corner_radius_bottom_right = 8
corner_radius_bottom_left = 8

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_avagm"]
bg_color = Color(0.984314, 0.980392, 0.960784, 1)
corner_radius_top_right = 24
corner_radius_bottom_right = 8
corner_radius_bottom_left = 8

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_o7x11"]
bg_color = Color(0.078125, 0.445313, 0.726563, 1)
corner_radius_bottom_left = 12

[node name="InventoryItem" type="Control"]
custom_minimum_size = Vector2(96, 120)
layout_mode = 3
anchors_preset = 0
offset_right = 96.0
offset_bottom = 120.0

[node name="BG1" type="Panel" parent="."]
clip_contents = true
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_2aphv")

[node name="Design" type="Control" parent="BG1"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="TextBG1" type="Panel" parent="BG1/Design"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = 78.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_avagm")

[node name="TextBG2" type="Panel" parent="BG1/Design"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -1.0
offset_top = 48.0
offset_right = -24.0
offset_bottom = -20.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_avagm")

[node name="TextBG3" type="Panel" parent="BG1/Design"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -1.0
offset_top = 46.0
offset_right = 1.0
offset_bottom = -42.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_o7x11")

[node name="Label" type="Label" parent="."]
custom_minimum_size = Vector2(96, 36)
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_top = -36.0
offset_right = 96.0
grow_vertical = 0
theme_override_colors/font_color = Color(0.0941176, 0.101961, 0.0941176, 1)
theme_override_constants/line_spacing = -1
theme_override_fonts/font = ExtResource("1_r5ffr")
theme_override_font_sizes/font_size = 12
text = "Wooden Sword of the Damned"
horizontal_alignment = 1
vertical_alignment = 1
autowrap_mode = 3

[node name="Icon" type="TextureRect" parent="."]
custom_minimum_size = Vector2(96, 78)
layout_mode = 2
offset_right = 96.0
offset_bottom = 78.0
texture = ExtResource("2_aa0ph")
expand_mode = 3
stretch_mode = 5
30 changes: 28 additions & 2 deletions scripts/inventory/ui/player_inventory.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[gd_scene load_steps=10 format=3 uid="uid://dud8gf6n8gvk"]
[gd_scene load_steps=12 format=3 uid="uid://dud8gf6n8gvk"]

[ext_resource type="Shader" path="res://shaders/screen_space/blur.gdshader" id="1_26j76"]
[ext_resource type="Script" path="res://scripts/inventory/player_inventory.gd" id="1_42t1g"]
[ext_resource type="Theme" uid="uid://cvudtn0hd6gap" path="res://scenes/main_menu/main_menu.tres" id="2_oytrn"]
[ext_resource type="Texture2D" uid="uid://br4fw1ofxo8ib" path="res://assets/ui/ui_header_atlas.png" id="3_7rn8e"]
[ext_resource type="FontFile" uid="uid://db8hdu6hj307i" path="res://fonts/Nunito/static/Nunito-ExtraBold.ttf" id="3_hyp47"]
[ext_resource type="PackedScene" uid="uid://cgd2msq0xf0d8" path="res://scripts/inventory/ui/header_tab.tscn" id="4_bogme"]
[ext_resource type="PackedScene" uid="uid://mnb51x6xo73p" path="res://scripts/inventory/ui/inventory_item.tscn" id="4_to4l4"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_2aahi"]
shader = ExtResource("1_26j76")
Expand All @@ -14,6 +15,10 @@ shader_parameter/amount = 3.0
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kavop"]
bg_color = Color(0.027451, 0.14902, 0.239216, 0.784314)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_hl1u6"]
bg_color = Color(0.984314, 0.980392, 0.960784, 1)
corner_radius_bottom_right = 77

[sub_resource type="AtlasTexture" id="AtlasTexture_07wub"]
atlas = ExtResource("3_7rn8e")
region = Rect2(0, 0, 128, 128)
Expand All @@ -28,6 +33,7 @@ grow_vertical = 2
script = ExtResource("1_42t1g")
ui_header_atlas = ExtResource("3_7rn8e")
header_tab = ExtResource("4_bogme")
inventory_item = ExtResource("4_to4l4")

[node name="Content" type="MarginContainer" parent="."]
layout_mode = 1
Expand All @@ -47,7 +53,15 @@ color = Color(1, 0.14902, 1, 1)
[node name="MarginContainer" type="MarginContainer" parent="Content"]
layout_mode = 2
mouse_filter = 2
theme_override_constants/margin_top = 77
theme_override_constants/margin_left = 24
theme_override_constants/margin_top = 101
theme_override_constants/margin_right = 24

[node name="CurrentItems" type="HFlowContainer" parent="Content/MarginContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_constants/h_separation = 16
theme_override_constants/v_separation = 16

[node name="Panel" type="Panel" parent="."]
custom_minimum_size = Vector2(0, 77)
Expand All @@ -59,6 +73,18 @@ mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_kavop")
metadata/_edit_lock_ = true

[node name="BGDesignContainer" type="HBoxContainer" parent="Panel"]
layout_mode = 1
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 77.0
grow_horizontal = 2

[node name="Panel" type="Panel" parent="Panel/BGDesignContainer"]
custom_minimum_size = Vector2(240, 77)
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_hl1u6")

[node name="Header" type="MarginContainer" parent="Panel"]
custom_minimum_size = Vector2(0, 77)
layout_mode = 1
Expand Down
12 changes: 4 additions & 8 deletions scripts/items/1000_wooden_sword.tres
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
[gd_resource type="Resource" script_class="ItemData" load_steps=4 format=3 uid="uid://bpfgq786xxx6s"]
[gd_resource type="Resource" script_class="ItemData" load_steps=3 format=3 uid="uid://c4a1s2i7jowa8"]

[ext_resource type="Script" path="res://scripts/items/item_data.gd" id="1_j87ir"]
[ext_resource type="Texture2D" uid="uid://mfj02y3po58g" path="res://scripts/items/textures/items_atlas.png" id="2_leyx1"]

[sub_resource type="AtlasTexture" id="AtlasTexture_qqo6s"]
atlas = ExtResource("2_leyx1")
region = Rect2(512, 384, 128, 128)
[ext_resource type="Texture2D" uid="uid://d7eyaepxetvj" path="res://scripts/items/1000_wooden_sword_atlas.tres" id="2_81fgv"]

[resource]
script = ExtResource("1_j87ir")
unique_id = 1
name = "Wooden Sword"
description = "Lookin' sharp."
description = "That'll do, wood. That'll do."
stackable = false
texture = SubResource("AtlasTexture_qqo6s")
texture = ExtResource("2_81fgv")
7 changes: 7 additions & 0 deletions scripts/items/1000_wooden_sword_atlas.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://d7eyaepxetvj"]

[ext_resource type="Texture2D" uid="uid://mfj02y3po58g" path="res://scripts/items/textures/items_atlas.png" id="1_1hmn4"]

[resource]
atlas = ExtResource("1_1hmn4")
region = Rect2(0, 0, 128, 128)
2 changes: 0 additions & 2 deletions scripts/mob/attackable/player/my_player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,3 @@ fov = 70.0

[node name="PlayerInventory" parent="UI" instance=ExtResource("4_tvn1c")]
visible = false
essence = 0
ui_shown = false

0 comments on commit d33e0d0

Please sign in to comment.