From a39f4a0a9833a2cfc0884a8e6de1e7c41f889f36 Mon Sep 17 00:00:00 2001 From: dingo Date: Tue, 20 Jan 2026 16:23:00 -0500 Subject: [PATCH] Loot changes --- export_presets.cfg | 70 ++++++- project.godot | 1 + scenes/dungeon/dungeon.tscn | 6 +- scenes/dungeon/dungeon.tscn1556396123.tmp | 44 ++++ scenes/main/main.tscn | 6 +- scenes/ui/char_sheet.tscn | 15 +- scenes/ui/loading_screen.tscn | 46 +++++ scenes/ui/mob_loot_ui.tscn | 57 ++++++ scripts/autoload/game_state.gd | 24 +++ scripts/autoload/opcodes.gd | 17 ++ scripts/dungeon/dungeon_manager.gd | 78 +++++++- scripts/dungeon/mob_visual.gd | 52 +++++ scripts/ui/hub_ui.gd | 16 +- scripts/ui/hud.gd | 31 +++ scripts/ui/inventory_ui.gd | 68 +++++-- scripts/ui/loading_screen.gd | 52 +++++ scripts/ui/loading_screen.gd.uid | 1 + scripts/ui/main.gd | 24 ++- scripts/ui/mob_loot_ui.gd | 232 ++++++++++++++++++++++ scripts/ui/mob_loot_ui.gd.uid | 1 + 20 files changed, 791 insertions(+), 50 deletions(-) create mode 100644 scenes/dungeon/dungeon.tscn1556396123.tmp create mode 100644 scenes/ui/loading_screen.tscn create mode 100644 scenes/ui/mob_loot_ui.tscn create mode 100644 scripts/ui/loading_screen.gd create mode 100644 scripts/ui/loading_screen.gd.uid create mode 100644 scripts/ui/mob_loot_ui.gd create mode 100644 scripts/ui/mob_loot_ui.gd.uid diff --git a/export_presets.cfg b/export_presets.cfg index dde3554..c84f3f8 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -25,7 +25,7 @@ custom_template/release="" variant/extensions_support=true variant/thread_support=true vram_texture_compression/for_desktop=true -vram_texture_compression/for_mobile=false +vram_texture_compression/for_mobile=true html/export_icon=true html/custom_html_shell="" html/head_include="" @@ -43,3 +43,71 @@ progressive_web_app/icon_512x512="" progressive_web_app/background_color=Color(0, 0, 0, 1) threads/emscripten_pool_size=8 threads/godot_pool_size=4 + +[preset.1] + +name="Windows Desktop" +platform="Windows Desktop" +runnable=true +advanced_options=false +dedicated_server=false +custom_features="" +export_filter="all_resources" +include_filter="" +exclude_filter="" +export_path="../DDivers-Win/DungeonDivers.exe" +patches=PackedStringArray() +encryption_include_filters="" +encryption_exclude_filters="" +seed=0 +encrypt_pck=false +encrypt_directory=false +script_export_mode=2 + +[preset.1.options] + +custom_template/debug="" +custom_template/release="" +debug/export_console_wrapper=1 +binary_format/embed_pck=false +texture_format/s3tc_bptc=true +texture_format/etc2_astc=false +shader_baker/enabled=false +binary_format/architecture="x86_64" +codesign/enable=false +codesign/timestamp=true +codesign/timestamp_server_url="" +codesign/digest_algorithm=1 +codesign/description="" +codesign/custom_options=PackedStringArray() +application/modify_resources=true +application/icon="" +application/console_wrapper_icon="" +application/icon_interpolation=4 +application/file_version="" +application/product_version="" +application/company_name="" +application/product_name="" +application/file_description="" +application/copyright="" +application/trademarks="" +application/export_angle=0 +application/export_d3d12=0 +application/d3d12_agility_sdk_multiarch=true +ssh_remote_deploy/enabled=false +ssh_remote_deploy/host="user@host_ip" +ssh_remote_deploy/port="22" +ssh_remote_deploy/extra_args_ssh="" +ssh_remote_deploy/extra_args_scp="" +ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}' +$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}' +$trigger = New-ScheduledTaskTrigger -Once -At 00:00 +$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries +$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings +Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true +Start-ScheduledTask -TaskName godot_remote_debug +while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 } +Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue" +ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue +Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue +Remove-Item -Recurse -Force '{temp_dir}'" diff --git a/project.godot b/project.godot index c65e4ab..2e7520f 100644 --- a/project.godot +++ b/project.godot @@ -158,3 +158,4 @@ crafting={ renderer/rendering_method="gl_compatibility" renderer/rendering_method.mobile="gl_compatibility" +textures/vram_compression/import_etc2_astc=true diff --git a/scenes/dungeon/dungeon.tscn b/scenes/dungeon/dungeon.tscn index 4dbe80d..2d7e1c1 100644 --- a/scenes/dungeon/dungeon.tscn +++ b/scenes/dungeon/dungeon.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=3 uid="uid://cldp1w744fs2l"] +[gd_scene load_steps=8 format=3 uid="uid://cldp1w744fs2l"] [ext_resource type="Script" uid="uid://cwcnvv5ptewf6" path="res://scripts/dungeon/dungeon_manager.gd" id="1_dungeon"] [ext_resource type="PackedScene" uid="uid://cctw06lt2ffgb" path="res://scenes/ui/hud.tscn" id="2_4f38h"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://3nr0vpkyyy0y" path="res://scenes/dungeon/player.tscn" id="2_player"] [ext_resource type="PackedScene" uid="uid://cd2vqevj7ggok" path="res://scenes/ui/chat.tscn" id="3_frwky"] [ext_resource type="PackedScene" uid="uid://bwlmaoeg3gbrn" path="res://scenes/ui/inventory.tscn" id="5_0fky6"] +[ext_resource type="PackedScene" uid="uid://bevuo5j02po14" path="res://scenes/ui/char_sheet.tscn" id="7_bsb75"] [node name="DungeonScene" type="Node2D"] script = ExtResource("1_dungeon") @@ -37,4 +38,7 @@ tile_set = ExtResource("2_frwky") [node name="Chat" parent="." instance=ExtResource("3_frwky")] +[node name="CharSheet" parent="." instance=ExtResource("7_bsb75")] +visible = false + [node name="Camera2D" type="Camera2D" parent="."] diff --git a/scenes/dungeon/dungeon.tscn1556396123.tmp b/scenes/dungeon/dungeon.tscn1556396123.tmp new file mode 100644 index 0000000..2d7e1c1 --- /dev/null +++ b/scenes/dungeon/dungeon.tscn1556396123.tmp @@ -0,0 +1,44 @@ +[gd_scene load_steps=8 format=3 uid="uid://cldp1w744fs2l"] + +[ext_resource type="Script" uid="uid://cwcnvv5ptewf6" path="res://scripts/dungeon/dungeon_manager.gd" id="1_dungeon"] +[ext_resource type="PackedScene" uid="uid://cctw06lt2ffgb" path="res://scenes/ui/hud.tscn" id="2_4f38h"] +[ext_resource type="TileSet" uid="uid://jruqgfbry8sy" path="res://assets/sprites/dungeon_tileset.tres" id="2_frwky"] +[ext_resource type="PackedScene" uid="uid://3nr0vpkyyy0y" path="res://scenes/dungeon/player.tscn" id="2_player"] +[ext_resource type="PackedScene" uid="uid://cd2vqevj7ggok" path="res://scenes/ui/chat.tscn" id="3_frwky"] +[ext_resource type="PackedScene" uid="uid://bwlmaoeg3gbrn" path="res://scenes/ui/inventory.tscn" id="5_0fky6"] +[ext_resource type="PackedScene" uid="uid://bevuo5j02po14" path="res://scenes/ui/char_sheet.tscn" id="7_bsb75"] + +[node name="DungeonScene" type="Node2D"] +script = ExtResource("1_dungeon") + +[node name="TileMapLayer" type="TileMapLayer" parent="."] +tile_set = ExtResource("2_frwky") + +[node name="Entities" type="Node2D" parent="."] + +[node name="Players" type="Node2D" parent="Entities"] + +[node name="Mobs" type="Node2D" parent="Entities"] + +[node name="Chests" type="Node2D" parent="Entities"] + +[node name="DroppedItems" type="Node2D" parent="Entities"] + +[node name="Portals" type="Node2D" parent="Entities"] + +[node name="LootChests" type="Node2D" parent="Entities"] + +[node name="Projectiles" type="Node2D" parent="Entities"] + +[node name="Player" parent="." instance=ExtResource("2_player")] + +[node name="Hud" parent="." instance=ExtResource("2_4f38h")] + +[node name="Inventory" parent="." instance=ExtResource("5_0fky6")] + +[node name="Chat" parent="." instance=ExtResource("3_frwky")] + +[node name="CharSheet" parent="." instance=ExtResource("7_bsb75")] +visible = false + +[node name="Camera2D" type="Camera2D" parent="."] diff --git a/scenes/main/main.tscn b/scenes/main/main.tscn index 8ffd25a..6ac0467 100644 --- a/scenes/main/main.tscn +++ b/scenes/main/main.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=6 format=3 uid="uid://cug0ub6ft1ka"] +[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://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"] @@ -9,7 +10,10 @@ [node name="Main" type="Node"] script = ExtResource("1_hyk8p") +[node name="LoadingScreen" parent="." instance=ExtResource("2_loading")] + [node name="AuthScreen" parent="." instance=ExtResource("2_6q06x")] +visible = false [node name="HubScreen" parent="." instance=ExtResource("3_hub")] visible = false diff --git a/scenes/ui/char_sheet.tscn b/scenes/ui/char_sheet.tscn index 181681f..d617c7e 100644 --- a/scenes/ui/char_sheet.tscn +++ b/scenes/ui/char_sheet.tscn @@ -34,9 +34,18 @@ grow_horizontal = 2 grow_vertical = 2 [node name="Panel" type="Panel" parent="Control"] -layout_mode = 0 -offset_right = 400.0 -offset_bottom = 500.0 +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -200.0 +offset_top = -250.0 +offset_right = 200.0 +offset_bottom = 250.0 +grow_horizontal = 2 +grow_vertical = 2 theme_override_styles/panel = SubResource("StyleBoxTexture_x3x6m") [node name="Border" type="Sprite2D" parent="Control/Panel"] diff --git a/scenes/ui/loading_screen.tscn b/scenes/ui/loading_screen.tscn new file mode 100644 index 0000000..dfeb87b --- /dev/null +++ b/scenes/ui/loading_screen.tscn @@ -0,0 +1,46 @@ +[gd_scene load_steps=2 format=3 uid="uid://dxgmcjmjxpenn"] + +[ext_resource type="Script" path="res://scripts/ui/loading_screen.gd" id="1_loading"] + +[node name="LoadingScreen" type="CanvasLayer"] +script = ExtResource("1_loading") + +[node name="Panel" type="Panel" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="Panel"] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -200.0 +offset_top = -100.0 +offset_right = 200.0 +offset_bottom = 100.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Title" type="Label" parent="Panel/VBoxContainer"] +layout_mode = 2 +text = "Loading Assets..." +horizontal_alignment = 1 + +[node name="ProgressBar" type="ProgressBar" parent="Panel/VBoxContainer"] +custom_minimum_size = Vector2(0, 30) +layout_mode = 2 +value = 50.0 + +[node name="StatusLabel" type="Label" parent="Panel/VBoxContainer"] +layout_mode = 2 +text = "Checking for updates..." +horizontal_alignment = 1 + +[node name="FileLabel" type="Label" parent="Panel/VBoxContainer"] +layout_mode = 2 +text = "" +horizontal_alignment = 1 diff --git a/scenes/ui/mob_loot_ui.tscn b/scenes/ui/mob_loot_ui.tscn new file mode 100644 index 0000000..e35aa25 --- /dev/null +++ b/scenes/ui/mob_loot_ui.tscn @@ -0,0 +1,57 @@ +[gd_scene load_steps=2 format=3 uid="uid://c8vmcjmjxpenn"] + +[ext_resource type="Script" path="res://scripts/ui/mob_loot_ui.gd" id="1_mob_loot"] + +[node name="MobLootUI" type="CanvasLayer"] +script = ExtResource("1_mob_loot") + +[node name="PanelContainer" type="PanelContainer" parent="."] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -200.0 +offset_top = -200.0 +offset_right = 200.0 +offset_bottom = 200.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"] +layout_mode = 2 + +[node name="Header" type="HBoxContainer" parent="PanelContainer/VBoxContainer"] +layout_mode = 2 + +[node name="MobNameLabel" type="Label" parent="PanelContainer/VBoxContainer/Header"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Mob's Loot" +horizontal_alignment = 1 + +[node name="CloseButton" type="Button" parent="PanelContainer/VBoxContainer/Header"] +layout_mode = 2 +text = "X" + +[node name="Content" type="VBoxContainer" parent="PanelContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="ScrollContainer" type="ScrollContainer" parent="PanelContainer/VBoxContainer/Content"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="LootGrid" type="GridContainer" parent="PanelContainer/VBoxContainer/Content/ScrollContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +columns = 5 + +[node name="Footer" type="HBoxContainer" parent="PanelContainer/VBoxContainer"] +layout_mode = 2 + +[node name="TakeAllButton" type="Button" parent="PanelContainer/VBoxContainer/Footer"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Take All" diff --git a/scripts/autoload/game_state.gd b/scripts/autoload/game_state.gd index afa3ecd..7742092 100644 --- a/scripts/autoload/game_state.gd +++ b/scripts/autoload/game_state.gd @@ -12,6 +12,7 @@ signal loot_received(items: Array) signal player_died signal loot_chest_spawned(chest_data: Dictionary) signal loot_chest_state_received(chest_data: Dictionary) +signal mob_loot_state_received(mob_data: Dictionary) signal death_loot_lost(data: Dictionary) signal dungeon_list_received(data: Dictionary) signal crafting_skills_updated(skills: Dictionary) @@ -163,6 +164,8 @@ func _on_message_received(opcode: int, data: Dictionary): _handle_loot_chest_spawned(data) OpCodes.LOOT_CHEST_STATE: _handle_loot_chest_state(data) + OpCodes.MOB_LOOT_STATE: + _handle_mob_loot_state(data) OpCodes.PLAYER_DEATH_LOOT_LOST: _handle_death_loot_lost(data) OpCodes.DUNGEON_LIST_RESPONSE: @@ -543,6 +546,9 @@ func send_unequip_item(slot: String): func send_use_item(slot_index: int): Network.send_message(OpCodes.USE_ITEM, {"SlotIndex": slot_index}) +func send_stack_items(source_slot: int, target_slot: int): + Network.send_message(OpCodes.STACK_ITEMS, {"SourceSlot": source_slot, "TargetSlot": target_slot}) + func send_chat(message: String): Network.send_message(OpCodes.CHAT_SEND, {"Message": message}) @@ -605,6 +611,11 @@ func _handle_loot_chest_state(data: Dictionary): print("[GameState] Loot chest state received") loot_chest_state_received.emit(data) +func _handle_mob_loot_state(data: Dictionary): + print("[GameState] Mob loot state received for mob: ", data.get("mobName", "Unknown")) + # Signal will be connected by mob loot UI + mob_loot_state_received.emit(data) + func _handle_death_loot_lost(data: Dictionary): print("[GameState] Death loot lost: ", data) death_loot_lost.emit(data) @@ -626,6 +637,19 @@ func take_all_loot_chest(chest_id: int): func close_loot_chest(chest_id: int): Network.send_message(OpCodes.LOOT_CHEST_CLOSE, {"ChestId": chest_id}) +# Mob loot actions +func request_mob_loot(mob_id: int): + Network.send_message(OpCodes.MOB_LOOT_REQUEST, {"mobId": mob_id}) + +func take_mob_loot_item(mob_id: int, item_index: int): + Network.send_message(OpCodes.MOB_LOOT_TAKE_ITEM, { + "mobId": mob_id, + "itemIndex": item_index + }) + +func take_all_mob_loot(mob_id: int): + Network.send_message(OpCodes.MOB_LOOT_TAKE_ALL, {"mobId": mob_id}) + # Dungeon list handler func _handle_dungeon_list(data: Dictionary): print("[GameState] Received dungeon list") diff --git a/scripts/autoload/opcodes.gd b/scripts/autoload/opcodes.gd index 08d8de0..a04053a 100644 --- a/scripts/autoload/opcodes.gd +++ b/scripts/autoload/opcodes.gd @@ -81,6 +81,9 @@ const DROP_ITEM = 255 ## Client -> Server: Assign item to hotbar slot const HOTBAR_ASSIGN = 256 +## Client -> Server: Stack two consumable items together +const STACK_ITEMS = 257 + # ===== Chat (260-269) ===== ## Client -> Server: Send chat message @@ -117,6 +120,20 @@ const LOOT_CHEST_REMOVED = 276 ## Server -> Client: Notify player what loot they lost on death const PLAYER_DEATH_LOOT_LOST = 280 +# ===== Mob Loot (290-299) ===== + +## Client -> Server: Request loot from a dead mob +const MOB_LOOT_REQUEST = 290 + +## Server -> Client: Mob loot contents response +const MOB_LOOT_STATE = 291 + +## Client -> Server: Take specific item from mob +const MOB_LOOT_TAKE_ITEM = 292 + +## Client -> Server: Take all items from mob +const MOB_LOOT_TAKE_ALL = 293 + # ===== Dungeon Core (300-309) ===== ## Client -> Server: Request to enter a dungeon diff --git a/scripts/dungeon/dungeon_manager.gd b/scripts/dungeon/dungeon_manager.gd index 72e3ff3..a06d6bc 100644 --- a/scripts/dungeon/dungeon_manager.gd +++ b/scripts/dungeon/dungeon_manager.gd @@ -21,9 +21,11 @@ const WORLD_TILE_SIZE := TILE_SIZE * TILE_SCALE # 32 pixels per tile in world @onready var hud = $Hud @onready var inventory_panel = $Inventory @onready var chat_panel = $Chat +@onready var char_sheet_ui = $CharSheet # Crafting panel (loaded dynamically) var crafting_panel = null +var mob_loot_ui = null # Visual tile renderer (for V2 dungeons) var visual_renderer: VisualTileMapRenderer = null @@ -74,6 +76,13 @@ func _ready(): crafting_panel.visible = false add_child(crafting_panel) + # Load mob loot UI + if ResourceLoader.exists("res://scenes/ui/mob_loot_ui.tscn"): + var mob_loot_scene = load("res://scenes/ui/mob_loot_ui.tscn") + mob_loot_ui = mob_loot_scene.instantiate() + mob_loot_ui.visible = false + add_child(mob_loot_ui) + # Create visual tile renderer visual_renderer = VisualTileMapRenderer.new() visual_renderer.name = "VisualTileRenderer" @@ -276,6 +285,8 @@ func _handle_input(): inventory_panel.visible = false elif chat_panel and chat_panel.visible: chat_panel.visible = false + elif char_sheet_ui and char_sheet_ui.visible: + char_sheet_ui.visible = false else: # Player pressed escape but no UI open - hint about portals print("[Dungeon] To exit, walk into the purple exit portal near spawn") @@ -283,7 +294,11 @@ func _handle_input(): # Chat (Enter key) if Input.is_action_just_pressed("chat"): _open_chat() - + + # Interact with dead mobs (E key) + if Input.is_key_pressed(KEY_E) and not ui_open: + _try_loot_nearby_mob() + # Hotbar keys 1-8 if not ui_open: for i in range(1, 9): @@ -291,6 +306,11 @@ func _handle_input(): _use_hotbar_slot(i - 1) 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) + if ui_open: + return + # Check attack cooldown var current_time = Time.get_ticks_msec() / 1000.0 var time_since_last_attack = current_time - last_attack_time @@ -437,30 +457,45 @@ func _on_state_updated(): func _update_entities(container: Node2D, data: Dictionary, scene: PackedScene): if scene == null or container == null: return - + var seen_ids = [] - + for id in data: seen_ids.append(id) var entity_data = data[id] var entity_node = _find_entity_by_id(container, id) - + if entity_node == null: entity_node = scene.instantiate() entity_node.set_meta("entity_id", id) container.add_child(entity_node) - + var x = entity_data.get("x", entity_data.get("X", 0)) var y = entity_data.get("y", entity_data.get("Y", 0)) entity_node.position = Vector2(x, y) - + + # Check if this is a mob that just died + if container == mobs_container: + var hp = entity_data.get("health", entity_data.get("Health", 100)) + var was_alive = not entity_node.get_meta("is_dead", false) + + if hp <= 0 and was_alive: + # Mark as dead and play death animation + entity_node.set_meta("is_dead", true) + if entity_node.has_method("play_death_animation"): + entity_node.play_death_animation() + if entity_node.has_method("update_data"): entity_node.update_data(entity_data) - + for child in container.get_children(): if child.has_meta("entity_id"): var id = child.get_meta("entity_id") if id not in seen_ids: + # For mobs, keep dead bodies for looting + if container == mobs_container and child.get_meta("is_dead", false): + # Don't remove dead mob bodies + continue child.queue_free() func _find_entity_by_id(container: Node2D, id) -> Node2D: @@ -484,6 +519,10 @@ func _toggle_crafting(): else: print("[DungeonManager] Crafting UI not loaded") +func _toggle_char_sheet(): + if char_sheet_ui: + char_sheet_ui.visible = not char_sheet_ui.visible + func _open_chat(): if chat_panel: chat_panel.visible = true @@ -497,6 +536,31 @@ func _use_hotbar_slot(index: int): if hotbar_entry and hotbar_entry.has("inventory_slot"): GameState.send_use_item(hotbar_entry.inventory_slot) +func _try_loot_nearby_mob(): + if not player_scene or not mobs_container: + return + + var player_pos = $Player.position + var loot_range = 50.0 # Pixels + + # Find nearest dead mob within range + var nearest_mob = null + var nearest_distance = loot_range + + for child in mobs_container.get_children(): + if child.get_meta("is_dead", false): + var distance = player_pos.distance_to(child.position) + if distance < nearest_distance: + nearest_distance = distance + nearest_mob = child + + if nearest_mob: + var mob_id = nearest_mob.get_meta("entity_id", -1) + if mob_id >= 0: + # Request loot from server + GameState.request_mob_loot(mob_id) + print("[DungeonManager] Requesting loot from mob ID: %d at distance %.1f" % [mob_id, nearest_distance]) + func _update_loot_chests(): if loot_chest_scene == null or loot_chests_container == null: return diff --git a/scripts/dungeon/mob_visual.gd b/scripts/dungeon/mob_visual.gd index d099e0b..95be0a8 100644 --- a/scripts/dungeon/mob_visual.gd +++ b/scripts/dungeon/mob_visual.gd @@ -506,3 +506,55 @@ func play_hurt_effect(): await get_tree().create_timer(0.1).timeout if is_instance_valid(sprite_to_flash): sprite_to_flash.modulate = original_color + +func play_death_animation(): + """Play death animation and stop on last frame""" + _current_state = "dead" + + if _animated_sprite and _animated_sprite.sprite_frames: + # Try to play death animation + var frames = _animated_sprite.sprite_frames + var death_anim_name = "" + + # Try different death animation names + var names_to_try = [ + "dead_%s" % _facing_direction, + "dead", + "death_%s" % _facing_direction, + "death" + ] + + for anim_name in names_to_try: + if frames.has_animation(anim_name): + death_anim_name = anim_name + break + + if death_anim_name != "": + # Play the death animation + _animated_sprite.play(death_anim_name) + + # Wait for animation to finish + if _animated_sprite.sprite_frames.get_animation_loop(death_anim_name): + # If it loops, disable looping temporarily + _animated_sprite.sprite_frames.set_animation_loop(death_anim_name, false) + + # Wait for animation to complete + await _animated_sprite.animation_finished + + # Stop on last frame + var frame_count = _animated_sprite.sprite_frames.get_frame_count(death_anim_name) + if frame_count > 0: + _animated_sprite.frame = frame_count - 1 + _animated_sprite.stop() + else: + # No death animation, just fade out the fallback + _update_fallback_state("dead") + else: + # Using fallback sprite, just update its appearance + _update_fallback_state("dead") + + # Hide health bar and name label for dead mobs + if health_bar: + health_bar.visible = false + if name_label: + name_label.visible = false diff --git a/scripts/ui/hub_ui.gd b/scripts/ui/hub_ui.gd index 660a0cf..a44973b 100644 --- a/scripts/ui/hub_ui.gd +++ b/scripts/ui/hub_ui.gd @@ -123,7 +123,7 @@ func _toggle_char_sheet(): char_sheet_ui.visible = not char_sheet_ui.visible func _create_settings_panel(): - # Create settings button (top right corner, smaller) + # Create settings button (top right corner, 1/3 original size) settings_btn = TextureButton.new() settings_btn.custom_minimum_size = Vector2(16, 16) @@ -133,7 +133,7 @@ func _create_settings_panel(): var settings_texture = UpdateManager.load_texture("textures/ui/buttons/settings.png") if settings_texture: settings_btn.texture_normal = settings_texture - settings_btn.scale = Vector2(.5,.5) + settings_btn.scale = Vector2(.17,.17) # 1/3 of 0.5 = 0.167 texture_loaded = true # Fallback: add a visible background if texture doesn't load @@ -144,12 +144,12 @@ func _create_settings_panel(): fallback_style.set_border_width_all(2) fallback_style.set_corner_radius_all(8) settings_btn.add_theme_stylebox_override("normal", fallback_style) - + # Add a label to show "โš™" gear icon var label = Label.new() label.text = "โš™" - label.add_theme_font_size_override("font_size", 18) + label.add_theme_font_size_override("font_size", 6) # Smaller for 1/3 size label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER label.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) @@ -158,12 +158,12 @@ func _create_settings_panel(): settings_btn.pressed.connect(_toggle_settings_panel) add_child(settings_btn) - # Position top right corner (moved further left) + # Position top right corner (moved further left and down) settings_btn.set_anchors_and_offsets_preset(Control.PRESET_TOP_RIGHT) - settings_btn.offset_left = -100 + settings_btn.offset_left = -50 settings_btn.offset_top = 10 - settings_btn.offset_right = -118 - settings_btn.offset_bottom = 42 + settings_btn.offset_right = -56 + settings_btn.offset_bottom = 24 # Create settings panel (initially hidden) settings_panel = Panel.new() diff --git a/scripts/ui/hud.gd b/scripts/ui/hud.gd index b48cea1..1586e96 100644 --- a/scripts/ui/hud.gd +++ b/scripts/ui/hud.gd @@ -26,6 +26,7 @@ var minimap_tex: ImageTexture = null # Mobile UI buttons var inventory_button: Button = null var crafting_button: Button = null +var stats_button: Button = null const MINIMAP_SIZE := 120 const MINIMAP_SCALE := 3 # How many world pixels per minimap pixel @@ -172,6 +173,28 @@ func _setup_mobile_buttons(): crafting_button.offset_right = -10 crafting_button.offset_bottom = -150 + # Create stats button (bottom right, above crafting) + stats_button = Button.new() + stats_button.text = "Stats" + stats_button.custom_minimum_size = Vector2(60, 60) + + var stats_style = StyleBoxFlat.new() + stats_style.bg_color = Color(0.3, 0.5, 0.3, 0.9) + stats_style.border_color = Color(0.5, 0.7, 0.5) + stats_style.set_border_width_all(2) + stats_style.set_corner_radius_all(8) + stats_button.add_theme_stylebox_override("normal", stats_style) + + stats_button.pressed.connect(_on_mobile_stats_pressed) + add_child(stats_button) + + # Position bottom right, above crafting button + stats_button.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_RIGHT) + stats_button.offset_left = -70 + stats_button.offset_top = -280 + stats_button.offset_right = -10 + stats_button.offset_bottom = -220 + func _on_mobile_inventory_pressed(): # Toggle inventory visibility var dungeon_manager = get_tree().get_first_node_in_group("dungeon_manager") @@ -184,6 +207,12 @@ func _on_mobile_crafting_pressed(): if dungeon_manager and dungeon_manager.has_method("_toggle_crafting"): dungeon_manager._toggle_crafting() +func _on_mobile_stats_pressed(): + # Toggle char sheet visibility + var dungeon_manager = get_tree().get_first_node_in_group("dungeon_manager") + if dungeon_manager and dungeon_manager.has_method("_toggle_char_sheet"): + dungeon_manager._toggle_char_sheet() + func _generate_minimap(): if not GameState or GameState.dungeon.tiles.is_empty(): return @@ -438,6 +467,8 @@ func set_mobile_controls_visible(visible: bool): inventory_button.visible = visible if crafting_button: crafting_button.visible = visible + if stats_button: + stats_button.visible = visible # Show/hide touch joystick var joystick = get_node_or_null("TouchJoystick") diff --git a/scripts/ui/inventory_ui.gd b/scripts/ui/inventory_ui.gd index 3d0f84b..033efd8 100644 --- a/scripts/ui/inventory_ui.gd +++ b/scripts/ui/inventory_ui.gd @@ -302,10 +302,22 @@ func _get_item_emoji(item: Dictionary) -> String: 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 - - if event.button_index == MOUSE_BUTTON_LEFT: + + 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) + + elif event.button_index == MOUSE_BUTTON_RIGHT: if event.pressed: # Start drag if has item if item and not item.is_empty() and DragManager: @@ -313,25 +325,18 @@ func _on_inventory_gui_input(event: InputEvent, slot_index: int): else: # End drag on release (if still dragging) if DragManager and DragManager.is_dragging: - # Check if we should equip or use + # 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 item_type = drag_item.get("type", drag_item.get("Type", "")) - GameState.send_use_item(slot_index) - # If released over same slot or no target, treat as click - # For now, just end the drag + + # 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) + + # Just end the drag - drop handling is done by the drop target DragManager.end_drag() - - elif event.button_index == MOUSE_BUTTON_RIGHT and event.pressed: - if item == null: - return - # Right click: context action - var item_type = item.get("type", item.get("Type", "")) - if item_type == "Consumable": - # Use consumable on right click - _show_hotbar_menu(slot_index) - elif item_type in ["Weapon", "Armor", "Accessory"]: - # Equip on right click - GameState.send_equip_item(slot_index) func _on_equipment_gui_input(event: InputEvent, slot_name: String): if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT: @@ -339,6 +344,27 @@ func _on_equipment_gui_input(event: InputEvent, slot_name: String): if item != null: 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", "")) + + if type1 != "Consumable" or type2 != "Consumable": + return false + + # Check if same item type + var name1 = item1.get("name", item1.get("Name", "")) + var name2 = item2.get("name", item2.get("Name", "")) + + if name1 != name2: + 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 @@ -347,7 +373,7 @@ func _show_hotbar_menu(inv_slot: int): 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]) diff --git a/scripts/ui/loading_screen.gd b/scripts/ui/loading_screen.gd new file mode 100644 index 0000000..e2d8908 --- /dev/null +++ b/scripts/ui/loading_screen.gd @@ -0,0 +1,52 @@ +extends CanvasLayer + +@onready var progress_bar = $Panel/VBoxContainer/ProgressBar +@onready var status_label = $Panel/VBoxContainer/StatusLabel +@onready var file_label = $Panel/VBoxContainer/FileLabel + +func _ready(): + print("[LoadingScreen] _ready called") + + # Connect to UpdateManager signals + if UpdateManager: + UpdateManager.update_check_started.connect(_on_update_check_started) + UpdateManager.update_progress.connect(_on_update_progress) + UpdateManager.update_completed.connect(_on_update_completed) + UpdateManager.update_failed.connect(_on_update_failed) + + progress_bar.value = 0 + +func _on_update_check_started(): + status_label.text = "Checking for updates..." + progress_bar.value = 0 + +func _on_update_progress(downloaded: int, total: int, current_file: String): + if total > 0: + progress_bar.value = (float(downloaded) / float(total)) * 100.0 + status_label.text = "Downloading assets... (%d/%d)" % [downloaded, total] + file_label.text = current_file + else: + progress_bar.value = 100.0 + status_label.text = "No updates needed" + file_label.text = "" + +func _on_update_completed(updated_count: int): + progress_bar.value = 100.0 + if updated_count > 0: + status_label.text = "Downloaded %d assets" % updated_count + else: + status_label.text = "All assets up to date" + file_label.text = "" + + # Wait a moment then proceed to auth screen + await get_tree().create_timer(0.5).timeout + GameState.set_state(0) + +func _on_update_failed(error: String): + status_label.text = "Update failed: " + error + file_label.text = "Click to continue anyway" + progress_bar.value = 0 + + # Allow continuing anyway after 2 seconds + await get_tree().create_timer(2.0).timeout + GameState.set_state(0) diff --git a/scripts/ui/loading_screen.gd.uid b/scripts/ui/loading_screen.gd.uid new file mode 100644 index 0000000..bdf9b18 --- /dev/null +++ b/scripts/ui/loading_screen.gd.uid @@ -0,0 +1 @@ +uid://dpavdbbtbxlao diff --git a/scripts/ui/main.gd b/scripts/ui/main.gd index ea5fa90..20d2060 100644 --- a/scripts/ui/main.gd +++ b/scripts/ui/main.gd @@ -1,5 +1,6 @@ extends Node +@onready var loading_screen = $LoadingScreen @onready var auth_screen = $AuthScreen @onready var hub_screen = $HubScreen @onready var dungeon_scene = $DungeonScene @@ -7,8 +8,18 @@ extends Node func _ready(): print("[Main] _ready called") - _show_screen("AUTH") + _show_screen("LOADING") call_deferred("_setup_signals") + call_deferred("_start_loading") + +func _start_loading(): + # Connect to server and start asset download + if not Network.is_socket_connected(): + print("[Main] Connecting to server...") + Network.connect_to_server() + await Network.connected + print("[Main] Connected! Calling check_for_updates...") + UpdateManager.check_for_updates() func _setup_signals(): print("[Main] _setup_signals called") @@ -25,16 +36,13 @@ func _on_state_changed(new_state: String): func _show_screen(state: String): print("[Main] _show_screen called with: ", state) - + + if loading_screen: + _set_screen_visible(loading_screen, state == "LOADING") + print("[Main] LoadingScreen visible: ", state == "LOADING") if auth_screen: _set_screen_visible(auth_screen, state == "AUTH") print("[Main] AuthScreen visible: ", state == "AUTH") - if state == "AUTH" and not Network.is_socket_connected(): - print("[Main] Connecting to server...") - Network.connect_to_server() - await Network.connected - print("[Main] Connected! Calling check_for_updates...") - UpdateManager.check_for_updates() if hub_screen: _set_screen_visible(hub_screen, state == "HUB") print("[Main] HubScreen visible: ", state == "HUB") diff --git a/scripts/ui/mob_loot_ui.gd b/scripts/ui/mob_loot_ui.gd new file mode 100644 index 0000000..9a1f924 --- /dev/null +++ b/scripts/ui/mob_loot_ui.gd @@ -0,0 +1,232 @@ +extends CanvasLayer + +## Mob Loot UI +## Displays loot from a dead mob in a 5x4 grid with scrollbar + +@onready var panel_container = $PanelContainer +@onready var close_button = $PanelContainer/VBoxContainer/Header/CloseButton +@onready var mob_name_label = $PanelContainer/VBoxContainer/Header/MobNameLabel +@onready var loot_grid = $PanelContainer/VBoxContainer/Content/ScrollContainer/LootGrid +@onready var scroll_container = $PanelContainer/VBoxContainer/Content/ScrollContainer +@onready var take_all_button = $PanelContainer/VBoxContainer/Footer/TakeAllButton + +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 current_mob_id: int = -1 +var loot_slots: Array = [] + +func _ready(): + visible = false + + if close_button: + close_button.pressed.connect(_on_close) + + if take_all_button: + take_all_button.pressed.connect(_on_take_all) + + _setup_loot_grid() + + # Connect to GameState signal + if GameState: + GameState.mob_loot_state_received.connect(_on_mob_loot_state_received) + +func _on_mob_loot_state_received(data: Dictionary): + var mob_id = data.get("mobId", -1) + var mob_name = data.get("mobName", "Mob") + var items = data.get("items", []) + + show_loot(mob_id, mob_name, items) + +func _setup_loot_grid(): + if not loot_grid: + return + + # Create 20 slots (5x4 grid) initially + for i in range(20): + var slot = _create_slot_button() + slot.set_meta("slot_index", i) + slot.set_meta("item", null) + slot.gui_input.connect(_on_slot_gui_input.bind(i)) + loot_grid.add_child(slot) + loot_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))) + 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 show_loot(mob_id: int, mob_name: String, loot_items: Array): + current_mob_id = mob_id + + if mob_name_label: + mob_name_label.text = "%s's Loot" % mob_name + + # Clear existing slots + for slot in loot_slots: + _clear_slot(slot) + + # Add more slots if needed (expandable to show all loot) + var needed_slots = loot_items.size() + while loot_slots.size() < needed_slots: + var slot = _create_slot_button() + var slot_index = loot_slots.size() + slot.set_meta("slot_index", slot_index) + slot.set_meta("item", null) + slot.gui_input.connect(_on_slot_gui_input.bind(slot_index)) + loot_grid.add_child(slot) + loot_slots.append(slot) + + # Populate loot items + for i in range(loot_items.size()): + if i < loot_slots.size(): + _update_slot(loot_slots[i], loot_items[i]) + + visible = true + +func _clear_slot(slot: Button): + for child in slot.get_children(): + child.queue_free() + slot.set_meta("item", null) + slot.text = "" + slot.add_theme_stylebox_override("normal", _create_slot_style(Color(0.15, 0.15, 0.2))) + +func _update_slot(slot: Button, item: Dictionary): + _clear_slot(slot) + + if item.is_empty(): + return + + slot.set_meta("item", item) + slot.text = "" + + # 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) + + # 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 + var quantity = item.get("quantity", item.get("Quantity", 1)) + if quantity > 1: + 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_slot_gui_input(event: InputEvent, slot_index: int): + if not event is InputEventMouseButton: + return + + if event.button_index == MOUSE_BUTTON_LEFT and event.pressed: + var item = loot_slots[slot_index].get_meta("item", null) + if item and not item.is_empty(): + _take_item(slot_index) + +func _take_item(slot_index: int): + if current_mob_id < 0: + return + + # Send message to server to take item from mob loot + GameState.take_mob_loot_item(current_mob_id, slot_index) + print("[MobLootUI] Taking item at index %d from mob %d" % [slot_index, current_mob_id]) + + # Clear slot locally (server will update inventory) + _clear_slot(loot_slots[slot_index]) + +func _on_take_all(): + if current_mob_id < 0: + return + + # Send message to server to take all items from mob loot + GameState.take_all_mob_loot(current_mob_id) + print("[MobLootUI] Taking all items from mob %d" % current_mob_id) + + # Clear all slots locally (server will update inventory) + for slot in loot_slots: + _clear_slot(slot) + + _on_close() + +func _on_close(): + visible = false + current_mob_id = -1 + +func _input(event): + if visible and event.is_action_pressed("escape_menu"): + _on_close() + get_viewport().set_input_as_handled() diff --git a/scripts/ui/mob_loot_ui.gd.uid b/scripts/ui/mob_loot_ui.gd.uid new file mode 100644 index 0000000..959075b --- /dev/null +++ b/scripts/ui/mob_loot_ui.gd.uid @@ -0,0 +1 @@ +uid://bo2ai0nxfcwas