Add purchasing icons
This commit is contained in:
@@ -5238,7 +5238,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!224 &1866125038
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -142,7 +142,7 @@ public class BazookaManager : MonoBehaviour
|
||||
public void SetCustomBirdIconData(MarketplaceIconStorageType value)
|
||||
{
|
||||
if (saveFile["bird"] == null) saveFile["bird"] = new JObject();
|
||||
saveFile["bird"]["customIcon"] = value.ConvertTo<JObject>();
|
||||
saveFile["bird"]["customIcon"] = JObject.FromObject(value);
|
||||
}
|
||||
|
||||
public void UnsetCustomBirdIconData()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -12,6 +14,8 @@ public class IconMarketplaceDownloadIcon : MonoBehaviour
|
||||
public Button backButton;
|
||||
public GameObject content;
|
||||
public GameObject sample;
|
||||
private string statusMessage;
|
||||
private Coroutine statusRoutine;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
@@ -21,6 +25,7 @@ public class IconMarketplaceDownloadIcon : MonoBehaviour
|
||||
internal void Load()
|
||||
{
|
||||
GetIcons();
|
||||
balanceText.text = "You have " + Tools.FormatWithCommas(BazookaManager.Instance.GetCustomBirdIconData().Balance) + " coins to spend";
|
||||
}
|
||||
|
||||
async void GetIcons()
|
||||
@@ -32,7 +37,7 @@ public class IconMarketplaceDownloadIcon : MonoBehaviour
|
||||
Destroy(item.gameObject);
|
||||
}
|
||||
}
|
||||
Tools.UpdateStatusText(statusText, "Loading...", Color.white);
|
||||
ShowStatus("Loading...");
|
||||
using UnityWebRequest request = UnityWebRequest.Get(SensitiveInfo.SERVER_DATABASE_PREFIX + "getMarketplaceIcons.php");
|
||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", Application.version);
|
||||
@@ -40,33 +45,33 @@ public class IconMarketplaceDownloadIcon : MonoBehaviour
|
||||
await request.SendWebRequest();
|
||||
if (request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Tools.UpdateStatusText(statusText, "Failed to make HTTP request", Color.red);
|
||||
ShowStatus("Failed to make HTTP request");
|
||||
return;
|
||||
}
|
||||
string response = SensitiveInfo.Decrypt(request.downloadHandler.text, SensitiveInfo.SERVER_RECEIVE_TRANSFER_KEY);
|
||||
if (response == "-999")
|
||||
{
|
||||
Tools.UpdateStatusText(statusText, "Server error while fetching data", Color.red);
|
||||
ShowStatus("Server error while fetching data");
|
||||
return;
|
||||
}
|
||||
else if (response == "-998")
|
||||
{
|
||||
Tools.UpdateStatusText(statusText, "Client version too outdated to access servers", Color.red);
|
||||
ShowStatus("Client version too outdated to access servers");
|
||||
return;
|
||||
}
|
||||
else if (response == "-997")
|
||||
{
|
||||
Tools.UpdateStatusText(statusText, "Encryption/decryption issues", Color.red);
|
||||
ShowStatus("Encryption/decryption issues");
|
||||
return;
|
||||
}
|
||||
else if (response == "-996")
|
||||
{
|
||||
Tools.UpdateStatusText(statusText, "Can't send requests on self-built instance", Color.red);
|
||||
ShowStatus("Can't send requests on self-built instance");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Tools.UpdateStatusText(statusText, "", Color.red);
|
||||
ShowStatus(null);
|
||||
var jsonResponse = JArray.Parse(response);
|
||||
foreach (var item in jsonResponse)
|
||||
{
|
||||
@@ -77,17 +82,89 @@ public class IconMarketplaceDownloadIcon : MonoBehaviour
|
||||
Tools.RenderFromBase64(entry.Data, newIcon.transform.GetChild(0).GetChild(0).GetComponent<Image>());
|
||||
newIcon.transform.GetChild(1).GetComponent<TMP_Text>().text = "Bird Name: " + entry.Name;
|
||||
newIcon.transform.GetChild(2).GetComponent<TMP_Text>().text = "Price " + entry.Price + " coin";
|
||||
newIcon.transform.GetChild(3).GetComponent<TMP_Text>().text = "Designer Name: " + entry.CreatorUsername;
|
||||
newIcon.transform.GetChild(4).GetChild(0).GetComponent<TMP_Text>().text = "Purchase";
|
||||
newIcon.transform.GetChild(4).GetComponent<Button>().onClick.AddListener(() => HandlePurchase(entry));
|
||||
newIcon.transform.GetChild(3).GetComponent<TMP_Text>().text = "Designer Name: " + ((JObject)item)["username"].ToString();
|
||||
|
||||
var btn = newIcon.transform.GetChild(4).GetComponent<Button>();
|
||||
var btnText = btn.transform.GetChild(0).GetComponent<TMP_Text>();
|
||||
|
||||
bool alreadyBought = BazookaManager.Instance.GetCustomBirdIconData().Data.Any(d => d.UUID == entry.UUID);
|
||||
if (alreadyBought)
|
||||
{
|
||||
btn.interactable = false;
|
||||
btnText.text = "Purchased";
|
||||
}
|
||||
else
|
||||
{
|
||||
btn.onClick.AddListener(() => HandlePurchase(entry, btn));
|
||||
btnText.text = "Purchase";
|
||||
}
|
||||
|
||||
newIcon.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandlePurchase(MarketplaceIconType data)
|
||||
void HandlePurchase(MarketplaceIconType data, Button button)
|
||||
{
|
||||
//will work on this
|
||||
MarketplaceIconStorageType marketplaceIconStorage = BazookaManager.Instance.GetCustomBirdIconData();
|
||||
if (data.Price > marketplaceIconStorage.Balance)
|
||||
{
|
||||
ShowStatus("You can't afford this icon! You need " + (data.Price - marketplaceIconStorage.Balance) + " more coins");
|
||||
return;
|
||||
}
|
||||
var list = marketplaceIconStorage.Data.ToList();
|
||||
list.Add(data);
|
||||
marketplaceIconStorage.Data = list.ToArray();
|
||||
marketplaceIconStorage.Balance -= data.Price;
|
||||
button.interactable = false;
|
||||
button.transform.GetChild(0).GetComponent<TMP_Text>().text = "Purchased";
|
||||
balanceText.text = "You have " + Tools.FormatWithCommas(marketplaceIconStorage.Balance) + " coins to spend";
|
||||
BazookaManager.Instance.SetCustomBirdIconData(marketplaceIconStorage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ShowStatus(string content)
|
||||
{
|
||||
if (content == null)
|
||||
{
|
||||
if (statusRoutine != null) StopCoroutine(statusRoutine);
|
||||
statusText.gameObject.SetActive(false);
|
||||
statusText.text = "";
|
||||
}
|
||||
statusMessage = content;
|
||||
if (statusRoutine != null) StopCoroutine(statusRoutine);
|
||||
statusRoutine = StartCoroutine(StatusRoutine());
|
||||
}
|
||||
|
||||
IEnumerator StatusRoutine()
|
||||
{
|
||||
statusText.gameObject.SetActive(true);
|
||||
statusText.text = statusMessage;
|
||||
statusText.color = new Color(statusText.color.r, statusText.color.g, statusText.color.b, 0f);
|
||||
|
||||
float t = 0f;
|
||||
while (t < 0.5f)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
float a = t / 0.5f;
|
||||
statusText.color = new Color(statusText.color.r, statusText.color.g, statusText.color.b, a);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(2f);
|
||||
|
||||
t = 0f;
|
||||
while (t < 0.5f)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
float a = 1f - (t / 0.5f);
|
||||
statusText.color = new Color(statusText.color.r, statusText.color.g, statusText.color.b, a);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
statusText.gameObject.SetActive(false);
|
||||
statusText.text = "";
|
||||
statusRoutine = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,11 +48,17 @@ public class IconMarketplaceManager : MonoBehaviour
|
||||
uploadPanel.SetActive(false);
|
||||
break;
|
||||
case 1:
|
||||
downloadPanelScript.Load();
|
||||
downloadPanelScript.balanceText.text = "You have " + Tools.FormatWithCommas(BazookaManager.Instance.GetCustomBirdIconData().Balance) + " coins to spend";
|
||||
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();
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
using System.Numerics;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public class MarketplaceIconType {
|
||||
[JsonProperty("username")]
|
||||
public string CreatorUsername { get; set; }
|
||||
[JsonProperty("userid")]
|
||||
public string CreatorUserID { get; set; }
|
||||
[JsonProperty("data")]
|
||||
public string Data { get; set; }
|
||||
[JsonProperty("uuid")]
|
||||
public string UUID { get; set; }
|
||||
[JsonProperty("price")]
|
||||
public int Price { get; set; }
|
||||
public BigInteger Price { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user