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.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
@@ -38,6 +36,8 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
|
|
||||||
[SerializeField] private bool canVote = true;
|
[SerializeField] private bool canVote = true;
|
||||||
|
|
||||||
|
private GameObject popupObject;
|
||||||
|
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@@ -282,6 +282,7 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
void VotePost(BigInteger postId, TMP_Text entryLikesCount, TMP_Text entryLikesTexture)
|
void VotePost(BigInteger postId, TMP_Text entryLikesCount, TMP_Text entryLikesTexture)
|
||||||
{
|
{
|
||||||
var popup = Instantiate(voteOverlay, voteOverlay.transform.parent);
|
var popup = Instantiate(voteOverlay, voteOverlay.transform.parent);
|
||||||
|
popupObject = popup;
|
||||||
popup.SetActive(true);
|
popup.SetActive(true);
|
||||||
var exitButton = popup.transform.GetChild(0).GetChild(0).GetComponent<Button>();
|
var exitButton = popup.transform.GetChild(0).GetChild(0).GetComponent<Button>();
|
||||||
var likeButton = popup.transform.GetChild(0).GetChild(2).GetComponent<Button>();
|
var likeButton = popup.transform.GetChild(0).GetChild(2).GetComponent<Button>();
|
||||||
@@ -290,6 +291,7 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
likeButton.onClick.AddListener(async () =>
|
likeButton.onClick.AddListener(async () =>
|
||||||
{
|
{
|
||||||
canVote = false;
|
canVote = false;
|
||||||
|
popupObject = null;
|
||||||
Destroy(popup);
|
Destroy(popup);
|
||||||
await SendPostVote(postId, true, entryLikesCount, entryLikesTexture);
|
await SendPostVote(postId, true, entryLikesCount, entryLikesTexture);
|
||||||
canVote = true;
|
canVote = true;
|
||||||
@@ -297,6 +299,7 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
dislikeButton.onClick.AddListener(async () =>
|
dislikeButton.onClick.AddListener(async () =>
|
||||||
{
|
{
|
||||||
canVote = false;
|
canVote = false;
|
||||||
|
popupObject = null;
|
||||||
Destroy(popup);
|
Destroy(popup);
|
||||||
await SendPostVote(postId, false, entryLikesCount, entryLikesTexture);
|
await SendPostVote(postId, false, entryLikesCount, entryLikesTexture);
|
||||||
canVote = true;
|
canVote = true;
|
||||||
@@ -350,14 +353,20 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
void UploadPostPopup()
|
void UploadPostPopup()
|
||||||
{
|
{
|
||||||
var popup = Instantiate(postOverlay, postOverlay.transform.parent);
|
var popup = Instantiate(postOverlay, postOverlay.transform.parent);
|
||||||
|
popupObject = popup;
|
||||||
popup.SetActive(true);
|
popup.SetActive(true);
|
||||||
var inputBox = popup.transform.GetChild(0).GetChild(1).GetComponent<TMP_InputField>();
|
var inputBox = popup.transform.GetChild(0).GetChild(1).GetComponent<TMP_InputField>();
|
||||||
var cancelButton = popup.transform.GetChild(0).GetChild(2).GetComponent<Button>();
|
var cancelButton = popup.transform.GetChild(0).GetChild(2).GetComponent<Button>();
|
||||||
var submitButton = popup.transform.GetChild(0).GetChild(3).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 () =>
|
submitButton.onClick.AddListener(async () =>
|
||||||
{
|
{
|
||||||
if (inputBox.text.Trim().Length == 0) return;
|
if (inputBox.text.Trim().Length == 0) return;
|
||||||
|
popupObject = null;
|
||||||
Destroy(popup);
|
Destroy(popup);
|
||||||
await UploadPost(inputBox.text);
|
await UploadPost(inputBox.text);
|
||||||
});
|
});
|
||||||
@@ -395,6 +404,14 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
|
|
||||||
void Update()
|
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