Comitting lobby code without testing.
This commit is contained in:
parent
66f84652dc
commit
60fa58b07f
14 changed files with 1207 additions and 37 deletions
|
|
@ -1322,12 +1322,25 @@ namespace TD.UI
|
|||
matchEndTitle.style.unityFontStyleAndWeight = FontStyle.Bold;
|
||||
panel.Add(matchEndTitle);
|
||||
|
||||
// Action row — Retry (back to lobby with everyone who retried)
|
||||
// and Return to Main Menu (this player only disconnects).
|
||||
var actionRow = new VisualElement();
|
||||
actionRow.style.flexDirection = FlexDirection.Row;
|
||||
actionRow.style.marginTop = 8;
|
||||
panel.Add(actionRow);
|
||||
|
||||
var retryBtn = new Button(OnRetryClicked) { text = "Retry" };
|
||||
retryBtn.style.minWidth = 120;
|
||||
retryBtn.style.minWidth = 140;
|
||||
retryBtn.style.height = 36;
|
||||
retryBtn.style.fontSize = 16;
|
||||
retryBtn.style.marginTop = 8;
|
||||
panel.Add(retryBtn);
|
||||
retryBtn.style.marginRight = 12;
|
||||
actionRow.Add(retryBtn);
|
||||
|
||||
var menuBtn = new Button(OnReturnToMainMenuClicked) { text = "Return to Main Menu" };
|
||||
menuBtn.style.minWidth = 200;
|
||||
menuBtn.style.height = 36;
|
||||
menuBtn.style.fontSize = 16;
|
||||
actionRow.Add(menuBtn);
|
||||
|
||||
matchEndOverlay.Add(panel);
|
||||
root.Add(matchEndOverlay);
|
||||
|
|
@ -1368,41 +1381,34 @@ namespace TD.UI
|
|||
// sceneLoaded callback survives the scene reload (HUDController dies),
|
||||
// re-arms StartHost once the fresh scene has finished loading, and
|
||||
// unsubscribes itself.
|
||||
// Retry: take everyone back to the Lobby scene via LobbyService. The
|
||||
// lobby preserves race picks, clears ready state. Anyone who clicked
|
||||
// Return to Main Menu instead has already disconnected — they don't
|
||||
// come along.
|
||||
private void OnRetryClicked()
|
||||
{
|
||||
var svc = LobbyService.Instance;
|
||||
if (svc != null)
|
||||
{
|
||||
svc.RequestReturnToLobbyRpc();
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback: LobbyService isn't spawned (e.g. testing the gameplay
|
||||
// scene standalone without the lobby flow). Hard-reload the scene.
|
||||
Debug.LogWarning("[HUDController] LobbyService not found — falling back to scene reload.");
|
||||
var nm = NetworkManager.Singleton;
|
||||
if (nm == null)
|
||||
{
|
||||
Debug.LogWarning("[HUDController] Retry clicked but NetworkManager is null.");
|
||||
return;
|
||||
}
|
||||
if (!nm.IsServer)
|
||||
{
|
||||
Debug.LogWarning("[HUDController] Retry only works on the host. " +
|
||||
"Clients should ask the host to retry.");
|
||||
return;
|
||||
}
|
||||
|
||||
Scene active = SceneManager.GetActiveScene();
|
||||
s_pendingHostRestartBuildIndex = active.buildIndex;
|
||||
SceneManager.sceneLoaded += OnSceneLoadedForRetry;
|
||||
|
||||
nm.Shutdown();
|
||||
SceneManager.LoadScene(active.buildIndex);
|
||||
if (nm != null && nm.IsServer && nm.SceneManager != null)
|
||||
nm.SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
|
||||
}
|
||||
|
||||
private static int s_pendingHostRestartBuildIndex = -1;
|
||||
|
||||
private static void OnSceneLoadedForRetry(Scene loaded, LoadSceneMode mode)
|
||||
// Return to Main Menu: disconnect only this player. SessionFlow's
|
||||
// OnClientDisconnect handler routes us back to MainMenu locally. Other
|
||||
// peers remain in the match (until the host quits, at which point
|
||||
// SessionFlow on each remaining client routes them out too).
|
||||
private void OnReturnToMainMenuClicked()
|
||||
{
|
||||
if (loaded.buildIndex != s_pendingHostRestartBuildIndex) return;
|
||||
|
||||
SceneManager.sceneLoaded -= OnSceneLoadedForRetry;
|
||||
s_pendingHostRestartBuildIndex = -1;
|
||||
|
||||
var nm = NetworkManager.Singleton;
|
||||
if (nm != null) nm.StartHost();
|
||||
else Debug.LogWarning("[HUDController] Retry: no NetworkManager in reloaded scene.");
|
||||
TD.Net.NetworkBootstrap.Disconnect();
|
||||
}
|
||||
|
||||
// ----- Helpers ----------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue