using System.Collections; using UnityEngine; using UI.ActivityHuaRongDao; using System.Collections.Generic; using FairyGUI; using System.Threading.Tasks; using ET; namespace GFGGame { public class ActivityHuaRongDaoEntryView : BaseWindow { private UI_ActivityHuaRongDaoEntryUI _ui; private int curLevel; private int _activityID; private List IDList; protected override void OnInit() { base.OnInit(); packageName = UI_ActivityHuaRongDaoEntryUI.PACKAGE_NAME; _ui = UI_ActivityHuaRongDaoEntryUI.Create(); viewCom = _ui.target; isfullScreen = true; _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gf_pjxq_bj"); _ui.m_btnStart.onClick.Add(OnBtnStartClick); _ui.m_btnBack.onClick.Add(OnBtnBackClick); _ui.m_btnClose.onClick.Add(OnBtnBackClick); InitBtnRule(); _ui.m_scrollPane.m_listBg.itemRenderer = RenderListItem; _ui.m_scrollPane.m_listItems.itemRenderer = RenderRewardListItem; //_ui.m_scrollPane.m_listBg.onClickItem.Add(OnClickReward); } public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override async void OnShown() { base.OnShown(); _ui.m_hide.Play(); _activityID = (int)viewData; InitIDList(); _ui.m_activityID.selectedPage = _activityID.ToString(); isReturnView = _ui.m_btnBack.touchable; await UpdateUIAsync(); if (!isShowing) { return; } _ui.m_show.Play(); UpdateTime(null); Timers.inst.Remove(UpdateTime); Timers.inst.Add(1, 0, UpdateTime); } protected override void OnHide() { base.OnHide(); Timers.inst.Remove(UpdateTime); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.ACTIVITY_HUARONGDAO_UPDATE, UpdateUI); EventAgent.AddEventListener(ConstMessage.RESET_DAILY_DATA, UpdateUI); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_HUARONGDAO_UPDATE, UpdateUI); EventAgent.RemoveEventListener(ConstMessage.RESET_DAILY_DATA, UpdateUI); } /// /// 初始化关卡列表 /// private void InitIDList() { IDList = new List(); string gameID = ActivityOpenCfgArray.Instance.GetCfg(_activityID).params5Arr[0]; int gameTypeID = int.Parse(gameID.Split('_')[1]); HuarongRoadGame[] cfgs = HuarongRoadGameArray.Instance.dataArray; foreach (var t in cfgs) { if(t.subType == gameTypeID) { IDList.Add(t.id); } } } private void UpdateUI() { UpdateUIAsync(); } private async Task UpdateUIAsync() { await InitInfo(); UpdateRedDots(); return true; } private async Task InitInfo() { curLevel = await GetCurLevel(_activityID); RoleLimitData limitData; _ui.m_curLevel.text = curLevel.ToString(); // 所有关卡都通关了 if (curLevel == IDList.Count) { _ui.m_challengeTimes.SetVar("have", "0").SetVar("sum", "0").FlushVars(); } else { limitData = RoleLimitDataManager.GetLimitData(HuarongRoadGameArray.Instance.GetCfg(IDList[curLevel]).comsumeLimit); int times = limitData.TotalPlayMax - limitData.PlayTimes; _ui.m_challengeTimes.SetVar("have", times.ToString()) .SetVar("sum", limitData.TotalPlayMax.ToString()).FlushVars(); } InitProgress(); ProgressAutoLocate(); } private void InitProgress() { _ui.m_scrollPane.m_listBar.numItems = curLevel; _ui.m_scrollPane.m_listBg.numItems = IDList.Count; _ui.m_scrollPane.m_listItems.numItems = IDList.Count; _ui.m_scrollPane.m_listBg.ResizeToFit(); } private void ProgressAutoLocate() { _ui.m_scrollPane.target.scrollPane.posX = curLevel * (_ui.m_scrollPane.m_listBg.GetChildAt(0).width + _ui.m_scrollPane.m_listBg.columnGap) + (curLevel > 0 ? -150 : 0); } private void RenderListItem(int index, GObject gObject) { gObject.data = index; UI_progressBgItem item = UI_progressBgItem.Proxy(gObject); item.m_levelNum.text = (index + 1).ToString(); UI_progressBgItem.ProxyEnd(); } private void RenderRewardListItem(int index, GObject gObject) { gObject.data = index; UI_reward reward = UI_reward.Proxy(gObject); int id = HuarongRoadGameArray.Instance.GetCfg(IDList[index]).bonusWinArr[0][0]; reward.m_loaIcon.url = ResPathUtil.GetIconPath(ItemCfgArray.Instance.GetCfg(id)); reward.m_c1.SetSelectedIndex(curLevel > index ? 1 : 0); reward.target.touchable = (curLevel <= index); reward.target.data = index; reward.target.onClick.Add(OnClickReward); UI_reward.ProxyEnd(); } private void OnClickReward(EventContext eventContext) { GObject obj = (GObject)eventContext.sender; int id = (int)obj.data; //ViewManager.Show(HuarongRoadGameArray.Instance.GetCfg(IDList[id]).bonusWinArr); GoodsItemTipsController.ShowItemTips(HuarongRoadGameArray.Instance.GetCfg(IDList[id]).bonusWinArr[0][0]); } private void OnBtnBackClick() { Hide(); } private void InitBtnRule() { if (_ui.m_btnRule.data == null) { _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView); _ui.m_btnRule.data = 300025; } } private async void OnBtnStartClick() { // 通关了所有 if(curLevel == IDList.Count) { PromptController.Instance.ShowFloatTextPrompt("已通关所有关卡"); return; } HuarongRoadGame cfg = HuarongRoadGameArray.Instance.GetCfg(IDList[curLevel]); var result = await MiniGameProxy.ReqMiniGameStart(cfg.id, cfg.type, _activityID); if (!result || !isShowing) return; ViewManager.Show(new object[] { cfg, _activityID }); } private async Task GetCurLevel(int id) { var result = await MiniGameProxy.ReqGetActivityGameInfos(id); if (!result) { return -1; } int i; for (i = 0; i < MiniGameDateManager.Instance.gameinfoList.Count; i++) { if (!MiniGameDateManager.Instance.gameinfoList[i].IsCleared) { return i; } } return i; } private void UpdateTime(object param) { long curTime = ActivityDataManager.Instance.GetActivityTime(_activityID); if (curTime > 0) { _ui.m_txtTime.text = "剩余" + TimeUtil.FormattingTimeTo_DDHHmm(curTime); } else { _ui.m_txtTime.visible = false; } } private void UpdateRedDots() { RedDotController.Instance.SetComRedDot(_ui.m_btnStart, RedDotDataManager.Instance.GetActivityFYJYRed(), "", -16, -8, false); EventAgent.DispatchEvent(ConstMessage.ACTIVITY_RED_CHANGE, ActivityType.AfternoonLeisure); } } }