using System.Collections.Generic; using ET; using FairyGUI; using UI.DailyWelfare; using UI.CommonGame; using UnityEngine; namespace GFGGame { public class LimitChargeView : BaseWindow { private UI_LimitChargeUI _ui; private List _rechargeCfgs; private ActivityInfo _activityInfo; 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_LimitChargeUI.Create(); this.viewCom = _ui.target; isfullScreen = true; _ui.m_list.itemRenderer = RenderListItem; _ui.m_btnBack.onClick.Add(OnBtnBackClick); _ui.m_btnCharge.onClick.Add(OnBtnChargeClick); ActivityOpenCfg openCfg = ActivityOpenCfgArray.Instance.GetCfg(ActivityDataManager.Instance.actLimitChargeId); _ui.m_loaBg.url = ResPathUtil.GetBgImgPath(openCfg.res); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.ACTIVITY_REWARD_ADD, UpdateView); } protected override void OnShown() { base.OnShown(); _rechargeCfgs = ActivityRechargeCfgArray.Instance.GetCfgsByactivityId(ActivityDataManager.Instance.actLimitChargeId); UpdateView(); Timers.inst.Add(1, 0, UpdateTime); } protected override void OnHide() { base.OnHide(); if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0); Timers.inst.Remove(UpdateTime); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_REWARD_ADD, UpdateView); } private void OnBtnBackClick() { ViewManager.GoBackFrom(typeof(LimitChargeView).FullName); } private void UpdateTime(object param) { ActivityOpenCfg openCfg = ActivityOpenCfgArray.Instance.GetCfg(ActivityDataManager.Instance.actLimitChargeId); long curTime = TimeHelper.ServerNow(); long endTime = TimeUtil.DateTimeToTimestamp(openCfg.endTime); _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime); } private void OnBtnChargeClick() { ViewManager.Show(new object[] { ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE }); } private void UpdateView() { _activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(ActivityDataManager.Instance.actLimitChargeId); _ui.m_list.numItems = _rechargeCfgs.Count; } private void RenderListItem(int index, GObject obj) { UI_ListChargeItem item = UI_ListChargeItem.Proxy(obj); item.m_txtTitle.text = string.Format("活动期间累计获得{0}会员积分({1}/{2})", _rechargeCfgs[index].value, RoleDataManager.vipExp, _rechargeCfgs[index].value); int limitChargeExp = GameGlobal.myNumericComponent.GetAsInt(NumericType.RechargeTotal); if (limitChargeExp >= _rechargeCfgs[index].value) { item.m_c1.selectedIndex = _activityInfo.GetRewards.IndexOf(_rechargeCfgs[index].id) > 0 ? 2 : 1; } else { item.m_c1.selectedIndex = 0; } if (item.m_btnGet.data == null) { item.m_btnGet.onClick.Add(OnBtnGetClick); } item.m_btnGet.data = _rechargeCfgs[index].id; if (item.m_listRewards.data == null) { item.m_listRewards.itemRenderer = RenderListRewardItem; } item.m_listRewards.data = _rechargeCfgs[index].bonusArr; item.m_listRewards.numItems = _rechargeCfgs[index].bonusArr.Length; UI_ListChargeItem.ProxyEnd(); } private void RenderListRewardItem(int index, GObject obj) { UI_ComItem item = UI_ComItem.Proxy(obj); int[] reward = GlobalCfgArray.globalCfg.firstChargeBonusArr[index]; ItemData itemData = ItemUtil.createItemData(reward); if (obj.data == null) { obj.data = new ItemView(obj as GComponent); } (obj.data as ItemView).SetData(itemData); UI_ComItem.ProxyEnd(); } private void OnBtnGetClick(EventContext context) { GObject obj = context.sender as GObject; int id = (int)obj.data; ActivityGlobalSProxy.ReqGetActivityBonus(id, ActivityDataManager.Instance.actLimitChargeId).Coroutine(); } } }