Browse Source

wip: Add notes about the inital quickslot highlight and create remove_slots()

pull/24/head
Ryan Reed 3 weeks ago
parent
commit
60a71f07e2
2 changed files with 13 additions and 3 deletions
  1. +2
    -0
      autoloads/inventory_manager.gd
  2. +11
    -3
      scenes/ui/quickslots/quick_slots.gd

+ 2
- 0
autoloads/inventory_manager.gd View File

@ -44,6 +44,7 @@ func _ready() -> void:
self.remove_from_quickslot.connect(_on_remove_from_quickslot)
self.remove_from_slot.connect(_on_remove_from_slot)
func available_space(item_id: String) -> int:
var full_stacks: int = floor(_inventory_cache[item_id].total / DBItems.data[item_id].max_stack_size)
var space_in_stacks: int = (
@ -67,6 +68,7 @@ func get_inventory_item(item_slot: int = selected_quick_slot) -> DBItemResource:
func get_quick_slot_item_id(item_slot: int = selected_quick_slot) -> String:
return inventory[item_slot].id
func _find_stacks_by_id(item_resource: DBItemResource, item_id: String) -> bool:
return item_resource != null and item_resource.id == item_id


+ 11
- 3
scenes/ui/quickslots/quick_slots.gd View File

@ -23,9 +23,13 @@ func _init() -> void:
InventoryManager.select_quick_slot.connect(select_quick_slot)
func _ready() -> void:
clear_slots()
remove_slots()
generate_quick_slots()
update_highlighted_slot()
# This doesn't quite work on ready as, for some reason, it will select
# Slot0 (one of the slots BEFORE remove_slots()) instead of the first slot
# create in generate_quick_slots()
select_quick_slot(0)
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("quickslot1"):
@ -56,7 +60,7 @@ func _unhandled_input(event: InputEvent) -> void:
func clear_slots() -> void:
for slot: QuickSlotsSlot in slots_container.get_children():
slot.queue_free()
slot.clear()
func generate_quick_slots() -> void:
for slot_index: int in range(InventoryManager.quick_slot_count):
@ -64,6 +68,10 @@ func generate_quick_slots() -> void:
slots_container.add_child(slot)
slot.init(slot_index)
func remove_slots() -> void:
for slot: QuickSlotsSlot in slots_container.get_children():
slot.queue_free()
func select_next_item() -> void:
select_quick_slot(_selected_item + 1)


Loading…
Cancel
Save