Cute_demon_attacks/meng_yao/Assets/script/ConnactServer/JinShaBuy.cs
2024-11-04 06:56:09 +08:00

157 lines
5.8 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[Serializable]
public class RootObject
{
public List<Item> List;
public int ErrorCode;
public string ErrorMessage;
}
public class JinShaBuy : mount
{
public int number=1;
public int max = 10;
public int minerjiage = 0;
public override void Awake()
{
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void Show_buy(Sprite minerIcon,string minerName,int CurrencyId,int Num,float minerjiage)//购买弹窗
{
Debug.Log(int.Parse(AssestPanel.instance.Coin.text));
Debug.Log(minerjiage);
if (int.Parse(AssestPanel.instance.Coin.text) < (int)minerjiage)
{
Promptmgr.Instance.PromptBubble("金币不够!!!",Color.black,Color.red);
return;
}
Debug.Log("弹窗成功");
List<BoxType> boxTypes = new List<BoxType>();
boxTypes.Add(new BoxType
{
Name = "account_number",
textName = "道具兑换道具",
Type = 10,
is_required = false,
icon = LoadSprite(mount.mountitem.itemDataList[CurrencyId].IconPath),
icon2 = minerIcon,
nametext1 = "金币",
nametext2 = minerName,
numbertext1 = "1",//单个矿工的价钱
numbertext2 = number.ToString()//几个矿工
});
boxTypes.Add(new BoxType { Name = "account_number", textName = " 数量:", prompt = "请输入购买数量", Type = 6, is_required = false});
boxTypes.Add(new BoxType { Name = "submit", textName = " 取消购买 ", Type = 2 });
GameObject gameObject = add_pop_up(true);//生成弹窗母体
gameObject.GetComponent<input_box_pop_up_window>().minHeight = 800;//设置最低高度
List<GameObject> gameObjects = gameObject.GetComponent<input_box_pop_up_window>().updateUI(boxTypes, "购买");//测试输入框回调处理
//初始化
number = 1;
this.minerjiage = (int)minerjiage;
max = int.Parse(AssestPanel.instance.Coin.text) / this.minerjiage;
gameObjects[0].GetComponent<input_box_pop_up_window_item>().numbertextobj1.GetComponent<Text>().text = (this.minerjiage * number).ToString();
gameObjects[0].GetComponent<input_box_pop_up_window_item>().numbertextobj2.GetComponent<Text>().text = number.ToString();
UpdateText(gameObjects[1].GetComponent<input_box_pop_up_window_item>().contentobj.GetComponent<Text>());
UpdateText(gameObjects[1].GetComponent<input_box_pop_up_window_item>().contentobj.GetComponent<Text>());
gameObjects[1].GetComponent<input_box_pop_up_window_item>().register_click(async (BoxType boxType, int type) =>//登录确定或取消
{
if (type == 0)
{
if (number>1)
{
number--;
gameObjects[0].GetComponent<input_box_pop_up_window_item>().numbertextobj1.GetComponent<Text>().text = (this.minerjiage*number).ToString();
gameObjects[0].GetComponent<input_box_pop_up_window_item>().numbertextobj2.GetComponent<Text>().text = number.ToString();
UpdateText(gameObjects[1].GetComponent<input_box_pop_up_window_item>().contentobj.GetComponent<Text>());
}
}
else if (type == 1)
{
if (number < max)
{
number++;
gameObjects[0].GetComponent<input_box_pop_up_window_item>().numbertextobj1.GetComponent<Text>().text = (this.minerjiage * number).ToString();
gameObjects[0].GetComponent<input_box_pop_up_window_item>().numbertextobj2.GetComponent<Text>().text = number.ToString();
UpdateText(gameObjects[1].GetComponent<input_box_pop_up_window_item>().contentobj.GetComponent<Text>());
}
}
else if (type == 2)
{
if (number!= max)
{
number=max;
gameObjects[0].GetComponent<input_box_pop_up_window_item>().numbertextobj1.GetComponent<Text>().text = (this.minerjiage * number).ToString();
gameObjects[0].GetComponent<input_box_pop_up_window_item>().numbertextobj2.GetComponent<Text>().text = number.ToString();
UpdateText(gameObjects[1].GetComponent<input_box_pop_up_window_item>().contentobj.GetComponent<Text>());
}
}
});
gameObjects[2].GetComponent<input_box_pop_up_window_item>().register_click(async (BoxType boxType, int type) =>//登录确定或取消
{
if (type == 0)
{
gameObject.GetComponent<input_box_pop_up_window>().destroy();
}
else if (type == 1)
{
Debug.Log(Num);
GenerateForFisherElf generateForFisherElf = new GenerateForFisherElf(); // 购买矿工
generateForFisherElf.Num = Num;
generateForFisherElf.Count =Convert.ToInt32(boxTypes[1].content);
//Debug.Log(generateForFisherElf);
string response = await web.SendRequest(web.URL+ "/Voucher/GenerateForMinerElf", "POST", JsonUtility.ToJson(generateForFisherElf));
Debug.Log("用户产生代金卷"+response);
string daijinjuanponse = await web.SendRequest(web.URL + "/Voucher/GetList", "POST");
Debug.Log("用户所有代金卷" + daijinjuanponse);
}
});
}
void UpdateText(Text text) {
text.text = number.ToString();
}
}