123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- 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[] _listBannerDatas = new int[3] { ConstBannerId.ZHAI_XING, ConstBannerId.ZHAI_XING, ConstBannerId.ZHAI_XING };
- 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 };
- 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;
- _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;
- _ui.m_openViewAction.Play();
- Timers.inst.StartCoroutine(UpdatePrgress());
- }
- 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()
- {
- // this.Hide();
- _ui.m_listGuide.scrollPane.ScrollTop();
- ViewManager.GoBackFrom(ViewName.FIELD_GUIDE_VIEW);
- }
- private void UpdateList()
- {
- _ui.m_listGuide.numItems = _listGuideDatas.Length;
- }
- private void ListBannerItemRenderer(int index, GObject item)
- {
- UI_ButtonBannerPage listItem = UI_ButtonBannerPage.Proxy(item);
- int id = _listBannerDatas[index];
- listItem.target.data = id;
- UI_ButtonBannerPage.ProxyEnd();
- }
- 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;
- bool red = actions[index] == null ? false : actions[index]();
- RedDotController.Instance.SetComRedDot(listItem.target, red, "", -46, 51);
- 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>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
- break;
- case ConstFieldGuideId.CHAPTER_ITEM:
- ViewManager.Show<ChapterItemGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
- break;
- case ConstFieldGuideId.TRAVEL_GUIDE:
- ViewManager.Show<TravelGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
- break;
- case ConstFieldGuideId.DRESS_UP_GUIDE:
- ViewManager.Show<DressUpGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
- break;
- case ConstFieldGuideId.CARD_GUIDE:
- ViewManager.Show<CardGuideView>(null, new object[] { ViewName.FIELD_GUIDE_VIEW, this.viewData });
- 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 UpdatePrgress()
- {
- int num = _ui.m_listGuide.numChildren;
- for (int i = 0; i < num; i++)
- {
- UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(_ui.m_listGuide.GetChildAt(i));
- int id = (int)listItem.target.data;
- int haveCount = 0;
- int totalCount = 1;
- GetGuideProgress(id, out haveCount, out totalCount);
- decimal value = ProgressCalculate(haveCount, totalCount);
- listItem.m_txtProgress.text = value.ToString();
- listItem.m_In.Play();
- UI_CompGuideItem.ProxyEnd();
- yield return new WaitForSeconds(0.02f);
- }
- }
- public static int ProgressCalculate(int haveCount, int totalCount)
- {
- float rate = haveCount * 100.0f / totalCount;
- int result = 0;
- if (rate > 0 && rate <= 1)
- {
- result = 1;
- }
- else if (rate >= 99 && rate < 100)
- {
- result = 99;
- }
- else
- {
- result = (int)Math.Round(rate);
- }
- return result;
- }
- }
- }
|