using System.Collections.Generic; using System.Text.RegularExpressions; using ET; using FairyGUI; using UI.League; using UnityEngine; namespace GFGGame { //联盟礼包 public class LeagueGiftView : BaseWindow { private UI_LeagueGiftUI _ui; private List _getDatas; private List _buyDatas; public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_LeagueGiftUI.PACKAGE_NAME; _ui = UI_LeagueGiftUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; viewAnimationType = EnumViewAnimationType.ZOOM_CENTER; _ui.m_btnClose.onClick.Add(Hide); _ui.m_btnGet.onClick.Add(OnBtnGetClick); _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView); _ui.m_btnRule.data = 300003; _ui.m_listBuy.itemRenderer = RenderListBuyItem; _ui.m_listGet.itemRenderer = RenderListGetItem; } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBuyList); EventAgent.AddEventListener(ConstMessage.LEAGUE_NUMBERIC_CHANGE, UpdateView); } protected override void OnShown() { base.OnShown(); UpdateView(); } protected override void OnHide() { base.OnHide(); if (_ui.m_listBuy.numItems > 0) _ui.m_listBuy.ScrollToView(0); if (_ui.m_listGet.numItems > 0) _ui.m_listGet.ScrollToView(0); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBuyList); EventAgent.RemoveEventListener(ConstMessage.LEAGUE_NUMBERIC_CHANGE, UpdateView); } private void OnBtnCreatClick() { } private void UpdateView() { UpdateGetList(); UpdateBuyList(); } private void UpdateGetList() { _getDatas = LeagueDataManager.Instance.GetGiftGetDatas(); _ui.m_listGet.numItems = _getDatas.Count; _ui.m_txtTips.visible = _getDatas.Count == 0; } private void UpdateBuyList() { _buyDatas = LeagueDataManager.Instance.GetGiftBuyDatas(); _ui.m_listBuy.numItems = _buyDatas.Count; } private void RenderListGetItem(int index, GObject obj) { UI_ListGiftGetItem item = UI_ListGiftGetItem.Proxy(obj); if (item.m_listGift.data == null) { item.m_listGift.itemRenderer = RenderListRewardItem; } item.m_listGift.data = _getDatas[index].GiftCfg.bonusArr; item.m_listGift.numItems = _getDatas[index].GiftCfg.bonusArr.Length; UI_ListGiftGetItem.ProxyEnd(); } private void RenderListBuyItem(int index, GObject obj) { UI_ListGiftBuyItem item = UI_ListGiftBuyItem.Proxy(obj); LeagueGiftBuyData buyData = _buyDatas[index]; string strCount = buyData.GiftCfg.limitType == 1 ? "今日剩余:{0}/{1}" : "本周剩余:{0}/{1}"; item.m_txtCount.text = string.Format(strCount, buyData.GiftCfg.limit - buyData.BuyCount, buyData.GiftCfg.limit); int day = TimeUtil.FormattingTime11(TimeHelper.ServerNow(), buyData.EndTime); item.m_txtTime.text = buyData.EndTime == 0 ? "" : string.Format("(剩余{0}天)", day); ItemUtil.UpdateItemNeedNum(item.m_comCost, buyData.GiftCfg.consumeArr[0]); if (item.m_listGift.data == null) { item.m_listGift.itemRenderer = RenderListRewardItem; } item.m_listGift.data = _buyDatas[index].GiftCfg.bonusArr; item.m_listGift.numItems = _buyDatas[index].GiftCfg.bonusArr.Length; if (item.m_btnBuy.data == null) { item.m_btnBuy.onClick.Add(OnBtnBuyClick); } item.m_btnBuy.data = buyData; UI_ListGiftBuyItem.ProxyEnd(); } private void RenderListRewardItem(int index, GObject obj) { int[][] reward = (int[][])obj.parent.data; ItemData itemData = ItemUtil.createItemData(reward[index]); if (obj.data == null) { obj.data = new ItemView(obj as GComponent); } (obj.data as ItemView).SetData(itemData); (obj.data as ItemView).SetComItemScale = 0.7f; (obj.data as ItemView).SetTxtCountPos(185, 155); } private void OnBtnBuyClick(EventContext context) { GObject obj = context.sender as GObject; LeagueGiftBuyData buyData = obj.data as LeagueGiftBuyData; int myPos = LeagueDataManager.Instance.GetMyPos(); bool isLeader = myPos == LeaguePos.Owner || myPos == LeaguePos.SubOwner; if (!isLeader!) { PromptController.Instance.ShowFloatTextPrompt("权限不足"); return; } int needNum = buyData.GiftCfg.consumeArr[0][1]; int hasNum = (int)ItemDataManager.GetItemNum(buyData.GiftCfg.consumeArr[0][0]); if (hasNum < needNum) { PromptController.Instance.ShowFloatTextPrompt("消耗不足"); return; } if (buyData.BuyCount == buyData.GiftCfg.limit) { PromptController.Instance.ShowFloatTextPrompt("购买次数不足"); return; } LeagueSproxy.ReqBuyLeagueWelfare(buyData.GiftCfg.type).Coroutine(); } private void OnBtnGetClick() { // LeagueSproxy.ReqGetLeagueWelfare().Coroutine(); } } }