Skip to content

Commit 1617ba7

Browse files
committed
Displaying new messages to console if popup window is already in use
1 parent f071d90 commit 1617ba7

File tree

2 files changed

+58
-52
lines changed

2 files changed

+58
-52
lines changed
Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,51 @@
11
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
4-
using Unity.Multiplayer.Samples.BossRoom;
52
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
6-
using Unity.Multiplayer.Samples.BossRoom.Visual;
73
using UnityEngine;
84

9-
public class ConnectionStatusMessageUIManager : MonoBehaviour
5+
namespace Unity.Multiplayer.Samples.BossRoom.Visual
106
{
11-
12-
IDisposable m_Subscriptions;
13-
14-
[Inject]
15-
void InjectDependencies(ISubscriber<ConnectStatus> connectStatusSub)
7+
public class ConnectionStatusMessageUIManager : MonoBehaviour
168
{
17-
m_Subscriptions = connectStatusSub.Subscribe(OnConnectStatus);
18-
}
9+
IDisposable m_Subscriptions;
1910

20-
void Awake()
21-
{
22-
DontDestroyOnLoad(gameObject);
23-
}
11+
[Inject]
12+
void InjectDependencies(ISubscriber<ConnectStatus> connectStatusSub)
13+
{
14+
m_Subscriptions = connectStatusSub.Subscribe(OnConnectStatus);
15+
}
2416

25-
void OnDestroy()
26-
{
27-
m_Subscriptions?.Dispose();
28-
}
17+
void Awake()
18+
{
19+
DontDestroyOnLoad(gameObject);
20+
}
2921

30-
void OnConnectStatus(ConnectStatus status)
31-
{
32-
switch (status)
22+
void OnDestroy()
23+
{
24+
m_Subscriptions?.Dispose();
25+
}
26+
27+
void OnConnectStatus(ConnectStatus status)
3328
{
34-
case ConnectStatus.Undefined:
35-
case ConnectStatus.UserRequestedDisconnect:
36-
break;
37-
case ConnectStatus.ServerFull:
38-
PopupPanel.ShowPopupPanel("Connection Failed", "The Host is full and cannot accept any additional connections.");
39-
break;
40-
case ConnectStatus.Success:
41-
break;
42-
case ConnectStatus.LoggedInAgain:
43-
PopupPanel.ShowPopupPanel("Connection Failed", "You have logged in elsewhere using the same account.");
44-
break;
45-
case ConnectStatus.GenericDisconnect:
46-
PopupPanel.ShowPopupPanel("Disconnected From Host", "The connection to the host was lost");
47-
break;
48-
default:
49-
Debug.LogWarning($"New ConnectStatus {status} has been added, but no connect message defined for it.");
50-
break;
29+
switch (status)
30+
{
31+
case ConnectStatus.Undefined:
32+
case ConnectStatus.UserRequestedDisconnect:
33+
break;
34+
case ConnectStatus.ServerFull:
35+
PopupPanel.ShowPopupPanel("Connection Failed", "The Host is full and cannot accept any additional connections.");
36+
break;
37+
case ConnectStatus.Success:
38+
break;
39+
case ConnectStatus.LoggedInAgain:
40+
PopupPanel.ShowPopupPanel("Connection Failed", "You have logged in elsewhere using the same account.");
41+
break;
42+
case ConnectStatus.GenericDisconnect:
43+
PopupPanel.ShowPopupPanel("Disconnected From Host", "The connection to the host was lost");
44+
break;
45+
default:
46+
Debug.LogWarning($"New ConnectStatus {status} has been added, but no connect message defined for it.");
47+
break;
48+
}
5149
}
5250
}
5351
}

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using System;
22
using UnityEngine;
3-
using UnityEngine.UI;
43
using TMPro;
5-
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
6-
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure;
7-
using UnityEngine.SceneManagement;
84

95
namespace Unity.Multiplayer.Samples.BossRoom.Visual
106
{
@@ -18,10 +14,13 @@ public class PopupPanel : MonoBehaviour
1814
[SerializeField]
1915
TextMeshProUGUI m_MainText;
2016

17+
bool m_IsPopupShown;
18+
2119
static PopupPanel s_Instance;
2220

2321
void Awake()
2422
{
23+
if (s_Instance != null) throw new Exception("Invalid state, instance is not null");
2524
s_Instance = this;
2625
ResetState();
2726
}
@@ -44,34 +43,43 @@ void ResetState()
4443
m_TitleText.text = string.Empty;
4544
m_MainText.text = string.Empty;
4645
gameObject.SetActive(false);
46+
m_IsPopupShown = false;
4747
}
4848

4949
/// <summary>
5050
/// Sets the panel to match the given specifications to notify the player. If display image is set to true, it will display
5151
/// </summary>
5252
/// <param name="titleText">The title text at the top of the panel</param>
5353
/// <param name="mainText"> The text just under the title- the main body of text</param>
54-
/// <param name="confirmFunction"> The function to call when the confirm button is pressed.</param>
55-
public static void ShowPopupPanel(string titleText, string mainText, Action confirmFunction = null)
54+
public static void ShowPopupPanel(string titleText, string mainText)
5655
{
5756
if (s_Instance != null)
5857
{
59-
s_Instance.SetupPopupPanel(titleText, mainText, confirmFunction);
58+
s_Instance.SetupPopupPanel(titleText, mainText);
6059
}
6160
else
6261
{
6362
Debug.LogError($"No PopupPanel instance found. Cannot display message: {titleText}: {mainText}");
6463
}
6564
}
6665

67-
void SetupPopupPanel(string titleText, string mainText, Action confirmFunction = null)
66+
void SetupPopupPanel(string titleText, string mainText)
6867
{
69-
ResetState();
68+
if (m_IsPopupShown)
69+
{
70+
Debug.Log("Trying to show popup, but another popup is already being shown.");
71+
Debug.Log($"{titleText}. {mainText}");
72+
}
73+
else
74+
{
75+
ResetState();
7076

71-
m_TitleText.text = titleText;
72-
m_MainText.text = mainText;
77+
m_TitleText.text = titleText;
78+
m_MainText.text = mainText;
7379

74-
gameObject.SetActive(true);
80+
gameObject.SetActive(true);
81+
m_IsPopupShown = true;
82+
}
7583
}
7684
}
7785
}

0 commit comments

Comments
 (0)