| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- using UI.Store;
- using UI.CommonGame;
- using FairyGUI;
- using System.Collections.Generic;
- using ET;
- using System;
- using cfg.GfgCfg;
- using Hutool;
- using UnityEngine;
- namespace GFGGame
- {
- public class StoreChargeAddUpView : BaseWindow
- {
- private UI_StoreChargeAddUpUI _ui;
- private ValueBarController _valueBarController;
- private List<ShopCfg> _shopCfgs;
- private DressUpObjUI _dressUpObjUI;
- private List<DressUpObjUI> _dressUpObjUIs = new List<DressUpObjUI>();
- private int _curSelectIndex = 0;
- //按钮锁定一段时间,防止点太快
- private float _leftRightBtnLockEndTime = 0;
- public override void Dispose()
- {
- if (_valueBarController != null)
- {
- _valueBarController.Dispose();
- _valueBarController = null;
- }
- if (_dressUpObjUI != null)
- {
- _dressUpObjUI.Dispose();
- _dressUpObjUI = null;
- }
- for (int i = 0; i < _dressUpObjUIs.Count; i++)
- {
- if (_dressUpObjUIs[i] != null)
- {
- _dressUpObjUIs[i].Dispose();
- _dressUpObjUIs[i] = null;
- }
- }
- if (_ui != null)
- {
- _ui.Dispose();
- }
- _ui = null;
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_StoreChargeAddUpUI.PACKAGE_NAME;
- _ui = UI_StoreChargeAddUpUI.Create();
- this.viewCom = _ui.target;
- isfullScreen = true;
- this.clickBlankToClose = false;
- this.bringToFontOnClick = false;
- _dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
- _valueBarController = new ValueBarController(_ui.m_valueBar);
- _ui.m_list.itemRenderer = ListItemRenderer;
- _ui.m_list.SetVirtual();
- _ui.m_list.scrollPane.onScrollEnd.Add(UpdateSuitView);
- _ui.m_list.scrollPane.decelerationRate = 0.8f;
- _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
- _ui.m_btnRight.onClick.Add(OnBtnRightClick);
- }
- protected override void AddEventListener()
- {
- base.AddEventListener();
- EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
- EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
- }
- protected override void OnShown()
- {
- base.OnShown();
- _valueBarController.OnShown();
- RefreshList();
- _curSelectIndex = Math.Max(0, RoleDataManager.vipLv - 1);
- _ui.m_list.selectedIndex = _curSelectIndex;
- _ui.m_list.ScrollToView(_curSelectIndex);
- _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
- _ui.m_btnRight.visible = _curSelectIndex < _ui.m_list.numItems - 1 ? true : false;
- _ui.m_comVipLv.m_loaIcon.url = ResPathUtil.GetIconPath("tb_hyjf", "png");
- ShopViewManager.Instance.UpdateVipProgressCom(_ui.m_comVipLv.target);
- UpdateRedDot();
- }
- protected override void OnHide()
- {
- base.OnHide();
- _valueBarController.OnHide();
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
- EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
- }
- private void RefreshList()
- {
- //这个列表用了特殊的做法,左边屏幕外添加了一个无用的项
- _ui.m_list.numItems = CommonDataManager.Tables.TblVipCfg.DataList.Count;
- }
- private void ListItemRenderer(int index, GObject obj)
- {
- //索引修复,这个列表用了特殊的做法,左边屏幕外添加了一个无用的项
- index--;
- if (index < 0) index = 0;
- VipCfg lastVipCfg = CommonDataManager.Tables.TblVipCfg.DataList[index];
- VipCfg vipCfg = CommonDataManager.Tables.TblVipCfg.DataList[index + 1];
- UI_ListVipItem item = UI_ListVipItem.Proxy(obj);
- string name = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(vipCfg.SuitId).Name;
- item.m_txtName0.text = name.Length > 0 ? name.Substring(0, 1) : "";
- item.m_txtName1.text = name.Length > 1 ? name.Substring(1, 1) : "";
- item.m_txtName2.text = name.Length > 2 ? name.Substring(2, 1) : "";
- item.m_txtName3.text = name.Length > 3 ? name.Substring(3, 1) : "";
- item.m_txtName4.text = name.Length > 4 ? name.Substring(4) : "";
- item.m_txtGiftBag.SetVar("value", vipCfg.Id.ToString()).FlushVars();
- if (item.m_listGiftBag.data == null)
- {
- item.m_listGiftBag.itemRenderer = ListRewardItemRender;
- item.m_listGiftBag.onClickItem.Add(OnListItemClick);
- }
- item.m_listGiftBag.data = lastVipCfg.BonusOnce.ToGfgGameItemParam();
- item.m_listGiftBag.numItems = lastVipCfg.BonusOnce.Count;
- if (item.m_holder.data == null)
- {
- DressUpObjUI dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
- item.m_holder.data = dressUpObjUI;
- _dressUpObjUIs.Add(dressUpObjUI);
- }
- _dressUpObjUI = item.m_holder.data as DressUpObjUI;
- // 改为异步加载场景对象
- _dressUpObjUI.ResetSceneObjAsync(80, true, true, null, false, (go) =>
- {
- if (go != null)
- {
- _dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.SuitId, true,
- new int[] { ConstDressUpItemType.BEI_JING },
- false, false);
- _dressUpObjUI.UpdateWrapper(item.m_holder);
- }
- });
- if (item.m_btnShow.data == null)
- {
- item.m_btnShow.onClick.Add(OnBtnShowClick);
- }
- item.m_btnShow.data = vipCfg.SuitId;
- if (item.m_btnGetGiftBag.data == null)
- {
- item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick);
- }
- item.m_btnGetGiftBag.data = vipCfg.Id;
- bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.Id);
- item.m_btnGetGiftBag.grayed = isGet || vipCfg.Id > RoleDataManager.vipLv;
- RedDotController.Instance.SetComRedDot(item.m_btnGetGiftBag, !isGet && RoleDataManager.vipLv >= vipCfg.Id);
- if (item.m_btnWeek.data == null)
- {
- item.m_btnWeek.onClick.Add(OnBtnWeekClick);
- }
- item.m_btnWeek.data = vipCfg.Id;
- bool isWeekGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus),
- vipCfg.Id);
- bool canGet = !isWeekGet && vipCfg.Id <= RoleDataManager.vipLv;
- item.m_btnWeek.grayed = !canGet;
- RedDotController.Instance.SetComRedDot(item.m_btnWeek, canGet, "", -28, -3);
- UI_ListVipItem.ProxyEnd();
- }
- private void ListRewardItemRender(int index, GObject obj)
- {
- var rewards = (List<ItemParamProto>)obj.parent.data;
- UI_ComItem item = UI_ComItem.Proxy(obj);
- ItemData itemData = ItemUtil.createItemData(rewards[index]);
- ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemData.id);
- item.m_txtCount.text = itemData.num.ToString();
- item.target.data = itemCfg;
- item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
- item.m_QualityType.selectedIndex = itemCfg.Rarity - 1;
- RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.Id, false);
- UI_ComItem.ProxyEnd();
- }
- private void OnBtnShowClick(EventContext context)
- {
- GObject obj = context.sender as GObject;
- int suitId = (int)obj.data;
- int _suitTypeId = 0;
- for (int i = 0; i < CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList.Count; i++)
- {
- string[] suitIds = CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList[i].SuitIds.ToArray();
- if (Array.IndexOf(suitIds, suitId.ToString()) >= 0)
- {
- _suitTypeId = CommonDataManager.Tables.TblSuitGuideMenuCfg.DataList[i].Id;
- break;
- }
- }
- ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
- }
- private void OnBtnWeekClick(EventContext context)
- {
- GObject obj = context.sender as GObject;
- int vipLv = (int)obj.data;
- ViewManager.Show<WeekGiftView>(vipLv);
- }
- private void OnBtnGetGiftBagClick(EventContext context)
- {
- GObject obj = context.sender as GObject;
- int vipLv = (int)obj.data;
- bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipLv);
- if (isGet)
- {
- PromptController.Instance.ShowFloatTextPrompt("会员等级礼包已领取");
- return;
- }
- if (RoleDataManager.vipLv < vipLv)
- {
- PromptController.Instance.ShowFloatTextPrompt("会员等级不足");
- return;
- }
- ShopSProxy.ReqGetVipGiftBag(vipLv).Coroutine();
- }
- private void OnBtnLeftClick()
- {
- //LogUtil.LogDev($"OnBtnLeftClick _curSelectIndex {_curSelectIndex}");
- if (_leftRightBtnLockEndTime > Time.time) return;
- if (_curSelectIndex == 0) return;
- _curSelectIndex = _curSelectIndex - 1;
- //索引修复,这个列表用了特殊的做法,左边屏幕外添加了一个无用的项
- _curSelectIndex = Mathf.Min(_curSelectIndex, _ui.m_list.numItems - 3);
- _ui.m_list.ScrollToView(_curSelectIndex, true, true);
- _leftRightBtnLockEndTime = Time.time + 0.2f;
- }
- private void OnBtnRightClick()
- {
- //LogUtil.LogDev($"OnBtnRightClick _curSelectIndex {_curSelectIndex}");
- if (_leftRightBtnLockEndTime > Time.time) return;
- if (_curSelectIndex == _ui.m_list.numItems - 1) return;
- _curSelectIndex = _curSelectIndex + 1;
- _ui.m_list.ScrollToView(_curSelectIndex, true, true);
- _leftRightBtnLockEndTime = Time.time + 0.2f;
- }
- private void UpdateSuitView()
- {
- _curSelectIndex = _ui.m_list.GetFirstChildInView();
- //LogUtil.LogDev($"UpdateSuitView _curSelectIndex {_curSelectIndex}");
- _ui.m_list.selectedIndex = _curSelectIndex;
- _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
- //索引修复,这个列表用了特殊的做法,左边屏幕外添加了一个无用的项
- _ui.m_btnRight.visible = _curSelectIndex < _ui.m_list.numItems - 2 ? true : false;
- UpdateRedDot();
- }
- private void UpdateRedDot()
- {
- bool leftRed = false;
- bool rightRed = false;
- List<VipCfg> vipCfgs = CommonDataManager.Tables.TblVipCfg.DataList;
- for (int i = 1; i < vipCfgs.Count; i++)
- {
- bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus),
- vipCfgs[i].Id);
- bool red = !isGet && RoleDataManager.vipLv >= vipCfgs[i].Id;
- if (red && _curSelectIndex > i - 1)
- {
- leftRed = true;
- }
- if (red && _curSelectIndex + 1 < i)
- {
- rightRed = true;
- }
- }
- if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 &&
- RoleDataManager.vipLv > 0 && _curSelectIndex > RoleDataManager.vipLv - 1)
- {
- leftRed = true;
- }
- if (GameGlobal.myNumericComponent.GetAsInt(NumericType.VipWeekGetStatus) == 0 &&
- RoleDataManager.vipLv > 0 && _curSelectIndex + 1 < RoleDataManager.vipLv)
- {
- rightRed = true;
- }
- RedDotController.Instance.SetComRedDot(_ui.m_btnLeft, leftRed);
- RedDotController.Instance.SetComRedDot(_ui.m_btnRight, rightRed);
- }
- private void OnListItemClick(EventContext context)
- {
- GComponent comItem = (context.data as GComponent);
- ItemCfg itemCfg = comItem.data as ItemCfg;
- GoodsItemTipsController.ShowItemTips(itemCfg.Id);
- }
- }
- }
|