-
Notifications
You must be signed in to change notification settings - Fork 562
feat: popup panel for connection status messages #494
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
932b9d8
Added basic popup panel
LPLafontaineB b51461d
Adding usage of Popup panel for connection status and auth errors
LPLafontaineB 85c3bc8
Created manager to handle connection status messages
LPLafontaineB c02f613
Reverted unnecessary change
LPLafontaineB f071d90
Removing unused field
LPLafontaineB 1617ba7
Displaying new messages to console if popup window is already in use
LPLafontaineB 764ccc6
repositionned text on popupPanel
LPLafontaineB 78c114d
Setup popup panel through DI instead of a singleton
LPLafontaineB 04d3108
removed unneeded method
LPLafontaineB 9a78a28
Revert "removed unneeded method"
LPLafontaineB 2613def
Revert "Setup popup panel through DI instead of a singleton"
LPLafontaineB 5543bcf
Updated class summaries
LPLafontaineB 715bfc9
Added publishing connect status when successful
LPLafontaineB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Git LFS file not shown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Assets/BossRoom/Scripts/Client/UI/ConnectionStatusMessageUIManager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure; | ||
using UnityEngine; | ||
|
||
namespace Unity.Multiplayer.Samples.BossRoom.Visual | ||
{ | ||
/// <summary> | ||
/// Subscribes to connection status messages to display them through the popup panel. | ||
/// </summary> | ||
public class ConnectionStatusMessageUIManager : MonoBehaviour | ||
{ | ||
IDisposable m_Subscriptions; | ||
|
||
[Inject] | ||
void InjectDependencies(ISubscriber<ConnectStatus> connectStatusSub) | ||
{ | ||
m_Subscriptions = connectStatusSub.Subscribe(OnConnectStatus); | ||
} | ||
|
||
void Awake() | ||
{ | ||
DontDestroyOnLoad(gameObject); | ||
} | ||
|
||
void OnDestroy() | ||
{ | ||
m_Subscriptions?.Dispose(); | ||
} | ||
|
||
void OnConnectStatus(ConnectStatus status) | ||
{ | ||
switch (status) | ||
{ | ||
case ConnectStatus.Undefined: | ||
case ConnectStatus.UserRequestedDisconnect: | ||
break; | ||
case ConnectStatus.ServerFull: | ||
PopupPanel.ShowPopupPanel("Connection Failed", "The Host is full and cannot accept any additional connections."); | ||
break; | ||
case ConnectStatus.Success: | ||
break; | ||
case ConnectStatus.LoggedInAgain: | ||
PopupPanel.ShowPopupPanel("Connection Failed", "You have logged in elsewhere using the same account."); | ||
break; | ||
case ConnectStatus.GenericDisconnect: | ||
PopupPanel.ShowPopupPanel("Disconnected From Host", "The connection to the host was lost"); | ||
break; | ||
default: | ||
Debug.LogWarning($"New ConnectStatus {status} has been added, but no connect message defined for it."); | ||
break; | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/BossRoom/Scripts/Client/UI/ConnectionStatusMessageUIManager.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using UnityEngine; | ||
using TMPro; | ||
|
||
namespace Unity.Multiplayer.Samples.BossRoom.Visual | ||
{ | ||
/// <summary> | ||
/// Simple popup panel to display information to players. | ||
/// </summary> | ||
public class PopupPanel : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
TextMeshProUGUI m_TitleText; | ||
[SerializeField] | ||
TextMeshProUGUI m_MainText; | ||
|
||
bool m_IsPopupShown; | ||
|
||
static PopupPanel s_Instance; | ||
|
||
void Awake() | ||
{ | ||
if (s_Instance != null) throw new Exception("Invalid state, instance is not null"); | ||
s_Instance = this; | ||
LPLafontaineB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ResetState(); | ||
} | ||
|
||
void OnDestroy() | ||
{ | ||
s_Instance = null; | ||
} | ||
|
||
public void OnConfirmClick() | ||
{ | ||
ResetState(); | ||
} | ||
|
||
/// <summary> | ||
/// Helper method to help us reset all state for the popup. | ||
/// </summary> | ||
void ResetState() | ||
{ | ||
m_TitleText.text = string.Empty; | ||
m_MainText.text = string.Empty; | ||
gameObject.SetActive(false); | ||
m_IsPopupShown = false; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the panel to match the given specifications to notify the player. If display image is set to true, it will display | ||
/// </summary> | ||
/// <param name="titleText">The title text at the top of the panel</param> | ||
/// <param name="mainText"> The text just under the title- the main body of text</param> | ||
public static void ShowPopupPanel(string titleText, string mainText) | ||
{ | ||
if (s_Instance != null) | ||
SamuelBellomo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
s_Instance.SetupPopupPanel(titleText, mainText); | ||
} | ||
else | ||
{ | ||
Debug.LogError($"No PopupPanel instance found. Cannot display message: {titleText}: {mainText}"); | ||
} | ||
} | ||
|
||
void SetupPopupPanel(string titleText, string mainText) | ||
{ | ||
if (m_IsPopupShown) | ||
{ | ||
Debug.Log("Trying to show popup, but another popup is already being shown."); | ||
Debug.Log($"{titleText}. {mainText}"); | ||
} | ||
else | ||
{ | ||
ResetState(); | ||
|
||
m_TitleText.text = titleText; | ||
m_MainText.text = mainText; | ||
|
||
gameObject.SetActive(true); | ||
m_IsPopupShown = true; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.