Fix back button closing entire profile page if popup open
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using TMPro;
|
||||
@@ -38,6 +36,8 @@ public class ProfileMenu : MonoBehaviour
|
||||
|
||||
[SerializeField] private bool canVote = true;
|
||||
|
||||
private GameObject popupObject;
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
@@ -282,6 +282,7 @@ public class ProfileMenu : MonoBehaviour
|
||||
void VotePost(BigInteger postId, TMP_Text entryLikesCount, TMP_Text entryLikesTexture)
|
||||
{
|
||||
var popup = Instantiate(voteOverlay, voteOverlay.transform.parent);
|
||||
popupObject = popup;
|
||||
popup.SetActive(true);
|
||||
var exitButton = popup.transform.GetChild(0).GetChild(0).GetComponent<Button>();
|
||||
var likeButton = popup.transform.GetChild(0).GetChild(2).GetComponent<Button>();
|
||||
@@ -290,6 +291,7 @@ public class ProfileMenu : MonoBehaviour
|
||||
likeButton.onClick.AddListener(async () =>
|
||||
{
|
||||
canVote = false;
|
||||
popupObject = null;
|
||||
Destroy(popup);
|
||||
await SendPostVote(postId, true, entryLikesCount, entryLikesTexture);
|
||||
canVote = true;
|
||||
@@ -297,6 +299,7 @@ public class ProfileMenu : MonoBehaviour
|
||||
dislikeButton.onClick.AddListener(async () =>
|
||||
{
|
||||
canVote = false;
|
||||
popupObject = null;
|
||||
Destroy(popup);
|
||||
await SendPostVote(postId, false, entryLikesCount, entryLikesTexture);
|
||||
canVote = true;
|
||||
@@ -350,14 +353,20 @@ public class ProfileMenu : MonoBehaviour
|
||||
void UploadPostPopup()
|
||||
{
|
||||
var popup = Instantiate(postOverlay, postOverlay.transform.parent);
|
||||
popupObject = popup;
|
||||
popup.SetActive(true);
|
||||
var inputBox = popup.transform.GetChild(0).GetChild(1).GetComponent<TMP_InputField>();
|
||||
var cancelButton = popup.transform.GetChild(0).GetChild(2).GetComponent<Button>();
|
||||
var submitButton = popup.transform.GetChild(0).GetChild(3).GetComponent<Button>();
|
||||
cancelButton.onClick.AddListener(() => Destroy(popup));
|
||||
cancelButton.onClick.AddListener(() =>
|
||||
{
|
||||
Destroy(popup);
|
||||
popupObject = null;
|
||||
});
|
||||
submitButton.onClick.AddListener(async () =>
|
||||
{
|
||||
if (inputBox.text.Trim().Length == 0) return;
|
||||
popupObject = null;
|
||||
Destroy(popup);
|
||||
await UploadPost(inputBox.text);
|
||||
});
|
||||
@@ -395,6 +404,14 @@ public class ProfileMenu : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Keyboard.current.escapeKey.wasPressedThisFrame) Destroy(gameObject);
|
||||
if (Keyboard.current.escapeKey.wasPressedThisFrame)
|
||||
{
|
||||
if (popupObject != null)
|
||||
{
|
||||
if (!canVote) canVote = true;
|
||||
Destroy(popupObject);
|
||||
}
|
||||
else Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user