110 lines
3.4 KiB
C#
110 lines
3.4 KiB
C#
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;
|
|
using Newtonsoft.Json;
|
|
|
|
public class ConversionItem : BaseUIPanel
|
|
{
|
|
public TMP_InputField inputField;
|
|
public TextMeshProUGUI TextMeshProUGUI;
|
|
|
|
public Button button1;
|
|
public Button button2;
|
|
|
|
|
|
public Image Image1;
|
|
public Image Image2;
|
|
public Sprite shellSprite;
|
|
public Sprite eggSprite;
|
|
public mode mymode = mode.ShellToEgg;
|
|
|
|
public class coinsConvert
|
|
{
|
|
public float voluteCoin;
|
|
public float beansCoin;
|
|
public int convertType;
|
|
}
|
|
|
|
|
|
private async void Start()
|
|
{
|
|
inputField.onValueChanged.AddListener(GetInputData);
|
|
button1.onClick.AddListener(() => CancelOnClick(button1));
|
|
button2.onClick.AddListener(() => ConfirmOnClick(button2));
|
|
TextMeshProUGUI.text = "0";
|
|
|
|
//testhead = await testLogo();//꿎桿되쩌
|
|
}
|
|
public enum mode
|
|
{
|
|
ShellToEgg = 0,//卦옳瘻卦뎔
|
|
EggToShell = 1//卦뎔瘻卦옳
|
|
}
|
|
private void Update()
|
|
{
|
|
if (mymode == mode.ShellToEgg)
|
|
{
|
|
Image1.sprite = shellSprite;
|
|
Image2.sprite = eggSprite;
|
|
}
|
|
else
|
|
{
|
|
Image2.sprite = shellSprite;
|
|
Image1.sprite = eggSprite;
|
|
}
|
|
}
|
|
public async void CancelOnClick(Button button)//혤句객큐
|
|
{
|
|
await ButtonClickAnimationAsync(button.gameObject);
|
|
Destroy(gameObject);
|
|
}
|
|
public async void ConfirmOnClick(Button button)//횅땍객큐
|
|
{
|
|
await ButtonClickAnimationAsync(button.gameObject);
|
|
if (IsGreaterThanZeroDecimal(inputField.text))
|
|
{
|
|
coinsConvert body = new coinsConvert();
|
|
if (mymode == mode.ShellToEgg)
|
|
{
|
|
body.voluteCoin = float.Parse(inputField.text);
|
|
body.beansCoin = float.Parse(TextMeshProUGUI.text);
|
|
}
|
|
else
|
|
{
|
|
body.voluteCoin = float.Parse(TextMeshProUGUI.text);
|
|
body.beansCoin = float.Parse(inputField.text);
|
|
}
|
|
body.convertType = (int)mymode;
|
|
//string response = await web.SendRequest(web.URL + "/snail/user/coinsConvert", "POST", JsonUtility.ToJson(body), testhead);//꿎桿
|
|
string response = await web.SendRequest(web.URL + "/snail/user/coinsConvert", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());//攣駕쌈흙
|
|
Debug.Log("흙꽝:"+ JsonUtility.ToJson(body) + " 1.8럿쀼: " + response);
|
|
ServerResponse18 serverResponse = JsonConvert.DeserializeObject<ServerResponse18>(response);
|
|
addEventPopUp(serverResponse.message);
|
|
Destroy(gameObject);
|
|
}
|
|
else
|
|
{
|
|
addEventPopUp("헝渴흙攣횅돨鑒좆");
|
|
}
|
|
}
|
|
|
|
public void GetInputData(string userInput)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(userInput) || !IsGreaterThanZeroDecimal(inputField.text)) {
|
|
userInput = "0";
|
|
}
|
|
TextMeshProUGUI.text = "0";
|
|
if (mymode == mode.ShellToEgg)
|
|
TextMeshProUGUI.text = (float.Parse(userInput) * 3).ToString("F2");
|
|
if (mymode == mode.EggToShell)
|
|
TextMeshProUGUI.text = (float.Parse(userInput) / 3).ToString("F2");
|
|
|
|
ButtonClickAnimationAsync(TextMeshProUGUI.gameObject);
|
|
}
|
|
}
|