using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UnLockShw : MonoBehaviour
{
    //种子样式
    public enum SeedType
    {
        BAI_CAI,
        FAN_QIE,
        NAN_GUA,
        LUO_BO,
        YU_MI,
        QIE_ZI,
        XI_GUA,
        PU_TAO,
        CAO_MEI
    }
    [System.Serializable]
    public struct SeedSprite
    {
        public SeedType seedType;
        public Sprite seedsprite;
    }

    public SeedSprite[] Sprites;
    public Dictionary<SeedType, Sprite> ColorDic;
    public SeedType Spriteflower;
    private string[] goodsName = { "白菜", "番茄", "南瓜", "萝卜", "玉米", "茄子", "西瓜", "葡萄", "草莓" };
    public SpriteRenderer spriteCompent;
    public Text unLockDesc;
    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 int goodsId;
    public bool isSuccess = false;
    private void Update()
    {
        if (isSuccess)
        {
            setSeedType(goodsId);
            isSuccess = false;
        }
    }

    public void setSeedTypeData(int id)
    {
        goodsId = id;
        isSuccess = true;
    }


    public void setSeedType(int id)
    {
        SeedType type;
        switch (id)
        {
            case 1:
                type = SeedType.BAI_CAI;
                break;
            case 2:
                type = SeedType.FAN_QIE;
                break;
            case 3:
                type = SeedType.NAN_GUA;
                break;
            case 4:
                type = SeedType.LUO_BO;
                break;
            case 5:
                type = SeedType.YU_MI;
                break;
            case 6:
                type = SeedType.QIE_ZI;
                break;
            case 7:
                type = SeedType.XI_GUA;
                break;
            case 8:
                type = SeedType.PU_TAO;
                break;
            case 9:
                type = SeedType.CAO_MEI;
                break;
            default:
                type = SeedType.BAI_CAI;
                break;
        }
        Spriteflower = type;
        if (ColorDic.ContainsKey(type))
        {
            spriteCompent.sprite = ColorDic[type];
            if (id >= 1)
            {
                unLockDesc.text = "恭喜解锁" + goodsName[id - 1];
            }
        }
    }

}
