Crafting v4
This commit is contained in:
+129
-7
@@ -411,16 +411,123 @@ func _drop_on_crafting_slot(slot_index: int):
|
||||
|
||||
var slot = crafting_slots[slot_index]
|
||||
var item = drag_data.get("item", {})
|
||||
var source_slot = drag_data.get("source_slot", -1)
|
||||
var max_qty = item.get("quantity", 1)
|
||||
|
||||
# Place in crafting slot (visual only - items stay in inventory)
|
||||
slot.set_meta("item", item.duplicate())
|
||||
_update_slot_display(slot, item)
|
||||
# If item has quantity > 1, show quantity selector
|
||||
if max_qty > 1:
|
||||
_show_quantity_popup(slot_index, item, source_slot, max_qty)
|
||||
else:
|
||||
# Just place 1
|
||||
_place_in_crafting_slot(slot_index, item, source_slot, 1)
|
||||
|
||||
_end_drag()
|
||||
|
||||
func _show_quantity_popup(slot_index: int, item: Dictionary, source_slot: int, max_qty: int):
|
||||
# Create a simple popup for quantity selection
|
||||
var popup = PopupPanel.new()
|
||||
popup.name = "QuantityPopup"
|
||||
|
||||
var vbox = VBoxContainer.new()
|
||||
popup.add_child(vbox)
|
||||
|
||||
var label = Label.new()
|
||||
label.text = "How many %s?" % item.get("name", "items")
|
||||
vbox.add_child(label)
|
||||
|
||||
var hbox = HBoxContainer.new()
|
||||
vbox.add_child(hbox)
|
||||
|
||||
var spin = SpinBox.new()
|
||||
spin.min_value = 1
|
||||
spin.max_value = max_qty
|
||||
spin.value = 1
|
||||
spin.name = "SpinBox"
|
||||
hbox.add_child(spin)
|
||||
|
||||
var max_btn = Button.new()
|
||||
max_btn.text = "Max"
|
||||
max_btn.pressed.connect(func(): spin.value = max_qty)
|
||||
hbox.add_child(max_btn)
|
||||
|
||||
var btn_row = HBoxContainer.new()
|
||||
vbox.add_child(btn_row)
|
||||
|
||||
var ok_btn = Button.new()
|
||||
ok_btn.text = "OK"
|
||||
ok_btn.pressed.connect(func():
|
||||
var qty = int(spin.value)
|
||||
_place_in_crafting_slot(slot_index, item, source_slot, qty)
|
||||
popup.queue_free()
|
||||
)
|
||||
btn_row.add_child(ok_btn)
|
||||
|
||||
var cancel_btn = Button.new()
|
||||
cancel_btn.text = "Cancel"
|
||||
cancel_btn.pressed.connect(func(): popup.queue_free())
|
||||
btn_row.add_child(cancel_btn)
|
||||
|
||||
add_child(popup)
|
||||
popup.popup_centered()
|
||||
|
||||
func _place_in_crafting_slot(slot_index: int, item: Dictionary, source_slot: int, quantity: int):
|
||||
var slot = crafting_slots[slot_index]
|
||||
|
||||
# Create crafting slot item with selected quantity
|
||||
var craft_item = item.duplicate()
|
||||
craft_item["quantity"] = quantity
|
||||
craft_item["_source_slot"] = source_slot
|
||||
|
||||
slot.set_meta("item", craft_item)
|
||||
_update_slot_display(slot, craft_item)
|
||||
|
||||
# Green border to show it's in crafting grid
|
||||
var style = _create_slot_style(Color(0.15, 0.2, 0.15), Color(0.3, 0.6, 0.3))
|
||||
slot.add_theme_stylebox_override("normal", style)
|
||||
|
||||
_end_drag()
|
||||
# Update the visual quantity remaining in inventory display
|
||||
_update_inventory_visual()
|
||||
|
||||
func _update_inventory_visual():
|
||||
# Recalculate what's "used" in crafting grid and show reduced quantities
|
||||
if not GameState or inventory_slots.is_empty():
|
||||
return
|
||||
|
||||
# Count what's in crafting grid by source slot
|
||||
var used_by_slot = {}
|
||||
for slot in crafting_slots:
|
||||
var item = slot.get_meta("item")
|
||||
if item and not item.is_empty():
|
||||
var src = item.get("_source_slot", -1)
|
||||
if src >= 0:
|
||||
if not used_by_slot.has(src):
|
||||
used_by_slot[src] = 0
|
||||
used_by_slot[src] += item.get("quantity", 1)
|
||||
|
||||
# Update inventory display with reduced quantities
|
||||
for i in range(30):
|
||||
if i >= inventory_slots.size():
|
||||
break
|
||||
var inv_slot = inventory_slots[i]
|
||||
var item = GameState.inventory[i] if i < GameState.inventory.size() else null
|
||||
|
||||
if item and not item.is_empty():
|
||||
var used = used_by_slot.get(i, 0)
|
||||
var remaining = item.get("quantity", 1) - used
|
||||
|
||||
if remaining <= 0:
|
||||
# All used in crafting, show empty/grayed
|
||||
_update_slot_display(inv_slot, null)
|
||||
inv_slot.modulate = Color(0.5, 0.5, 0.5, 0.5)
|
||||
else:
|
||||
# Show reduced quantity
|
||||
var display_item = item.duplicate()
|
||||
display_item["quantity"] = remaining
|
||||
_update_slot_display(inv_slot, display_item)
|
||||
inv_slot.modulate = Color.WHITE
|
||||
else:
|
||||
_update_slot_display(inv_slot, item)
|
||||
inv_slot.modulate = Color.WHITE
|
||||
|
||||
func _end_drag():
|
||||
is_dragging = false
|
||||
@@ -435,10 +542,21 @@ func _clear_crafting_slot(slot_index: int):
|
||||
for child in slot.get_children():
|
||||
child.queue_free()
|
||||
slot.add_theme_stylebox_override("normal", _create_slot_style(Color(0.15, 0.15, 0.2)))
|
||||
|
||||
# Update inventory visuals
|
||||
_update_inventory_visual()
|
||||
|
||||
func _clear_crafting_grid():
|
||||
for i in range(crafting_slots.size()):
|
||||
_clear_crafting_slot(i)
|
||||
var slot = crafting_slots[i]
|
||||
slot.set_meta("item", null)
|
||||
slot.text = ""
|
||||
for child in slot.get_children():
|
||||
child.queue_free()
|
||||
slot.add_theme_stylebox_override("normal", _create_slot_style(Color(0.15, 0.15, 0.2)))
|
||||
|
||||
# Reset inventory display
|
||||
_refresh_inventory_display()
|
||||
|
||||
func _input(event):
|
||||
if not visible:
|
||||
@@ -583,13 +701,14 @@ func _on_discover_pressed():
|
||||
_show_result("Place ingredients in the grid!", Color.YELLOW)
|
||||
return
|
||||
|
||||
# Count ingredients
|
||||
# Count ingredients by definition ID, using the quantity in each slot
|
||||
var ingredient_counts = {}
|
||||
for item in items:
|
||||
var def_id = item.get("definitionId", 0)
|
||||
var qty = item.get("quantity", 1)
|
||||
if not ingredient_counts.has(def_id):
|
||||
ingredient_counts[def_id] = 0
|
||||
ingredient_counts[def_id] += 1
|
||||
ingredient_counts[def_id] += qty
|
||||
|
||||
var ingredients = []
|
||||
for def_id in ingredient_counts:
|
||||
@@ -598,6 +717,8 @@ func _on_discover_pressed():
|
||||
"quantity": ingredient_counts[def_id]
|
||||
})
|
||||
|
||||
print("[Crafting] Attempting discovery with skill %d: %s" % [selected_skill_type, ingredients])
|
||||
|
||||
if GameState:
|
||||
# Send with skill type for filtering
|
||||
GameState.send_discover_recipe_with_skill(ingredients, selected_skill_type)
|
||||
@@ -605,6 +726,7 @@ func _on_discover_pressed():
|
||||
discover_button.disabled = true
|
||||
|
||||
func _on_crafting_result(result: Dictionary):
|
||||
print("[Crafting] Received result: %s" % result)
|
||||
craft_button.disabled = false
|
||||
if discover_button:
|
||||
discover_button.disabled = false
|
||||
|
||||
Reference in New Issue
Block a user