Big fixes

This commit is contained in:
dingo
2026-01-26 17:42:23 -05:00
parent c1a97b219e
commit b434eb6031
10 changed files with 303 additions and 76 deletions
+2 -2
View File
@@ -45,13 +45,13 @@ func start_drag(item: Dictionary, source_type: String, source_slot: int):
"source_type": source_type,
"source_slot": source_slot
}
if drag_preview:
var label = drag_preview.get_node_or_null("Label")
if label:
label.text = item.get("name", "Item")
drag_preview.visible = true
drag_started.emit(drag_data)
func end_drag():
+1 -1
View File
@@ -421,7 +421,7 @@ func _find_file_recursive(dir: DirAccess, current_path: String, filename: String
func load_texture(file_path: String) -> Texture2D:
# Check already-loaded texture cache
if _loaded_textures.has(file_path):
print("[UpdateManager] load_texture(%s) - Found in _loaded_textures cache" % file_path)
#iprint("[UpdateManager] load_texture(%s) - Found in _loaded_textures cache" % file_path)
return _loaded_textures[file_path]
var buffer: PackedByteArray
+4 -4
View File
@@ -220,7 +220,7 @@ func _build_tiles():
func _input(event: InputEvent):
# Handle touch screen taps for attacking
if event is InputEventScreenTouch and event.pressed:
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible)
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible) or (crafting_panel and crafting_panel.visible) or (char_sheet_ui and char_sheet_ui.visible) or (loot_popup and loot_popup.visible)
# Don't attack if UI is open
if ui_open:
@@ -258,7 +258,7 @@ func _handle_input():
return
# Don't process game input if inventory or chat is open
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible)
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible) or (crafting_panel and crafting_panel.visible) or (char_sheet_ui and char_sheet_ui.visible) or (loot_popup and loot_popup.visible)
# Calculate aim angle from mouse/touch position
var mouse_pos = get_global_mouse_position()
@@ -315,7 +315,7 @@ func _handle_input():
func _perform_attack(attack_angle: float):
# Don't attack if UI is open
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible) or (crafting_panel and crafting_panel.visible)
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible) or (crafting_panel and crafting_panel.visible) or (char_sheet_ui and char_sheet_ui.visible) or (loot_popup and loot_popup.visible)
if ui_open:
return
@@ -408,7 +408,7 @@ func _perform_attack(attack_angle: float):
func _send_movement():
# Don't move if UI is open
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible)
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible) or (crafting_panel and crafting_panel.visible) or (char_sheet_ui and char_sheet_ui.visible) or (loot_popup and loot_popup.visible)
if ui_open:
return
+1 -1
View File
@@ -72,7 +72,7 @@ func _process(delta: float) -> void:
_handle_input()
func _handle_input():
if Input.is_action_just_pressed("charSheet"):
if Input.is_action_just_pressed("charSheet") and GameState.current_state != GameState.STATE_AUTH:
_toggle_char_sheet()
#if Input.is_action_just_pressed("inventory"):
#_toggle_inventory()
+17 -10
View File
@@ -93,12 +93,16 @@ func _setup_hotbar():
func _on_hotbar_slot_input(event: InputEvent, slot_index: int):
if not event is InputEventMouseButton:
return
# Check if dropping from DragManager
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
# Check if dropping from DragManager (on press or release)
if event.button_index == MOUSE_BUTTON_LEFT:
if DragManager and DragManager.is_dragging:
# Drop on either press or release to catch the item
DragManager.drop_on("hotbar", slot_index)
elif not event.pressed:
# Not dragging, clicked hotbar slot - use the item
_on_hotbar_pressed(slot_index)
# Right click to clear hotbar slot
elif event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
GameState.assign_hotbar(slot_index, -1) # -1 to clear
@@ -336,7 +340,7 @@ func _update_hotbar():
var inv_slot = hotbar_entry.inventory_slot
if inv_slot < GameState.inventory.size():
var item = GameState.inventory[inv_slot]
if item and item.get("type") == "Consumable":
if item and (item.get("type") == "Consumable" or item.get("type") == "Weapon" or item.get("type") == "Armor" or item.get("type") == "Accessory"):
slot.text = ""
# Try to load sprite from CDN
@@ -461,16 +465,19 @@ func _get_mobile_controls_enabled() -> bool:
return ProjectSettings.get_setting("application/config/mobile_controls_enabled", true)
return ProjectSettings.get_setting("application/config/mobile_controls_enabled", false)
func set_mobile_controls_visible(visible: bool):
func set_mobile_controls_visible(is_visible: bool):
# Show/hide mobile UI buttons
if inventory_button:
inventory_button.visible = visible
inventory_button.visible = is_visible
if crafting_button:
crafting_button.visible = visible
crafting_button.visible = is_visible
if stats_button:
stats_button.visible = visible
stats_button.visible = is_visible
# Show/hide touch joystick
var joystick = get_node_or_null("TouchJoystick")
if joystick:
joystick.visible = visible
joystick.visible = is_visible
func get_hotbar_slots() -> Array:
return hotbar_slots
+216 -48
View File
@@ -49,8 +49,11 @@ 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
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
@@ -71,6 +74,23 @@ func _connect_gamestate():
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/"):
@@ -114,6 +134,11 @@ func _create_slot_button() -> Button:
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:
@@ -124,6 +149,7 @@ func _create_slot_style(color: Color) -> StyleBoxFlat:
style.set_corner_radius_all(4)
return style
func _create_tooltip():
tooltip = PanelContainer.new()
tooltip.z_index = 100
@@ -302,51 +328,58 @@ func _get_item_emoji(item: Dictionary) -> String:
_: return "❓"
func _on_inventory_gui_input(event: InputEvent, slot_index: int):
if not event is InputEventMouseButton:
return
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 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:
# 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:
# Right click release
if DragManager and DragManager.is_dragging:
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
# 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:
@@ -376,10 +409,68 @@ func _drop_item_on_slot(slot_index: int, target_item):
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:
var item = GameState.equipment.get(slot_name)
if item != null:
GameState.send_unequip_item(slot_name)
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
@@ -559,6 +650,28 @@ 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()
@@ -567,3 +680,58 @@ func _input(event):
# 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()