Show display names everywhere accountId was shown in GameScreen

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 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-26 10:52:08 -04:00
co-authored by Claude Happy
parent a50b60ad82
commit 7b1e7e346a
6 changed files with 59 additions and 18 deletions
+12
View File
@@ -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
@@ -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
+14 -11
View File
@@ -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);
});
+1
View File
@@ -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<CardInstanceDto>? Hand, // null for opponent
+2 -1
View File
@@ -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;
/// <summary>0-based position in the turn order. Set during game initialization.</summary>
public int SeatIndex { get; set; } = 0;
@@ -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;