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
+40 -28
View File
@@ -251,13 +251,21 @@ func _on_host_pressed():
int_goals.append(g) int_goals.append(g)
preset_goals.append(int_goals) preset_goals.append(int_goals)
# Sync goals to all clients
rpc("sync_preset_goals", preset_goals)
# Now add host with first set of goals # Now add host with first set of goals
add_player_character(1) 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) 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 # Only add bots if enable_bots is true
if enable_bots: if enable_bots:
# Add bots with their own goals # 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() 10: slot_node.get_node("TileCoin").show()
func update_all_players_goals(): func update_all_players_goals():
if not game_started: if not game_started and not multiplayer.is_server():
return return
var all_players = get_tree().get_nodes_in_group("Players") 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) 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)): for i in range(min(all_players.size(), 4)):
var player = all_players[i] var player = all_players[i]
var goals_grid = $AllPlayerGoals.get_child(i) # Playergoals_1, _2, _3, or _4 if player and player.goals.size() > 0:
_update_player_goals_ui(i, player.goals)
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()
@rpc("any_peer", "call_local") @rpc("any_peer", "call_local")
func sync_player_goals(player_id: int, goals: Array): func sync_player_goals(player_id: int, goals: Array):
@@ -666,13 +667,24 @@ func sync_player_goals(player_id: int, goals: Array):
if player: if player:
player.goals = goals.duplicate() player.goals = goals.duplicate()
# Then update UI # Get player index in current players list
update_all_players_goals() 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))
)
# Force update for specific player in AllPlayerGoals for idx in range(sorted_players.size()):
var player_idx = players.find(player_id) if sorted_players[idx] == player:
if player_idx >= 0 and player_idx < 4: player_idx = idx
_update_player_goals_ui(player_idx, goals) break
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 # Helper function to update specific player's goals UI
func _update_player_goals_ui(player_idx: int, goals: Array): func _update_player_goals_ui(player_idx: int, goals: Array):
+2 -2
View File
@@ -2691,12 +2691,11 @@ theme_override_styles/tab_focus = SubResource("StyleBoxEmpty_s1l63")
theme_override_styles/tab_selected = ExtResource("18_u5x6e") theme_override_styles/tab_selected = ExtResource("18_u5x6e")
theme_override_styles/tab_hovered = ExtResource("19_w1rqq") theme_override_styles/tab_hovered = ExtResource("19_w1rqq")
theme_override_styles/tab_unselected = ExtResource("20_q6bc1") theme_override_styles/tab_unselected = ExtResource("20_q6bc1")
current_tab = 1 current_tab = 0
tabs_position = 1 tabs_position = 1
clip_tabs = false clip_tabs = false
[node name="1" type="MarginContainer" parent="AllPlayerBoards"] [node name="1" type="MarginContainer" parent="AllPlayerBoards"]
visible = false
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 10 theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10 theme_override_constants/margin_top = 10
@@ -3511,6 +3510,7 @@ offset_bottom = 24.0
texture = ExtResource("10_my1qp") texture = ExtResource("10_my1qp")
[node name="2" type="MarginContainer" parent="AllPlayerBoards"] [node name="2" type="MarginContainer" parent="AllPlayerBoards"]
visible = false
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 10 theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10 theme_override_constants/margin_top = 10