Get further on icon marketplace I will work on it tmr
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -138,6 +138,46 @@ public class BazookaManager : MonoBehaviour
|
|||||||
return int.Parse(saveFile["bird"]["pastOverlay"].ToString());
|
return int.Parse(saveFile["bird"]["pastOverlay"].ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetCustomBirdIcon(string value)
|
||||||
|
{
|
||||||
|
if (saveFile["bird"] == null) saveFile["bird"] = new JObject();
|
||||||
|
saveFile["bird"]["customIcon"] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnsetCustomBirdIcon()
|
||||||
|
{
|
||||||
|
if (saveFile["bird"] == null) return;
|
||||||
|
if (saveFile["bird"]["customIcon"] == null) return;
|
||||||
|
(saveFile["bird"] as JObject)?.Remove("customIcon");
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetCustomBirdIcon()
|
||||||
|
{
|
||||||
|
if (saveFile["bird"] == null) return null;
|
||||||
|
if (saveFile["bird"]["customIcon"] == null) return null;
|
||||||
|
return saveFile["bird"]["customIcon"].ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetCustomBirdIconID(int value)
|
||||||
|
{
|
||||||
|
if (saveFile["bird"] == null) saveFile["bird"] = new JObject();
|
||||||
|
saveFile["bird"]["customIconID"] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnsetCustomBirdIconID()
|
||||||
|
{
|
||||||
|
if (saveFile["bird"] == null) return;
|
||||||
|
if (saveFile["bird"]["customIconID"] == null) return;
|
||||||
|
(saveFile["bird"] as JObject)?.Remove("customIconID");
|
||||||
|
}
|
||||||
|
|
||||||
|
public int? GetCustomBirdIconID()
|
||||||
|
{
|
||||||
|
if (saveFile["bird"] == null) return null;
|
||||||
|
if (saveFile["bird"]["customIconID"] == null) return null;
|
||||||
|
return int.Parse(saveFile["bird"]["customIconID"].ToString());
|
||||||
|
}
|
||||||
|
|
||||||
//Settings stuff
|
//Settings stuff
|
||||||
|
|
||||||
public void SetSettingFullScreen(bool value)
|
public void SetSettingFullScreen(bool value)
|
||||||
|
|||||||
8
Assets/Scripts/IconMarketplace.meta
Normal file
8
Assets/Scripts/IconMarketplace.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2857b1f848102f577abc6acc5bd1885f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class IconMarketplaceDownloadIcon : MonoBehaviour
|
||||||
|
{
|
||||||
|
public TMP_Text statusText;
|
||||||
|
public Button backButton;
|
||||||
|
private IconMarketplaceManager marketplaceManager;
|
||||||
|
public GameObject content;
|
||||||
|
public GameObject sample;
|
||||||
|
|
||||||
|
public void Load(IconMarketplaceManager loadedFrom)
|
||||||
|
{
|
||||||
|
marketplaceManager = loadedFrom;
|
||||||
|
backButton.onClick.AddListener(() => marketplaceManager.SwitchPanel(0));
|
||||||
|
GetIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
async void GetIcons()
|
||||||
|
{
|
||||||
|
foreach (Transform item in content.transform)
|
||||||
|
{
|
||||||
|
if (item.gameObject.activeSelf)
|
||||||
|
{
|
||||||
|
Destroy(item.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Loading...", Color.white);
|
||||||
|
using UnityWebRequest request = UnityWebRequest.Get(SensitiveInfo.SERVER_DATABASE_PREFIX + "getMarketplaceIcons.php");
|
||||||
|
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||||
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
|
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||||
|
await request.SendWebRequest();
|
||||||
|
if (request.result != UnityWebRequest.Result.Success)
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Failed to make HTTP request", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string response = SensitiveInfo.Decrypt(request.downloadHandler.text, SensitiveInfo.SERVER_RECEIVE_TRANSFER_KEY);
|
||||||
|
if (response == "-999")
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Server error while fetching data", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (response == "-998")
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Client version too outdated to access servers", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (response == "-997")
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Encryption/decryption issues", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (response == "-996")
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Can't send requests on self-built instance", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "", Color.red);
|
||||||
|
var jsonResponse = JArray.Parse(response);
|
||||||
|
foreach (var item in jsonResponse)
|
||||||
|
{
|
||||||
|
JObject entry = (JObject)item;
|
||||||
|
GameObject newIcon = Instantiate(sample, content.transform);
|
||||||
|
|
||||||
|
ImageUtil.RenderFromBase64(entry["data"].ToString(), newIcon.transform.GetChild(0).GetChild(0).GetComponent<Image>());
|
||||||
|
newIcon.transform.GetChild(1).GetComponent<TMP_Text>().text = "Bird Name: " + entry["name"].ToString();
|
||||||
|
newIcon.transform.GetChild(2).GetComponent<TMP_Text>().text = "Designer Name: " + entry["username"].ToString();
|
||||||
|
newIcon.transform.GetChild(3).GetComponent<TMP_Text>().text = "Price " + entry["price"].ToString() + " coin";
|
||||||
|
newIcon.transform.GetChild(4).GetChild(0).GetComponent<TMP_Text>().text = "Purchase";
|
||||||
|
|
||||||
|
newIcon.SetActive(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b8133693b9ee6eec098e9cef8b719edf
|
||||||
61
Assets/Scripts/IconMarketplace/IconMarketplaceManager.cs
Normal file
61
Assets/Scripts/IconMarketplace/IconMarketplaceManager.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class IconMarketplaceManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
public GameObject normalPanel;
|
||||||
|
public GameObject downloadPanel;
|
||||||
|
public GameObject uploadPanel;
|
||||||
|
|
||||||
|
public IconMarketplaceUploadIcon uploadPanelScript;
|
||||||
|
public IconMarketplaceDownloadIcon downloadPanelScript;
|
||||||
|
|
||||||
|
public Button downloadButton;
|
||||||
|
public Button uploadButton;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
downloadButton.onClick.AddListener(() => SwitchPanel(1));
|
||||||
|
#if !UNITY_STANDALONE_OSX && !UNITY_STANDALONE_WIN && !UNITY_STANDALONE_LINUX && !UNITY_EDITOR
|
||||||
|
uploadButton.interactable = false;
|
||||||
|
uploadButton.transform.GetChild(0).transform.localPosition = new Vector3(0, 10, 0);
|
||||||
|
uploadButton.transform.GetChild(1).GetComponent<TMP_Text>().text = "Unsupported platform";
|
||||||
|
#else
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SwitchPanel(int panelIndex)
|
||||||
|
{
|
||||||
|
switch (panelIndex)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
normalPanel.SetActive(true);
|
||||||
|
downloadPanel.SetActive(false);
|
||||||
|
uploadPanel.SetActive(false);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
downloadPanelScript.Load(this);
|
||||||
|
normalPanel.SetActive(false);
|
||||||
|
downloadPanel.SetActive(true);
|
||||||
|
uploadPanel.SetActive(false);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
uploadPanelScript.Load();
|
||||||
|
normalPanel.SetActive(false);
|
||||||
|
downloadPanel.SetActive(false);
|
||||||
|
uploadPanel.SetActive(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dd46bad161f2c81e2a36dd6a25154ad4
|
||||||
98
Assets/Scripts/IconMarketplace/IconMarketplaceUploadIcon.cs
Normal file
98
Assets/Scripts/IconMarketplace/IconMarketplaceUploadIcon.cs
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using SFB;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
|
public class IconMarketplaceUploadIcon : MonoBehaviour
|
||||||
|
{
|
||||||
|
public TMP_Text statusText;
|
||||||
|
|
||||||
|
public void Load()
|
||||||
|
{
|
||||||
|
OpenFilePicker();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenFilePicker()
|
||||||
|
{
|
||||||
|
#if UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_EDITOR
|
||||||
|
var filters = new[] {
|
||||||
|
new ExtensionFilter("Image Files", "png"),
|
||||||
|
};
|
||||||
|
var paths = StandaloneFileBrowser.OpenFilePanel("Select an icon file", "", filters, false);
|
||||||
|
if (paths.Length > 0 && !string.IsNullOrEmpty(paths[0]))
|
||||||
|
{
|
||||||
|
UploadFile(paths[0]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
async void UploadFile(string path)
|
||||||
|
{
|
||||||
|
byte[] fileContent;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fileContent = File.ReadAllBytes(path);
|
||||||
|
if (fileContent.Length > 1024 * 1024)
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "File size exceeds 1 MB limit", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Failed to read file: " + e.Message, Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EncryptedWWWForm dataForm = new();
|
||||||
|
dataForm.AddField("token", BazookaManager.Instance.GetAccountSession());
|
||||||
|
dataForm.AddField("username", BazookaManager.Instance.GetAccountName());
|
||||||
|
dataForm.AddField("filecontent", Convert.ToBase64String(fileContent));
|
||||||
|
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "uploadMarketplaceIcon.php", dataForm.GetWWWForm());
|
||||||
|
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||||
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
|
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||||
|
await request.SendWebRequest();
|
||||||
|
if (request.result != UnityWebRequest.Result.Success)
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Failed to make HTTP request", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string response = SensitiveInfo.Decrypt(request.downloadHandler.text, SensitiveInfo.SERVER_RECEIVE_TRANSFER_KEY);
|
||||||
|
if (response == "-999")
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Server error while fetching data", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (response == "-998")
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Client version too outdated to access servers", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (response == "-997")
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Encryption/decryption issues", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (response == "-996")
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Can't send requests on self-built instance", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var jsonResponse = JObject.Parse(response);
|
||||||
|
if ((bool)jsonResponse["success"])
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, "Icon uploaded successfully!", Color.green);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AccountHandler.UpdateStatusText(statusText, (string)jsonResponse["message"], Color.red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ac25b048bc0f6aded8697b98caef8382
|
||||||
Reference in New Issue
Block a user