using UI.RechargeStore; using UI.CommonGame; using FairyGUI; using System.Collections.Generic; using ET; namespace GFGGame { public class RechargeStoreView : BaseWindow { private UI_RechargeStoreUI _ui; private ValueBarController _valueBarController; private List _giftCfgs; private List _exchangeCfgs; public override void Dispose() { _valueBarController.Dispose(); _valueBarController = null; if (_ui != null) { _ui.Dispose(); } _ui = null; base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_RechargeStoreUI.PACKAGE_NAME; _ui = UI_RechargeStoreUI.Create(); this.viewCom = _ui.target; isfullScreen = true; _valueBarController = new ValueBarController(_ui.m_valueBar); _ui.m_btnBack.onClick.Add(OnClickBtnBack); _ui.m_list.itemRenderer = ListItemRenderer; _ui.m_listGift.itemRenderer = ListGiftItemRenderer; _ui.m_listExchange.itemRenderer = ListExchangeItemRenderer; _ui.m_comTab.m_c1.onChanged.Add(OnComTabChange); _ui.m_c1.onChanged.Add(OnTabChange); EventAgent.AddEventListener(ConstMessage.BUY_RECHARGE_SUCCESS, () => { _ui.m_list.numItems = RechargeCfgArray.Instance.dataArray.Length; }); EventAgent.AddEventListener(ConstMessage.BUY_EXCHANGE_SUCCESS, UpdateExchangeList); EventAgent.AddEventListener(ConstMessage.BUY_GIFT_SUCCESS, UpdateGiftBagList); } protected override void OnShown() { base.OnShown(); _valueBarController.OnShown(); _ui.m_c1.selectedIndex = 0; _ui.m_comTab.m_c1.selectedIndex = 0; _ui.m_list.numItems = RechargeCfgArray.Instance.dataArray.Length; UpdateExchangeList(); UpdateGiftBagList(); OnTabChange(); Timers.inst.Add(1, 0, UpdateExchangeTime); } protected override void OnHide() { base.OnHide(); _valueBarController.OnHide(); Timers.inst.Remove(UpdateExchangeTime); } private void OnClickBtnBack() { this.Hide(); } private void OnComTabChange() { _ui.m_c1.selectedIndex = _ui.m_comTab.m_c1.selectedIndex; } private void OnTabChange() { _ui.m_list.ScrollToView(0); _ui.m_listGift.ScrollToView(0); _ui.m_listExchange.ScrollToView(0); } private void UpdateGiftBagList() { _giftCfgs = RechargeDataManager.Instance.GetGiftBagCfgs(); _ui.m_listGift.numItems = _giftCfgs.Count; } private void UpdateExchangeList() { _exchangeCfgs = RechargeDataManager.Instance.GetExchangeCfgs(); _ui.m_listExchange.numItems = _exchangeCfgs.Count; } private void UpdateExchangeTime(object param) { int endTime = TimeUtil.GetTomorrowTime(GlobalCfgArray.globalCfg.refreshTime); string time = TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, endTime); _ui.m_txtRefreshTime.text = time + "后刷新"; for (int i = 0; i < _ui.m_listGift.numItems; i++) { UI_ListGiftItem item = UI_ListGiftItem.Proxy(_ui.m_listGift.GetChildAt(i)); GiftBagCfg cfg = _giftCfgs[i]; item.m_txtEndTime.text = RechargeDataManager.Instance.GetEndTime(cfg.id); } } private void ListItemRenderer(int index, GObject obj) { RechargeCfg itemData = RechargeCfgArray.Instance.dataArray[index]; UI_StoreListItem item = UI_StoreListItem.Proxy(obj); item.m_btnBuy.m_c1.selectedIndex = 1; item.m_btnBuy.m_txtTitle.text = itemData.price.ToString(); if (item.m_btnBuy.target.data == null) { item.m_btnBuy.target.onClick.Add(() => { RechargeSProxy.ReqRecharge(itemData.id).Coroutine(); }); } item.m_btnBuy.target.data = index; item.m_txtName.text = string.Format("{0}{1}", itemData.itemNum, itemData.name); item.m_txtDesc.text = string.Format("首充赠送+{0}{1}", itemData.itemNum, itemData.name); bool isDouble = RechargeDataManager.Instance.GetRechargeBuyNumById(itemData.id) < itemData.doubleTimes; item.m_imgDouble.visible = isDouble; item.m_txtDesc.visible = isDouble; item.m_icon.url = "ui://RechargeStore/sc_zizhuan_" + itemData.id; UI_StoreListItem.ProxyEnd(); } private void ListGiftItemRenderer(int index, GObject obj) { UI_ListGiftItem item = UI_ListGiftItem.Proxy(obj); GiftBagCfg cfg = _giftCfgs[index]; item.m_txtName.text = cfg.name; item.m_icon.url = string.Format("ui://RechargeStore/{0}", cfg.res); item.m_txtDesc.SetVar("count", cfg.desc).FlushVars(); ; item.m_grpDiscount.visible = cfg.desc != ""; item.m_txtEndTime.text = RechargeDataManager.Instance.GetEndTime(cfg.id); item.m_grpEndTime.visible = cfg.endTime != ""; item.m_c2.selectedIndex = RechargeDataManager.Instance.GetGiftStateById(cfg.id) ? 0 : 1; if (cfg.lockType == LockType.STORY_LV) { StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(cfg.storyLevelId); item.m_txtLock.text = string.Format("通关{0}-{1}解锁", StoryUtil.GetChapterOrder(storyLevelCfg.chapterId), storyLevelCfg.order); } else if (cfg.lockType == LockType.ROLE_LV) { item.m_txtLock.text = string.Format("角色达到{0}级解锁", cfg.lv); } int buyNum = RechargeDataManager.Instance.GetGiftBuyNumById(cfg.id); item.m_txtLimit.text = string.Format("{0}({1}/{2})", RechargeDataManager.Instance.refreshType[cfg.refreshType], StringUtil.GetColorText(buyNum.ToString(), "#DA8870"), cfg.maxBuyNum); item.m_txtLimit.visible = cfg.maxBuyNum > 0; item.m_c1.selectedIndex = cfg.maxBuyNum == 0 || buyNum < cfg.maxBuyNum ? 0 : 1; if (item.m_c1.selectedIndex == 0) { item.m_txtOriginalPrice.text = cfg.originalPrice.ToString(); if (cfg.price > 0 && cfg.costType != CostType.FREE) { item.m_grpOriginalPrice.visible = cfg.originalPrice > 0; item.m_grpIcon.visible = true; item.m_txtPrice.text = cfg.price.ToString(); if (cfg.costType == CostType.RMB) { item.m_loaIcon.visible = false; item.m_txtIcon.visible = true; item.m_txtIcon.text = "¥"; } else { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.costId); item.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(itemCfg.res); item.m_loaIcon.visible = true; item.m_txtIcon.visible = false; } } else { item.m_grpIcon.visible = false; item.m_grpOriginalPrice.visible = false; item.m_txtPrice.text = "免费"; } } if (item.target.data == null) { item.target.onClick.Add(OnBtnBuyClick); } item.target.data = cfg.id; UI_ListGiftItem.ProxyEnd(); } private void OnBtnBuyClick(EventContext context) { GObject btn = context.sender as GObject; int giftId = (int)btn.data; GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId); if (cfg.maxBuyNum != 0 && RechargeDataManager.Instance.GetGiftBuyNumById(giftId) == cfg.maxBuyNum) { PromptController.Instance.ShowFloatTextPrompt("已售罄"); return; } ViewManager.Show(btn.data); } private void ListExchangeItemRenderer(int index, GObject obj) { ShopExchangeCfg cfg = _exchangeCfgs[index]; UI_StoreListItem item = UI_StoreListItem.Proxy(obj); item.m_btnBuy.m_c1.selectedIndex = 0; item.m_btnBuy.m_txtTitle.text = cfg.costNum.ToString(); if (item.m_btnBuy.target.data == null) { item.m_btnBuy.target.onClick.Add(() => { if (cfg.num > 0 && cfg.num - RechargeDataManager.Instance.GetExchangeBuyNumById(cfg.id) <= 0) { PromptController.Instance.ShowFloatTextPrompt("已售罄"); return; } ViewManager.Show(cfg.id); }); } ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.itemId); item.m_btnBuy.target.data = cfg.id; item.m_btnBuy.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(cfg.costId).res); item.m_txtName.text = itemCfg.name; item.m_txtDesc.text = string.Format("剩余:{0}", cfg.maxLimit - RechargeDataManager.Instance.GetExchangeBuyNumById(cfg.id)); if (cfg.maxLimit == 0) item.m_txtDesc.text = "剩余:不限"; item.m_imgDouble.visible = false; item.m_icon.url = ResPathUtil.GetIconPath(itemCfg); UI_StoreListItem.ProxyEnd(); } } }