Skip to content

Refactor Party Game flow and UI state management#121

Open
Shombith03 wants to merge 7 commits into
claude/add-party-game-mode-gJ8AEfrom
claude/add-party-game-mode-Go0YH
Open

Refactor Party Game flow and UI state management#121
Shombith03 wants to merge 7 commits into
claude/add-party-game-mode-gJ8AEfrom
claude/add-party-game-mode-Go0YH

Conversation

@Shombith03

Copy link
Copy Markdown
Contributor

Summary

This PR refactors the Party Game controller and UI to improve state management, fix phase transition bugs, and clarify the game flow. The main changes involve fixing the ready state tracking, improving phase callbacks, adding a party components root for better UI control, and enhancing logging throughout.

Key Changes

PartyGameController.cs

  • Fixed phase callback bug: Added manual invocation of OnNetPhaseChanged when re-entering the same phase (e.g., WaitingForReadyWaitingForReady), since NetworkVariable.OnValueChanged doesn't fire when the value doesn't change
  • Improved ready state tracking: Replaced _readyPlayerCount with dynamic calculation via _playerStates.Count(p => p.IsReady) to avoid sync issues
  • Added party components root: New serialized field to control visibility of party UI during gameplay (disabled during active play, re-enabled between rounds)
  • Removed mini-game controller discovery: Deleted DiscoverMiniGameControllers() method and _miniGameControllers list as they were unused
  • Enhanced phase management: Refactored CheckAllPlayersReady() to use a switch statement with explicit logging for each phase transition
  • Improved player join logic: Added max player enforcement and better duplicate detection with logging
  • Better UI synchronization: Added ReinitializePanelWithPlayers_ClientRpc() to sync panel state when all players are known
  • Separated UI hide/show: Split HideMiniGameHUD_ClientRpc() into HidePartyUI_ClientRpc() and ShowPartyUI_ClientRpc() to properly manage party components root
  • Added comprehensive logging: Extensive CSDebug.Log calls throughout for better debugging and flow visibility
  • Clarified flow documentation: Updated class docstring with detailed phase flow diagram

PartyPausePanel.cs

  • Updated ready count tracking: Modified OnPlayerReadyChanged() to accept readyCount and totalCount parameters for server-authoritative updates
  • Added ready state reset callback: New OnReadyStatesReset() method to handle UI updates when ready states are reset between phases
  • Improved initialization: Added logging and better button state initialization
  • Simplified scroll logic: Minor cleanup of scroll-to-round logic

PartyRoundTab.cs

  • Refactored ready count updates: Replaced SetPlayerReady() with SetReadyCount() for direct server-authoritative updates
  • Added reset method: New ResetReadyCount() to clear ready count when transitioning between ready phases

PartyPauseButton.cs

  • Added null safety: Better null checks for gameData and localPlayer references
  • Improved logging: Added debug logging for pause/resume operations
  • Simplified async calls: Changed _ = SetInputPauseDelayed() to .Forget() for clarity

PartyEndGameHandler.cs

  • Added party components root: New field to re-enable party UI after cinematic
  • Improved logging: Added debug logging for end-game sequence
  • Fixed XP service reference: Corrected namespace reference to XPRewardService

Notable Implementation Details

  • Phase re-entry handling: The fix for phase callbacks ensures UI updates correctly when the same phase is re-entered (critical for the two-ready flow: 1st ready accepts game, 2nd ready starts gameplay)
  • Party components visibility: The new partyComponentsRoot provides clean control over all party UI elements, preventing interference during active gameplay
  • Server-authoritative ready counts: Ready state is now tracked on the server and broadcast to clients, eliminating sync issues
  • Improved flow clarity: The detailed phase flow diagram in the class docstring documents the complete party game lifecycle

https://claude.ai/code/session_01NWZJqFYbashBgydLxkmGub

claude and others added 7 commits February 25, 2026 11:18
- Fix initial Lobby phase callback not firing (NetworkVariable.OnValueChanged
  skips when default matches initial value) by manually invoking it
- Fix SetPhase for re-entering same phase (force callback on same-value set)
- Add CSDebug logging to all silent failure paths in ready system
  (OnLocalPlayerReady, OnPlayerReady_ServerRpc, CheckAllPlayersReady)
- Add max player limit check in OnPlayerJoined for solo mode
- Fix ready count tracking: pass server-authoritative count to UI instead of
  accumulating on the client (SetReadyCount/ResetReadyCount on PartyRoundTab)
- Add ResetReadyStates_ClientRpc so UI resets between 1st→2nd ready phases
- Add partyComponentsRoot field for disabling party UI during gameplay and
  re-enabling after cinematic completes
- Fix PartyEndGameHandler: explicit using for XPRewardService, re-enable
  party components after cinematic sequence
- Fix PartyPauseButton: null-safe access to InputStatus and InputController
- Fix ResetGameDataForRound_ClientRpc: guard against empty RoundStatsList
  on first round
- Add ReinitializePanelWithPlayers_ClientRpc for proper panel refresh after
  lobby fills

https://claude.ai/code/session_01NWZJqFYbashBgydLxkmGub
…tion B flow

- Disable MiniGameControllerBase components on environments at startup and
  when activating them, preventing KeyNotFoundException from RPC dispatch
  and InitializeAfterDelay interference
- Remove free flight lobby phase (Option B: UI-only entry, wait for players)
- PartyEndGameHandler intercepts scoreboard, shows party panel instead
- PartyGameController now drives all game flow with controllers disabled

https://claude.ai/code/session_01NWZJqFYbashBgydLxkmGub
…tsRoot

- Delete PartyEndGameHandler — each environment has its own end-game
  handler; PartyGameController just listens for gameData events
- Remove partyComponentsRoot field — was set to PartyGameManager itself,
  which would disable the controller during gameplay. Panel show/hide
  is sufficient.
- Collapse HidePartyUI/ShowPartyUI into simple ShowPanel/HidePanel RPCs
- Strip redundant logging and comments for cleaner code

https://claude.ai/code/session_01NWZJqFYbashBgydLxkmGub
- Guard ServerPlayerVesselInitializer.OnNetworkSpawn against null/empty
  _playerOrigins — disables itself instead of crashing
- Register human player directly in StartSoloLobby if SPVI didn't
  spawn one (covers party mode where SPVI may be absent)
- Fix OnLocalPlayerReady to fall back to _playerStates when
  gameData.LocalPlayer is null (no vessel needed for Ready)
- Call CheckAllPlayersReady after ResetReadyStates for auto-progress
  when all players are AI/already ready

https://claude.ai/code/session_01NWZJqFYbashBgydLxkmGub
…d guard

Four fixes:
1. MiniGameControllerBase.OnReadyClicked now checks `enabled` before
   delegating — prevents NPE when environment buttons are clicked but
   controllers are disabled in party mode
2. Solo and multiplayer lobbies now transition to WaitingForReady instead
   of auto-starting rounds. Player must click Ready to begin.
3. ActivateMiniGameEnvironment disables environment Canvas components
   to prevent the mini-game's Ready button, cameras, and scoreboard
   from overlapping party UI
4. UpdateSpawnPositionsFromEnv no longer calls gameData.ResetPlayers()
   which was NPE-ing on players without vessels (spawned by environment
   SPVIs before PartyGameController could disable them)

https://claude.ai/code/session_01NWZJqFYbashBgydLxkmGub
In party mode, environment SPVIs spawn Player objects during the scene
sweep before PartyGameController can disable them. These players have
no vessel linked, causing NPEs in StartPlayer (Vessel.StartVessel)
and ResetForPlay (Vessel.ResetForPlay).

Early-return when Vessel is null — safe for normal games where Vessel
is always assigned.

https://claude.ai/code/session_01NWZJqFYbashBgydLxkmGub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants