Quest menu closeable
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
extends Node
|
||||
|
||||
var debugMenu:DebugMenu
|
||||
|
||||
func _ready() -> void:
|
||||
debugMenu = $SubsceneUI/DebugMenu;
|
||||
debugMenu.hide()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("debug"):
|
||||
print("Debug key pressed")
|
||||
if debugMenu.is_visible():
|
||||
hideMenu()
|
||||
else:
|
||||
showMenu()
|
||||
|
||||
func showMenu() -> void:
|
||||
debugMenu.show()
|
||||
print("Debug menu shown")
|
||||
|
||||
func hideMenu() -> void:
|
||||
debugMenu.hide()
|
@@ -1 +0,0 @@
|
||||
uid://d36d3fnpi8y30
|
@@ -1,106 +1,8 @@
|
||||
extends Node
|
||||
const Inventory = preload("res://scripts/Item/Inventory.gd")
|
||||
|
||||
const Item = preload("res://scripts/Item/Item.gd");
|
||||
const ItemStack = preload("res://scripts/Item/ItemStack.gd");
|
||||
# Item Constants
|
||||
static var POTION = preload("res://scripts/Item/Potion.gd").new();
|
||||
|
||||
enum ItemSortType {
|
||||
NAME,
|
||||
TYPE
|
||||
};
|
||||
|
||||
class ItemStackNameComparator:
|
||||
static func _sort(a, b):
|
||||
return a.item.getName().to_lower() < b.item.getName().to_lower()
|
||||
|
||||
class ItemStackTypeComparator:
|
||||
static func _sort(a, b):
|
||||
return a.item.getCategory() < b.item.getCategory()
|
||||
|
||||
# Constants
|
||||
const ITEM_STACK_SIZE_MAX = 99;
|
||||
static var ITEM_POTION = preload("res://scripts/Item/Potion.gd").new();
|
||||
|
||||
# Class
|
||||
var inventory:Array[ItemStack] = [];
|
||||
|
||||
# Methods
|
||||
func addItem(item: Item, quantity: int = 1) -> void:
|
||||
print("Adding ", quantity, "x ", item.getName());
|
||||
if !item.isStackable():
|
||||
# Item cannot be stacked, add each item to inv
|
||||
for i in range(quantity):
|
||||
inventory.append(ItemStack.new(item, 1))
|
||||
return
|
||||
|
||||
# Check for existing stacks
|
||||
for stack in inventory:
|
||||
if stack.item != item or stack.quantity >= ITEM_STACK_SIZE_MAX:
|
||||
continue
|
||||
|
||||
var spaceAvailable = ITEM_STACK_SIZE_MAX - stack.quantity
|
||||
|
||||
if quantity <= spaceAvailable:
|
||||
stack.quantity += quantity;
|
||||
return
|
||||
|
||||
stack.quantity = ITEM_STACK_SIZE_MAX;
|
||||
quantity -= spaceAvailable;
|
||||
|
||||
# Add any remaining inventory as new stack.
|
||||
while quantity > 0:
|
||||
var newStackQuantity = min(quantity, ITEM_STACK_SIZE_MAX);
|
||||
inventory.append(ItemStack.new(item, newStackQuantity));
|
||||
quantity -= newStackQuantity;
|
||||
|
||||
func removeItem(item: Item, quantity: int) -> void:
|
||||
var totalQuantity = 0
|
||||
|
||||
# Calculate total quantity of the item in the inventory
|
||||
for stack in inventory:
|
||||
if stack.item != item:
|
||||
continue
|
||||
totalQuantity += stack.quantity
|
||||
|
||||
if totalQuantity < quantity:
|
||||
push_error("Not enough quantity to remove");
|
||||
return
|
||||
|
||||
# Remove the quantity from the stacks
|
||||
for stack in inventory:
|
||||
if stack.item != item:
|
||||
continue
|
||||
|
||||
if stack.quantity < quantity:
|
||||
quantity -= stack.quantity
|
||||
inventory.erase(stack)
|
||||
|
||||
stack.quantity -= quantity
|
||||
if stack.quantity == 0:
|
||||
inventory.erase(stack)
|
||||
|
||||
if quantity == 0:
|
||||
return
|
||||
|
||||
func removeStack(stack: ItemStack) -> void:
|
||||
self.removeItem(stack.item, stack.quantity);
|
||||
|
||||
func hasItem(item: Item, quantity: int = 1) -> bool:
|
||||
var totalQuantity = 0
|
||||
|
||||
for stack in inventory:
|
||||
if stack.item != item:
|
||||
continue
|
||||
|
||||
totalQuantity += stack.quantity
|
||||
|
||||
if totalQuantity >= quantity:
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
func sortBy(by:ItemSortType) -> void:
|
||||
match by:
|
||||
ItemSortType.NAME:
|
||||
inventory.sort_custom(ItemStackNameComparator._sort)
|
||||
ItemSortType.TYPE:
|
||||
inventory.sort_custom(ItemStackTypeComparator._sort)
|
||||
# Static inventories
|
||||
static var PLAYER_INVENTORY = Inventory.new();
|
||||
|
@@ -1,9 +1,12 @@
|
||||
class_name UISystem extends Control
|
||||
|
||||
var QUEST_MENU:QuestMenu
|
||||
var DEBUG_MENU:DebugMenu
|
||||
|
||||
func _ready() -> void:
|
||||
QUEST_MENU = $QuestMenu
|
||||
DEBUG_MENU = $DebugMenu
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
# This needs to always be at the end of the parent node's tree
|
||||
get_parent().move_child(self, get_parent().get_child_count() - 1)
|
||||
|
||||
func showQuestsMenu(questKey = null) -> void:
|
||||
$QuestMenu.setQuest(questKey)
|
||||
$QuestMenu.show()
|
||||
|
Reference in New Issue
Block a user