From 7b9712f33f42b14e4d277166fa533a379021312d Mon Sep 17 00:00:00 2001
From: chenxin <chenxin6991@163.com>
Date: Fri, 18 Dec 2020 09:52:45 +0800
Subject: [PATCH] Merge branch 'master' of http://47.95.218.140:8090/r/GemBattle into master

---
 Assets/Scripts/TowerDefense/UI/HUD/EndlessRandomTower.cs |  176 +++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 129 insertions(+), 47 deletions(-)

diff --git a/Assets/Scripts/TowerDefense/UI/HUD/EndlessRandomTower.cs b/Assets/Scripts/TowerDefense/UI/HUD/EndlessRandomTower.cs
index c45a17c..bef5e3e 100644
--- a/Assets/Scripts/TowerDefense/UI/HUD/EndlessRandomTower.cs
+++ b/Assets/Scripts/TowerDefense/UI/HUD/EndlessRandomTower.cs
@@ -8,6 +8,8 @@
 using UnityEngine.UI;
 using TMPro;
 using KTGMGemClient;
+using DG.Tweening;
+using System.Collections;
 
 public class EndlessRandomTower : Singleton<EndlessRandomTower>
 {
@@ -18,6 +20,9 @@
     /// 购买二级宝石的按钮贴图.
     /// </summary>
     public Sprite buyBtnLevelUp;
+
+    [SerializeField]
+    private TextMeshProUGUI cashText;
 
     protected bool bSetBuyLvlUp;
 
@@ -53,9 +58,32 @@
 
     public ParticleSystem btnPS;
 
+    IEnumerator ReadJson()
+    {
+        while (!GameConfig.JsonReadDone)
+        {
+            yield return 10;
+        }
+
+        countDownLimit = JsonDataCenter.GetById<battle>(23).value;
+        Debug.Log("设置了倒计时:" + countDownLimit);
+        yield break;
+    }
+
     // Start is called before the first frame update
     void Start()
     {
+#if UNITY_ANDROID
+
+#endif
+#if UNITY_IPHONE
+
+#endif
+#if UNITY_EDITOR
+
+#endif
+        StartCoroutine(ReadJson());
+
         if (!EndlessLevelManager.instanceExists)
             Debug.LogError("[UI] No level manager for tower list");
 
@@ -77,17 +105,16 @@
         bSetBuyLvlUp = false;
         bCdTimeStart = false;
         randomBtn.onClick.AddListener(delegate () { onClick(EFeatureTower.NULL); });
-        UpdateDescDisplay();
+        NormalDesc.text = $"购买{0 + 1}级精灵";
+        Invoke("UpdateDescDisplay", 1.0f);
+        //UpdateDescDisplay();
     }
 
     public void UpdateDescDisplay()
     {
-        int minLevel = 0;
+        int minLevel = GameConfig.IsUpgradeTowerLevel ? 1 : 0;
 
-        if (EndlessUIStart.instance.GameStartTime >= JsonDataCenter.DOUBLE_GEM_TIME)
-            minLevel = Mathf.Min(EndlessGameUI.instance.MinLevel, 1);
-
-        NormalDesc.text = $"购买{minLevel + 1}级宝石";
+        NormalDesc.text = $"购买{minLevel + 1}级精灵";
     }
 
     public void ChangeBtnClickNormal()
@@ -225,7 +252,9 @@
 
         if (EndlessGameUI.instance.tdBuyDisable)
         {
-            EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.SetTowerGridOpenRed);
+            cashText.color = new Color(218f / 255f, 32f / 255f, 32f / 255f);
+            DOTween.To(() => cashText.color, (Color v) => cashText.color = v, cashText.color, 0.2f)
+                .OnComplete(CheckCurrencyEnough);
             return;
         }
 
@@ -239,43 +268,102 @@
         RandomPlaceTower(newTower, -1, -1, -1, -1, true);
 
         btnPS?.Play();
+        //重置倒计时
 
-        // if (newTower.towerFeature == EFeatureTower.NULL)
-        // {
-        //     string tmpTowerName = newTower.towerName;
-        //     towerNameLis.Add(tmpTowerName);
-        //     int count = 0;
-        //     bool isFirstBuy = true;
-        //     for (int i = 0; i < towerNameLis.Count; i++)
-        //     {
-        //         if (towerNameLis[i] == tmpTowerName)
-        //         {
-        //             count++;
-        //             if (count == 2)
-        //             {
-        //                 isFirstBuy = false;
-        //                 break;
-        //             }
-        //         }
-        //     }
+        if (!isCountStartDown)
+        {
+            needClickPS.Stop();
+            isCountStartDown = true;
+        }
 
-        //     if (isFirstBuy)
-        //     {
-        //         //Debug.Log("首次购买:" + tmpTowerName);
+        countDownTime = 0f;
+    }
 
-        //     }
-        //     else
-        //     {
-        //         //Debug.Log("购买了多次了:" + tmpTowerName);
-        //     }
-        //     RandomPlaceTower(newTower, -1, -1, -1, -1, isFirstBuy);
 
-        // }
-        // else
-        // {
-        //     RandomPlaceTower(newTower, -1, -1, -1, -1, false);
-        // }
+    private bool isCountStartDown = false;//是否开始倒计时
+    public void SetCountDown(bool isOn, bool isReset = false)
+    {
+        isCountStartDown = isOn;
+        if (isReset)
+        {
+            countDownTime = 0;
+            if (needClickPS.isPlaying)
+                needClickPS.Stop();
+        }
+    }
 
+    public void SetPS(bool isOn)
+    {
+        if (needClickPS.gameObject.activeSelf != isOn)
+        {
+            needClickPS.gameObject.SetActive(isOn);
+        }
+
+    }
+    float countDownTime = 0f;
+    float countDownLimit = 5f;
+    public ParticleSystem needClickPS;//提示点击按钮
+    /// <summary>
+    /// This function is called every fixed framerate frame, if the MonoBehaviour is enabled.
+    /// </summary>
+    void FixedUpdate()
+    {
+        if (isCountStartDown)
+        {
+            countDownTime += Time.deltaTime;
+            if (countDownTime > countDownLimit)
+            {
+
+                CheckTower();
+                countDownTime = 0;
+            }
+        }
+    }
+
+    /// <summary>
+    /// 查看是否满足播放按钮提示
+    /// </summary>
+    private void CheckTower()
+    {
+        Debug.Log("判断是否提示");
+
+        //条件 金币是否满足,合成区是否有位置
+        int result;
+        int.TryParse(cashText.text.ToString(), out result);
+        int current = EndlessLevelManager.instance.Currency.currentCurrency;
+        int num = EndlessGameUI.instance.GetTowerNum();
+
+        if (current >= result && num < 10)//自己的钱多
+        {
+            //Debug.Log($"当前金币 :{current}  下一次购买需要金币:{result}  塔的数量:{num}");
+            isCountStartDown = false;
+            needClickPS.Play();
+        }
+    }
+
+    public void CheckMoney()
+    {
+        int result;
+        int.TryParse(cashText.text.ToString(), out result);
+        int current = EndlessLevelManager.instance.Currency.currentCurrency;
+        if (current < result && needClickPS.isPlaying)//自己的钱多
+        {
+            needClickPS.Stop();
+            isCountStartDown = true;
+            countDownTime = 0;
+        }
+    }
+
+    private void CheckCurrencyEnough()
+    {
+        int result;
+        int.TryParse(cashText.text.ToString(), out result);
+        int current = EndlessLevelManager.instance.Currency.currentCurrency;
+
+        if (current >= result)
+            EndlessGameUI.instance.enableRandomTowerBtn();
+        else
+            EndlessGameUI.instance.disableRandomTowerBtn();
     }
 
     private List<string> towerNameLis = new List<string>();//用来判断是否是首次购买宝石
@@ -291,15 +379,9 @@
         if (gameUI.isBuilding)
             gameUI.CancelGhostPlacement();
 
-        if (EndlessUIStart.instance.GameStartTime >= JsonDataCenter.DOUBLE_GEM_TIME)
+        if (level == -1)
         {
-            if (level == -1)
-                level = Mathf.Min(EndlessGameUI.instance.MinLevel, 1);
-        }
-        else
-        {
-            if (level == -1)
-                level = 0;
+            level = GameConfig.IsUpgradeTowerLevel ? 1 : 0;
         }
 
         return gameUI.RandomPlaceTower(tower, posx, posy, level, cost, false, isFirstAppear);

--
Gitblit v1.9.1