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

public class LandShowControl : MonoBehaviour
{

    public GameObject UnLockLand;//未解锁
    public GameObject WaitLockLand;//待解锁
    public GameObject LockLandPlant;//已种植
    public GameObject LockLandPlantReward;//待收获
    public GameObject LockLandUnPlant;//未种植
    //public GameObject GetRewardAnim;//收获动画
    //public GameObject LockLandUnPlant;//浇水动画
    private CanvasGroup m_CanvasGroup;
    private Fruit_Time time;//倒计时
    //data
    private LandDataControl mLandData;
    private LandEntity entity;
    private void Start()
    {
        time = GetComponentInChildren<Fruit_Time>();
        mLandData = GetComponent<LandDataControl>();
        //第一次
        //entity = LandListDataControl.GetIns().getLandListData(transform.tag);
        //entity = mLandData.getMyLandEntity;
        updateLand();
    }
    public void updateLand()
    {
        //entity = LandListDataControl.GetIns().getLandListData(transform.tag);
        entity = mLandData.getMyLandEntity;
        if (entity != null)
        {
            landType(entity.status, entity);
        }
        else
        {   //没有数据
            landType(-1, null);
        }
    }

    public void updateLand2(LandEntity bean)
    {
        entity = bean;
        if (entity != null)
        {
            landType(entity.status, entity);
        }
        else
        {   //没有数据
            landType(-1, null);
        }
    }

    //int index = 1;
    //private void Update()
    //{
    //    landType(index++ % 5, entity);
    //}

    //0 未解锁 1 未种植 2 已种植（显示倒计时）3 已成熟 4 待解锁
    public void landType(int type, LandEntity en)
    {
        //GetRewardAnim.SetActive(false);
        switch (type)
        {
            case 0:
                showLand(UnLockLand);
                dissmissLand(WaitLockLand);
                dissmissLand(LockLandPlant);
                dissmissLand(LockLandUnPlant);
                dissmissLand(LockLandPlantReward);
                break;
            case 1:
                showLand(LockLandUnPlant);
                dissmissLand(WaitLockLand);
                dissmissLand(LockLandPlant);
                dissmissLand(UnLockLand);
                dissmissLand(LockLandPlantReward);
                break;
            case 2:
                showLand(LockLandPlant);
                dissmissLand(LockLandPlantReward);
                dissmissLand(WaitLockLand);
                dissmissLand(UnLockLand);
                dissmissLand(LockLandUnPlant);
                if (time != null)
                {
                    time.initTime(en);
                }
                break;
            case 3:
                showLand(LockLandPlantReward);
                dissmissLand(LockLandPlant);
                dissmissLand(WaitLockLand);
                dissmissLand(UnLockLand);
                dissmissLand(LockLandUnPlant);
                break;
            case 4:
                showLand(WaitLockLand);
                dissmissLand(UnLockLand);
                dissmissLand(LockLandPlant);
                dissmissLand(LockLandUnPlant);
                dissmissLand(LockLandPlantReward);
                break;
            default:
                Debug.Log("没有地块数据");
                showLand(UnLockLand);
                dissmissLand(WaitLockLand);
                dissmissLand(LockLandPlant);
                dissmissLand(LockLandUnPlant);
                dissmissLand(LockLandPlantReward);
                break;
        }
    }
    private void showLand(GameObject obj)
    {
        m_CanvasGroup = obj.GetComponent<CanvasGroup>();
        m_CanvasGroup.alpha = 1;
        m_CanvasGroup.interactable = true;
        m_CanvasGroup.blocksRaycasts = true;
    }

    private void dissmissLand(GameObject obj)
    {
        m_CanvasGroup = obj.GetComponent<CanvasGroup>();
        m_CanvasGroup.alpha = 0;
        m_CanvasGroup.interactable = false;
        m_CanvasGroup.blocksRaycasts = false;
    }

}
