diff --git a/assets/ui/stash.png b/assets/ui/stash.png new file mode 100644 index 0000000..03f3db0 Binary files /dev/null and b/assets/ui/stash.png differ diff --git a/assets/ui/stash.png.import b/assets/ui/stash.png.import new file mode 100644 index 0000000..d7cb5b4 --- /dev/null +++ b/assets/ui/stash.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://wpoldw1vbl0f" +path="res://.godot/imported/stash.png-b6e23a42d6354516d7e81458355f026e.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/stash.png" +dest_files=["res://.godot/imported/stash.png-b6e23a42d6354516d7e81458355f026e.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scenes/hub/hub_screen.tscn b/scenes/hub/hub_screen.tscn index 09f0530..877bf19 100644 --- a/scenes/hub/hub_screen.tscn +++ b/scenes/hub/hub_screen.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=20 format=3 uid="uid://linskq5jx4uh"] +[gd_scene load_steps=21 format=3 uid="uid://linskq5jx4uh"] [ext_resource type="Script" uid="uid://c4v4vw32gyxbl" path="res://scripts/ui/hub_ui.gd" id="1_u7qci"] [ext_resource type="PackedScene" uid="uid://ctsfevsx6nnv2" path="res://scenes/hub/dungeon_browser.tscn" id="2_browser"] @@ -15,6 +15,7 @@ [ext_resource type="Texture2D" uid="uid://cweri4tanbppf" path="res://assets/ui/plusBtnDown.png" id="8_2dc6d"] [ext_resource type="Texture2D" uid="uid://bniu06cdeknuj" path="res://assets/ui/inventory.png" id="9_nk0ko"] [ext_resource type="Texture2D" uid="uid://ds0ugfvjt1ate" path="res://assets/ui/sheet.png" id="10_8wxbt"] +[ext_resource type="Texture2D" uid="uid://wpoldw1vbl0f" path="res://assets/ui/stash.png" id="10_hx8vm"] [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_nobn3"] texture = ExtResource("2_x5h0m") @@ -490,6 +491,25 @@ offset_bottom = 836.0 scale = Vector2(0.44, 0.44) texture_normal = ExtResource("9_nk0ko") +[node name="CraftingBtn2" type="TextureButton" parent="Control"] +visible = false +layout_mode = 0 +offset_left = 183.29343 +offset_top = 653.0 +offset_right = 366.29343 +offset_bottom = 836.0 +scale = Vector2(0.44, 0.44) +texture_normal = ExtResource("9_nk0ko") + +[node name="StashBtn" type="TextureButton" parent="Control"] +layout_mode = 0 +offset_left = 372.56387 +offset_top = 652.0 +offset_right = 567.56384 +offset_bottom = 847.0 +scale = Vector2(0.44, 0.44) +texture_normal = ExtResource("10_hx8vm") + [node name="CraftingBtn" type="Button" parent="Control"] layout_mode = 0 offset_left = 292.87106 @@ -498,14 +518,6 @@ offset_right = 362.87106 offset_bottom = 712.0 text = "Crafting" -[node name="StashBtn" type="Button" parent="Control"] -layout_mode = 0 -offset_left = 375.55234 -offset_top = 681.0 -offset_right = 452.55234 -offset_bottom = 712.0 -text = "Stash 🔐" - [node name="CharSheetBtn" type="TextureButton" parent="Control"] layout_mode = 0 offset_left = 101.60833 diff --git a/scenes/main/main.tscn b/scenes/main/main.tscn index 6ac0467..2f483f6 100644 --- a/scenes/main/main.tscn +++ b/scenes/main/main.tscn @@ -1,8 +1,8 @@ [gd_scene load_steps=7 format=3 uid="uid://cug0ub6ft1ka"] [ext_resource type="Script" uid="uid://dxdsmo8kp5ppi" path="res://scripts/ui/main.gd" id="1_hyk8p"] -[ext_resource type="PackedScene" uid="uid://loading123456" path="res://scenes/ui/loading_screen.tscn" id="2_loading"] [ext_resource type="PackedScene" uid="uid://dl1ohomaanbth" path="res://scenes/auth/AuthScene.tscn" id="2_6q06x"] +[ext_resource type="PackedScene" uid="uid://dxgmcjmjxpenn" path="res://scenes/ui/loading_screen.tscn" id="2_loading"] [ext_resource type="PackedScene" uid="uid://linskq5jx4uh" path="res://scenes/hub/hub_screen.tscn" id="3_hub"] [ext_resource type="PackedScene" uid="uid://cldp1w744fs2l" path="res://scenes/dungeon/dungeon.tscn" id="4_dungeon"] [ext_resource type="PackedScene" uid="uid://cbpaygd2cw45c" path="res://scenes/ui/death_screen.tscn" id="5_death"] diff --git a/scripts/autoload/drag_manager.gd b/scripts/autoload/drag_manager.gd index 353fc2c..001c286 100644 --- a/scripts/autoload/drag_manager.gd +++ b/scripts/autoload/drag_manager.gd @@ -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(): diff --git a/scripts/autoload/update_manager.gd b/scripts/autoload/update_manager.gd index 5345a84..18688a1 100644 --- a/scripts/autoload/update_manager.gd +++ b/scripts/autoload/update_manager.gd @@ -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 diff --git a/scripts/dungeon/dungeon_manager.gd b/scripts/dungeon/dungeon_manager.gd index 049cca5..4d1a431 100644 --- a/scripts/dungeon/dungeon_manager.gd +++ b/scripts/dungeon/dungeon_manager.gd @@ -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 diff --git a/scripts/ui/hub_ui.gd b/scripts/ui/hub_ui.gd index 633e3b6..99be3d8 100644 --- a/scripts/ui/hub_ui.gd +++ b/scripts/ui/hub_ui.gd @@ -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() diff --git a/scripts/ui/hud.gd b/scripts/ui/hud.gd index 1586e96..229042f 100644 --- a/scripts/ui/hud.gd +++ b/scripts/ui/hud.gd @@ -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 diff --git a/scripts/ui/inventory_ui.gd b/scripts/ui/inventory_ui.gd index 99eb072..7ffb885 100644 --- a/scripts/ui/inventory_ui.gd +++ b/scripts/ui/inventory_ui.gd @@ -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()