using UI.CommonGame; using FairyGUI; using System.Collections.Generic; using ET; using System; using Hutool; using UI.DailyWelfare; namespace GFGGame { public class NewLimitChargeView : BaseWindow { private UI_NewLimitChargeUI _ui; private List _shopCfgs; private int _curSelectIndex = 0; private int _activityId = 0; private ActivityInfo _activityInfo; private List _rechargeCfgs; private int previousIndex = 0; private bool isGoChargeView = false; public override void Dispose() { if (_ui != null) { _ui.Dispose(); } _ui = null; base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_LimitChargeUI.PACKAGE_NAME; _ui = UI_NewLimitChargeUI.Create(); this.viewCom = _ui.target; isfullScreen = true; isReturnView = true; this.clickBlankToClose = false; this.bringToFontOnClick = false; _ui.m_btnLeft.onClick.Add(OnBtnLeftClick); _ui.m_btnRight.onClick.Add(OnBtnRightClick); _ui.m_btnBack.onClick.Add(OnBtnBackClick); _ui.m_btnCharge.onClick.Add(OnBtnChargeClick); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList); EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot); EventAgent.AddEventListener(ConstMessage.NEWLIMITCHARGE_GET, UpdateSuitView); } protected override void OnShown() { base.OnShown(); _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zjm_bg1", "jpg"); _activityId = (int)(this.viewData as object[])[0]; _rechargeCfgs = ActivityRechargeCfgArray.Instance.GetCfgsByactivityId(_activityId); _activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(_activityId); //RefreshList(); //由于这个需要外部参数所以在onshown里面预加载 PreDownloadManager.Instance.PreDownloadSuitRes(_rechargeCfgs[0].suitId, ResType.Both, new int[] { ConstDressUpItemType.BEI_JING }, false); string name = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[0].suitId).name; _ui.m_packageName.text = name; if (!isGoChargeView) { for (int i = 0; i < _rechargeCfgs.Count; i++) { if (_activityInfo.CountValue >= _rechargeCfgs[i].value) { if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[i].id) < 0) { _curSelectIndex = i; break; } } } } isGoChargeView = false; _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true; _ui.m_btnRight.visible = _curSelectIndex < _rechargeCfgs.Count - 1 ? true : false; _ui.m_packageName.text = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[_curSelectIndex].suitId).name; UpdateRedDot(); //预加载套装,对于不同suitid for (int i = 1; i < _rechargeCfgs.Count; i++) { if (_rechargeCfgs[i].suitId != _rechargeCfgs[i - 1].suitId) { PreDownloadManager.Instance.PreDownloadSuitRes(_rechargeCfgs[i].suitId, ResType.Both, new int[] { ConstDressUpItemType.BEI_JING }, false); } } ItemRenderer(_curSelectIndex); Timers.inst.Add(1, 0, UpdateTime); } protected override void OnHide() { base.OnHide(); DressUpObjUI dressUpObjUI = _ui.m_showItem.m_holder.data as DressUpObjUI; if (dressUpObjUI != null) { dressUpObjUI.Dispose(); } _ui.m_showItem.m_holder.data = null; previousIndex = 0; Timers.inst.Remove(UpdateTime); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList); EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot); EventAgent.RemoveEventListener(ConstMessage.NEWLIMITCHARGE_GET, UpdateSuitView); } private void RefreshList() { ItemRenderer(_curSelectIndex); } private void ItemRenderer(int index) { ActivityRechargeCfg lastVipCfg = _rechargeCfgs[index]; ActivityRechargeCfg vipCfg = _rechargeCfgs[index]; UI_ListShowItem item = _ui.m_showItem; string name = SuitCfgArray.Instance.GetCfg(vipCfg.suitId).name; item.m_txtName0.text = name; if (vipCfg.res != "") { item.m_cardIcon.visible = true; item.m_cardBg.visible = true; item.m_cardIcon.url = "ui://DailyWelfare/" + vipCfg.res; } else { item.m_cardIcon.visible = false; item.m_cardBg.visible = false; } if (item.m_listGiftBag.data == null) { item.m_listGiftBag.itemRenderer = ListRewardItemRender; item.m_listGiftBag.onClickItem.Add(OnListItemClick); } item.m_listGiftBag.data = lastVipCfg.bonusArr; item.m_listGiftBag.numItems = lastVipCfg.bonusArr.Length; item.m_listGiftBag.scrollPane.SetPosX(0, false); if (_rechargeCfgs[index].suitId != previousIndex) { DressUpObjUI dressUpObjUI; if (item.m_holder.data == null) { item.m_holder.data = new DressUpObjUI("SceneSuitFoster"); } dressUpObjUI = item.m_holder.data as DressUpObjUI; dressUpObjUI.ResetSceneObj(120, false, true, null, false); dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.suitId, true, new int[] { ConstDressUpItemType.BEI_JING }, false, false); dressUpObjUI.UpdateWrapper(item.m_holder); } previousIndex = _rechargeCfgs[index].suitId; if (item.m_btnShow.data == null) { item.m_btnShow.onClick.Add(OnBtnShowClick); } item.m_btnShow.data = vipCfg.suitId; if (item.m_btnGetGiftBag.data == null) { item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick); } item.m_btnGetGiftBag.data = vipCfg.id; //bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.id); long limitChargeExp = _activityInfo.CountValue; //item.m_btnGetGiftBag.grayed = limitChargeExp < _rechargeCfgs[index].value; item.m_txtGiftBag.text = string.Format("活动期间累计获得{0}会员积分({1}/{2})", _rechargeCfgs[index].value, limitChargeExp, _rechargeCfgs[index].value); if (limitChargeExp >= _rechargeCfgs[index].value) { if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[index].id) >= 0) { item.m_btnGetGiftBag.grayed = true; item.m_btnGetGiftBag.title = "已领取"; } else { item.m_btnGetGiftBag.grayed = false; item.m_btnGetGiftBag.title = "领取"; } } else { item.m_btnGetGiftBag.grayed = true; item.m_btnGetGiftBag.title = "领取"; } } private void ListRewardItemRender(int index, GObject obj) { int[][] rewards = (int[][])obj.parent.data; UI_ComItem item = UI_ComItem.Proxy(obj); ItemData itemData = ItemUtil.createItemData(rewards[index]); ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id); item.m_txtCount.text = itemData.num.ToString(); item.target.data = itemCfg; item.m_QualityType.selectedIndex = itemCfg.rarity - 1; item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg); UI_ComItem.ProxyEnd(); } private void OnBtnShowClick(EventContext context) { GObject obj = context.sender as GObject; int suitId = (int)obj.data; int _suitTypeId = 0; for (int i = 0; i < SuitGuideMenuCfgArray.Instance.dataArray.Length; i++) { string[] suitIds = SuitGuideMenuCfgArray.Instance.dataArray[i].suitIds.Split(';'); if (Array.IndexOf(suitIds, suitId.ToString()) >= 0) { _suitTypeId = SuitGuideMenuCfgArray.Instance.dataArray[i].id; break; } } ViewManager.Show(new object[] { _suitTypeId, suitId, new List() { suitId }, false }); } private void OnBtnGetGiftBagClick(EventContext context) { GObject obj = context.sender as GObject; int id = (int)obj.data; ActivityGlobalSProxy.ReqGetActivityBonus(_activityId, id).Coroutine(); } private void OnBtnLeftClick() { if (_curSelectIndex == 0) return; _curSelectIndex = _curSelectIndex - 1; string name = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[_curSelectIndex].suitId).name; _ui.m_packageName.text = name; UpdateSuitView(); UpdateRedDot(); } private void OnBtnRightClick() { if (_curSelectIndex == _rechargeCfgs.Count - 1) { ItemRenderer(_curSelectIndex); return; } _curSelectIndex = _curSelectIndex + 1; string name = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[_curSelectIndex].suitId).name; _ui.m_packageName.text = name; UpdateSuitView(); UpdateRedDot(); } private void UpdateRedDot() { int indexPrior = Math.Max(0, _curSelectIndex - 1); int indexNext = Math.Min(_rechargeCfgs.Count - 1, _curSelectIndex + 1); TraverseList(indexPrior); TraverseList(indexNext); } private void TraverseList(int index) { if (index < _curSelectIndex) { for (int i = index; i >= 0; i--) { if(SetRedDot(i)) { RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, true); break; } RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, false); } } else { for (int i = index; i < _rechargeCfgs.Count; i++) { if (SetRedDot(i)) { RedDotController.Instance.SetComRedDot(_ui.m_btnRight, true); break; } RedDotController.Instance.SetComRedDot(_ui.m_btnRight, false); } } } private bool SetRedDot(int index) { long limitChargeExp = _activityInfo.CountValue; if (limitChargeExp >= _rechargeCfgs[index].value) { if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[index].id) < 0) { return true; } } return false; } private void OnBtnChargeClick() { ViewManager.Show(new object[] { ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE }); isGoChargeView = true; } private void UpdateSuitView() { _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true; _ui.m_btnRight.visible = _curSelectIndex < _rechargeCfgs.Count - 1 ? true : false; ItemRenderer(_curSelectIndex); } private void UpdateTime(object param) { long curTime = TimeHelper.ServerNow(); long endTime = _activityInfo.EndTime; _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime); } private void OnListItemClick(EventContext context) { GComponent comItem = (context.data as GComponent); ItemCfg itemCfg = comItem.data as ItemCfg; GoodsItemTipsController.ShowItemTips(itemCfg.id); } private void OnBtnBackClick() { ViewManager.GoBackFrom(typeof(NewLimitChargeView).FullName); } } }