diff --git a/scenes/main.gd b/scenes/main.gd index d1e9935..f39b27f 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -251,13 +251,21 @@ func _on_host_pressed(): int_goals.append(g) preset_goals.append(int_goals) - # Sync goals to all clients - rpc("sync_preset_goals", preset_goals) - # Now add host with first set of goals add_player_character(1) + + # Explicitly assign host's goals and force UI update + var host_player = get_node_or_null("1") + if host_player: + host_player.goals = preset_goals[0].duplicate() + rpc("sync_player_goals", 1, preset_goals[0]) + update_all_players_goals() + players.append(1) + # Sync goals to all clients after host is set up + rpc("sync_preset_goals", preset_goals) + # Only add bots if enable_bots is true if enable_bots: # Add bots with their own goals @@ -627,7 +635,7 @@ func update_board_slot(board_ui: Node, slot_idx: int, value: int): 10: slot_node.get_node("TileCoin").show() func update_all_players_goals(): - if not game_started: + if not game_started and not multiplayer.is_server(): return var all_players = get_tree().get_nodes_in_group("Players") @@ -638,26 +646,19 @@ func update_all_players_goals(): return int(a_str) < int(b_str) ) + # Force clear all goals first + for i in range(4): # 4 goal boards + var goals_grid = $AllPlayerGoals.get_child(i) + for slot_idx in range(9): # 9 slots per goal board + var slot = goals_grid.get_child(slot_idx) + for tile in ["TileHeart", "TileDiamond", "TileStar", "TileCoin"]: + slot.get_node(tile).hide() + + # Then update with current player goals for i in range(min(all_players.size(), 4)): var player = all_players[i] - var goals_grid = $AllPlayerGoals.get_child(i) # Playergoals_1, _2, _3, or _4 - - for slot_idx in range(9): - var slot = goals_grid.get_child(slot_idx) - var goal_value = player.goals[slot_idx] - - # Hide all tile textures first - slot.get_node("TileHeart").hide() - slot.get_node("TileDiamond").hide() - slot.get_node("TileStar").hide() - slot.get_node("TileCoin").hide() - - # Show the appropriate texture based on goal value - match goal_value: - 7: slot.get_node("TileHeart").show() - 8: slot.get_node("TileDiamond").show() - 9: slot.get_node("TileStar").show() - 10: slot.get_node("TileCoin").show() + if player and player.goals.size() > 0: + _update_player_goals_ui(i, player.goals) @rpc("any_peer", "call_local") func sync_player_goals(player_id: int, goals: Array): @@ -665,14 +666,25 @@ func sync_player_goals(player_id: int, goals: Array): var player = get_node_or_null(str(player_id)) if player: player.goals = goals.duplicate() + + # Get player index in current players list + var player_idx = -1 + var sorted_players = get_tree().get_nodes_in_group("Players") + sorted_players.sort_custom(func(a, b): + return int(String(a.name).get_slice("@", 0)) < int(String(b.name).get_slice("@", 0)) + ) + + for idx in range(sorted_players.size()): + if sorted_players[idx] == player: + player_idx = idx + break + + if player_idx >= 0 and player_idx < 4: + _update_player_goals_ui(player_idx, goals) - # Then update UI - update_all_players_goals() - - # Force update for specific player in AllPlayerGoals - var player_idx = players.find(player_id) - if player_idx >= 0 and player_idx < 4: - _update_player_goals_ui(player_idx, goals) + # Update full UI if we're the server or if this is our local player + if multiplayer.is_server() or player_id == multiplayer.get_unique_id(): + update_all_players_goals() # Helper function to update specific player's goals UI func _update_player_goals_ui(player_idx: int, goals: Array): diff --git a/scenes/main.tscn b/scenes/main.tscn index d5e126d..51718c0 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -2691,12 +2691,11 @@ theme_override_styles/tab_focus = SubResource("StyleBoxEmpty_s1l63") theme_override_styles/tab_selected = ExtResource("18_u5x6e") theme_override_styles/tab_hovered = ExtResource("19_w1rqq") theme_override_styles/tab_unselected = ExtResource("20_q6bc1") -current_tab = 1 +current_tab = 0 tabs_position = 1 clip_tabs = false [node name="1" type="MarginContainer" parent="AllPlayerBoards"] -visible = false layout_mode = 2 theme_override_constants/margin_left = 10 theme_override_constants/margin_top = 10 @@ -3511,6 +3510,7 @@ offset_bottom = 24.0 texture = ExtResource("10_my1qp") [node name="2" type="MarginContainer" parent="AllPlayerBoards"] +visible = false layout_mode = 2 theme_override_constants/margin_left = 10 theme_override_constants/margin_top = 10