using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using GCGame.Table; using System; using Module.Log; using Games.Events; // 日常副本进度面板 public class DailyCopyInfoCtr : MonoBehaviour { private static DailyCopyInfoCtr instance; public static DailyCopyInfoCtr Instance { get { return instance; } } private int copyID; public int CopyID { private set { copyID = value; } get { return copyID; } } public Text copyName; public GameObject countDownGO; public Text countDownTitle; public Text countDown; public GameObject tipGO; public Text tip; // 限时 public GameObject progress_LimitGO; public Text progerss_LimitTitle; public UIImgText progress_Limit; // 非限时 public GameObject progress_UnlimitGO; public Text progress_UnlimitTitle; public Text progress_Unlimit; // 评分面板 public GameObject ScorePanel; public Image scoreImage; public Text reduceTime; public Text reduceDesc; public Button exitBtn; public GameObject useItemGO; // 使用物品节点 public Button useItemBtn; // 经验副本使用经验丹按钮 public GameObject[] starGOs; // 星级数组 public string sceneAnimGOName; // 挂在场景动画物体名称 private bool hasConfirm = false; // 是否已经确认离开 private Coroutine copyCountDown; private Coroutine reduceCountDown; private int curStar = 0; private long beginTicks = (new DateTime(1970, 1, 1, 8, 0, 0)).Ticks; private bool needBossKillDesc = false; private int killBossCound = 0; private DailyCopySceneAnimCtr sceneAnim; private bool hasStopAnim = false; private void Awake() { if (instance == null) { instance = this; exitBtn.onClick.AddListener(OnExitBtnClick); animBtn.onClick.AddListener(OnAnimBtnClick); } useItemBtn.onClick.AddListener(OnShowUseItemPanelBtnClick); Hashtable param = new Hashtable(); param["name"] = "DailyCopy"; Games.Events.MessageEventCallBack cb = OnBossKill; param["callFun"] = cb; EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.CopyRightFresh, param); } private void OnBossKill(Hashtable addparam, Hashtable Sendparam) { GC_NOTIFY_COPY_MONSTER_INFO pack = Sendparam["packet"] as GC_NOTIFY_COPY_MONSTER_INFO; killBossCound = pack.BossKilledCount; if (needBossKillDesc == true) { if (pack != null) { Tab_DailyCopy tab = TableManager.GetDailyCopyByID(CopyID); if (tab != null) { SetText(progress_UnlimitTitle, StrDictionary.GetClientDictionaryString("#{51911}")); string desc = string.Format(tab.TargetDesc, pack.BossKilledCount); SetText(progress_Unlimit, desc); } } } } public void OnEnable() { OnAnimBtnClick(); // 初始化标题 hasConfirm = false; // 是否已经确认离开 if (PlayerFrameLogic.Instance() != null) { PlayerFrameLogic.Instance().L_ExperienceDoubleBuff(); } } private void OnDestroy() { instance = null; EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.CopyRightFresh, "DailyCopy"); } private IEnumerator ShowResultPanelAndExit() { //ReqDailyCopyFinish req = new ReqDailyCopyFinish(); //start yield return null; } private void OnExitBtnClick() { string exitTip = ""; Tab_DailyCopy tab = TableManager.GetDailyCopyByID(CopyID); if (tab == null) { if (Singleton.Instance.MainPlayer != null) { Singleton.Instance.MainPlayer.AskLeaveCopy(); } LogModule.ErrorLog("Can't confirm current copy scene type (Time limit / Time unlimt)"); return; } else if (tab.IsLimitedTime == 1) { exitTip = StrDictionary.GetClientDictionaryString("#{51908}"); } else { exitTip = StrDictionary.GetClientDictionaryString("#{51909}"); } if (tab.IsLimitedTime == 1) { if (hasConfirm == false) { MessageBoxLogic.OpenAutoCancelBox(exitTip, null, 5.0f, () => { ReqDailyCopyFinish req = new ReqDailyCopyFinish(); req.copyid = copyID; hasConfirm = true; req.SendMsg(); }); } else { ReqDailyCopyFinish req = new ReqDailyCopyFinish(); req.copyid = copyID; hasConfirm = true; req.SendMsg(); } } else { if (hasConfirm == false) { MessageBoxLogic.OpenOKCancelBox(exitTip, null, () => { CG_LEAVE_COPYSCENE send = (CG_LEAVE_COPYSCENE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_LEAVE_COPYSCENE); send.NoParam = 1; hasConfirm = true; send.SendPacket(); }); } else { CG_LEAVE_COPYSCENE send = (CG_LEAVE_COPYSCENE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_LEAVE_COPYSCENE); send.NoParam = 1; send.SendPacket(); } } } private void ShowCountDownTime(long endTick, ref Coroutine c, Action cb) { if (c != null) { StopCoroutine(c); } if (endTick > 0) { long remainSecond = endTick - GlobalData.ServerAnsiTime; if (remainSecond < 0) { remainSecond = 0; } c = StartCoroutine(CountTime((int)remainSecond, cb)); } else { c = StartCoroutine(CountTime(0, cb)); } } private IEnumerator CountTime(int remainSecond, Action cb) { countDown.gameObject.SetActive(true); float j = 0.0f; cb(remainSecond); for (; remainSecond >= 0; --remainSecond) { cb(remainSecond); for (; j < 1.0f; j += Time.deltaTime) { yield return 0; } j -= 1.0f; } } // 限时 public void Show(SyncTimeLimitedCopyInfo packet) { CopyID = packet.copyid; needBossKillDesc = false; progress_LimitGO.SetActive(true); progress_UnlimitGO.SetActive(false); ScorePanel.SetActive(false); ShowCountDownTime(packet.endTick, ref copyCountDown, OnCountDown); var tab = TableManager.GetDailyCopyByID(packet.copyid); if (tab != null) { SetText(copyName, tab.SceneName); } // 经验 if (packet.awardType == 1) { //useItemGO.SetActive(false); if (useItemGO.activeSelf == false) { useItemGO.SetActive(true); } SetText(progerss_LimitTitle, StrDictionary.GetClientDictionaryString("#{51912}")); progress_Limit.text = packet.awardNum.ToString(); if (hasStopAnim == false) { PlaySceneAnim(); } } // 银票 else if (packet.awardType == 2) { useItemGO.SetActive(false); SetText(progerss_LimitTitle, StrDictionary.GetClientDictionaryString("#{51913}")); progress_Limit.text = packet.awardNum.ToString(); } else { useItemGO.SetActive(false); progress_Limit.gameObject.SetActive(false); } var tempTab = TableManager.GetDailyCopyByID(packet.copyid); // Tip SetText(tip, tempTab.InfoPanelTip); //L_ShowUseItemPanel(); } // 非限时 public void Show(SyncTimeUnlimitedCopyInfo packet) { CopyID = packet.copyid; needBossKillDesc = true; progress_UnlimitGO.SetActive(true); progress_LimitGO.SetActive(false); ScorePanel.SetActive(true); useItemGO.SetActive(false); ShowCountDownTime(packet.endTick, ref copyCountDown, OnCountDown); var tab = TableManager.GetDailyCopyByID(packet.copyid); if (tab != null) { SetText(copyName, tab.SceneName); } // Tip SetText(tip, tab.InfoPanelTip); SetText(progress_UnlimitTitle, StrDictionary.GetClientDictionaryString("#{51911}")); string desc = string.Format(tab.TargetDesc, killBossCound); SetText(progress_Unlimit, desc); curStar = packet.curStar; reduceTime.gameObject.SetActive(true); ShowCountDownTime(packet.reduceStarTick, ref reduceCountDown, OnReduceCountDown); ScorePanel.SetActive(true); int cur = packet.curStar - 1; for (int i = 0; i < starGOs.Length; ++i) { starGOs[i].SetActive(i == cur); } } private void PlaySceneAnim() { if (sceneAnim == null) { var go = GameObject.Find(sceneAnimGOName); if (go != null) { sceneAnim = go.GetComponent(); } } if (sceneAnim != null) { sceneAnim.MoveNext(); } else { LogModule.ErrorLog("Can't get sceneAnim"); } } public void StopSceneAnim() { hasStopAnim = true; if (sceneAnim != null) { sceneAnim.StopMoveNext(); } } private void OnCountDown(int remainSecond) { string mStr = ""; string sStr = ""; int m = (remainSecond / 60); int s = (remainSecond % 60); if (m > 0) { mStr = StrDictionary.GetClientDictionaryString("#{51906}", m.ToString()); } if (s >= 0) { sStr = StrDictionary.GetClientDictionaryString("#{51918}", s.ToString()); } SetText(countDown, mStr + sStr); } private void OnReduceCountDown(int remainSecond) { string mStr = ""; string sStr = ""; int m = (remainSecond / 60); int s = (remainSecond % 60); if (m > 0) { mStr = StrDictionary.GetClientDictionaryString("#{51906}", m.ToString()); } if (s >= 0) { sStr = StrDictionary.GetClientDictionaryString("#{51918}", s.ToString()); } SetText(reduceTime, mStr + sStr); if (curStar == 1) { reduceTime.gameObject.SetActive(false); SetText(reduceDesc, StrDictionary.GetClientDictionaryString("#{51907}")); } else { reduceTime.gameObject.SetActive(true); SetText(reduceDesc, StrDictionary.GetClientDictionaryString("#{51915}", curStar - 1)); } } private void SetText(Text text, string info) { string resultString = info.Replace("#r", "\n"); if (text.text != resultString) { text.text = resultString; } text.gameObject.SetActive(true); } private void OnShowUseItemPanelBtnClick() { DailyCopyInfoItemsPanelCtr.Show(CopyID); } private void CloseOpeningWindow() { UIManager.CloseUI(UIInfo.DailyCopyInfoItemsPanel); } #region 动画相关 public Animator panelAnim; public Button animBtn; private bool isShow = false; private void OnAnimBtnClick() { isShow = !isShow; if (isShow) { panelAnim.Play("Show"); GCGame.Utils.HideMainTopRightUI(); } else { panelAnim.Play("Hide"); GCGame.Utils.ShowMainTopRightUI(); } CloseOpeningWindow(); } #endregion }