extends CanvasLayer @onready var close_button = $PanelContainer/VBoxContainer/Header/CloseButton @onready var equipment_grid = $PanelContainer/VBoxContainer/Content/EquipmentSection/EquipmentGrid @onready var inventory_grid = $PanelContainer/VBoxContainer/Content/BagSection/InventoryGrid @onready var gold_label = $PanelContainer/VBoxContainer/Footer/GoldLabel const EQUIPMENT_SLOTS = ["weapon", "offhand", "helm", "chest", "gloves", "legs", "boots", "necklace", "ring1", "ring2", "quiver"] # Emoji fallbacks for equipment slots (used when CDN texture not available) const EQUIPMENT_ICONS = { "weapon": "โš”๏ธ", "offhand": "๐Ÿ›ก๏ธ", "helm": "๐ŸŽฉ", "chest": "๐Ÿ‘•", "gloves": "๐Ÿงค", "legs": "๐Ÿ‘–", "boots": "๐Ÿ‘ข", "necklace": "๐Ÿ“ฟ", "ring1": "๐Ÿ’", "ring2": "๐Ÿ’", "quiver": "๐Ÿน" } # CDN paths for equipment slot background icons const EQUIPMENT_SLOT_TEXTURES = { "weapon": "textures/ui/slots/mainhand.png", "offhand": "textures/ui/slots/offhand.png", "helm": "textures/ui/slots/head.png", "chest": "textures/ui/slots/chest.png", "gloves": "textures/ui/slots/gloves.png", "legs": "textures/ui/slots/legs.png", "boots": "textures/ui/slots/boots.png", "necklace": "textures/ui/slots/neck.png", "ring1": "textures/ui/slots/ring.png", "ring2": "textures/ui/slots/ring.png", "quiver": "textures/ui/slots/back.png" } const RARITY_COLORS = { "Common": Color(0.7, 0.7, 0.7), "Uncommon": Color(0.18, 0.8, 0.44), "Rare": Color(0.2, 0.6, 0.86), "Epic": Color(0.61, 0.35, 0.71), "Legendary": Color(0.95, 0.61, 0.07) } var inventory_slots: Array = [] var equipment_slots: Dictionary = {} var tooltip: PanelContainer = null var selected_hotbar_slot: int = -1 # For hotbar assignment var left_click_start_time: int = 0 # Track left-click duration for drag detection var left_click_slot: int = -1 var left_click_start_pos: Vector2 = Vector2.ZERO const DRAG_THRESHOLD_TIME: int = 150 # ms before drag starts const DRAG_THRESHOLD_DISTANCE: float = 5.0 # pixels before drag starts func _ready(): visible = false if close_button: close_button.pressed.connect(_on_close) _setup_equipment_slots() _setup_inventory_slots() _create_tooltip() call_deferred("_connect_gamestate") func _connect_gamestate(): if GameState: GameState.inventory_updated.connect(_refresh_inventory) if UpdateManager: UpdateManager.file_downloaded.connect(_on_file_downloaded) UpdateManager.update_completed.connect(_on_updates_completed) func _process(_delta): if not visible: return # Check for drag initiation while holding left click if left_click_slot >= 0 and not DragManager.is_dragging: if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT): var current_pos = get_viewport().get_mouse_position() var distance = current_pos.distance_to(left_click_start_pos) var elapsed = Time.get_ticks_msec() - left_click_start_time # Start drag if held long enough OR moved far enough if elapsed >= DRAG_THRESHOLD_TIME or distance >= DRAG_THRESHOLD_DISTANCE: var item = GameState.inventory[left_click_slot] if left_click_slot < GameState.inventory.size() else null if item and not item.is_empty(): DragManager.start_drag(item, "inventory", left_click_slot) func _on_file_downloaded(file_path: String): # If an item texture was downloaded, refresh inventory to show it if file_path.begins_with("textures/items/"): _refresh_inventory() func _on_updates_completed(_count: int): # Refresh inventory after all updates complete _refresh_inventory() func _setup_equipment_slots(): if not equipment_grid: return for slot_name in EQUIPMENT_SLOTS: var slot = _create_slot_button() slot.set_meta("slot_type", "equipment") slot.set_meta("slot_name", slot_name) slot.set_meta("item", null) slot.text = EQUIPMENT_ICONS.get(slot_name, "?") slot.gui_input.connect(_on_equipment_gui_input.bind(slot_name)) slot.mouse_entered.connect(_on_slot_hover.bind(slot)) slot.mouse_exited.connect(_hide_tooltip) equipment_grid.add_child(slot) equipment_slots[slot_name] = slot func _setup_inventory_slots(): if not inventory_grid: return for i in range(30): var slot = _create_slot_button() slot.set_meta("slot_type", "inventory") slot.set_meta("slot_index", i) slot.set_meta("item", null) slot.gui_input.connect(_on_inventory_gui_input.bind(i)) slot.mouse_entered.connect(_on_slot_hover.bind(slot)) slot.mouse_exited.connect(_hide_tooltip) inventory_grid.add_child(slot) inventory_slots.append(slot) func _create_slot_button() -> Button: var btn = Button.new() btn.custom_minimum_size = Vector2(48, 48) btn.add_theme_stylebox_override("normal", _create_slot_style(Color(0.408, 0.408, 0.322, 1.0))) btn.add_theme_stylebox_override("hover", _create_slot_style(Color(0.408, 0.408, 0.322, 0.902))) btn.add_theme_stylebox_override("pressed", _create_slot_style(Color(0.408, 0.408, 0.322, 0.902))) btn.add_theme_stylebox_override("focus", _create_slot_style(Color(0.408, 0.408, 0.322, 1.0))) # Disable built-in button behavior btn.disabled = false btn.focus_mode = Control.FOCUS_NONE return btn func _create_slot_style(color: Color) -> StyleBoxFlat: var style = StyleBoxFlat.new() style.bg_color = color style.border_color = Color(0.0, 0.0, 0.0, 1.0) style.set_border_width_all(2) style.set_corner_radius_all(4) return style func _create_tooltip(): tooltip = PanelContainer.new() tooltip.z_index = 100 var style = StyleBoxFlat.new() style.bg_color = Color(0.1, 0.1, 0.15, 0.95) style.border_color = Color(0.4, 0.4, 0.5) style.set_border_width_all(1) style.set_corner_radius_all(4) style.set_content_margin_all(8) tooltip.add_theme_stylebox_override("panel", style) var vbox = VBoxContainer.new() vbox.name = "VBox" var name_label = Label.new() name_label.name = "ItemName" name_label.add_theme_font_size_override("font_size", 14) vbox.add_child(name_label) var type_label = Label.new() type_label.name = "ItemType" type_label.add_theme_font_size_override("font_size", 11) type_label.modulate = Color(0.7, 0.7, 0.7) vbox.add_child(type_label) var sep = HSeparator.new() vbox.add_child(sep) var stats_label = Label.new() stats_label.name = "ItemStats" stats_label.add_theme_font_size_override("font_size", 12) vbox.add_child(stats_label) var desc_label = Label.new() desc_label.name = "ItemDesc" desc_label.add_theme_font_size_override("font_size", 10) desc_label.modulate = Color(0.6, 0.6, 0.6) desc_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART desc_label.custom_minimum_size.x = 200 vbox.add_child(desc_label) var hint_label = Label.new() hint_label.name = "Hint" hint_label.add_theme_font_size_override("font_size", 10) hint_label.modulate = Color(0.5, 0.7, 0.5) vbox.add_child(hint_label) tooltip.add_child(vbox) tooltip.visible = false add_child(tooltip) func _refresh_inventory(): for i in range(30): if i >= inventory_slots.size(): break var item = GameState.inventory[i] if i < GameState.inventory.size() else null _update_slot(inventory_slots[i], item) for slot_name in EQUIPMENT_SLOTS: if equipment_slots.has(slot_name): var item = GameState.equipment.get(slot_name) _update_slot(equipment_slots[slot_name], item, EQUIPMENT_ICONS.get(slot_name, "?"), slot_name) func _update_slot(slot: Button, item, default_text: String = "", slot_name: String = ""): # Clear any existing children (sprites, labels) for child in slot.get_children(): child.queue_free() if item == null or (item is Dictionary and item.is_empty()): # Empty slot: try to load CDN slot texture, fall back to emoji slot.set_meta("item", null) slot.add_theme_stylebox_override("normal", _create_slot_style(Color(0.15, 0.15, 0.2))) # Try to load slot icon from CDN if this is an equipment slot if slot_name != "" and EQUIPMENT_SLOT_TEXTURES.has(slot_name) and UpdateManager: var slot_texture_path = EQUIPMENT_SLOT_TEXTURES.get(slot_name) var texture = UpdateManager.load_texture(slot_texture_path) if texture: var sprite = TextureRect.new() sprite.texture = texture sprite.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL sprite.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED sprite.custom_minimum_size = Vector2(32, 32) sprite.anchors_preset = Control.PRESET_CENTER sprite.position = Vector2(8, 8) # Center in 48x48 slot sprite.modulate = Color(1, 1, 1, 0.3) # Dim the slot icon to show it's empty slot.add_child(sprite) slot.text = "" # Clear emoji text since we have a texture return # Fall back to emoji if CDN texture not available slot.text = default_text else: # Equipped item: show the item's sprite, NOT the slot icon slot.text = "" # Clear text, we'll use sprite instead slot.set_meta("item", item) # Try to load sprite from CDN var sprite_path = item.get("spritePath", item.get("SpritePath", "")) var has_sprite = false if sprite_path and not sprite_path.is_empty() and UpdateManager: var texture = UpdateManager.load_texture(sprite_path) if texture: var sprite = TextureRect.new() sprite.texture = texture sprite.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL sprite.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED sprite.custom_minimum_size = Vector2(32, 32) sprite.anchors_preset = Control.PRESET_CENTER sprite.position = Vector2(8, 8) # Center in 48x48 slot # Apply tint if specified var tint = item.get("tintColor", item.get("TintColor", "")) if tint and not tint.is_empty(): sprite.modulate = Color.from_string(tint, Color.WHITE) slot.add_child(sprite) has_sprite = true # Fall back to emoji if no sprite if not has_sprite: slot.text = _get_item_emoji(item) # Add stack count label if quantity > 1 OR if this is equipped ammunition/quiver var quantity = item.get("quantity", item.get("Quantity", 1)) var show_count = quantity > 1 # Always show count for equipped quiver or ammunition slots if slot_name == "quiver" and quantity >= 1: show_count = true if show_count: var count_label = Label.new() count_label.text = str(quantity) count_label.add_theme_font_size_override("font_size", 10) count_label.add_theme_color_override("font_color", Color.WHITE) count_label.add_theme_color_override("font_shadow_color", Color.BLACK) count_label.add_theme_constant_override("shadow_offset_x", 1) count_label.add_theme_constant_override("shadow_offset_y", 1) count_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT count_label.vertical_alignment = VERTICAL_ALIGNMENT_BOTTOM count_label.anchors_preset = Control.PRESET_BOTTOM_RIGHT count_label.position = Vector2(slot.custom_minimum_size.x - 20, slot.custom_minimum_size.y - 16) slot.add_child(count_label) # Style based on rarity var rarity = item.get("rarity", item.get("Rarity", "Common")) var style = _create_slot_style(Color(0.15, 0.15, 0.2)) style.border_color = RARITY_COLORS.get(rarity, Color.GRAY) style.border_width_bottom = 3 slot.add_theme_stylebox_override("normal", style) func _get_item_emoji(item: Dictionary) -> String: var item_type = item.get("type", item.get("Type", "")).to_lower() var item_name = item.get("name", item.get("Name", "")).to_lower() match item_type: "consumable": if "health" in item_name: return "โค๏ธ" if "mana" in item_name: return "๐Ÿ’™" if "escape" in item_name: return "๐Ÿƒ" return "๐Ÿงช" "material": if "bone" in item_name: return "๐Ÿฆด" if "hide" in item_name or "leather" in item_name: return "๐Ÿฅฉ" if "essence" in item_name or "soul" in item_name: return "๐Ÿ‘ป" if "shard" in item_name or "crystal" in item_name: return "๐Ÿ’Ž" return "๐Ÿ“ฆ" "weapon": return "โš”๏ธ" "armor": if "helm" in item_name: return "๐ŸŽฉ" return "๐Ÿ›ก๏ธ" "accessory": return "๐Ÿ’" _: return "โ“" func _on_inventory_gui_input(event: InputEvent, slot_index: int): var item = GameState.inventory[slot_index] if slot_index < GameState.inventory.size() else null # Handle mouse button events if event is InputEventMouseButton: # Left click if event.button_index == MOUSE_BUTTON_LEFT: if event.pressed: if DragManager and DragManager.is_dragging: # Drop item here _drop_item_on_slot(slot_index, item) elif item != null and not item.is_empty(): # Start tracking for potential drag left_click_start_time = Time.get_ticks_msec() left_click_slot = slot_index left_click_start_pos = get_viewport().get_mouse_position() else: # Left click release - handled by _input for drag, here for quick click if not (DragManager and DragManager.is_dragging): if left_click_slot == slot_index and item != null: # Quick click (not a drag) - use or equip var click_duration = Time.get_ticks_msec() - left_click_start_time if click_duration < DRAG_THRESHOLD_TIME: var item_type = item.get("type", item.get("Type", "")) if item_type == "Consumable": GameState.send_use_item(slot_index) elif item_type in ["Weapon", "Armor", "Accessory"]: GameState.send_equip_item(slot_index) # Reset tracking left_click_slot = -1 # Right click - assign consumable to hotbar elif event.button_index == MOUSE_BUTTON_RIGHT and event.pressed: if DragManager and DragManager.is_dragging: # Cancel drag on right click DragManager.end_drag() elif item and not item.is_empty(): var item_type = item.get("type", item.get("Type", "")) if item_type == "Consumable": _show_hotbar_menu(slot_index) # Handle mouse motion for drag detection elif event is InputEventMouseMotion: if left_click_slot == slot_index and left_click_slot >= 0: if not DragManager.is_dragging: var current_pos = get_viewport().get_mouse_position() var distance = current_pos.distance_to(left_click_start_pos) var elapsed = Time.get_ticks_msec() - left_click_start_time # Start drag if held long enough OR moved far enough if elapsed >= DRAG_THRESHOLD_TIME or distance >= DRAG_THRESHOLD_DISTANCE: if item and not item.is_empty(): DragManager.start_drag(item, "inventory", slot_index) func _drop_item_on_slot(slot_index: int, target_item): if not DragManager or not DragManager.is_dragging: return 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 not event is InputEventMouseButton: return if event.button_index == MOUSE_BUTTON_LEFT: if event.pressed: if DragManager and DragManager.is_dragging: # Drop dragged item onto equipment slot _drop_item_on_equipment(slot_name) else: # Left click on equipped item - unequip it var item = GameState.equipment.get(slot_name) if item != null: GameState.send_unequip_item(slot_name) func _drop_item_on_equipment(slot_name: String): if not DragManager or not DragManager.is_dragging: return var drag_item = DragManager.get_drag_item() var source_type = DragManager.drag_data.get("source_type", "") var source_slot = DragManager.drag_data.get("source_slot", -1) # Only allow drops from inventory if source_type != "inventory" or source_slot < 0: DragManager.end_drag() return # Check if item can be equipped in this slot var item_type = drag_item.get("type", drag_item.get("Type", "")) var item_slot = drag_item.get("slot", drag_item.get("Slot", "")) # Validate the item can go in this equipment slot var valid_slot = false match slot_name: "weapon": valid_slot = item_type == "Weapon" and item_slot in ["MainHand", "TwoHand", "Ranged"] "offhand": valid_slot = item_type == "Weapon" and item_slot == "OffHand" or item_type == "Armor" and item_slot == "Shield" "helm": valid_slot = item_type == "Armor" and item_slot == "Head" "chest": valid_slot = item_type == "Armor" and item_slot == "Chest" "gloves": valid_slot = item_type == "Armor" and item_slot == "Hands" "legs": valid_slot = item_type == "Armor" and item_slot == "Legs" "boots": valid_slot = item_type == "Armor" and item_slot == "Feet" "necklace": valid_slot = item_type == "Accessory" and item_slot == "Neck" "ring1", "ring2": valid_slot = item_type == "Accessory" and item_slot == "Ring" "quiver": valid_slot = item_slot == "Quiver" or item_slot == "Back" if valid_slot: # Equip the item from the source inventory slot GameState.send_equip_item(source_slot) else: print("Cannot equip %s in %s slot" % [drag_item.get("name", "item"), slot_name]) DragManager.end_drag() func _can_stack_items(item1: Dictionary, item2: Dictionary) -> bool: # 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)) # Must have same ID if id1 != id2 or id1 == 0: return false # Must be stackable var stackable1 = item1.get("stackable", item1.get("Stackable", false)) var stackable2 = item2.get("stackable", item2.get("Stackable", false)) if not stackable1 or not stackable2: return false # Check if target has room (not already at max stack) var max_stack = item2.get("maxStack", item2.get("MaxStack", 99)) var current_quantity = item2.get("quantity", item2.get("Quantity", 1)) return current_quantity < max_stack func _show_hotbar_menu(inv_slot: int): # Simple approach: assign to next empty hotbar slot or use slot 0 # For now, find first empty slot or use slot 0 var target_slot = 0 for i in range(8): if GameState.hotbar[i] == null: target_slot = i break GameState.assign_hotbar(target_slot, inv_slot) print("Assigned inventory slot %d to hotbar slot %d" % [inv_slot, target_slot]) func _on_slot_hover(slot: Button): if not slot.has_meta("item"): _hide_tooltip() return var item = slot.get_meta("item") if item == null: _hide_tooltip() return _show_tooltip(item, slot) func _show_tooltip(item: Dictionary, slot: Button): if not tooltip: return var vbox = tooltip.get_node_or_null("VBox") if not vbox: return var name_label = vbox.get_node_or_null("ItemName") var type_label = vbox.get_node_or_null("ItemType") var stats_label = vbox.get_node_or_null("ItemStats") var desc_label = vbox.get_node_or_null("ItemDesc") var hint_label = vbox.get_node_or_null("Hint") if not name_label: return var rarity = item.get("rarity", item.get("Rarity", "Common")) var item_name = item.get("name", item.get("Name", "Unknown")) var item_type = item.get("type", item.get("Type", "")) var quantity = item.get("quantity", item.get("Quantity", 1)) # Show quantity in name if > 1 if quantity > 1: name_label.text = "%s (x%d)" % [item_name, quantity] else: name_label.text = item_name name_label.modulate = RARITY_COLORS.get(rarity, Color.WHITE) if type_label: type_label.text = "%s %s" % [rarity, item_type] # Build stats text var stats = [] var min_dmg = item.get("minDamage", item.get("MinDamage", 0)) var max_dmg = item.get("maxDamage", item.get("MaxDamage", 0)) if min_dmg > 0 and max_dmg > 0: stats.append("Damage: %d-%d" % [int(min_dmg), int(max_dmg)]) var armor = item.get("armor", item.get("Armor", 0)) if armor > 0: stats.append("Armor: +%d" % int(armor)) var bonus_str = item.get("bonusStrength", item.get("BonusStrength", 0)) if bonus_str > 0: stats.append("Strength: +%d" % int(bonus_str)) var bonus_int = item.get("bonusIntelligence", item.get("BonusIntelligence", 0)) if bonus_int > 0: stats.append("Intelligence: +%d" % int(bonus_int)) var bonus_wis = item.get("bonusWisdom", item.get("BonusWisdom", 0)) if bonus_wis > 0: stats.append("Wisdom: +%d" % int(bonus_wis)) var bonus_end = item.get("bonusEndurance", item.get("BonusEndurance", 0)) if bonus_end > 0: stats.append("Endurance: +%d" % int(bonus_end)) var bonus_dex = item.get("bonusDexterity", item.get("BonusDexterity", 0)) if bonus_dex > 0: stats.append("Dexterity: +%d" % int(bonus_dex)) var bonus_hp = item.get("bonusHealth", item.get("BonusHealth", 0)) if bonus_hp > 0: stats.append("Health: +%d" % int(bonus_hp)) var bonus_mp = item.get("bonusMana", item.get("BonusMana", 0)) if bonus_mp > 0: stats.append("Mana: +%d" % int(bonus_mp)) var heal = item.get("healAmount", item.get("HealAmount", 0)) if heal > 0: stats.append("Heals: %d HP" % int(heal)) var mana_restore = item.get("manaRestore", item.get("ManaRestore", 0)) if mana_restore > 0: stats.append("Restores: %d MP" % int(mana_restore)) # Add crafted item info var is_crafted = item.get("isCrafted", item.get("IsCrafted", false)) if is_crafted: stats.append("") # Empty line separator var crafter_name = item.get("crafterName", item.get("CrafterName", "Unknown")) var quality = item.get("qualityRating", item.get("QualityRating", 0)) var crafted_at = item.get("craftedAt", item.get("CraftedAt", "")) stats.append("Crafted by: %s" % crafter_name) stats.append("Quality: %d%%" % int(quality)) if stats_label: stats_label.text = "\n".join(stats) if stats.size() > 0 else "" stats_label.visible = stats.size() > 0 if desc_label: var desc = item.get("description", item.get("Description", "")) desc_label.text = desc desc_label.visible = desc != "" # Hint for actions if hint_label: if item_type == "Consumable": hint_label.text = "Left-click: Use | Right-click: Add to hotbar" elif item_type in ["Weapon", "Armor", "Accessory"]: hint_label.text = "Left-click: Equip" else: hint_label.text = "" hint_label.visible = hint_label.text != "" # Position tooltip near slot await get_tree().process_frame var screen_size = get_viewport().get_visible_rect().size var pos = slot.global_position + Vector2(slot.size.x + 10, 0) # Keep on screen if pos.x + tooltip.size.x > screen_size.x: pos.x = slot.global_position.x - tooltip.size.x - 10 if pos.y + tooltip.size.y > screen_size.y: pos.y = screen_size.y - tooltip.size.y - 10 tooltip.global_position = pos tooltip.visible = true func _hide_tooltip(): if tooltip: tooltip.visible = false func _on_close(): visible = false func _input(event): if not visible: return # Handle mouse release for drag operations - find what's under the mouse if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and not event.pressed: if DragManager and DragManager.is_dragging: # Find what slot is under the mouse and drop there var drop_slot = _get_inventory_slot_at_mouse() var equip_slot = _get_equipment_slot_at_mouse() var hotbar_slot = _get_hotbar_slot_at_mouse() if drop_slot >= 0: var target_item = GameState.inventory[drop_slot] if drop_slot < GameState.inventory.size() else null _drop_item_on_slot(drop_slot, target_item) elif equip_slot != "": _drop_item_on_equipment(equip_slot) elif hotbar_slot >= 0: _drop_item_on_hotbar(hotbar_slot) else: DragManager.end_drag() left_click_slot = -1 get_viewport().set_input_as_handled() 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() func _get_inventory_slot_at_mouse() -> int: var mouse_pos = get_viewport().get_mouse_position() for i in range(inventory_slots.size()): var slot = inventory_slots[i] var rect = Rect2(slot.global_position, slot.size) if rect.has_point(mouse_pos): return i return -1 func _get_equipment_slot_at_mouse() -> String: var mouse_pos = get_viewport().get_mouse_position() for slot_name in equipment_slots: var slot = equipment_slots[slot_name] var rect = Rect2(slot.global_position, slot.size) if rect.has_point(mouse_pos): return slot_name return "" func _get_hotbar_slot_at_mouse() -> int: var mouse_pos = get_viewport().get_mouse_position() # Find the HUD and check hotbar slots var hud = get_tree().get_first_node_in_group("hud") if hud and hud.has_method("get_hotbar_slots"): var hotbar_slots = hud.get_hotbar_slots() for i in range(hotbar_slots.size()): var slot = hotbar_slots[i] var rect = Rect2(slot.global_position, slot.size) if rect.has_point(mouse_pos): return i return -1 func _drop_item_on_hotbar(hotbar_slot: int): if not DragManager or not DragManager.is_dragging: return var drag_item = DragManager.get_drag_item() var source_type = DragManager.drag_data.get("source_type", "") var source_slot = DragManager.drag_data.get("source_slot", -1) # Only allow drops from inventory if source_type != "inventory" or source_slot < 0: DragManager.end_drag() return # Allow consumables and equipment in hotbar var item_type = drag_item.get("type", drag_item.get("Type", "")) print("[Type]" , item_type) if item_type not in ["Consumable", "Weapon", "Armor", "Accessory"]: DragManager.end_drag() return # Assign to hotbar GameState.assign_hotbar(hotbar_slot, source_slot) DragManager.end_drag()