using FairyGUI; using UI.FieldGuide; using System.Collections.Generic; using System; 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[1] { ConstFieldGuideId.SUIT_GUIDE }; GetRedCall[] actions = new GetRedCall[] { RedDotDataManager.Instance.GetFieldGuideRed }; public override void Dispose() { 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_compBanner.m_listTab.itemRenderer = ListBannerItemRenderer; _ui.m_compBanner.m_listTab.numItems = _listBannerDatas.Length; _ui.m_listGuide.itemRenderer = ListGuideItemRenderer; _ui.m_listGuide.numItems = _listGuideDatas.Length; _ui.m_btnBack.onClick.Add(OnClickBtnBack); _ui.m_listGuide.onClickItem.Add(OnClickListGuideItem); _ui.m_compBanner.m_listTab.onClickItem.Add(OnClickListBannerItem); _ui.m_compBanner.m_loaderPic.onClick.Add(OnClickBannerPic); EventAgent.AddEventListener(ConstMessage.SUIT_GUIDE_BOX_BONUS, () => { _ui.m_listGuide.numItems = _listGuideDatas.Length; }); } protected override void OnShown() { base.OnShown(); _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("fuben_bjbj"); _ui.m_listGuide.numItems = _listGuideDatas.Length; UpdatePrgress(); _ui.m_compBanner.m_listTab.selectedIndex = 0; UpdateBanner(_ui.m_compBanner.m_listTab.GetChildAt(_ui.m_compBanner.m_listTab.selectedIndex)); Timers.inst.Add(3, 0, SwitchBannerPic); } protected override void OnHide() { base.OnHide(); Timers.inst.Remove(SwitchBannerPic); } private void OnClickBtnBack() { // this.Hide(); ViewManager.GoBackFrom(ViewName.FIELD_GUIDE_VIEW); } private void ListBannerItemRenderer(int index, GObject item) { UI_ButtonBannerPage listItem = UI_ButtonBannerPage.Proxy(item); int id = _listBannerDatas[index]; listItem.target.data = id; } private void OnClickBannerPic() { int id = _listBannerDatas[_ui.m_compBanner.m_listTab.selectedIndex]; switch (id) { case ConstBannerId.ZHAI_XING: ViewManager.Show(ViewName.LUCKY_BOX_VIEW); break; } } private void ListGuideItemRenderer(int index, GObject item) { UI_CompGuideItem listItem = UI_CompGuideItem.Proxy(item); int id = _listGuideDatas[index]; listItem.m_loaderTitle.url = "ui://FieldGuide/tujian_taoz_" + id; listItem.m_loaderPic.url = "ui://FieldGuide/tujian_tup_" + id; listItem.target.data = id; bool red = actions[index](); RedDotController.Instance.SetComRedDot(listItem.target, red, "", 10); } private void OnClickListBannerItem(EventContext context) { UpdateBanner(context.data as GObject); } private void OnClickListGuideItem(EventContext context) { GObject listItem = context.data as GObject; int id = (int)listItem.data; switch (id) { case ConstFieldGuideId.SUIT_GUIDE: ViewManager.Show(ViewName.SUIT_GUIDE_VIEW, 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; default: haveCount = 0; totalCount = 1; break; } } private void 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 = Math.Floor((decimal)100 * haveCount / totalCount); listItem.m_txtProgress.text = value + "%"; } } private void UpdateBanner(GObject listItem) { string resName = "tujian_huodtu_1"; int id = (int)listItem.data; switch (id) { case ConstBannerId.ZHAI_XING: resName = "tujian_huodtu_1"; break; } _ui.m_compBanner.m_loaderPic.url = "ui://FieldGuide/" + resName; UpdateListBannerItems(); } private void UpdateListBannerItems() { int num = _ui.m_compBanner.m_listTab.numChildren; // for (int i = 0; i < num; i++) // { // UI_ButtonBannerPage listItem = UI_ButtonBannerPage.Proxy(_ui.m_compBanner.m_listTab.GetChildAt(i)); // if (listItem.target.selected) // { // listItem.target.width = 47; // } // else // { // listItem.target.width = 15; // } // } // _ui.m_compBanner.m_listTab.ResizeToFit(); } private void SwitchBannerPic(object param) { int index = _ui.m_compBanner.m_listTab.selectedIndex; index++; if (index >= _listBannerDatas.Length) { index = 0; } _ui.m_compBanner.m_listTab.selectedIndex = index; UpdateBanner(_ui.m_compBanner.m_listTab.GetChildAt(_ui.m_compBanner.m_listTab.selectedIndex)); } } }