You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.5 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//using DG.Tweening;
public class GoodsTrdePandle : MonoBehaviour
{
public static GoodsTrdePandle instance;
public Image goodsImage;
public Text goodsNameText;
public Text goodsPrinceText;
public Text playerMoneyText;
public Button sellButton;
public Button buyButton;
public SingleGoods singleGoods;
public Transform sellsScrollView;
public Inventory playerInventory;
public Item RedBottle;
public Item BlueBottle;
//调用其他的类
public Character character;
public TownInfo townInfo;
// Start is called before the first frame update
private void Awake()
{
instance = this;
}
void Start()
{
Debug.Log(townInfo.goodsInTown.Count);
//Debug.Log(townInfo.townGoodsTempTransform.childCount);
OpenTradePanel();
}
void Update()
{
playerMoneyText.text = character.money + "";
}
public void OpenTradePanel()
{
//transform.DOScale(1, 0.3f);
for (int i = 0; i < sellsScrollView.childCount; i++)
{
Destroy(sellsScrollView.GetChild(i).gameObject);
}
for (int i = 0; i < townInfo.goodsInTown.Count; i++)
{
GameObject gameObject = Instantiate(townInfo.goodsInTown[i], sellsScrollView, false);
//gameObject.transform.DOScale(1, 0.3f);
//gameObject.transform.rotation = Quaternion.identity;
}
//townNameText.text = townInfo.townName;
//PlayerNameText.text= character.playerName;
playerMoneyText.text = character.money + "";
goodsImage.enabled = false;
//goodsNameText.text = "";
goodsPrinceText.text = "";
buyButton.interactable = false;
//sellButton.interactable = false;
}
public void CloseTradePanel()
{
if (singleGoods != null)
{
singleGoods.goodsNameText.color = Color.white;
singleGoods = null;
}
goodsImage.enabled = false;
goodsPrinceText.text = "";
buyButton.interactable = false;
gameObject.SetActive(false);
}
public void UpdateUI()
{
if (singleGoods != null)
{
goodsImage.enabled = true;
goodsImage.sprite = singleGoods.goodsSprite;
goodsPrinceText.text = singleGoods.goodsPrice+"";
buyButton.interactable = true;
playerMoneyText.text = character.money + "";
}
}
public void BuyGoods()
{
if(character.money>= singleGoods.goodsPrice)
{
//Destroy(singleGoods.gameObject);
character.money -= singleGoods.goodsPrice;
if (singleGoods.goodsName == "RedBottle")
{
AddNewGoods(RedBottle);
}
if (singleGoods.goodsName == "BuleBottle")
{
AddNewGoods(BlueBottle);
}
//character.
UpdateUI();
}
}
private void AddNewGoods(Item thisItem)
{
if (!playerInventory.itemList.Contains(thisItem))
{
for (int i = 0; i < playerInventory.itemList.Count; i++)
{
if (playerInventory.itemList[i] == null)
{
playerInventory.itemList[i] = thisItem;
break;
}
}
}
else
{
thisItem.itemHeld += 1;
}
}
}