RustHacker/inv_system/crafting_panel.gd

113 lines
3.2 KiB
GDScript3
Raw Normal View History

2026-01-11 16:05:12 +11:00
extends Inventory
@export var action_button : Button
2026-01-11 18:11:14 +11:00
@export var craft_recipes : Array[CraftRecipe]
2026-01-11 18:49:11 +11:00
@export var scavenge_recipes : Array[ScavengeRecipe]
var matched_recipe : Recipe
2026-01-11 16:05:12 +11:00
#@export var no_style : StyleBox
@export var assemble_style : StyleBox
@export var assemble_style_hover : StyleBox
@export var assemble_style_pressed : StyleBox
@export var scavenge_style : StyleBox
@export var scavenge_style_hover : StyleBox
@export var scavenge_style_pressed : StyleBox
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
super()
2026-01-11 17:38:55 +11:00
#style_scavenge()
2026-01-11 18:49:11 +11:00
check_recipes()
2026-01-11 16:05:12 +11:00
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
super(delta)
pass
func _notification(what: int) -> void:
super(what)
if what == Node.NOTIFICATION_DRAG_END:
2026-01-11 18:11:14 +11:00
check_recipes()
2026-01-11 16:05:12 +11:00
pass
2026-01-11 18:11:14 +11:00
func check_recipes():
print("checking now")
2026-01-11 18:49:11 +11:00
style_none()
2026-01-11 18:11:14 +11:00
# write checking logic
2026-01-11 18:49:11 +11:00
if filled_slots() == 1:
# check scavenging recipes
var item_to_scavenge : ItemData
for slot in slots:
if slot.item:
item_to_scavenge = slot.item
break
for recipe in scavenge_recipes:
if recipe.input.item_name == item_to_scavenge.item_name:
matched_recipe = recipe
style_scavenge()
return
elif filled_slots() > 1:
# check crafting recipes
var possible_recipes : Array[CraftRecipe] = craft_recipes.duplicate()
for x in range(9):
for recipe in possible_recipes:
if recipe.ingredients[x] and slots[x].item:
if recipe.ingredients[x].item_name != slots[x].item.item_name:
possible_recipes.erase(recipe)
elif recipe.ingredients[x] or slots[x].item:
possible_recipes.erase(recipe)
2026-01-11 18:49:11 +11:00
print("Possible recipes: " + str(possible_recipes.size()))
if possible_recipes.size() == 1:
print("found our recipe!")
matched_recipe = possible_recipes[0]
style_assemble()
return
2026-01-11 18:11:14 +11:00
2026-01-11 16:05:12 +11:00
func style_assemble():
action_button.add_theme_stylebox_override("normal",assemble_style)
action_button.add_theme_stylebox_override("hover",assemble_style_hover)
action_button.add_theme_stylebox_override("pressed",assemble_style_pressed)
action_button.text = "Assemble!"
action_button.disabled = false
2026-01-11 16:05:12 +11:00
func style_scavenge():
action_button.add_theme_stylebox_override("normal",scavenge_style)
action_button.add_theme_stylebox_override("hover",scavenge_style_hover)
action_button.add_theme_stylebox_override("pressed",scavenge_style_pressed)
action_button.text = "Scavenge!"
action_button.disabled = false
2026-01-11 16:05:12 +11:00
func style_none():
action_button.remove_theme_stylebox_override("normal")
action_button.remove_theme_stylebox_override("hover")
action_button.remove_theme_stylebox_override("pressed")
action_button.text = "no matching recipe"
action_button.disabled = true
2026-01-11 18:49:11 +11:00
func _on_action_button_pressed() -> void:
2026-01-11 18:54:03 +11:00
if not matched_recipe:
return
2026-01-11 19:06:59 +11:00
elif matched_recipe is CraftRecipe:
2026-01-11 18:54:03 +11:00
var crafting : CraftRecipe = matched_recipe
empty_grid()
add_item(crafting.output)
2026-01-11 19:06:59 +11:00
check_recipes()
elif matched_recipe is ScavengeRecipe:
empty_grid()
for x in range(matched_recipe.rolls):
add_item(matched_recipe.roll())
check_recipes()
2026-01-11 18:49:11 +11:00
pass # Replace with function body.
2026-01-11 18:54:03 +11:00
func empty_grid():
for slot in slots:
slot.item = null
slot.update_ui()