using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class WareItem2 : MonoBehaviour
{
    //样式
    public enum SeedType
    {
        //果实
        LAND_BAI_CAI,
        LAND_FAN_QIE,
        LAND_NAN_GUA,
        LAND_LUO_BO,
        LAND_YU_MI,
        LAND_QIE_ZI,
        LAND_XI_GUA,
        LAND_PU_TAO,
        LAND_CAO_MEI
    }
    [System.Serializable]
    public struct SeedSprite
    {
        public SeedType seedType;
        public Sprite seedsprite;
    }

    public SeedSprite[] Sprites;
    public Dictionary<SeedType, Sprite> ColorDic;
    public SeedType Spriteflower;

    public SpriteRenderer spriteCompent;

    public Text getGoodsNum;
    public Text getCoinNum;


    private void Awake()
    {
        //spriteCompent = transform.GetComponent<SpriteRenderer>();
        ColorDic = new Dictionary<SeedType, Sprite>();

        for (int i = 0; i < Sprites.Length; i++)
        {
            if (!ColorDic.ContainsKey(Sprites[i].seedType))
            {
                ColorDic.Add(Sprites[i].seedType, Sprites[i].seedsprite);
            }
        }
    }
    //果实
    public void setFruitType(int id)
    {
        SeedType type;
        switch (id)
        {
            case 1:
                type = SeedType.LAND_BAI_CAI;
                break;
            case 2:
                type = SeedType.LAND_FAN_QIE;
                break;
            case 3:
                type = SeedType.LAND_NAN_GUA;
                break;
            case 4:
                type = SeedType.LAND_LUO_BO;
                break;
            case 5:
                type = SeedType.LAND_YU_MI;
                break;
            case 6:
                type = SeedType.LAND_QIE_ZI;
                break;
            case 7:
                type = SeedType.LAND_XI_GUA;
                break;
            case 8:
                type = SeedType.LAND_PU_TAO;
                break;
            case 9:
                type = SeedType.LAND_CAO_MEI;
                break;
            default:
                type = SeedType.LAND_BAI_CAI;
                break;
        }

        Spriteflower = type;
        if (ColorDic.ContainsKey(type))
        {
            spriteCompent.sprite = ColorDic[type];
        }
    }

    //收获果实设置
    public void setGoodsData(int coinNum)
    {
        getGoodsNum.text = "1";
        getCoinNum.text = coinNum.ToString();
    }
    //显示的时候刷新
    private void OnEnable()
    {
        Debug.Log("设置1");
        setFruitType(GetComponentInParent<LandAnimation>().getTempFruitId);
        Debug.Log("设置2");
        setGoodsData(GetComponentInParent<LandAnimation>().getTempCoinNum);
        Debug.Log("设置3");
    }
}
