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 int _activityId = 0; 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); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.ACTIVITY_REWARD_ADD, UpdateView); EventAgent.AddEventListener(ConstMessage.ACTIVITY_COUNT_VALUE_CHANGE, UpdateView); } protected override void OnShown() { base.OnShown(); _activityId = (int)(this.viewData as object[])[0]; _rechargeCfgs = ActivityRechargeCfgArray.Instance.GetCfgsByactivityId(_activityId); 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); EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_COUNT_VALUE_CHANGE, UpdateView); } private void OnBtnBackClick() { ViewManager.GoBackFrom(typeof(LimitChargeView).FullName); } private void UpdateTime(object param) { long curTime = TimeHelper.ServerNow(); long endTime = _activityInfo.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(_activityId); _rechargeCfgs = SoreCfg(_rechargeCfgs); _ui.m_list.numItems = _rechargeCfgs.Count; ActivityOpenCfg openCfg = ActivityOpenCfgArray.Instance.GetCfg(_activityId); _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("xslc_banner_" + openCfg.res); } private void RenderListItem(int index, GObject obj) { UI_ListChargeItem item = UI_ListChargeItem.Proxy(obj); long limitChargeExp = _activityInfo.CountValue;// GameGlobal.myNumericComponent.GetAsInt(NumericType.TotalRechargeScore); item.m_txtTitle.text = string.Format("活动期间累计获得{0}会员积分({1}/{2})", _rechargeCfgs[index].value, limitChargeExp, _rechargeCfgs[index].value); 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) { int[] reward = ((int[][])obj.parent.data)[index]; ItemData itemData = ItemUtil.createItemData(reward); if (obj.data == null) { obj.data = new ItemView(obj as GComponent); } (obj.data as ItemView).SetData(itemData); } private void OnBtnGetClick(EventContext context) { GObject obj = context.sender as GObject; int id = (int)obj.data; ActivityGlobalSProxy.ReqGetActivityBonus(_activityId, id).Coroutine(); } private List SoreCfg(List rechargeCfgs) { rechargeCfgs.Sort((ActivityRechargeCfg a, ActivityRechargeCfg b) => { long limitChargeExp = _activityInfo.CountValue;// GameGlobal.myNumericComponent.GetAsInt(NumericType.TotalRechargeScore); int stateA = _activityInfo.GetRewards.IndexOf(a.id); int stateB = _activityInfo.GetRewards.IndexOf(b.id); if (limitChargeExp >= a.value && limitChargeExp < b.value && stateA < 0) return -1; if (limitChargeExp >= b.value && limitChargeExp < a.value && stateB < 0) return 1; if (stateA >= 0 && stateB < 0) return 1; if (stateB >= 0 && stateA < 0) return -1; return a.id - b.id; }); return rechargeCfgs; } } }