Added debug inventory menu
This commit is contained in:
@@ -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;
|
||||
|
||||
|
1
scripts/Event/EventFlagChange.gd.uid
Normal file
1
scripts/Event/EventFlagChange.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dq35fj8r206nj
|
19
scripts/Event/EventFlagModify.gd
Normal file
19
scripts/Event/EventFlagModify.gd
Normal 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)
|
1
scripts/Event/EventFlagModify.gd.uid
Normal file
1
scripts/Event/EventFlagModify.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://0ygswaohp7kj
|
9
scripts/Event/EventFlagOn.gd
Normal file
9
scripts/Event/EventFlagOn.gd
Normal 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)
|
1
scripts/Event/EventFlagOn.gd.uid
Normal file
1
scripts/Event/EventFlagOn.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cbd7wpvkf76ux
|
@@ -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;
|
@@ -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()
|
||||
|
@@ -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 "";
|
||||
|
@@ -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;
|
||||
|
@@ -37,4 +37,4 @@ func _onPlayerInventoryUpdated() -> void:
|
||||
quest.objectiveUpdated(self)
|
||||
|
||||
func isCompleted() -> bool:
|
||||
return completed
|
||||
return completed
|
||||
|
39
scripts/Singleton/Event.gd
Normal file
39
scripts/Singleton/Event.gd
Normal 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;
|
1
scripts/Singleton/Event.gd.uid
Normal file
1
scripts/Singleton/Event.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cde8ji6yll5sl
|
@@ -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
|
||||
|
@@ -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()
|
||||
|
||||
|
1
scripts/UI/FullInventoryMenu.gd.uid
Normal file
1
scripts/UI/FullInventoryMenu.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bqe8ve2hn3coc
|
46
scripts/UI/Inventory/FullInventoryMenu.gd
Normal file
46
scripts/UI/Inventory/FullInventoryMenu.gd
Normal 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)
|
1
scripts/UI/Inventory/FullInventoryMenu.gd.uid
Normal file
1
scripts/UI/Inventory/FullInventoryMenu.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cla3ph1j2ligp
|
5
scripts/UI/Inventory/ItemLine.gd
Normal file
5
scripts/UI/Inventory/ItemLine.gd
Normal 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)
|
1
scripts/UI/Inventory/ItemLine.gd.uid
Normal file
1
scripts/UI/Inventory/ItemLine.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dgblia2ukssbe
|
Reference in New Issue
Block a user