Skip to content

Commit

Permalink
Merge pull request #77 from Ruben14789/main
Browse files Browse the repository at this point in the history
Added an inventory GUI
  • Loading branch information
MoldyPotat authored Apr 6, 2024
2 parents 4fa4f35 + e224119 commit 699f65a
Show file tree
Hide file tree
Showing 60 changed files with 2,442 additions and 4 deletions.
36 changes: 36 additions & 0 deletions Game/LifeQuest/Item.tscn
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"
38 changes: 38 additions & 0 deletions Game/LifeQuest/Items.gd
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)
18 changes: 18 additions & 0 deletions Game/LifeQuest/Items/Iron Sword.tres
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")
3 changes: 3 additions & 0 deletions Game/LifeQuest/Items/TestingHelmet2.tres
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
[resource]
script = ExtResource("1_xpd8c")
name = "Testing Helmet2"
description = ""
stackable = false
max_stack_size = 1
itemType = 1
equipLocation = 0
damage = 0
Expand Down
18 changes: 18 additions & 0 deletions Game/LifeQuest/Items/large health potion.tres
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")
18 changes: 18 additions & 0 deletions Game/LifeQuest/Items/small health potion.tres
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")
39 changes: 39 additions & 0 deletions Game/LifeQuest/Scripts/Items.gd
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)


11 changes: 9 additions & 2 deletions Game/LifeQuest/Scripts/Items/item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ extends Resource
class_name ItemResource

@export var name : String
@export_multiline var description : String
@export var stackable : bool = false
@export var max_stack_size : int = 1


enum ItemType { CONSUMABLE, EQUIPMENT, GENERIC }
enum EquipmentLocation { HEAD, CHEST, ARMS, HANDS, LEGS, FEET}
enum EquipmentLocation {INVENTORY,HEAD,PANTS,HANDS,SHOES,WEAPON,ACCESSORY,}
@export var itemType : ItemType
@export var equipLocation : EquipmentLocation
@export var damage : int = 0
@export var healthBonus : int = 0
@export var defenseBonus : int = 0
@export var magicBonus : int = 0

# Sprite properties
@export var icon : Texture

33 changes: 33 additions & 0 deletions Game/LifeQuest/Scripts/PlayerInventory.gd
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
71 changes: 71 additions & 0 deletions Game/LifeQuest/Scripts/Slot.gd
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()
20 changes: 20 additions & 0 deletions Game/LifeQuest/Scripts/UserInterface.gd
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

Loading

0 comments on commit 699f65a

Please sign in to comment.