123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- using FairyGUI;
- using UI.FieldGuide;
- using System.Collections.Generic;
- using System;
- using System.Collections;
- using UnityEngine;
- namespace GFGGame
- {
- public class FieldGuideView : BaseWindow
- {
- private delegate bool GetRedCall();
- private UI_FieldGuideUI _ui;
- private int[] _listGuideDatas = new int[5] { ConstFieldGuideId.SUIT_GUIDE, ConstFieldGuideId.CHAPTER_ITEM, ConstFieldGuideId.DRESS_UP_GUIDE, ConstFieldGuideId.CARD_GUIDE, ConstFieldGuideId.TRAVEL_GUIDE };
- GetRedCall[] actions = new GetRedCall[] { RedDotDataManager.Instance.GetFieldGuideRed, null, null, null, RedDotDataManager.Instance.GetTravelGuideRed };
- private bool _startInAnim;
- public override void Dispose()
- {
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_FieldGuideUI.PACKAGE_NAME;
- _ui = UI_FieldGuideUI.Create();
- this.viewCom = _ui.target;
- isfullScreen = true;
- isReturnView = true;
- _startInAnim = true;
- _ui.m_listGuide.itemRenderer = ListGuideItemRenderer;
- _ui.m_btnBack.onClick.Add(OnClickBtnBack);
- _ui.m_listGuide.onClickItem.Add(OnClickListGuideItem);
- }
- protected override void AddEventListener()
- {
- EventAgent.AddEventListener(ConstMessage.SUIT_GUIDE_BOX_BONUS, UpdateList);
- EventAgent.AddEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
- }
- protected override void OnShown()
- {
- base.OnShown();
- _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjbg");
- _ui.m_listGuide.numItems = _listGuideDatas.Length;
- if (_startInAnim)
- {
- _ui.m_listGuide.scrollPane.ScrollTop();
- _ui.m_In.Play();
- }
- Timers.inst.StartCoroutine(UpdateProgress());
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- EventAgent.RemoveEventListener(ConstMessage.SUIT_GUIDE_BOX_BONUS, UpdateList);
- EventAgent.RemoveEventListener(ConstMessage.JUMP_TO_SOURCE, this.Hide);
- }
- private void OnClickBtnBack()
- {
- _startInAnim = true;
- ViewManager.GoBackFrom(typeof(FieldGuideView).FullName);
- HideAllRedDot();
- }
- private void UpdateList()
- {
- _ui.m_listGuide.numItems = _listGuideDatas.Length;
- UpdateRedDot();
- }
- private void UpdateRedDot()
- {
- int num = _ui.m_listGuide.numChildren;
- for (int i = 0; i < num; i++)
- {
- UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
- bool red = actions[i] == null ? false : actions[i]();
- RedDotController.Instance.SetComRedDot(listItem.target, red, "", -46, 51);
- UI_CompGuideItem.ProxyEnd();
- }
- }
- private void HideAllRedDot()
- {
- int num = _ui.m_listGuide.numChildren;
- for (int i = 0; i < num; i++)
- {
- RedDotController.Instance.SetComRedDot(_ui.m_listGuide.GetChildAt(i).asCom, false);
- }
- }
- private void ListGuideItemRenderer(int index, GObject item)
- {
- UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(item);
- int id = _listGuideDatas[index];
- listItem.m_loaderPic.url = "ui://FieldGuide/tujian_tup_" + id;
- listItem.target.data = id;
- if(id == ConstFieldGuideId.CARD_GUIDE)
- {
- bool open = FunctionOpenDataManager.Instance.CheckIsFunOpenById(typeof(CardDetailView).Name, false);
- listItem.m_lock.visible = !open;
- listItem.m_progressGroup.visible = open;
- }
- if (_startInAnim)
- {
- listItem.m_Init.Play();
- }
- UI_CompGuideItem.ProxyEnd();
- }
- private void OnClickListGuideItem(EventContext context)
- {
- GObject listItem = context.data as GObject;
- int id = (int)listItem.data;
- switch (id)
- {
- case ConstFieldGuideId.SUIT_GUIDE:
- ViewManager.Show<SuitGuideView>();
- break;
- case ConstFieldGuideId.CHAPTER_ITEM:
- ViewManager.Show<ChapterItemGuideView>();
- break;
- case ConstFieldGuideId.TRAVEL_GUIDE:
- ViewManager.Show<TravelGuideView>();
- ViewManager.Show<TravelGuideView>();
- break;
- case ConstFieldGuideId.DRESS_UP_GUIDE:
- ViewManager.Show<DressUpGuideView>();
- break;
- case ConstFieldGuideId.CARD_GUIDE:
- bool open = FunctionOpenDataManager.Instance.CheckIsFunOpenById(typeof(CardDetailView).Name, false);
- if (open)
- {
- ViewManager.Show<CardGuideView>();
- }
- else
- {
- PromptController.Instance.ShowFloatTextPrompt("此功能未开启~");
- }
- break;
- }
- }
- private void GetGuideProgress(int id, out int haveCount, out int totalCount)
- {
- switch (id)
- {
- case ConstFieldGuideId.SUIT_GUIDE:
- DressUpMenuSuitDataManager.GetTotalProgress(out haveCount, out totalCount);
- break;
- case ConstFieldGuideId.CHAPTER_ITEM:
- InstanceZonesDataManager.GetTotalProgress(out haveCount, out totalCount);
- break;
- case ConstFieldGuideId.TRAVEL_GUIDE:
- TravelDataManager.Instance.GetTotalTravelProgress(out haveCount, out totalCount);
- break;
- case ConstFieldGuideId.CARD_GUIDE:
- CardDataManager.GetTotalProgress(out haveCount, out totalCount);
- break;
- case ConstFieldGuideId.DRESS_UP_GUIDE:
- DressUpMenuItemDataManager.GetTotalProgress(out haveCount, out totalCount);
- break;
- default:
- haveCount = 0;
- totalCount = 1;
- break;
- }
- if (totalCount == 0) totalCount = 1;
- }
- private IEnumerator UpdateProgress()
- {
- int num = _ui.m_listGuide.numChildren;
- bool playAnim = _startInAnim;
- _startInAnim = false;
- for (int i = 0; i < num; i++)
- {
- UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
- int id = (int)listItem.target.data;
- GetGuideProgress(id, out int haveCount, out int totalCount);
- decimal value = ProgressCalculate(haveCount, totalCount);
- listItem.m_txtProgress.text = value.ToString();
- if (playAnim)
- {
- Action complete = null;
- if (i == num - 1)
- {
- complete = UpdateRedDot;
- }
- if(i > 0)
- {
- yield return new WaitForSeconds(0.07f);
- }
- listItem.m_In.Play(() =>
- {
- complete?.Invoke();
- });
- }
- UI_CompGuideItem.ProxyEnd();
- }
- if (!playAnim)
- {
- UpdateRedDot();
- }
- }
- public static int ProgressCalculate(int haveCount, int totalCount)
- {
- if(haveCount > totalCount)
- {
- haveCount = totalCount;
- }
- float rate = haveCount * 100.0f / totalCount;
- int result;
- if (rate > 0 && rate <= 1)
- {
- result = 1;
- }
- else if (rate >= 99 && rate < 100)
- {
- result = 99;
- }
- else
- {
- result = (int)Math.Round(rate);
- }
- return result;
- }
- }
- }
|