-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from Ruben14789/main
Added an inventory GUI
- Loading branch information
Showing
60 changed files
with
2,442 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://ckd8jvik4ymei"] | ||
|
||
[ext_resource type="Script" path="res://Scripts/Items.gd" id="1_3jq06"] | ||
[ext_resource type="Texture2D" uid="uid://2hcra8yo8sn2" path="res://Sprites/Equipment Icons/Iron Sword.png" id="2_wijr2"] | ||
|
||
[node name="Item" type="Node2D"] | ||
z_index = 1 | ||
script = ExtResource("1_3jq06") | ||
|
||
[node name="TextureRect2" type="TextureRect" parent="."] | ||
visible = false | ||
offset_right = 7.0 | ||
offset_bottom = 15.2069 | ||
mouse_filter = 2 | ||
texture = ExtResource("2_wijr2") | ||
expand_mode = 5 | ||
|
||
[node name="TextureRect" type="TextureRect" parent="."] | ||
offset_right = 40.0 | ||
offset_bottom = 63.0 | ||
mouse_filter = 2 | ||
|
||
[node name="Label" type="Label" parent="."] | ||
anchors_preset = 3 | ||
anchor_left = 1.0 | ||
anchor_top = 1.0 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
offset_left = 21.0 | ||
offset_top = 40.0 | ||
offset_right = 40.0 | ||
offset_bottom = 63.0 | ||
grow_horizontal = 0 | ||
grow_vertical = 0 | ||
theme_override_colors/font_color = Color(0, 0, 0, 1) | ||
text = "99" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
extends Node2D | ||
var itemname # variable for the items name | ||
var itemquantity # variable for the items quantity, amount of stacked items | ||
|
||
|
||
|
||
func _ready(): | ||
# Ensure that $TextureRect exists and is a TextureRect node | ||
if $TextureRect: | ||
if randi() % 2 == 0: | ||
itemname = "Iron Sword" | ||
else: | ||
itemname = "Wooden Sword" | ||
|
||
#To set the equipment texture | ||
$TextureRect.texture = load("res://Sprites/Equipment Icons/" + itemname + ".png") | ||
#var to set the stack size of each item | ||
var stacksize = int(Jsonitems.itemdata[itemname]["StackSize"]) | ||
|
||
#test: | ||
itemquantity = randi() % stacksize +1 | ||
|
||
|
||
#for the non-stacking items we do not need to show label amount | ||
if stacksize == 1: | ||
$Label.visible = false | ||
else: | ||
$Label.text = str(itemquantity) | ||
|
||
|
||
#add and combine or split inventory items | ||
func addquantity(amount): | ||
itemquantity += amount | ||
$Label.text = String(itemquantity) | ||
|
||
func decreasequantity(amount): | ||
itemquantity -= amount | ||
$Label.text = String(itemquantity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[gd_resource type="Resource" script_class="ItemResource" load_steps=3 format=3 uid="uid://ct3ukdhpt44wv"] | ||
|
||
[ext_resource type="Texture2D" uid="uid://2hcra8yo8sn2" path="res://Sprites/Equipment Icons/Iron Sword.png" id="1_ldxdw"] | ||
[ext_resource type="Script" path="res://Scripts/Items/item.gd" id="1_tq5fs"] | ||
|
||
[resource] | ||
script = ExtResource("1_tq5fs") | ||
name = "Iron Sword" | ||
description = "" | ||
stackable = false | ||
max_stack_size = 1 | ||
itemType = 1 | ||
equipLocation = 5 | ||
damage = 10 | ||
healthBonus = 0 | ||
defenseBonus = 0 | ||
magicBonus = 0 | ||
icon = ExtResource("1_ldxdw") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[gd_resource type="Resource" script_class="ItemResource" load_steps=3 format=3 uid="uid://25c2xrtjprg7"] | ||
|
||
[ext_resource type="Script" path="res://Scripts/Items/item.gd" id="1_gjrsj"] | ||
[ext_resource type="Texture2D" uid="uid://cdhog52vtvha0" path="res://Sprites/Equipment Icons/large health potion.png" id="1_iyue3"] | ||
|
||
[resource] | ||
script = ExtResource("1_gjrsj") | ||
name = "Large Health Potion" | ||
description = "Heals a Large portion of health" | ||
stackable = true | ||
max_stack_size = 99 | ||
itemType = 0 | ||
equipLocation = 0 | ||
damage = 0 | ||
healthBonus = 0 | ||
defenseBonus = 0 | ||
magicBonus = 0 | ||
icon = ExtResource("1_iyue3") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[gd_resource type="Resource" script_class="ItemResource" load_steps=3 format=3 uid="uid://8hgtl3bn8lig"] | ||
|
||
[ext_resource type="Texture2D" uid="uid://dhuxo31oaolsq" path="res://Sprites/Equipment Icons/small health potion.png" id="1_kq2oc"] | ||
[ext_resource type="Script" path="res://Scripts/Items/item.gd" id="1_p4ifm"] | ||
|
||
[resource] | ||
script = ExtResource("1_p4ifm") | ||
name = "Small Health Potion" | ||
description = "Heals a small portion of health" | ||
stackable = true | ||
max_stack_size = 99 | ||
itemType = 0 | ||
equipLocation = 0 | ||
damage = 0 | ||
healthBonus = 0 | ||
defenseBonus = 0 | ||
magicBonus = 0 | ||
icon = ExtResource("1_kq2oc") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
extends Node2D | ||
var itemname # variable for the items name | ||
var itemquantity # variable for the items quantity, amount of items | ||
|
||
|
||
|
||
func _ready(): | ||
pass | ||
|
||
|
||
#add and combine or split inventory items | ||
func addquantity(amount): | ||
itemquantity += amount | ||
$Label.text = str(itemquantity) | ||
|
||
func decreasequantity(amount): | ||
itemquantity -= amount | ||
$Label.text = str(itemquantity) | ||
|
||
func setitem(itemname2,itemquantity2): | ||
var item = ItemDatabase.get_item(itemname2) | ||
itemname = itemname2 | ||
itemquantity = itemquantity2 | ||
#$TextureRect.texture = load("res://Sprites/Equipment Icons/" + itemname + ".png") | ||
|
||
$TextureRect.texture = item.icon | ||
#var stacksize = int(Jsonitems.itemdata[itemname]["StackSize"]) | ||
|
||
var stacksize = item.max_stack_size | ||
#print("stacksize:",stacksize) | ||
#print("items:",item.name) | ||
|
||
#var stacksize = int(item.max_stack_size) | ||
if stacksize == 1: | ||
$Label.visible = false | ||
else: | ||
$Label.text = str(itemquantity) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
extends Node | ||
|
||
# Preload the scripts for the slot and items | ||
const SlotClass = preload("res://Scripts/Slot.gd") | ||
const ItemClass = preload("res://Scripts/Items.gd") | ||
#const for inventory slots | ||
const INVENTORYSLOTS = 15 | ||
#initial inventory data | ||
var inventory ={ | ||
0: ["Iron Sword", 1], | ||
#1: ["Wooden Sword", 1], | ||
1: ["Small Health Potion", 10], | ||
2: ["Small Health Potion", 5], | ||
3: ["Large Health Potion", 5], | ||
#can add more starting items | ||
} | ||
var equip = { | ||
#0: [ , ], | ||
|
||
|
||
|
||
} | ||
|
||
|
||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
pass # Replace with function body. | ||
|
||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
func _process(delta): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
extends Panel | ||
|
||
var defaulttexture: Texture | ||
var emptytexture: Texture | ||
|
||
# To access the item class vars | ||
var ItemScene: PackedScene = preload("res://Item.tscn") | ||
var item: Node2D = null | ||
|
||
|
||
enum SlotType { | ||
INVENTROY, | ||
HEAD, | ||
PANTS, | ||
HANDS, | ||
SHOES, | ||
WEAPON, | ||
ACCESSORY, | ||
} | ||
|
||
var slotType = null | ||
|
||
func _ready(): | ||
defaulttexture = preload("res://Sprites/Equipment Icons/full inventory slot.png") | ||
emptytexture = preload("res://Sprites/Equipment Icons/empty inventory slot.png") | ||
#if randi() % 2 == 0: | ||
#item = ItemScene.instantiate() | ||
#add_child(item) | ||
#refresh() | ||
|
||
#does not change slots TODO not a big part of functionality visual thing: | ||
func refresh(): | ||
if item == null: | ||
set("theme_override_styles/panel",emptytexture) | ||
#print("slot empty") | ||
else: | ||
set("theme_override_styles/panel",defaulttexture) | ||
#print("slot full") | ||
|
||
|
||
#to pick up items from the slot fuction | ||
func pickslot(): | ||
if item: #if there is an item | ||
remove_child(item) #pick up/ remove | ||
var inventoryNode = find_parent("Inventory") | ||
if inventoryNode: | ||
inventoryNode.add_child(item) | ||
item = null | ||
refresh() | ||
|
||
func putslot(newitem): | ||
if newitem: | ||
item = newitem | ||
item.position = Vector2(0, 0) | ||
var inventoryNode = find_parent("Inventory") | ||
if inventoryNode: | ||
inventoryNode.remove_child(item) | ||
add_child(item) | ||
refresh() | ||
|
||
func initializeitem(itemname, itemquantity): | ||
#print("item name:", itemname) | ||
#print("item quantity:", itemquantity) | ||
#check for null and if so then make an instance | ||
if item == null: | ||
item = ItemScene.instantiate() | ||
add_child(item) | ||
item.setitem(itemname,itemquantity)#function of item | ||
else: | ||
item.setitem(itemname,itemquantity) | ||
refresh() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
extends CanvasLayer | ||
|
||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
pass # Replace with function body. | ||
|
||
#function for when the I button assined as the inventory button is pressed | ||
func _input(event): | ||
if event.is_action_pressed("inventory"): | ||
$Inventory.visible = !$Inventory.visible | ||
$Inventory.initializeinventory() | ||
|
||
|
||
|
||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
func _process(delta): | ||
pass | ||
|
Oops, something went wrong.