Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send players back to their lobby on match end #715

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions Assets/Prefabs/UI/MenuCanvas.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -4012,23 +4012,21 @@ MonoBehaviour:
defaultMenu: {fileID: 110615194986557832}
galleryMenu: {fileID: 2684392273124228428}
creditsMenu: {fileID: 152431690657796851}
playerSelectMenu: {fileID: 4026824962317560842}
playerSelectMenuDefaultButton: {fileID: 2878829664369250595}
mapSelectMenu: {fileID: 3498704505247766114}
levelSelectManager: {fileID: 0}
playerSelectManager: {fileID: 0}
aIButton: {fileID: 5390649776347757468}
startButton: {fileID: 7502603491603641025}
innputManagerPrefab: {fileID: 0}
mapNames:
- CraterTown
- GrandCanyon
uiSelectSounds:
- {fileID: 8300000, guid: df56b3a96f5835849a7515c4036fdf84, type: 3}
- {fileID: 8300000, guid: 1b1b36f86c6a1de4d856a61793a0854d, type: 3}
- {fileID: 8300000, guid: d72483f8877f2684ba4d61b2e3dee9f3, type: 3}
- {fileID: 8300000, guid: 2fc59430bcd0be5418d8e7a5c9273c9d, type: 3}
- {fileID: 8300000, guid: 998e63f1e44797246a2dc7e0887d770e, type: 3}
uiChooseSounds: {fileID: 11400000, guid: 90b0dc5583765d64f81545c255b0fa3a, type: 2}
loadingScreen: {fileID: 0}
mainMenuCamera: {fileID: 0}
--- !u!82 &5626306360106808345
AudioSource:
Expand Down Expand Up @@ -5552,10 +5550,6 @@ PrefabInstance:
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3140668245959627490, guid: 58e54f7d80aca2645ab598618dffc039, type: 3}
propertyPath: m_Navigation.m_SelectOnDown
value:
objectReference: {fileID: 5921977457797426374}
- target: {fileID: 3140668245959627490, guid: 58e54f7d80aca2645ab598618dffc039, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size
value: 5
Expand Down Expand Up @@ -6017,17 +6011,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &5921977457797426374 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 4761102662359094921, guid: 58e54f7d80aca2645ab598618dffc039, type: 3}
m_PrefabInstance: {fileID: 1170305583697787471}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!224 &8203241732053331208 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 7055458770637592391, guid: 58e54f7d80aca2645ab598618dffc039, type: 3}
Expand Down
6 changes: 1 addition & 5 deletions Assets/Scenes/Menu.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 785370674}
m_IndirectSpecularColor: {r: 0.0583656, g: 0.21644169, b: 0.49412873, a: 1}
m_IndirectSpecularColor: {r: 0.062482566, g: 0.21938902, b: 0.4950583, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -5598,10 +5598,6 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4298729392729991341, guid: cbf30f348674af6ecb2ba42ec2aacaf6, type: 3}
propertyPath: m_Navigation.m_SelectOnDown
value:
objectReference: {fileID: 1776070626}
- target: {fileID: 4298729392729991341, guid: cbf30f348674af6ecb2ba42ec2aacaf6, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size
value: 5
Expand Down
14 changes: 13 additions & 1 deletion Assets/Scripts/Control&Input/Peer2PeerTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,15 @@ private void AddAiPlayers()
}
}

private void RemoveAiPlayers()
{
foreach (var ai in players.Values.Where(p => p.type is PlayerType.AI))
{
NetworkServer.SendToAll(new PlayerLeftMessage(ai.id));
}
}


// Called after shooting rounds (TODO just use the same matchcontroller stuff???)
private static void UpdatePlayerDetailsAfterShootingRound()
{
Expand Down Expand Up @@ -543,7 +552,8 @@ private static void UpdatePlayerInventoryForIdentity(PlayerIdentity identity)

public override void OnServerChangeScene(string newSceneName)
{
var needsExtraAiPlayers = PlayerInputManagerController.Singleton.MatchHasAI && !MatchController.Singleton;
var isAiEnabled = PlayerInputManagerController.Singleton.MatchHasAI;
var needsExtraAiPlayers = isAiEnabled && !MatchController.Singleton;
if (needsExtraAiPlayers)
{
AddAiPlayers();
Expand All @@ -560,6 +570,8 @@ public override void OnServerChangeScene(string newSceneName)
break;
case Scenes.Menu:
isInMatch = false;
if (isAiEnabled)
RemoveAiPlayers();
NetworkServer.RegisterHandler<PlayerConnectedMessage>(OnSpawnPlayerInput);
break;
default:
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Gamestate/MatchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ private void ReturnToMainMenu()
PlayerInputManagerController.Singleton.ChangeInputMaps("Menu");

// Mirror pulls us to the main menu automatically
NetworkManager.singleton.StopHost();
if (isServer)
NetworkManager.singleton.ServerChangeScene(Scenes.Menu);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should turn this into server changing scene to menu and clients changing to client lobby

}
}
34 changes: 32 additions & 2 deletions Assets/Scripts/UI/MainMenu/MainMenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
Expand Down Expand Up @@ -41,6 +42,10 @@ public class MainMenuController : MonoBehaviour
[SerializeField]
private CreditsMenu creditsMenu;
[SerializeField]
private GameObject playerSelectMenu;
[SerializeField]
private Selectable playerSelectMenuDefaultButton;
[SerializeField]
private GameObject mapSelectMenu;
[SerializeField]
private LevelSelectManager levelSelectManager;
Expand All @@ -54,8 +59,6 @@ public class MainMenuController : MonoBehaviour
private Button startButton;
[SerializeField]
private GameObject innputManagerPrefab;
[SerializeField]
private string[] mapNames;
private AudioSource audioSource;
[SerializeField]
private AudioClip[] uiSelectSounds;
Expand Down Expand Up @@ -111,6 +114,33 @@ private void Start()
defaultMenu.SetActive(false);
introRoutine = StartCoroutine(WaitForIntroVideoToEnd());
}

if (NetworkManager.singleton.isNetworkActive)
{
GoBackToLobby();
}
}

private void GoBackToLobby()
{
PlayerInputManagerController.Singleton.RemoveJoinListener();
if (NetworkServer.active)
{
// Hosts should be yeeted back into the lobby menu
mainMenuCamera.GetComponentInChildren<MainMenuMoveCamera>().MoveToPlayerSelect();
SwitchToMenu(playerSelectMenu);
SelectControl(playerSelectMenuDefaultButton);
SetStartButtonState();
playerSelectManager.UpdateLobby();
if (playerInputManagerController.MatchHasAI)
aIButton.Toggle();
}
else
{
// Clients should go to their own lobby scene
if (SceneManager.GetActiveScene().name == Scenes.Menu)
SceneManager.LoadScene(Scenes.ClientLobby);
}
}

private void StopFirstFrame(VideoPlayer source)
Expand Down