_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Conversion/DonatePanelItem.cs
舒荣森 c1ae0f6e2e add
2024-11-26 21:53:31 +08:00

85 lines
2.6 KiB
C#

using Newtonsoft.Json;
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;
public GameObject voluteCoinObj;
public Text Fees;
public Text Total;
public Button Button;
void Start()
{
GiftQuantity.onValueChanged.AddListener(GiftQuantityData);
Button.onClick.AddListener(buttonOnClick);
//testLogo();
}
public class voluteCoinItem
{
public string toCuteNo;
public int voluteCoin;
}
public mode mymode = mode.voluteCoin;
public enum mode{
voluteCoin = 0,//ÔùËÍÎÏ¿Ç
slot = 1//ÔùËÍ
}
private void FixedUpdate()
{
if (mymode == mode.voluteCoin)
{
voluteCoinObj.SetActive(true);
}
else
{
voluteCoinObj.SetActive(false);
}
}
async void buttonOnClick()
{
string response = "";//²âÊÔ
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());
}
ServerResponse18 serverResponse = JsonConvert.DeserializeObject<ServerResponse18>(response);
if (serverResponse.code != 200)
{
addEventPopUp(serverResponse.message);
}
Destroy(gameObject);
}
async void GiftQuantityData(string userInput)
{
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);
}
}
}