123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- using System;
- using System.Collections.Generic;
- using ET;
- using FairyGUI;
- using UI.CommonGame;
- using UI.TimeTracing;
- using UnityEngine;
- namespace GFGGame
- {
- public class TimeTracingSwitchView : BaseWindow
- {
- private UI_TimeTracingSwitchUI _ui;
- private List<int> suitIdList = new List<int>() { 201030, 201010, 202006, 0};
- private List<int> chapterIdList = new List<int>() { 61001,62002,62003 ,0};
- private List<string> NumStringList = new List<string>() {"", "一", "二", "三", "四", "五" };
- public override void Dispose()
- {
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_TimeTracingSwitchUI.PACKAGE_NAME;
- _ui = UI_TimeTracingSwitchUI.Create();
- this.viewCom = _ui.target;
- isfullScreen = true;
- modal = true;
- _ui.m_btnBack.onClick.Add(OnClickBtnBack);
- _ui.m_List.itemRenderer = RenderListItem;
- _ui.m_List.scrollPane.onScroll.Add(DoSpecialEffect);//滚动时派发事件
- }
- protected override void OnShown()
- {
- base.OnShown();
- UpdateList();
- _ui.m_List.numItems = suitIdList.Count + 2;
- for(int i = 0;i< suitIdList.Count;i++)
- {
- if(TimeTracingDataManager.SuitID == suitIdList[i])
- {
- _ui.m_List.ScrollToView(i, true, true);
- break;
- }
- }
- DoSpecialEffect();
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- private void RenderListItem(int index, GObject obj)
- {
- UI_TimeTracingSwitchItem listItem = UI_TimeTracingSwitchItem.Proxy(obj);
- int isLock = 1;
- if (index == 0 || index == _ui.m_List.numItems - 1)
- {
- listItem.target.visible = false;
- UI_TimeTracingSwitchItem.ProxyEnd();
- return;
- }
- if (index != _ui.m_List.numItems - 2)
- {
- listItem.m_TimeTracingSwitchItm.m_periodsNumText.text = "第" + NumStringList[index] + "期";
- listItem.m_TimeTracingSwitchItm.m_periodsNameText.text = "";
- listItem.m_TimeTracingSwitchItm.m_suitIcon.icon = string.Format("ui://TimeTracing/select{0}",index);
- listItem.m_TimeTracingSwitchItm.m_waitText.visible = false;
- }
- else
- {
- listItem.m_TimeTracingSwitchItm.m_periodsNumText.visible = false;
- listItem.m_TimeTracingSwitchItm.m_periodsNameText.visible = false;
- listItem.m_TimeTracingSwitchItm.m_suitIcon.icon = "";
- listItem.m_TimeTracingSwitchItm.m_waitText.visible = true;
- }
- if (index > 1 && index < _ui.m_List.numItems - 2)
- {
- int count;
- int totalCount;
- DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitIdList[index - 2], out count, out totalCount);
- if (count >= totalCount)
- {
- isLock = 1;
- }
- else
- {
- isLock = 0;
- }
- }
- if (listItem.target.data == null)
- {
- listItem.target.onClick.Add(OnClickListChapterItem);
- }
- RedDotController.Instance.SetComRedDot(listItem.target, TimeTracingDataManager.Instance.GetChapterIDRewardStatus(chapterIdList[index - 1]));
- listItem.target.data = new List<int>() { index, suitIdList[index - 1], chapterIdList[index - 1], isLock };
- UI_TimeTracingSwitchItem.ProxyEnd();
- }
- private void OnClickListChapterItem(EventContext context)
- {
- GObject chapterItem = context.sender as GObject;
- List<int> chapterID = (List<int>)chapterItem.data;
- StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterID[1]);
- //这里变成-1,是因为调整了item,最左右两边现在有item但是是透明没数据的
- int index = chapterID[0];
- int firstChildIndex = _ui.m_List.GetFirstChildInView();
- if (firstChildIndex + 1 != index)
- {
- _ui.m_List.ScrollToView(index - 1, true, true);
- }
- else
- {
- //if (chapterID[3] == 1)
- {
- if(chapterID[0] == _ui.m_List.numItems - 2 || chapterID[1] == 0)
- {
- return;
- }
- TimeTracingDataManager.SuitID = chapterID[1];
- TimeTracingDataManager._currentChapterId = chapterID[2];
- EventAgent.DispatchEvent(ConstMessage.TIMETRACINGUPDATE);
- this.Hide();
- }
- //else
- //{
- // PromptController.Instance.ShowFloatTextPrompt("需集齐前置套装");
- // return;
- //}
- }
- }
- private void OnClickBtnBack()
- {
- ViewManager.GoBackFrom(typeof(TimeTracingSwitchView).FullName);
- }
- private void UpdateList()
- {
- chapterIdList.Clear();
- suitIdList.Clear();
- for (int i = 0;i<TimeTracingDataManager.Instance.IdList.Count;i++)
- {
- ActivityOpenCfg activityDate = ActivityOpenCfgArray.Instance.GetCfg(TimeTracingDataManager.Instance.IdList[i]);
- chapterIdList.Add(activityDate.params3Arr[0]);
- ActivityFightCfg storydate = ActivityFightCfgArray.Instance.GetCfg(chapterIdList[i]);
- if(storydate.activitySuitIdArr == null || storydate.activitySuitIdArr.Length == 0)
- {
- suitIdList.Add(0);
- }
- else
- {
- suitIdList.Add(storydate.activitySuitIdArr[0]);
- }
- }
- chapterIdList.Add(0);
- suitIdList.Add(0);
- }
- private void DoSpecialEffect(object parm = null)
- {
- //scrollPane.scrollingPosX这个实时变化,。scrollPane.posX这个使用ScrlootoVIew直接取终值
- float listCenter = _ui.m_List.scrollPane.scrollingPosX + _ui.m_List.viewWidth / 2;
- float listLeft = _ui.m_List.scrollPane.posX + _ui.m_List.viewWidth / 2; ;
- for (int i = 0; i < _ui.m_List.numChildren; i++)
- {
- GObject item = _ui.m_List.GetChildAt(i);
- float itemCenter = item.x + item.width / 2;//循环列表内元素的中心x值
- float itemWidth = item.width;//列表元素的宽度
- float distance = Mathf.Abs(listCenter - itemCenter);
- // if (distance < item.width)
- {
- float distanceRange = 1 + (1 - distance / itemWidth) * 0.2f;//使放大动画有渐进效果
- item.SetScale(distanceRange, distanceRange);//设置放大比例
- ////设置颜色变化
- //if (distance < item.width / 2)
- //{
- // UI_TimeTracingSwitchItem listItem = UI_TimeTracingSwitchItem.Proxy(_ui.m_List.GetChildAt(i));
- // listItem.m_content.m_compPic.m_pic.color = new Color(1.0f, 1.0f, 1.0f, 1.000f);
- //}
- //else
- //{
- // UI_TimeTracingSwitchItem listItem = UI_TimeTracingSwitchItem.Proxy(_ui.m_List.GetChildAt(i));
- // listItem.m_content.m_compPic.m_pic.color = new Color(0.4f, 0.4f, 0.4f, 1.000f);
- //}
- }
- //float distanceX = ((1 - (listCenter - itemCenter)) / itemWidth) * 0.05f;//使y轴移动有渐进效果
- //item.y = -_ui.m_List.height * distanceX;
- }
- }
- }
- }
|