Mob looting fix and dungeon closure.
This commit is contained in:
+78
-32
@@ -49,6 +49,8 @@ var inventory_slots: Array = []
|
||||
var equipment_slots: Dictionary = {}
|
||||
var tooltip: PanelContainer = null
|
||||
var selected_hotbar_slot: int = -1 # For hotbar assignment
|
||||
var right_click_start_time: int = 0 # Track right-click duration
|
||||
var right_click_slot: int = -1
|
||||
|
||||
func _ready():
|
||||
visible = false
|
||||
@@ -305,38 +307,73 @@ func _on_inventory_gui_input(event: InputEvent, slot_index: int):
|
||||
|
||||
var item = GameState.inventory[slot_index] if slot_index < GameState.inventory.size() else null
|
||||
|
||||
# Left click
|
||||
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
if item == null:
|
||||
return
|
||||
# Left click: equip/unequip or assign to hotbar
|
||||
var item_type = item.get("type", item.get("Type", ""))
|
||||
if item_type == "Consumable":
|
||||
# Show hotbar menu for consumables
|
||||
_show_hotbar_menu(slot_index)
|
||||
elif item_type in ["Weapon", "Armor", "Accessory"]:
|
||||
# Equip on left click
|
||||
GameState.send_equip_item(slot_index)
|
||||
if DragManager and DragManager.is_dragging:
|
||||
# Drop item here
|
||||
_drop_item_on_slot(slot_index, item)
|
||||
elif item != null:
|
||||
var item_type = item.get("type", item.get("Type", ""))
|
||||
if item_type == "Consumable":
|
||||
# Use consumable on left click
|
||||
GameState.send_use_item(slot_index)
|
||||
elif item_type in ["Weapon", "Armor", "Accessory"]:
|
||||
# Equip on left click
|
||||
GameState.send_equip_item(slot_index)
|
||||
|
||||
# Right click
|
||||
elif event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
if event.pressed:
|
||||
# Start drag if has item
|
||||
if item and not item.is_empty() and DragManager:
|
||||
# Right click press - start drag if has item
|
||||
if DragManager and DragManager.is_dragging:
|
||||
# Already dragging, drop here
|
||||
_drop_item_on_slot(slot_index, item)
|
||||
elif item and not item.is_empty():
|
||||
# Start drag
|
||||
right_click_start_time = Time.get_ticks_msec()
|
||||
right_click_slot = slot_index
|
||||
DragManager.start_drag(item, "inventory", slot_index)
|
||||
else:
|
||||
# End drag on release (if still dragging)
|
||||
# Right click release
|
||||
if DragManager and DragManager.is_dragging:
|
||||
# Check if we're dropping onto another inventory slot
|
||||
var target_item = GameState.inventory[slot_index] if slot_index < GameState.inventory.size() else null
|
||||
var drag_item = DragManager.get_drag_item()
|
||||
var drag_time = Time.get_ticks_msec() - right_click_start_time
|
||||
# If released quickly (< 200ms) without moving, it's a quick click
|
||||
if drag_time < 200 and right_click_slot == slot_index and item:
|
||||
DragManager.end_drag()
|
||||
# Show hotbar menu for consumables
|
||||
var item_type = item.get("type", item.get("Type", ""))
|
||||
if item_type == "Consumable":
|
||||
_show_hotbar_menu(slot_index)
|
||||
else:
|
||||
# It was a drag, drop here
|
||||
_drop_item_on_slot(slot_index, item)
|
||||
|
||||
# Try to stack consumables
|
||||
if target_item and drag_item and _can_stack_items(drag_item, target_item):
|
||||
var source_slot = DragManager.drag_data.get("source_slot", -1)
|
||||
if source_slot >= 0 and source_slot != slot_index:
|
||||
GameState.send_stack_items(source_slot, slot_index)
|
||||
func _drop_item_on_slot(slot_index: int, target_item):
|
||||
if not DragManager or not DragManager.is_dragging:
|
||||
return
|
||||
|
||||
# Just end the drag - drop handling is done by the drop target
|
||||
DragManager.end_drag()
|
||||
var drag_source_type = DragManager.drag_data.get("source_type", "")
|
||||
var drag_source_slot = DragManager.drag_data.get("source_slot", -1)
|
||||
var drag_item = DragManager.get_drag_item()
|
||||
|
||||
# Can't drop onto the same slot
|
||||
if drag_source_type == "inventory" and drag_source_slot == slot_index:
|
||||
DragManager.end_drag()
|
||||
return
|
||||
|
||||
# Only handle inventory to inventory drops
|
||||
if drag_source_type != "inventory" or drag_source_slot < 0:
|
||||
DragManager.end_drag()
|
||||
return
|
||||
|
||||
# Try to stack if both items are stackable
|
||||
if target_item and drag_item and _can_stack_items(drag_item, target_item):
|
||||
GameState.send_stack_items(drag_source_slot, slot_index)
|
||||
else:
|
||||
# Move/swap items
|
||||
GameState.send_move_item(drag_source_slot, slot_index)
|
||||
|
||||
DragManager.end_drag()
|
||||
|
||||
func _on_equipment_gui_input(event: InputEvent, slot_name: String):
|
||||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
@@ -345,18 +382,19 @@ func _on_equipment_gui_input(event: InputEvent, slot_name: String):
|
||||
GameState.send_unequip_item(slot_name)
|
||||
|
||||
func _can_stack_items(item1: Dictionary, item2: Dictionary) -> bool:
|
||||
# Check if both items are consumables with the same name
|
||||
var type1 = item1.get("type", item1.get("Type", ""))
|
||||
var type2 = item2.get("type", item2.get("Type", ""))
|
||||
# Check if both items are the same and stackable
|
||||
var id1 = item1.get("id", item1.get("Id", 0))
|
||||
var id2 = item2.get("id", item2.get("Id", 0))
|
||||
|
||||
if type1 != "Consumable" or type2 != "Consumable":
|
||||
# Must have same ID
|
||||
if id1 != id2 or id1 == 0:
|
||||
return false
|
||||
|
||||
# Check if same item type
|
||||
var name1 = item1.get("name", item1.get("Name", ""))
|
||||
var name2 = item2.get("name", item2.get("Name", ""))
|
||||
# Must be stackable
|
||||
var stackable1 = item1.get("stackable", item1.get("Stackable", false))
|
||||
var stackable2 = item2.get("stackable", item2.get("Stackable", false))
|
||||
|
||||
if name1 != name2:
|
||||
if not stackable1 or not stackable2:
|
||||
return false
|
||||
|
||||
# Check if target has room (not already at max stack)
|
||||
@@ -518,6 +556,14 @@ func _on_close():
|
||||
visible = false
|
||||
|
||||
func _input(event):
|
||||
if visible and event.is_action_pressed("escape_menu"):
|
||||
if not visible:
|
||||
return
|
||||
|
||||
if event.is_action_pressed("escape_menu"):
|
||||
visible = false
|
||||
get_viewport().set_input_as_handled()
|
||||
elif event is InputEventKey and event.pressed and not event.echo:
|
||||
if event.keycode == KEY_S:
|
||||
# Auto-stack inventory
|
||||
GameState.send_auto_stack_inventory()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
Reference in New Issue
Block a user