2024-11-25 23:31:50 +08:00
|
|
|
|
using DG.Tweening;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2024-11-26 02:09:38 +08:00
|
|
|
|
using Newtonsoft.Json;
|
2024-11-25 23:31:50 +08:00
|
|
|
|
|
|
|
|
|
public class ConversionItem : BaseUIPanel
|
|
|
|
|
{
|
|
|
|
|
public TMP_InputField inputField;
|
|
|
|
|
public TextMeshProUGUI TextMeshProUGUI;
|
|
|
|
|
|
|
|
|
|
public Button button1;
|
|
|
|
|
public Button button2;
|
2024-11-26 02:09:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Image Image1;
|
|
|
|
|
public Image Image2;
|
|
|
|
|
public Sprite shellSprite;
|
|
|
|
|
public Sprite eggSprite;
|
2024-11-25 23:31:50 +08:00
|
|
|
|
public mode mymode = mode.ShellToEgg;
|
2024-11-26 02:09:38 +08:00
|
|
|
|
|
2024-11-26 15:50:49 +08:00
|
|
|
|
public class coinsConvertVolut
|
2024-11-26 02:09:38 +08:00
|
|
|
|
{
|
|
|
|
|
public float voluteCoin;
|
2024-11-26 15:50:49 +08:00
|
|
|
|
public int convertType;
|
|
|
|
|
}
|
|
|
|
|
public class coinsConvertBeans
|
|
|
|
|
{
|
|
|
|
|
|
2024-11-26 02:09:38 +08:00
|
|
|
|
public float beansCoin;
|
|
|
|
|
public int convertType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async void Start()
|
2024-11-25 23:31:50 +08:00
|
|
|
|
{
|
|
|
|
|
inputField.onValueChanged.AddListener(GetInputData);
|
|
|
|
|
button1.onClick.AddListener(() => CancelOnClick(button1));
|
|
|
|
|
button2.onClick.AddListener(() => ConfirmOnClick(button2));
|
2024-11-26 02:09:38 +08:00
|
|
|
|
TextMeshProUGUI.text = "0";
|
|
|
|
|
|
|
|
|
|
//testhead = await testLogo();//<2F><><EFBFBD>Ե<EFBFBD>¼
|
2024-11-25 23:31:50 +08:00
|
|
|
|
}
|
|
|
|
|
public enum mode
|
|
|
|
|
{
|
2024-11-26 02:09:38 +08:00
|
|
|
|
ShellToEgg = 0,//<2F>Ͽ<EFBFBD>ת<EFBFBD>ϵ<EFBFBD>
|
|
|
|
|
EggToShell = 1//<2F>ϵ<EFBFBD>ת<EFBFBD>Ͽ<EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
if (mymode == mode.ShellToEgg)
|
|
|
|
|
{
|
|
|
|
|
Image1.sprite = shellSprite;
|
|
|
|
|
Image2.sprite = eggSprite;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Image2.sprite = shellSprite;
|
|
|
|
|
Image1.sprite = eggSprite;
|
|
|
|
|
}
|
2024-11-25 23:31:50 +08:00
|
|
|
|
}
|
2024-11-26 15:50:49 +08:00
|
|
|
|
|
2024-11-25 23:31:50 +08:00
|
|
|
|
public async void ConfirmOnClick(Button button)//ȷ<><C8B7><EFBFBD><EFBFBD>ť
|
|
|
|
|
{
|
|
|
|
|
await ButtonClickAnimationAsync(button.gameObject);
|
2024-11-26 02:09:38 +08:00
|
|
|
|
if (IsGreaterThanZeroDecimal(inputField.text))
|
|
|
|
|
{
|
2024-11-26 15:50:49 +08:00
|
|
|
|
coinsConvertVolut body = new coinsConvertVolut();
|
|
|
|
|
string send = "";
|
2024-11-26 02:09:38 +08:00
|
|
|
|
if (mymode == mode.ShellToEgg)
|
2024-11-26 15:50:49 +08:00
|
|
|
|
send = "{\"convertType\":" + ((int)mymode).ToString() + ",\"voluteCoin\":" + inputField.text + "}";
|
2024-11-26 02:09:38 +08:00
|
|
|
|
else
|
2024-11-26 15:50:49 +08:00
|
|
|
|
send = "{\"convertType\":" + ((int)mymode).ToString() + ",\"beansCoin\":" + inputField.text + "}";
|
2024-11-26 02:09:38 +08:00
|
|
|
|
body.convertType = (int)mymode;
|
2024-11-26 15:50:49 +08:00
|
|
|
|
|
|
|
|
|
Debug.Log(send);
|
|
|
|
|
//string response = await web.SendRequest(web.URL + "/snail/user/coinsConvert", "POST", send, testhead);//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
string response = await web.SendRequest(web.URL + "/snail/user/coinsConvert", "POST", send, Global.global.CreateHeaders());//<2F><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
|
2024-11-26 02:09:38 +08:00
|
|
|
|
Debug.Log("<22><><EFBFBD><EFBFBD>:"+ JsonUtility.ToJson(body) + " 1.8<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " + response);
|
|
|
|
|
ServerResponse18 serverResponse = JsonConvert.DeserializeObject<ServerResponse18>(response);
|
2024-11-26 15:50:49 +08:00
|
|
|
|
if (serverResponse.code != 200)
|
|
|
|
|
{
|
|
|
|
|
addEventPopUp(serverResponse.message);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-26 02:09:38 +08:00
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
addEventPopUp("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
2024-11-25 23:31:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GetInputData(string userInput)
|
|
|
|
|
{
|
2024-11-26 02:09:38 +08:00
|
|
|
|
if (string.IsNullOrWhiteSpace(userInput) || !IsGreaterThanZeroDecimal(inputField.text)) {
|
2024-11-25 23:31:50 +08:00
|
|
|
|
userInput = "0";
|
|
|
|
|
}
|
|
|
|
|
TextMeshProUGUI.text = "0";
|
|
|
|
|
if (mymode == mode.ShellToEgg)
|
2024-11-26 02:09:38 +08:00
|
|
|
|
TextMeshProUGUI.text = (float.Parse(userInput) * 3).ToString("F2");
|
2024-11-25 23:31:50 +08:00
|
|
|
|
if (mymode == mode.EggToShell)
|
2024-11-26 02:09:38 +08:00
|
|
|
|
TextMeshProUGUI.text = (float.Parse(userInput) / 3).ToString("F2");
|
|
|
|
|
|
2024-11-25 23:31:50 +08:00
|
|
|
|
ButtonClickAnimationAsync(TextMeshProUGUI.gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|