diff --git a/scenes/ui/chat.tscn b/scenes/ui/chat.tscn index 60be26f..a734fe2 100644 --- a/scenes/ui/chat.tscn +++ b/scenes/ui/chat.tscn @@ -6,31 +6,40 @@ script = ExtResource("1_6bdm3") [node name="Control" type="Control" parent="."] +custom_minimum_size = Vector2(70, 0) layout_mode = 3 -anchors_preset = 2 -anchor_top = 1.0 +anchors_preset = 9 anchor_bottom = 1.0 -offset_left = 1.0 -offset_top = -87.0 -offset_right = 41.0 -offset_bottom = -47.0 -grow_vertical = 0 -scale = Vector2(8.839999, 2.1200001) +grow_vertical = 2 +scale = Vector2(4.17, 1) -[node name="ChatLog" type="ScrollContainer" parent="Control"] -layout_mode = 0 -offset_right = 70.0 -scale = Vector2(0.60795665, 0.29541135) +[node name="VBoxContainer" type="VBoxContainer" parent="Control"] +custom_minimum_size = Vector2(200, 0) +layout_mode = 1 +anchors_preset = -1 +anchor_top = 0.704 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = 0.4796219 +offset_top = 4.0 +offset_right = 130.47961 +offset_bottom = 4.0 +grow_horizontal = 2 +grow_vertical = 2 +scale = Vector2(0.31894487, 1) -[node name="ChatMessages" type="VBoxContainer" parent="Control/ChatLog"] +[node name="ChatLog" type="ScrollContainer" parent="Control/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="ChatMessages" type="VBoxContainer" parent="Control/VBoxContainer/ChatLog"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="InputContainer" type="HBoxContainer" parent="Control/VBoxContainer"] layout_mode = 2 -[node name="InputContainer" type="HBoxContainer" parent="Control"] -layout_mode = 0 -offset_top = 8.490566 -offset_right = 70.0 -offset_bottom = 39.490566 -scale = Vector2(0.3443181, 1) - -[node name="ChatInput" type="LineEdit" parent="Control/InputContainer"] +[node name="ChatInput" type="LineEdit" parent="Control/VBoxContainer/InputContainer"] layout_mode = 2 +expand_to_text_length = true diff --git a/scenes/ui/hud.tscn b/scenes/ui/hud.tscn index 33f3af0..51dfa33 100644 --- a/scenes/ui/hud.tscn +++ b/scenes/ui/hud.tscn @@ -144,6 +144,11 @@ grow_horizontal = 2 grow_vertical = 2 stretch_mode = 5 +[node name="EventLog" type="VBoxContainer" parent="TopRight"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + [node name="BottomCenter" type="Control" parent="."] layout_mode = 3 anchors_preset = 7 diff --git a/scripts/autoload/game_state.gd b/scripts/autoload/game_state.gd index c4fcd70..20abe88 100644 --- a/scripts/autoload/game_state.gd +++ b/scripts/autoload/game_state.gd @@ -4,6 +4,8 @@ signal state_changed(new_state: String) signal character_updated signal dungeon_entered signal dungeon_state_updated +signal dungeon_cleared +signal escaped signal inventory_updated signal chat_message_received(sender: String, message: String, type: String) signal loot_received(items: Array) @@ -99,17 +101,24 @@ func _on_message_received(opcode: int, data: Dictionary): OpCodes.INVENTORY_STATE: _handle_inventory_state(data) OpCodes.LOOT_RECEIVED: + print("[GameState] >>> LOOT_RECEIVED opcode matched! <<<") _handle_loot_received(data) OpCodes.CHAT_MESSAGE: + print("[GameState] >>> CHAT_MESSAGE opcode matched! <<<") _handle_chat_message(data) OpCodes.ESCAPE_INTERRUPTED: is_escaping = false + OpCodes.ESCAPE_SUCCESS: + print("[GameState] >>> ESCAPE_SUCCESS - Returning to hub <<<") + _handle_escape_success(data) OpCodes.EVENT_DAMAGE: _handle_damage(data) OpCodes.EVENT_DEATH: _handle_death(data) OpCodes.EVENT_LEVELUP: _handle_levelup(data) + _: + print("[GameState] Unhandled opcode: ", opcode) func _handle_auth_result(data: Dictionary): var ok = data.get("ok", data.get("Ok", false)) @@ -195,6 +204,14 @@ func _parse_tiles(tiles_string: String): dungeon.tiles[x][y] = 0 if row[x] == "." else 1 func _handle_dungeon_state(data: Dictionary): + # Check dungeon phase first + var phase = data.get("phase", data.get("Phase", "active")) + if phase == "cleared": + print("[GameState] Dungeon cleared! Waiting for hub state...") + # Server should send HUB_STATE next, but show a message + dungeon_cleared.emit() + return + var ps = data.get("players", data.get("Players", [])) for p in ps: var pid = int(p.get("id", p.get("Id", 0))) @@ -247,21 +264,27 @@ func _handle_inventory_state(data: Dictionary): inventory_updated.emit() func _handle_loot_received(data: Dictionary): + print("[GameState] _handle_loot_received called with: ", data) var items = data.get("items", data.get("Items", [])) + print("[GameState] Loot items count: ", items.size()) if items.size() > 0: + for item in items: + print("[GameState] Loot item: ", item.get("name", item.get("Name", "Unknown"))) loot_received.emit(items) Network.send_message(OpCodes.INVENTORY_REQUEST, {}) func _handle_chat_message(data: Dictionary): + print("[GameState] _handle_chat_message called with: ", data) var sender = data.get("sender", data.get("Sender", data.get("playerName", data.get("PlayerName", "Unknown")))) var message = data.get("message", data.get("Message", data.get("text", data.get("Text", "")))) var type = data.get("type", data.get("Type", data.get("channel", data.get("Channel", "normal")))) - print("[GameState] Chat: %s: %s" % [sender, message]) + print("[GameState] Chat parsed - Sender: '%s', Message: '%s', Type: '%s'" % [sender, message, type]) chat_messages.append({"sender": sender, "message": message, "type": type}) if chat_messages.size() > 100: chat_messages.pop_front() + print("[GameState] Emitting chat_message_received signal") chat_message_received.emit(sender, message, type) func _handle_damage(_data: Dictionary): @@ -281,6 +304,26 @@ func _handle_levelup(data: Dictionary): character.unspent_points = int(data.get("unspentPoints", data.get("UnspentPoints", character.unspent_points))) character_updated.emit() +func _handle_escape_success(_data: Dictionary): + print("[GameState] Escape successful! Returning to hub...") + is_escaping = false + + # Clear dungeon data + players.clear() + mobs.clear() + chests.clear() + dropped_items.clear() + dungeon = { + "id": "", + "tier": 1, + "width": 0, + "height": 0, + "tiles": [] + } + + escaped.emit() + # Server will send HUB_STATE next which will call set_state(STATE_HUB) + # Helper functions func send_move(dx: float, dy: float, aim_angle: float): Network.send_message(OpCodes.INPUT_MOVE, {"Dx": dx, "Dy": dy, "AimAngle": aim_angle}) diff --git a/scripts/ui/chat_ui.gd b/scripts/ui/chat_ui.gd index dcc4081..ef4c25a 100644 --- a/scripts/ui/chat_ui.gd +++ b/scripts/ui/chat_ui.gd @@ -1,8 +1,8 @@ extends CanvasLayer -@onready var chat_log = $Control/ChatLog -@onready var chat_messages_container = $Control/ChatLog/ChatMessages -@onready var chat_input = $Control/InputContainer/ChatInput +@onready var chat_log = $Control/VBoxContainer/ChatLog +@onready var chat_messages_container = $Control/VBoxContainer/ChatLog/ChatMessages +@onready var chat_input = $Control/VBoxContainer/InputContainer/ChatInput const MAX_MESSAGES = 50 const TYPE_COLORS = { @@ -13,6 +13,7 @@ const TYPE_COLORS = { } func _ready(): + print("[ChatUI] _ready called") chat_input.text_submitted.connect(_on_message_submitted) visible = false @@ -21,13 +22,20 @@ func _ready(): call_deferred("_connect_gamestate") func _connect_gamestate(): + print("[ChatUI] _connect_gamestate called") if GameState: + print("[ChatUI] Connecting to GameState.chat_message_received signal") GameState.chat_message_received.connect(_on_chat_message) + print("[ChatUI] Signal connected successfully") + else: + print("[ChatUI] ERROR: GameState not found!") func _on_chat_message(sender: String, message: String, type: String): + print("[ChatUI] _on_chat_message received - Sender: '%s', Message: '%s', Type: '%s'" % [sender, message, type]) _add_message(sender, message, type) func _add_message(sender: String, message: String, type: String = "normal"): + print("[ChatUI] Adding message to chat log") var label = RichTextLabel.new() label.bbcode_enabled = true label.fit_content = true @@ -35,13 +43,14 @@ func _add_message(sender: String, message: String, type: String = "normal"): var color = TYPE_COLORS.get(type, Color.WHITE) var color_hex = color.to_html(false) - + print("[ChatUI] set type") if type == "system": label.text = "[color=#%s][System] %s[/color]" % [color_hex, message] else: label.text = "[color=#ffd700]%s:[/color] [color=#%s]%s[/color]" % [sender, color_hex, message] - + print("[ChatUI] Bout to add") chat_messages_container.add_child(label) + print("[ChatUI] Message added: %s" % label.text) # Limit messages while chat_messages_container.get_child_count() > MAX_MESSAGES: @@ -58,7 +67,8 @@ func _on_message_submitted(text: String): if text.strip_edges().is_empty(): _close() return - + _add_message(GameState.character.get("name"),text,"normal") + print("[ChatUI] Sending chat message: %s" % text) GameState.send_chat(text) chat_input.text = "" _close() diff --git a/scripts/ui/hud.gd b/scripts/ui/hud.gd index b2e1ad4..839ec2d 100644 --- a/scripts/ui/hud.gd +++ b/scripts/ui/hud.gd @@ -12,6 +12,7 @@ extends CanvasLayer @onready var minimap_container = $TopRight/Minimap @onready var minimap_texture = $TopRight/Minimap/MinimapTexture +@onready var event_log = $TopRight/EventLog @onready var hotbar_container = $BottomCenter/Hotbar @@ -35,6 +36,7 @@ func _connect_gamestate(): GameState.dungeon_state_updated.connect(_update_resources) GameState.inventory_updated.connect(_update_hotbar) GameState.dungeon_entered.connect(_on_dungeon_entered) + GameState.loot_received.connect(_on_loot_received) func _on_dungeon_entered(): _generate_minimap() @@ -212,3 +214,31 @@ func _update_escape_indicator(): var remaining = max(0, 5 - elapsed) if escape_countdown: escape_countdown.text = "%.1f" % remaining + +func _on_loot_received(items: Array): + print("[HUD] Loot received! %d items" % items.size()) + for item in items: + var item_name = item.get("name", item.get("Name", "Unknown")) + var rarity = item.get("rarity", item.get("Rarity", "Common")) + var quantity = item.get("quantity", item.get("Quantity", 1)) + + var color = _get_rarity_color(rarity) + var text = "+%d %s" % [quantity, item_name] if quantity > 1 else "+ %s" % item_name + add_log_entry(text, color) + +func _get_rarity_color(rarity: String) -> Color: + match rarity.to_lower(): + "common": return Color(0.7, 0.7, 0.7) + "uncommon": return Color(0.18, 0.8, 0.44) + "rare": return Color(0.2, 0.6, 0.86) + "epic": return Color(0.61, 0.35, 0.71) + "legendary": return Color(0.95, 0.61, 0.07) + _: return Color.WHITE + +func add_log_entry(test: String, color: Color): + var label = RichTextLabel.new() + label.bbcode_enabled = true + label.fit_content = true + label.scroll_active = false + event_log.add_child(label) +