Cute_demon_attacks/meng_yao/Assets/script/scene_loading/JinShaBuy.cs
2024-12-06 16:18:17 +08:00

169 lines
7.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using static input_box_pop_up_window;
[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 List<GameObject> rooms;
public List<string> ids = new List<string>();
public override void Awake()
{
}
public void Show_buy(Sprite minerIcon,string minerName,int CurrencyId,int Num,float minerjiage,bool isMinr=true)//购买弹窗
{
if (float.Parse(Promptmgr.assestPanel.Coin.text) <minerjiage)
{
Promptmgr.Instance.PromptBubble("金币不够!!!", Color.black, Color.red);
return;
}
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)(float.Parse(Promptmgr.assestPanel.Coin.text) / minerjiage)>10?10: (int)(float.Parse(Promptmgr.assestPanel.Coin.text) / 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--;
max = (int)(float.Parse(Promptmgr.assestPanel.Coin.text) / minerjiage) > 10 ? 10 : (int)(float.Parse(Promptmgr.assestPanel.Coin.text) / 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>());
}
}
else if (type == 1)
{
if (number < max)
{
number++;
max = (int)(float.Parse(Promptmgr.assestPanel.Coin.text) / minerjiage) > 10 ? 10 : (int)(float.Parse(Promptmgr.assestPanel.Coin.text) / 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>());
}
}
else if (type == 2)
{
if (number!= max)
{
number=max;
max = (int)(float.Parse(Promptmgr.assestPanel.Coin.text) / minerjiage) > 10 ? 10 : (int)(float.Parse(Promptmgr.assestPanel.Coin.text) / 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>());
}
}
});
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)
{
if (isMinr)
{
GenerateForFisherElf generateForFisherElf = new GenerateForFisherElf(); // 购买矿工
generateForFisherElf.Num = Num;
generateForFisherElf.Count = Convert.ToInt32(number);
string response = await web.SendRequest(web.URL + "/Voucher/GenerateForMinerElf", "POST", JsonUtility.ToJson(generateForFisherElf));
Mining_Wizard_ID data = JsonUtility.FromJson<Mining_Wizard_ID>(response);
Debug.Log("购买对象的id"+data.Ids[0]);
Promptmgr.Instance.PromptBubble("购买精灵成功", Color.black,Color.blue);
int index1 = Num - 1;
int index2 = (Num - 1)*2;
rooms[index1].GetComponent<RoomJinsha>().addman(index2, number);
//Debug.Log(data.Ids[0]);
rooms[index1].GetComponent<RoomJinsha>().ids.Add(data.Ids[0]);
this.ids.Add(data.Ids[0]);
}
else
{
ItmeBuy itmebuy = new ItmeBuy();
itmebuy.Num = Num;
itmebuy.Count = Convert.ToInt32(number);
itmebuy.Type = 1;
string response = await web.SendRequest(web.URL + "/Item/Buy", "POST", JsonUtility.ToJson(itmebuy));
Debug.Log(response);
Promptmgr.Instance.PromptBubble("购买设备成功", Color.black, Color.blue);
int index1 = Num - 74;
int index2 = (Num - 74)*2;
rooms[index1].GetComponent<RoomJinsha>().addtools(index2, number);
}
}
});
}
void UpdateText(Text text)
{
text.text = number.ToString();
}
}