REM/scripts/construct_inventory.gd
2026-03-26 20:37:29 -06:00

89 lines
2.8 KiB
GDScript

extends Control
@onready var pause_menu: Control = get_tree().get_first_node_in_group("pause_menu")
@onready var construct: Node3D = get_tree().get_first_node_in_group("Constructs")
@onready var stick_button: Button = $StickButton
@onready var weight_button: Button = $WeightButton
var con_name: String = ""
var con_count: int
func _ready() -> void:
con_count = construct.constructs.size()
##TODO make buttons visible when player has construct
for i in range(con_count):
#print(i)
##Check if the player has the construct and the construct is not nothing
if construct.constructs.keys()[i] != "nothing" and construct.constructs.values()[i]:
##Make button visible and show assigned slot on button
get_node(construct.constructs.keys()[i].capitalize() + "Button").visible = true
if construct.assigned_slot.values()[i]:
get_node(construct.assigned_slot.values()[i].capitalize() + "Button/SlotLabel").text = str(i + 1)
func _input(event: InputEvent) -> void:
##Prevent crash if pause menu not found (like during isolated testing)
#if pause_menu != null:
if event.is_action_pressed("inventory"): #and pause_menu.visible == false:
Global.change_paused_state()
self.visible = !self.visible
con_name = ""
if con_name != "":
##Allow the player to assign the current selected construct to keys 1 - 10
for i in range(1,11):
if event.is_action_pressed("construct" + str(i)):
##Remove the old slot number assignment from the previous construct
if construct.assigned_slot[i] != null:
for j in range(1,11):
if construct.assigned_slot[j] == con_name:
get_node(construct.assigned_slot[j].capitalize() + "Button/SlotLabel").text = ""
construct.assigned_slot[j] = null
#print(construct.assigned_slot)
##Show assigned slot number on new construct button
get_node(con_name.capitalize() + "Button/SlotLabel").text = str(i)
##Set the new construct to the assigned slot
construct.assigned_slot[i] = con_name
construct.set_construct(i, con_name)
#print(construct.assigned_slot)
##TODO add logic to swap constructs if both assigned
##TESTING for labels showing correctly during construct swaps
#for j in range(1,construct.constructs.size()):
#print(j)
#if construct.assigned_slot[j] != null:
#get_node(construct.assigned_slot[j].capitalize() + "Button/SlotLabel").text = str(j)
func _on_stick_button_pressed() -> void:
con_name = "stick"
func _on_weight_button_pressed() -> void:
con_name = "weight"
func _on_flashlight_button_pressed() -> void:
con_name = "flashlight"
func _on_time_button_pressed() -> void:
con_name = "time"
func _on_light_button_pressed() -> void:
con_name = "light"
func _on_hammer_button_pressed() -> void:
con_name = "hammer"
func _on_fishing_rod_button_pressed() -> void:
con_name = "fishing_rod"
func _on_flag_button_pressed() -> void:
con_name = "flag"