This commit is contained in:
2025-02-18 15:47:57 +08:00
parent f66c6eeb63
commit c75af0c56f
2 changed files with 43 additions and 31 deletions
+41 -29
View File
@@ -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):