From 7b1e7e346a4ae0b6dd006edddc369bfa126151bb Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 26 Mar 2026 10:52:08 -0400 Subject: [PATCH] Show display names everywhere accountId was shown in GameScreen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Server: - PlayerState: add DisplayName property (populated from identity DB) - PlayerStateDto: add DisplayName field (falls back to truncated ID) - GameEngine.ToDto: include DisplayName in player DTO - GameReadyHandler: resolve display names from identity DB after state initialization so every subsequent state push carries them Client: - Game.gd: add get_display_name(account_id) helper — reads displayName from player state, falls back to substr(0,8) - game_screen.gd: replace all 5 pid/eid/elim_id.substr(0,8) UI sites with Game.get_display_name() — HUD opp name, turn order strip, game-over outcome list, discard scope selector, elimination dialog - Turn order strip chips: use resolved display name; add mouse_filter STOP + tooltip_text showing SP/ST/Hand/Deck for opponent chips on hover Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- Client/origin-client/autoloads/Game.gd | 12 +++++++++ .../origin-client/scenes/game/game_screen.gd | 22 +++++++++++----- Server/src/SOR.Game/GameEngine.cs | 25 +++++++++++-------- Server/src/SOR.Game/GameMessages.cs | 1 + Server/src/SOR.Game/GameState.cs | 3 ++- .../src/SOR.Game/Handlers/GameReadyHandler.cs | 14 +++++++++++ 6 files changed, 59 insertions(+), 18 deletions(-) diff --git a/Client/origin-client/autoloads/Game.gd b/Client/origin-client/autoloads/Game.gd index 4bd5967..a3bc109 100644 --- a/Client/origin-client/autoloads/Game.gd +++ b/Client/origin-client/autoloads/Game.gd @@ -123,6 +123,18 @@ func get_opponent() -> Dictionary: return opps[0] if not opps.is_empty() else {} +## Returns the display name for an account ID, using the name embedded in the game state. +## Falls back to the first 8 characters of the ID if no name is available. +func get_display_name(account_id: String) -> String: + if account_id.is_empty(): return "?" + for p: Dictionary in state.get("players", []): + if str(p.get("accountId", "")) == account_id: + var dn : String = str(p.get("displayName", "")) + if not dn.is_empty(): return dn + break + return account_id.substr(0, min(8, account_id.length())) + + ## Returns true when it is the local player's turn. func is_my_turn() -> bool: return str(state.get("activePlayerAccountId", "")) == Auth.user_id diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index c76ecc8..526e9f7 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -2934,7 +2934,7 @@ func _show_player_panel(scope: String, ownership: String) -> void: if show_enemy: for ep: Dictionary in Game.get_enemy_players(): var eid : String = str(ep.get("accountId", "")) - var ename : String = eid.substr(0, 8) + var ename : String = Game.get_display_name(eid) _add_player_option(vbox, ename, eid, scope) panel.add_child(vbox) @@ -3231,8 +3231,7 @@ func _update_hud(state: Dictionary) -> void: _st_lbl.text = "ST: %d" % int(my.get("currentSt", 0)) _deck_lbl.text = "Deck: %d" % int(my.get("deckCount", 0)) - _opp_name_lbl.text = Game.opponent_name if not Game.opponent_name.is_empty() \ - else str(opp.get("accountId", "Opponent")).substr(0, 8) + _opp_name_lbl.text = Game.get_display_name(str(opp.get("accountId", ""))) _opp_hand_lbl.text = "Hand: %d" % int(opp.get("handCount", 0)) _opp_deck_lbl.text = "Deck: %d" % int(opp.get("deckCount", 0)) @@ -3291,10 +3290,12 @@ func _rebuild_turn_order_strip(state: Dictionary) -> void: var eliminated : bool = bool(p.get("isEliminated", false)) var team_idx : int = int(p.get("teamIndex", -1)) var hex_str : String = str(team_colors.get(str(team_idx), "")) + var display : String = "You" if is_me else Game.get_display_name(pid) var chip := PanelContainer.new() chip.custom_minimum_size = Vector2(72, 36) chip.self_modulate = Color(1, 1, 1, 0.3 if eliminated else (0.95 if is_active else 0.6)) + chip.mouse_filter = Control.MOUSE_FILTER_STOP # Team-color left border via StyleBoxFlat. var style := StyleBoxFlat.new() @@ -3307,11 +3308,11 @@ func _rebuild_turn_order_strip(state: Dictionary) -> void: chip.add_theme_stylebox_override("panel", style) var lbl := Label.new() - var display : String = "You" if is_me else pid.substr(0, 8) lbl.text = ("★ " if is_active else "") + display + (" ✗" if eliminated else "") lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER lbl.vertical_alignment = VERTICAL_ALIGNMENT_CENTER lbl.add_theme_font_size_override("font_size", 10) + lbl.mouse_filter = Control.MOUSE_FILTER_IGNORE if is_active: lbl.add_theme_color_override("font_color", Color(1.0, 0.9, 0.3)) elif eliminated: @@ -3319,6 +3320,15 @@ func _rebuild_turn_order_strip(state: Dictionary) -> void: elif is_me: lbl.add_theme_color_override("font_color", Color(0.5, 1.0, 0.5)) + # Hover tooltip showing player specs (opponents only). + if not is_me: + var sp : int = int(p.get("currentSp", 0)) + var st : int = int(p.get("currentSt", 0)) + var hand : int = int(p.get("handCount", 0)) + var deck : int = int(p.get("deckCount", 0)) + chip.tooltip_text = "%s\nSP: %d ST: %d\nHand: %d Deck: %d" % [ + display, sp, st, hand, deck] + chip.add_child(lbl) _turn_order_strip.add_child(chip) @@ -3414,7 +3424,7 @@ func _on_game_over(winner_id: String, win_condition: String, var oc : String = str(po.get("outcome", "?")) var rd : int = int(po.get("rankDelta", 0)) var sign : String = "+" if rd >= 0 else "" - var label: String = "You" if pid == Auth.user_id else pid.substr(0, 8) + var label: String = "You" if pid == Auth.user_id else Game.get_display_name(pid) outcome_lines.append("%s: %s (%s%d)" % [label, oc, sign, rd]) _go_rank_lbl.text = "[%s] " % win_condition + " @@ -3495,7 +3505,7 @@ func _on_player_eliminated(session_id: String, elim_id: String, _seat_idx: int, "You have been eliminated! You can continue watching the game as a spectator." if is_me - else "Player %s has been eliminated from the game!" % elim_id.substr(0, 8)) + else "Player %s has been eliminated from the game!" % Game.get_display_name(elim_id)) var dlg := AcceptDialog.new() dlg.title = "Player Eliminated" dlg.dialog_text = msg diff --git a/Server/src/SOR.Game/GameEngine.cs b/Server/src/SOR.Game/GameEngine.cs index 05778d9..3bc1fec 100644 --- a/Server/src/SOR.Game/GameEngine.cs +++ b/Server/src/SOR.Game/GameEngine.cs @@ -1047,17 +1047,20 @@ public static class GameEngine var isSelf = p.AccountId == viewerAccountId; return new PlayerStateDto( - AccountId : Guid.Parse(p.AccountId), - HandCount : p.Hand.Count, - DeckCount : p.Deck.Count, - Hand : isSelf ? p.Hand.Select(ToCardDto) : null, - Field : p.Field.Select(ToCardDto), - Discard : p.Discard.Select(ToCardDto), - ArchSpirit : p.ArchSpirit != null ? ToCardDto(p.ArchSpirit) : null, - CurrentSp : p.CurrentSp, - CurrentSt : p.CurrentSt, - SeatIndex : p.SeatIndex, - TeamIndex : p.TeamIndex, + AccountId : Guid.Parse(p.AccountId), + DisplayName : !string.IsNullOrEmpty(p.DisplayName) + ? p.DisplayName + : p.AccountId.Length >= 8 ? p.AccountId[..8] : p.AccountId, + HandCount : p.Hand.Count, + DeckCount : p.Deck.Count, + Hand : isSelf ? p.Hand.Select(ToCardDto) : null, + Field : p.Field.Select(ToCardDto), + Discard : p.Discard.Select(ToCardDto), + ArchSpirit : p.ArchSpirit != null ? ToCardDto(p.ArchSpirit) : null, + CurrentSp : p.CurrentSp, + CurrentSt : p.CurrentSt, + SeatIndex : p.SeatIndex, + TeamIndex : p.TeamIndex, IsEliminated: p.IsEliminated); }); diff --git a/Server/src/SOR.Game/GameMessages.cs b/Server/src/SOR.Game/GameMessages.cs index 060cde2..feb1071 100644 --- a/Server/src/SOR.Game/GameMessages.cs +++ b/Server/src/SOR.Game/GameMessages.cs @@ -547,6 +547,7 @@ public sealed record GameStateDto( public sealed record PlayerStateDto( Guid AccountId, + string DisplayName, // resolved display name; never empty (falls back to truncated ID) int HandCount, // always shown; actual cards visible only to self int DeckCount, IEnumerable? Hand, // null for opponent diff --git a/Server/src/SOR.Game/GameState.cs b/Server/src/SOR.Game/GameState.cs index 1b28623..9c334c6 100644 --- a/Server/src/SOR.Game/GameState.cs +++ b/Server/src/SOR.Game/GameState.cs @@ -97,7 +97,8 @@ public sealed class GameState public sealed class PlayerState { - public string AccountId { get; set; } = string.Empty; + public string AccountId { get; set; } = string.Empty; + public string DisplayName { get; set; } = string.Empty; /// 0-based position in the turn order. Set during game initialization. public int SeatIndex { get; set; } = 0; diff --git a/Server/src/SOR.Game/Handlers/GameReadyHandler.cs b/Server/src/SOR.Game/Handlers/GameReadyHandler.cs index 7e2011b..b0b0599 100644 --- a/Server/src/SOR.Game/Handlers/GameReadyHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameReadyHandler.cs @@ -202,6 +202,20 @@ internal sealed class GameReadyHandler : GameHandlerBase, IMessageHandler rules); } + // Resolve display names for all players so every client can show real names. + var pidGuids = state.Players.Keys + .Select(k => Guid.TryParse(k, out var g) ? g : Guid.Empty) + .Where(g => g != Guid.Empty) + .ToArray(); + var nameMap = await _identityDb.Users + .AsNoTracking() + .Where(u => pidGuids.Contains(u.Id)) + .Select(u => new { u.Id, Name = u.DisplayName ?? u.UserName ?? u.Id.ToString().Substring(0, 8) }) + .ToDictionaryAsync(u => u.Id.ToString(), u => u.Name, ct); + foreach (var (pid, ps) in state.Players) + if (nameMap.TryGetValue(pid, out var dn)) + ps.DisplayName = dn; + session.StateJson = GameEngine.Serialize(state); session.Status = GameSessionStatus.Active; session.StartedAt = DateTimeOffset.UtcNow;