From 63eba1a8a153a39724b86e60a66090a225251291 Mon Sep 17 00:00:00 2001
From: Client_PangDeRong <593317293@qq.com>
Date: 星期五, 12 十月 2018 15:22:57 +0800
Subject: [PATCH] 4074  【前端】限时抢购开发

---
 System/OpenServerActivity/FlashRushToBuyCoolDown.cs |  118 ++++++++++++++++++++++++++--------------------------------
 1 files changed, 53 insertions(+), 65 deletions(-)

diff --git a/System/OpenServerActivity/FlashRushToBuyCoolDown.cs b/System/OpenServerActivity/FlashRushToBuyCoolDown.cs
index 9e3b1d9..29ba8ff 100644
--- a/System/OpenServerActivity/FlashRushToBuyCoolDown.cs
+++ b/System/OpenServerActivity/FlashRushToBuyCoolDown.cs
@@ -8,88 +8,76 @@
 {
     public class FlashRushToBuyCoolDown : MonoBehaviour
     {
-        [SerializeField] TimerBehaviour m_Time;
-        [SerializeField] RectTransform m_ContainerAdvance;
-        [SerializeField] Text m_AdvanceTime;
+        [SerializeField] Text timeText;
+        FlashRushToBuyModel rushToBuyModel { get { return ModelCenter.Instance.GetModel<FlashRushToBuyModel>(); } }
+        bool isReplace = false;
+        bool isStartReplace = false;
+        private void Awake()
+        {
+            GlobalTimeEvent.Instance.halfMinuteEvent += UpdateHalfMinute;
+        }
 
         private void OnEnable()
         {
             SecondEvent();
             GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
             GlobalTimeEvent.Instance.secondEvent += SecondEvent;
-            OperationTimeHepler.Instance.dayResetEvent -= DayResetEvent;
-            OperationTimeHepler.Instance.dayResetEvent += DayResetEvent;
-        }
-
-        private void DayResetEvent(int resetType)
-        {
-            SecondEvent();
-        }
-
-        private void SecondEvent()
-        {
-            OperationBase operationBase;
-            if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.FlashRushToBuy, out operationBase))
-            {
-                var operation = (operationBase as OperationFlashRushToBuy);
-                bool inAdvance = false;
-                var seconds = 0;
-                if (operation.InAdvanceTime(TimeUtility.ServerNow))
-                {
-                    inAdvance = true;
-                    seconds = operation.GetSecondsBeforeStart(TimeUtility.ServerNow);
-                }
-                else
-                {
-                    seconds = operation.GetResetSurplusTime();
-                }
-
-                m_ContainerAdvance.gameObject.SetActive(inAdvance);
-                if (inAdvance)
-                {
-                    if (m_Time.gameObject.activeSelf)
-                    {
-                        DisplayTime(0);
-                    }
-                    DisplayAdvance(seconds);
-                }
-                else
-                {
-                    if (seconds * TimeSpan.TicksPerSecond >= TimeSpan.TicksPerDay || seconds <= 0)
-                    {
-                        if (m_Time.gameObject.activeSelf)
-                        {
-                            DisplayTime(0);
-                        }
-                    }
-                    else
-                    {
-                        m_Time.timeShow.color = seconds > 3600 ? UIHelper.GetUIColor(TextColType.Green) : UIHelper.GetUIColor(TextColType.Red);
-                        if (!m_Time.gameObject.activeSelf)
-                        {
-                            DisplayTime(seconds);
-                        }
-                    }
-                }
-            }
         }
 
         private void OnDisable()
         {
             GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
-            OperationTimeHepler.Instance.dayResetEvent -= DayResetEvent;
-            m_Time.gameObject.SetActive(false);
         }
 
-        void DisplayTime(int seconds)
+        private void UpdateHalfMinute()
         {
-            m_Time.timeShow.color = seconds > 3600 ? UIHelper.GetUIColor(TextColType.Green) : UIHelper.GetUIColor(TextColType.Red);
-            m_Time.Begin(seconds);
+            if (!isStartReplace) return;
+
+            isReplace = !isReplace;
         }
 
-        void DisplayAdvance(int seconds)
+        private void SecondEvent()
         {
-            m_AdvanceTime.text = Language.Get("OperationAdvanceOpen", TimeUtility.SecondsToHMS(seconds));
+            DisplayTime();
+        }
+
+        void DisplayTime()
+        {
+            var operation = rushToBuyModel.GetOperationFlashRushToBuy();
+            if (operation == null) return;
+            int seconds = 0;
+            OperationTime operationTime;
+            FlashRushToBuyModel.FlashRushToBuySate flashState = rushToBuyModel.GetActivityState(out seconds,out operationTime);
+            isStartReplace = false;
+            switch (flashState)
+            {
+                case FlashRushToBuyModel.FlashRushToBuySate.NoOpen:
+                    break;
+                case FlashRushToBuyModel.FlashRushToBuySate.InAdvance:
+                    if(seconds <= 3600)
+                    {
+                        isStartReplace = true;
+                        if(!isReplace)
+                        {
+                            timeText.text = TimeUtility.SecondsToHMS(seconds);
+                        }
+                        else
+                        {
+                            timeText.text = operation.ToDisplayBuyTime(operationTime.startHour, operationTime.startMinute);
+                        }
+                    }
+                    else
+                    {
+                        timeText.text = operation.ToDisplayBuyTime(operationTime.startHour, operationTime.startMinute);
+                    }
+                    break;
+                case FlashRushToBuyModel.FlashRushToBuySate.Begining:
+                    timeText.text = "绉掓潃涓�";
+                    break;
+                case FlashRushToBuyModel.FlashRushToBuySate.End:
+                    timeText.text = "娲诲姩宸茬粨鏉�";
+                    break;
+            }
         }
     }
 }

--
Gitblit v1.8.0