_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Conversion/DonatePanelItem.cs

85 lines
2.6 KiB
C#
Raw Normal View History

2024-11-26 18:14:09 +08:00
using Newtonsoft.Json;
2024-11-26 15:50:49 +08:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class DonatePanelItem : BaseUIPanel
{
public TMP_InputField Recipient;
public TMP_InputField GiftQuantity;
public Text NumberOfFreeSnailShells;
2024-11-26 21:53:31 +08:00
public GameObject voluteCoinObj;
2024-11-26 15:50:49 +08:00
public Text Fees;
public Text Total;
2024-11-26 16:40:57 +08:00
public Button Button;
2024-11-26 15:50:49 +08:00
void Start()
{
GiftQuantity.onValueChanged.AddListener(GiftQuantityData);
2024-11-26 16:40:57 +08:00
Button.onClick.AddListener(buttonOnClick);
2024-11-26 21:53:31 +08:00
//testLogo();
2024-11-26 15:50:49 +08:00
}
2024-11-26 16:54:06 +08:00
public class voluteCoinItem
2024-11-26 15:50:49 +08:00
{
2024-11-26 16:54:06 +08:00
public string toCuteNo;
public int voluteCoin;
}
2024-11-26 21:53:31 +08:00
public mode mymode = mode.voluteCoin;
public enum mode{
voluteCoin = 0,//<2F><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD>
slot = 1//<2F><><EFBFBD><EFBFBD>
}
private void FixedUpdate()
{
if (mymode == mode.voluteCoin)
{
voluteCoinObj.SetActive(true);
}
else
{
voluteCoinObj.SetActive(false);
}
}
2024-11-26 16:54:06 +08:00
async void buttonOnClick()
{
2024-11-26 21:53:31 +08:00
string response = "";//<2F><><EFBFBD><EFBFBD>
if (mymode == mode.voluteCoin)
{
string body = "{\"toCuteNo\":" + (int.Parse(Recipient.text)).ToString() + ",\"voluteCoin\":" + GiftQuantity.text + "}";
response = await web.SendRequest(web.URL + "/snail/transfer/voluteCoin", "POST", body, Global.global.CreateHeaders());
}
else
{
string body = "{\"toCuteNo\":" + (int.Parse(Recipient.text)).ToString() + ",\"slotId\":" + GiftQuantity.text + "}";
response = await web.SendRequest(web.URL + "/snail/transfer/slot", "POST", body, Global.global.CreateHeaders());
}
2024-11-26 18:14:09 +08:00
ServerResponse18 serverResponse = JsonConvert.DeserializeObject<ServerResponse18>(response);
if (serverResponse.code != 200)
{
addEventPopUp(serverResponse.message);
}
Destroy(gameObject);
2024-11-26 15:50:49 +08:00
}
async void GiftQuantityData(string userInput)
{
2024-11-26 21:53:31 +08:00
if (mymode == mode.voluteCoin)
{
if (string.IsNullOrWhiteSpace(userInput))
{
userInput = "0";
}
NumberOfFreeSnailShells.text = userInput;
await ButtonClickAnimationAsync(NumberOfFreeSnailShells.gameObject, 1.05f);
Fees.text = (int.Parse(userInput) * 0.08).ToString();
await ButtonClickAnimationAsync(Fees.gameObject, 1.05f);
Total.text = (int.Parse(userInput) + (int.Parse(userInput) * 0.08)).ToString();
await ButtonClickAnimationAsync(Total.gameObject, 1.05f);
}
2024-11-26 15:50:49 +08:00
}
}