Files
source/Assets/Scripts/IconMarketplace/IconMarketplaceManager.cs

85 lines
3.3 KiB
C#

using SimpleFileBrowser;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class IconMarketplaceManager : MonoBehaviour
{
[SerializeField] private GameObject normalPanel;
[SerializeField] private GameObject downloadPanel;
[SerializeField] private GameObject uploadPanel;
[SerializeField] private IconMarketplaceUploadIcon uploadPanelScript;
[SerializeField] private IconMarketplaceDownloadIcon downloadPanelScript;
[SerializeField] private Button downloadButton;
[SerializeField] private Button uploadButton;
[SerializeField] private TMP_Text coinText;
void Start()
{
downloadPanelScript.iconPurchaseSound.volume = BazookaManager.Instance.GetSettingSFXVolume();
downloadButton.onClick.AddListener(() => SwitchPanel(1));
if (BazookaManager.Instance.GetAccountID() != null && BazookaManager.Instance.GetAccountName() != null && BazookaManager.Instance.GetAccountSession() != null)
{
uploadButton.onClick.AddListener(() => SwitchPanel(2));
}
else
{
uploadButton.interactable = false;
uploadButton.transform.GetChild(0).transform.localPosition = new Vector3(0, 10, 0);
uploadButton.transform.GetChild(1).GetComponent<TMP_Text>().text = "Not logged in to an account";
}
SwitchPanel(0);
}
internal void SwitchPanel(int panelIndex)
{
downloadPanelScript.iconPurchaseSound.Stop();
downloadPanelScript.anyChanges = false;
downloadPanelScript.optionsPanelSortByDropdown.value = 3;
downloadPanelScript.optionsPanelPriceRangeToggle.isOn = false;
downloadPanelScript.optionsPanelSearchForToggle.isOn = false;
switch (panelIndex)
{
case 0:
coinText.text = "You have " + Tools.FormatWithCommas(BazookaManager.Instance.GetCustomBirdIconData().Balance) + " coins";
normalPanel.SetActive(true);
downloadPanel.SetActive(false);
uploadPanel.SetActive(false);
break;
case 1:
foreach (Transform item in downloadPanelScript.content.transform)
{
if (item.gameObject.activeSelf)
{
Destroy(item.gameObject);
}
}
normalPanel.SetActive(false);
downloadPanel.SetActive(true);
uploadPanel.SetActive(false);
downloadPanelScript.Load();
break;
case 2:
uploadPanelScript.Reset();
normalPanel.SetActive(false);
downloadPanel.SetActive(false);
uploadPanel.SetActive(true);
break;
}
}
async void Update()
{
if (Keyboard.current.escapeKey.wasPressedThisFrame)
{
if (downloadPanelScript.optionsPanel.activeSelf) downloadPanelScript.optionsPanelSubmitButton.onClick.Invoke();
else if (uploadPanel.activeSelf && FileBrowser.IsOpen) return;
else if (downloadPanel.activeSelf || uploadPanel.activeSelf) SwitchPanel(0);
else await SceneManager.LoadSceneAsync("MainMenu");
}
}
}