//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Thursday, April 18, 2019 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class RechargeGiftActWin : Window { [SerializeField] Text buyCountGiftText; [SerializeField] Slider buyCountGiftSlider; [SerializeField] Text buyCountGiftSliderText; [SerializeField] List buyCountGiftItems; [SerializeField] Button buyCountGiftBtn; [SerializeField] Image gotYetImg; [SerializeField] ScrollerController m_Controller; [SerializeField] Text actTime; [SerializeField] Text resetTip; RechargeGiftActModel model { get { return ModelCenter.Instance.GetModel(); } } VipModel vipModel { get { return ModelCenter.Instance.GetModel(); } } StoreModel storeModel { get { return ModelCenter.Instance.GetModel(); } } #region Built-in protected override void BindController() { } protected override void AddListeners() { } protected override void OnPreOpen() { m_Controller.OnRefreshCell += OnRefreshCell; model.UpdateRechargeGiftActEvent += DisplayAward; GlobalTimeEvent.Instance.secondEvent += secondEvent; vipModel.rechargeCountEvent += VipModel_rechargeCountEvent; storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent; DisplayScroll(); DisplayAward(); secondEvent(); } private void VipModel_rechargeCountEvent(int obj) { m_Controller.m_Scorller.RefreshActiveCellViews(); DisplayAward(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { m_Controller.OnRefreshCell -= OnRefreshCell; model.UpdateRechargeGiftActEvent -= DisplayAward; GlobalTimeEvent.Instance.secondEvent -= secondEvent; vipModel.rechargeCountEvent -= VipModel_rechargeCountEvent; storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent; } protected override void OnAfterClose() { } #endregion private void RefreshBuyShopLimitEvent() { m_Controller.m_Scorller.RefreshActiveCellViews(); } void DisplayScroll() { m_Controller.Refresh(); OperationRechargeGiftAct act; OperationTimeHepler.Instance.TryGetOperation(RechargeGiftActModel.operaType, out act); List _list = null; StoreConfig.TryGetStoreConfigs(act.shopType, out _list); int totaleCnt = (_list == null ? 0 : _list.Count) + act.ctgIDs.Count; for (int i = 0; i < totaleCnt; i++) { m_Controller.AddCell(ScrollerDataType.Header, i); } m_Controller.Restart(); m_Controller.m_Scorller.RefreshActiveCellViews(); m_Controller.JumpIndex(GetDefaultSelect()); //取一档商品识别 是否有商品的每日重置,与活动的每日重置判断显示 var config = CTGConfig.Get(act.ctgIDs[0]); resetTip.SetActive(!act.dayReset && config.DailyBuyCount != 0); } void DisplayAward() { int index = GetAwardShowIndex(); OperationRechargeGiftAct act; OperationTimeHepler.Instance.TryGetOperation(RechargeGiftActModel.operaType, out act); int totalBuyCnt = model.GetBuyTotalCnt(); var awardInfo = act.buyCountGifts[index]; if (awardInfo.NeedBuyCount == 0) { //免费领取 buyCountGiftText.text = Language.Get("Z2014"); buyCountGiftSlider.value = 1; buyCountGiftSliderText.text = string.Empty; } else { buyCountGiftText.text = Language.Get("RechargeGiftActWin1", Math.Max(0,awardInfo.NeedBuyCount - totalBuyCnt)); buyCountGiftSlider.value = totalBuyCnt / (float)awardInfo.NeedBuyCount; buyCountGiftSliderText.text = string.Format("{0}/{1}", totalBuyCnt, awardInfo.NeedBuyCount); } var awards = awardInfo.AwardItemList; for (int i = 0; i < buyCountGiftItems.Count; i++) { if (i < awards.Length) { var award = awards[i]; buyCountGiftItems[i].SetActive(true); var itemData = new ItemCellModel((int)award.ItemID, false, award.ItemCount); buyCountGiftItems[i].Init(itemData); buyCountGiftItems[i].button.SetListener(() => { ItemTipUtility.Show((int)award.ItemID); }); } else { buyCountGiftItems[i].SetActive(false); } } buyCountGiftBtn.SetColorful(null, totalBuyCnt >= awardInfo.NeedBuyCount); buyCountGiftBtn.interactable = totalBuyCnt >= awardInfo.NeedBuyCount; buyCountGiftBtn.SetListener(() => { model.SendGetAward(awardInfo.NeedBuyCount); }); if (index == act.buyCountGifts.Count - 1 && model.GetBuyGiftState(awardInfo.NeedBuyCount) == 2) { gotYetImg.SetActive(true); buyCountGiftBtn.SetActive(false); } else { gotYetImg.SetActive(false); buyCountGiftBtn.SetActive(true); } } private void OnRefreshCell(ScrollerDataType type, CellView cell) { if (type != ScrollerDataType.Header) return; var _cell = cell as RechargeGiftActCell; _cell.Display(_cell.index); } int GetDefaultSelect() { OperationRechargeGiftAct act; OperationTimeHepler.Instance.TryGetOperation(RechargeGiftActModel.operaType, out act); List _list = null; StoreConfig.TryGetStoreConfigs(act.shopType, out _list); int storeCnt = _list == null ? 0 : _list.Count; for (int i = 0; i < storeCnt; i++) { int remainNum; storeModel.TryGetIsSellOut(_list[i], out remainNum); if (remainNum > 0) return i; } //跳过已购买 for (int i = 0; i < act.ctgIDs.Count; i++) { int ctgID = act.ctgIDs[i]; var countInfo = model.GetBuyCntInfo(ctgID); if (countInfo.x < countInfo.y) return i + storeCnt; } return 0; } void secondEvent() { OperationRechargeGiftAct act; OperationTimeHepler.Instance.TryGetOperation(RechargeGiftActModel.operaType, out act); actTime.text = Language.Get("BossFHLanguage2", TimeUtility.SecondsToHMS(act.GetResetSurplusTime())); } int GetAwardShowIndex() { OperationRechargeGiftAct act; OperationTimeHepler.Instance.TryGetOperation(RechargeGiftActModel.operaType, out act); if (act == null) return 0; for (int i = 0; i < act.buyCountGifts.Count; i++) { if (model.GetBuyGiftState(act.buyCountGifts[i].NeedBuyCount) != 2) { return i; } } return act.buyCountGifts.Count - 1; } } }