Added debug inventory menu

This commit is contained in:
2025-05-19 17:41:39 -05:00
parent 3b9986b4ee
commit 057ed10851
26 changed files with 309 additions and 24 deletions

View File

@@ -27,6 +27,7 @@ SCENE_MANAGER="*res://scripts/Singleton/SceneManager.gd"
UI="*res://scenes/Singletons/UI.tscn"
VN="*res://scripts/Singleton/VN.gd"
LOAD="*res://scenes/Singletons/Load.tscn"
EVENT="*res://scripts/Singleton/Event.gd"
[display]

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=3 uid="uid://dx6fv8n4jl5ku"]
[gd_scene load_steps=16 format=3 uid="uid://dx6fv8n4jl5ku"]
[ext_resource type="PackedScene" uid="uid://yhtpoum3eek7" path="res://scenes/Entities/Rosa.tscn" id="1_7b7hx"]
[ext_resource type="Script" uid="uid://c37crdel0m5mw" path="res://scripts/Map/Map.gd" id="1_ru75d"]
@@ -11,6 +11,7 @@
[ext_resource type="Script" uid="uid://c4d7nithqnx5y" path="res://scripts/Event/Quest/EventStartQuest.gd" id="7_brp0k"]
[ext_resource type="PackedScene" uid="uid://bkj630bhmnvsi" path="res://scenes/Entities/Sign.tscn" id="9_xfqoe"]
[ext_resource type="Script" uid="uid://b41umpbgqfuc2" path="res://scripts/Event/Item/EventGetItem.gd" id="10_avybc"]
[ext_resource type="Script" uid="uid://0ygswaohp7kj" path="res://scripts/Event/EventFlagModify.gd" id="12_ncdgy"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_e1h75"]
sky_horizon_color = Color(0.59625, 0.6135, 0.6375, 1)
@@ -44,6 +45,8 @@ interactEvent = NodePath("../../Events/TestConversation")
[node name="ItemOnGround" parent="Entities" instance=ExtResource("4_ejcqv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.546944, -0.547748, -3.46628)
itemType = 1
quantity = 2
[node name="Map" type="Node3D" parent="."]
metadata/_edit_lock_ = true
@@ -75,6 +78,13 @@ omni_range = 281.646
[node name="TestConversation" type="Node" parent="Events"]
script = ExtResource("5_cg1ph")
[node name="EventFlagModify" type="Node" parent="Events/TestConversation"]
script = ExtResource("12_ncdgy")
action = 2
event = 1
eventFlag = 1
metadata/_custom_type_script = "uid://0ygswaohp7kj"
[node name="Text 0" type="Node" parent="Events/TestConversation"]
script = ExtResource("6_gxq5o")
text = "I am giving you a quest to gather some ingredients."
@@ -87,10 +97,15 @@ metadata/_custom_type_script = "uid://c4d7nithqnx5y"
script = ExtResource("6_gxq5o")
text = "Thanks for closing the quest menu"
[node name="Get Item" type="Node" parent="Events/TestConversation"]
script = ExtResource("10_avybc")
getType = 1
metadata/_custom_type_script = "uid://b41umpbgqfuc2"
[node name="Text 2" type="Node" parent="Events/TestConversation"]
script = ExtResource("6_gxq5o")
text = "Thanks for taking that potion."
[node name="EventConversation" type="Node" parent="Events"]
script = ExtResource("5_cg1ph")
metadata/_custom_type_script = "uid://tkfc88q8m86f"
[node name="Get Item" type="Node" parent="Events"]
script = ExtResource("10_avybc")
metadata/_custom_type_script = "uid://b41umpbgqfuc2"

View File

@@ -1,9 +1,10 @@
[gd_scene load_steps=5 format=3 uid="uid://b5bwpsh0gcicf"]
[gd_scene load_steps=6 format=3 uid="uid://b5bwpsh0gcicf"]
[ext_resource type="Script" uid="uid://dahhuhiu8u88b" path="res://scripts/Singleton/UI.gd" id="1_g3au4"]
[ext_resource type="PackedScene" uid="uid://verg13jtqwvh" path="res://scenes/UI/DebugMenu.tscn" id="2_is0g4"]
[ext_resource type="PackedScene" uid="uid://bfioi52hjn2kf" path="res://scenes/UI/QuestMenu.tscn" id="2_mpokx"]
[ext_resource type="PackedScene" uid="uid://bkx3l0kckf4a8" path="res://scenes/UI/VNTextbox.tscn" id="3_btpxp"]
[ext_resource type="PackedScene" uid="uid://dl8iqhrpsplmk" path="res://scenes/UI/Inventory/FullInventoryMenu.tscn" id="5_6dyff"]
[node name="UI" type="Control"]
layout_mode = 3
@@ -17,8 +18,14 @@ script = ExtResource("1_g3au4")
metadata/_custom_type_script = "uid://dahhuhiu8u88b"
[node name="QuestMenu" parent="." instance=ExtResource("2_mpokx")]
visible = false
layout_mode = 1
[node name="FullInventory" parent="." instance=ExtResource("5_6dyff")]
visible = false
layout_mode = 2
anchors_preset = 0
[node name="VNTextbox" parent="." instance=ExtResource("3_btpxp")]
visible = false
layout_mode = 1

View File

@@ -30,6 +30,14 @@ layout_mode = 2
text = "Prototype Quests
"
[node name="Inventory" type="Button" parent="."]
layout_mode = 2
text = "Player Inventory"
[node name="Event" type="Button" parent="."]
layout_mode = 2
text = "Event Flags"
[node name="Cutscene" type="Button" parent="."]
layout_mode = 2
disabled = true

View File

@@ -0,0 +1,42 @@
[gd_scene load_steps=3 format=3 uid="uid://dl8iqhrpsplmk"]
[ext_resource type="Script" uid="uid://cla3ph1j2ligp" path="res://scripts/UI/Inventory/FullInventoryMenu.gd" id="1_m5r8e"]
[ext_resource type="PackedScene" uid="uid://dmu8i175kp35q" path="res://scenes/UI/Inventory/ItemLine.tscn" id="1_mmy80"]
[node name="FullInventory" type="Panel" node_paths=PackedStringArray("itemList")]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_m5r8e")
itemLine = ExtResource("1_mmy80")
itemList = NodePath("VBoxContainer/ScrollContainer/ItemList")
metadata/_custom_type_script = "uid://cla3ph1j2ligp"
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
[node name="ItemList" type="VBoxContainer" parent="VBoxContainer/ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="ItemLine" parent="VBoxContainer/ScrollContainer/ItemList" instance=ExtResource("1_mmy80")]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Add Item"

View File

@@ -0,0 +1,22 @@
[gd_scene load_steps=2 format=3 uid="uid://dmu8i175kp35q"]
[ext_resource type="Script" uid="uid://dgblia2ukssbe" path="res://scripts/UI/Inventory/ItemLine.gd" id="1_mcq7n"]
[node name="ItemLine" type="HBoxContainer"]
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 12.0
grow_horizontal = 2
script = ExtResource("1_mcq7n")
metadata/_custom_type_script = "uid://dgblia2ukssbe"
[node name="ItemName" type="Label" parent="."]
layout_mode = 2
size_flags_horizontal = 3
text = "Potion"
[node name="ItemQuantity" type="Label" parent="."]
custom_minimum_size = Vector2(24, 0)
layout_mode = 2
text = "255"
horizontal_alignment = 2

View File

@@ -1,5 +1,10 @@
class_name ItemOnGround extends StaticBody3D
enum Type {
SPAWNS_WITH_MAP,
AQUIRED_ONCE
}
@export var itemType:Item.Type = Item.Type.POTION;
@export var quantity:int = 1;

View File

@@ -0,0 +1 @@
uid://dq35fj8r206nj

View File

@@ -0,0 +1,19 @@
class_name EventFlagModify extends "res://scripts/Event/Event.gd"
enum Action {
TURN_ON,
TURN_OFF,
SET_TO,
ALL_ON,
ALL_OFF
}
@export var action:Action = Action.TURN_ON;
@export var event:EventSystem.SpecialEvent;
@export_flags("1:1", "2:2", "3:4", "4:8", "5:16", "6:32", "7:64", "8:128", "9:256", "10:512", "11:1024", "12:2048", "13:4096", "14:8192", "15:16384", "16:32768")
var eventFlag:int = 0;
func start() -> void:
super.start()
pass
# EVENT.eventFlagOn(event, eventFlag)

View File

@@ -0,0 +1 @@
uid://0ygswaohp7kj

View File

@@ -0,0 +1,9 @@
class_name EventFlagOn extends "res://scripts/Event/Event.gd"
@export var event:EventSystem.SpecialEvent;
@export_flags("1:1", "2:2", "3:4", "4:8", "5:16", "6:32", "7:64", "8:128", "9:256", "10:512", "11:1024", "12:2048", "13:4096", "14:8192", "15:16384", "16:32768")
var eventFlag:int = 0;
func start() -> void:
super.start()
EVENT.eventFlagOn(event, eventFlag)

View File

@@ -0,0 +1 @@
uid://cbd7wpvkf76ux

View File

@@ -1,6 +1,35 @@
class_name EventGetItem extends "res://scripts/Event/Item/EventItem.gd"
enum GetType {
FOUND,
GIVEN,
}
@export var showText: bool = true
@export var getType:GetType = GetType.FOUND;
func start() -> void:
super.start()
print("Got item")
getInventory().addItem(itemType, quantity)
getInventory().addItem(itemType, quantity)
if !showText:
return
var text:String = "";
match getType:
GetType.FOUND:
text = "Found " + str(quantity) + " " + Item.getName(itemType, quantity) + ".";
GetType.GIVEN:
text = "Received " + str(quantity) + " " + Item.getName(itemType, quantity) + ".";
_:
pass
VN.getTextbox().setText(text);
func isDone() -> bool:
if !super.isDone():
return false
if !showText:
return true
return VN.getTextbox().isClosed;

View File

@@ -1,6 +1,4 @@
class_name Inventory
const Item = preload("res://scripts/Item/Item.gd");
const ItemStack = preload("res://scripts/Item/ItemStack.gd");
enum ItemSortType {
NAME,
@@ -18,21 +16,22 @@ class ItemStackTypeComparator:
const ITEM_STACK_SIZE_MAX = 99;
var contents:Array[ItemStack] = [];
signal inventoryUpdated()
func isPlayerInventory() -> bool:
return self == ITEM.PLAYER_INVENTORY
func addItem(item:Item.Type, quantity: int = 1) -> void:
if !Item.isStackable(item):
func addItem(type:Item.Type, quantity: int = 1) -> void:
if !Item.isStackable(type):
# Item cannot be stacked, add each item to inv
for i in range(quantity):
contents.append(ItemStack.new(item, 1))
contents.append(ItemStack.new(type, 1))
_contentsUpdated()
return
# Check for existing stacks
for stack in contents:
if stack.item != item or stack.quantity >= ITEM_STACK_SIZE_MAX:
if stack.type != type or stack.quantity >= ITEM_STACK_SIZE_MAX:
continue
var spaceAvailable = ITEM_STACK_SIZE_MAX - stack.quantity
@@ -48,16 +47,16 @@ func addItem(item:Item.Type, quantity: int = 1) -> void:
# Add any remaining inventory as new stack.
while quantity > 0:
var newStackQuantity = min(quantity, ITEM_STACK_SIZE_MAX);
contents.append(ItemStack.new(item, newStackQuantity));
contents.append(ItemStack.new(type, newStackQuantity));
quantity -= newStackQuantity;
_contentsUpdated()
func removeItem(item:Item.Type, quantity:int) -> void:
func removeItem(type:Item.Type, quantity:int) -> void:
var totalQuantity = 0
# Calculate total quantity of the item in the inventory
for stack in contents:
if stack.item != item:
if stack.type != type:
continue
totalQuantity += stack.quantity
@@ -67,7 +66,7 @@ func removeItem(item:Item.Type, quantity:int) -> void:
# Remove the quantity from the stacks
for stack in contents:
if stack.item != item:
if stack.type != type:
continue
if stack.quantity < quantity:
@@ -85,11 +84,11 @@ func removeItem(item:Item.Type, quantity:int) -> void:
func removeStack(stack: ItemStack) -> void:
self.removeItem(stack.item, stack.quantity);
func hasItem(item:Item.Type, quantity: int = 1) -> bool:
func hasItem(type:Item.Type, quantity: int = 1) -> bool:
var totalQuantity = 0
for stack in contents:
if stack.item != item:
if stack.type != type:
continue
totalQuantity += stack.quantity
@@ -109,5 +108,6 @@ func sortBy(by:ItemSortType) -> void:
assert(false, "Invalid sort type: %s" % by)
func _contentsUpdated() -> void:
inventoryUpdated.emit()
if isPlayerInventory():
QUEST.playerInventoryUpdated.emit()

View File

@@ -13,9 +13,26 @@ enum Category {
static func isStackable(itemType:Type) -> bool:
match itemType:
_:
return true
static func getName(itemType:Type, count:int = 1) -> String:
match itemType:
Type.POTION:
if count != 1:
return "Potions"
return "Potion"
Type.ONION:
if count != 1:
return "Onions"
return "Onion"
_:
assert(false, "Invalid item type")
return ""
# func getName() -> String:
# push_error("getName() must be overridden in derived classes");
# return "";

View File

@@ -1,8 +1,8 @@
class_name ItemStack
var item:Item.Type;
var type:Item.Type;
var quantity:int;
func _init(item:Item.Type, quantity:int = 1):
self.item = item;
func _init(type:Item.Type, quantity:int = 1):
self.type = type;
self.quantity = quantity;

View File

@@ -37,4 +37,4 @@ func _onPlayerInventoryUpdated() -> void:
quest.objectiveUpdated(self)
func isCompleted() -> bool:
return completed
return completed

View File

@@ -0,0 +1,39 @@
class_name EventSystem extends Node
enum SpecialEvent {
INVALID = 0,
TEST_QUEST = 1,
};
var eventFlags:Dictionary[int, int] = {}
func eventFlagOn(event:SpecialEvent, flagsToTurnOn:int) -> void:
if !eventFlags.has(event):
eventFlags[event] = 0;
eventFlags[event] |= flagsToTurnOn;
func eventFlagOff(event:SpecialEvent, flagsToTurnOff:int) -> void:
if !eventFlags.has(event):
eventFlags[event] = 0;
eventFlags[event] &= ~flagsToTurnOff;
func eventAreFlagsOn(event:SpecialEvent, flagsToCheck:int) -> bool:
if !eventFlags.has(event):
eventFlags[event] = 0;
return (eventFlags[event] & flagsToCheck) == flagsToCheck;
func eventIsAnyOfFlagsOn(event:SpecialEvent, flagsToCheck:int) -> bool:
if !eventFlags.has(event):
eventFlags[event] = 0;
return (eventFlags[event] & flagsToCheck) != 0;
func eventAreFlagsOff(event:SpecialEvent, flagsToCheck:int) -> bool:
if !eventFlags.has(event):
eventFlags[event] = 0;
return (eventFlags[event] & flagsToCheck) == 0;
func eventIsAnyOfFlagsOff(event:SpecialEvent, flagsToCheck:int) -> bool:
if !eventFlags.has(event):
eventFlags[event] = 0;
return (eventFlags[event] & flagsToCheck) != flagsToCheck;

View File

@@ -0,0 +1 @@
uid://cde8ji6yll5sl

View File

@@ -2,10 +2,12 @@ class_name UISystem extends Control
var QUEST_MENU:QuestMenu
var DEBUG_MENU:DebugMenu
var INVENTORY_MENU:FullInventoryMenu
func _ready() -> void:
QUEST_MENU = $QuestMenu
DEBUG_MENU = $DebugMenu
INVENTORY_MENU = $FullInventory
func _process(delta: float) -> void:
# This needs to always be at the end of the parent node's tree

View File

@@ -6,6 +6,8 @@ func _ready() -> void:
$MainMenu.connect("pressed", _on_MainMenu_pressed);
$OverworldOption/Overworld.connect("pressed", _on_Overworld_pressed);
$Quests.connect("pressed", _on_Quests_pressed);
$Inventory.connect("pressed", _on_Inventory_pressed);
$Event.connect("pressed", _on_Event_pressed);
$Cutscene.connect("pressed", _on_Custscene_pressed);
$Cooking.connect("pressed", _on_Cooking_pressed);
$Battle.connect("pressed", _on_Battle_pressed);
@@ -58,6 +60,16 @@ func _on_Cooking_pressed():
func _on_Battle_pressed():
print("Battle pressed")
func _on_Event_pressed():
print("Event pressed")
func _on_Inventory_pressed():
close()
if UI.INVENTORY_MENU.isOpen():
UI.INVENTORY_MENU.close()
else:
UI.INVENTORY_MENU.open()
func open() -> void:
show()

View File

@@ -0,0 +1 @@
uid://bqe8ve2hn3coc

View File

@@ -0,0 +1,46 @@
class_name FullInventoryMenu extends Panel
@export var itemLine:PackedScene = null;
@export var itemList:Control = null;
var inventory:Inventory = null;
func _ready() -> void:
hide()
_updateItemList()
func _exit_tree() -> void:
pass
func open(inventory:Inventory = null) -> void:
if self.inventory != null:
self.inventory.inventoryUpdated.disconnect(_updateItemList)
if inventory == null:
inventory = ITEM.PLAYER_INVENTORY;
self.inventory = inventory;
self.inventory.inventoryUpdated.connect(_updateItemList)
_updateItemList()
self.show()
func close() -> void:
self.hide()
func isOpen() -> bool:
return self.visible
func _updateItemList() -> void:
if inventory == null:
return
# Clear item list
while itemList.get_child_count() > 0:
var child = itemList.get_child(0)
itemList.remove_child(child)
child.queue_free()
for stack in inventory.contents:
var node = itemLine.instantiate()
node.setStack(stack)
itemList.add_child(node)

View File

@@ -0,0 +1 @@
uid://cla3ph1j2ligp

View File

@@ -0,0 +1,5 @@
class_name ItemLine extends HBoxContainer
func setStack(stack:ItemStack) -> void:
$ItemName.text = Item.getName(stack.type, 1)
$ItemQuantity.text = str(stack.quantity)

View File

@@ -0,0 +1 @@
uid://dgblia2ukssbe