Skip to content

Commit 2613def

Browse files
committed
Revert "Setup popup panel through DI instead of a singleton"
This reverts commit 78c114d.
1 parent 9a78a28 commit 2613def

File tree

7 files changed

+31
-34
lines changed

7 files changed

+31
-34
lines changed

Assets/BossRoom/Scenes/Startup.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:13b1c488ad1662e224891150417b6946a08a8e84cbb0a3436bf15aa630faea99
3-
size 35452
2+
oid sha256:7b2c33d4681d53ec62b32b7ff2c81123b4457d8dcd8d0b6d643097e74ae36856
3+
size 35006

Assets/BossRoom/Scripts/Client/Game/State/ClientMainMenuState.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public class ClientMainMenuState : GameStateBehaviour
3232
[SerializeField] CanvasGroup m_MainMenuButtonsCanvasGroup;
3333
[SerializeField] GameObject m_SignInSpinner;
3434

35-
PopupPanel m_PopupPanel;
36-
3735
void Awake()
3836
{
3937
m_MainMenuButtonsCanvasGroup.interactable = false;
@@ -42,7 +40,7 @@ void Awake()
4240
}
4341

4442
[Inject]
45-
void InjectDependenciesAndInitialize(AuthenticationServiceFacade authServiceFacade, LocalLobbyUser localUser, LocalLobby localLobby, PopupPanel popupPanel)
43+
void InjectDependenciesAndInitialize(AuthenticationServiceFacade authServiceFacade, LocalLobbyUser localUser, LocalLobby localLobby)
4644
{
4745
m_Scope = new DIScope(DIScope.RootScope);
4846

@@ -51,8 +49,6 @@ void InjectDependenciesAndInitialize(AuthenticationServiceFacade authServiceFaca
5149

5250
var unityAuthenticationInitOptions = new InitializationOptions();
5351

54-
m_PopupPanel = popupPanel;
55-
5652
#if UNITY_EDITOR
5753
//The code below makes it possible for the clone instance to log in as a different user profile in Authentication service.
5854
//This allows us to test services integration locally by utilising Parrelsync.
@@ -104,7 +100,7 @@ void OnAuthSignIn()
104100

105101
void OnSignInFailed()
106102
{
107-
m_PopupPanel.ShowPopupPanel("Authentication Error", "For some reason we can't authenticate the user anonymously - that typically means that project is not properly set up with Unity services.");
103+
PopupPanel.ShowPopupPanel("Authentication Error", "For some reason we can't authenticate the user anonymously - that typically means that project is not properly set up with Unity services.");
108104
}
109105
}
110106

Assets/BossRoom/Scripts/Client/UI/ConnectionStatusMessageUIManager.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ namespace Unity.Multiplayer.Samples.BossRoom.Visual
77
public class ConnectionStatusMessageUIManager : MonoBehaviour
88
{
99
IDisposable m_Subscriptions;
10-
PopupPanel m_PopupPanel;
1110

1211
[Inject]
13-
void InjectDependencies(ISubscriber<ConnectStatus> connectStatusSub, PopupPanel popupPanel)
12+
void InjectDependencies(ISubscriber<ConnectStatus> connectStatusSub)
1413
{
1514
m_Subscriptions = connectStatusSub.Subscribe(OnConnectStatus);
16-
m_PopupPanel = popupPanel;
1715
}
1816

1917
void Awake()
@@ -34,15 +32,15 @@ void OnConnectStatus(ConnectStatus status)
3432
case ConnectStatus.UserRequestedDisconnect:
3533
break;
3634
case ConnectStatus.ServerFull:
37-
m_PopupPanel.ShowPopupPanel("Connection Failed", "The Host is full and cannot accept any additional connections.");
35+
PopupPanel.ShowPopupPanel("Connection Failed", "The Host is full and cannot accept any additional connections.");
3836
break;
3937
case ConnectStatus.Success:
4038
break;
4139
case ConnectStatus.LoggedInAgain:
42-
m_PopupPanel.ShowPopupPanel("Connection Failed", "You have logged in elsewhere using the same account.");
40+
PopupPanel.ShowPopupPanel("Connection Failed", "You have logged in elsewhere using the same account.");
4341
break;
4442
case ConnectStatus.GenericDisconnect:
45-
m_PopupPanel.ShowPopupPanel("Disconnected From Host", "The connection to the host was lost");
43+
PopupPanel.ShowPopupPanel("Disconnected From Host", "The connection to the host was lost");
4644
break;
4745
default:
4846
Debug.LogWarning($"New ConnectStatus {status} has been added, but no connect message defined for it.");

Assets/BossRoom/Scripts/Client/UI/Lobby/LobbyUIMediator.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class LobbyUIMediator : MonoBehaviour
2424
NameGenerationData m_NameGenerationData;
2525
GameNetPortal m_GameNetPortal;
2626
ClientGameNetPortal m_ClientNetPortal;
27-
PopupPanel m_PopupPanel;
2827

2928
[Inject]
3029
void InjectDependenciesAndInitialize(
@@ -34,8 +33,7 @@ void InjectDependenciesAndInitialize(
3433
LocalLobby localLobby,
3534
NameGenerationData nameGenerationData,
3635
GameNetPortal gameNetPortal,
37-
ClientGameNetPortal clientGameNetPortal,
38-
PopupPanel popupPanel
36+
ClientGameNetPortal clientGameNetPortal
3937
)
4038
{
4139
m_NameGenerationData = nameGenerationData;
@@ -44,7 +42,6 @@ PopupPanel popupPanel
4442
m_LocalLobby = localLobby;
4543
m_GameNetPortal = gameNetPortal;
4644
m_ClientNetPortal = clientGameNetPortal;
47-
m_PopupPanel = popupPanel;
4845

4946
RegenerateName();
5047

@@ -154,7 +151,7 @@ void OnJoinedLobby(Lobby remoteLobby)
154151

155152
void OnRelayJoinFailed(string message)
156153
{
157-
m_PopupPanel.ShowPopupPanel("Relay join failed", message);
154+
PopupPanel.ShowPopupPanel("Relay join failed", message);
158155
Debug.Log($"Relay join failed: {message}");
159156
//leave the lobby if relay failed for some reason
160157
m_LobbyServiceFacade.EndTracking();

Assets/BossRoom/Scripts/Shared/Game/UI/PopupPanel.cs renamed to Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@ public class PopupPanel : MonoBehaviour
1616

1717
bool m_IsPopupShown;
1818

19+
static PopupPanel s_Instance;
20+
1921
void Awake()
2022
{
23+
if (s_Instance != null) throw new Exception("Invalid state, instance is not null");
24+
s_Instance = this;
2125
ResetState();
2226
}
2327

28+
void OnDestroy()
29+
{
30+
s_Instance = null;
31+
}
32+
2433
public void OnConfirmClick()
2534
{
2635
ResetState();
@@ -42,9 +51,16 @@ void ResetState()
4251
/// </summary>
4352
/// <param name="titleText">The title text at the top of the panel</param>
4453
/// <param name="mainText"> The text just under the title- the main body of text</param>
45-
public void ShowPopupPanel(string titleText, string mainText)
54+
public static void ShowPopupPanel(string titleText, string mainText)
4655
{
47-
SetupPopupPanel(titleText, mainText);
56+
if (s_Instance != null)
57+
{
58+
s_Instance.SetupPopupPanel(titleText, mainText);
59+
}
60+
else
61+
{
62+
Debug.LogError($"No PopupPanel instance found. Cannot display message: {titleText}: {mainText}");
63+
}
4864
}
4965

5066
void SetupPopupPanel(string titleText, string mainText)

Assets/BossRoom/Scripts/Shared/ApplicationController.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
55
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure;
66
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Lobbies;
7-
using Unity.Multiplayer.Samples.BossRoom.Visual;
87
using Unity.Netcode;
98
using UnityEngine;
109
using UnityEngine.SceneManagement;
@@ -16,17 +15,9 @@ namespace Unity.Multiplayer.Samples.BossRoom.Shared
1615
/// </summary>
1716
public class ApplicationController : MonoBehaviour
1817
{
19-
[SerializeField]
20-
UpdateRunner m_UpdateRunner;
21-
22-
[SerializeField]
23-
GameNetPortal m_GameNetPortal;
24-
25-
[SerializeField]
26-
ClientGameNetPortal m_ClientNetPortal;
27-
28-
[SerializeField]
29-
PopupPanel m_PopupPanel;
18+
[SerializeField] UpdateRunner m_UpdateRunner;
19+
[SerializeField] GameNetPortal m_GameNetPortal;
20+
[SerializeField] ClientGameNetPortal m_ClientNetPortal;
3021

3122
LocalLobby m_LocalLobby;
3223
LobbyServiceFacade m_LobbyServiceFacade;
@@ -46,7 +37,6 @@ private void Awake()
4637
scope.BindInstanceAsSingle(m_UpdateRunner);
4738
scope.BindInstanceAsSingle(m_GameNetPortal);
4839
scope.BindInstanceAsSingle(m_ClientNetPortal);
49-
scope.BindInstanceAsSingle(m_PopupPanel);
5040

5141
//the following singletons represent the local representations of the lobby that we're in and the user that we are
5242
//they can persist longer than the lifetime of the UI in MainMenu where we set up the lobby that we create or join

0 commit comments

Comments
 (0)