using System; using System.Collections.Generic; using System.Linq; using cfg.GfgCfg; using ET; using FairyGUI; using UI.CommonGame; using UI.League; using UnityEngine; namespace GFGGame { //联盟技能激活 public class LeagueSkillUpView : BaseWindow { private UI_LeagueSkillUpUI _ui; private ValueBarController _valueBarController; private EffectUI _effectUI1; private EffectUI _effectUI2; private EffectUI _effectUI3; private List _effectUIs = new List(); private int _type; private int saveListPageIndex = 0; private bool _showEff = false; public override void Dispose() { EffectUIPool.Recycle(_effectUI1); _effectUI1 = null; EffectUIPool.Recycle(_effectUI2); _effectUI2 = null; EffectUIPool.Recycle(_effectUI3); _effectUI3 = null; if (_valueBarController != null) { _valueBarController.Dispose(); _valueBarController = null; } if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_LeagueSkillUpUI.PACKAGE_NAME; _ui = UI_LeagueSkillUpUI.Create(); this.viewCom = _ui.target; isfullScreen = true; isReturnView = true; _ui.m_btnBack.onClick.Add(OnBtnBackClick); _ui.m_comSkill.m_listScore.itemRenderer = RenderListScoreItem; _ui.m_comSkill.m_list.itemRenderer = RenderListItem; _ui.m_comSkill.m_list.SetVirtual(); _ui.m_comSkill.m_list.scrollPane.decelerationRate = 0.8f; // _ui.m_comSkill.m_list.onTouchBegin.Add(OnDropDisSkillList); _ui.m_comSkill.m_list.onTouchEnd.Add(OnTouchEndSkillList); _ui.m_comSkill.m_btnLeft.onClick.Add(OnBtnLeftClick); _ui.m_comSkill.m_btnRight.onClick.Add(OnBtnRightClick); _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView); _ui.m_btnRule.data = 300017; _valueBarController = new ValueBarController(_ui.m_comValue); _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("lm_ch_jnbg"); EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_league", "TEA", 110, onComplete: (effect) => { if (effect != null) { _effectUI1 = effect; } }); EffectUIPool.CreateEffectUI(_ui.m_holderSkill, "ui_league", "tea_unlock", onComplete: (effect) => { if (effect != null) { _effectUI2 = effect; } }); EffectUIPool.CreateEffectUI(_ui.m_holderScore, "ui_league", "tea_unlock", onComplete: (effect) => { if (effect != null) { _effectUI3 = effect; } }); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateView); } protected override void OnShown() { base.OnShown(); _type = (int)this.viewData; _valueBarController.OnShown(); _valueBarController.Controller(11); _showEff = false; _ui.m_comSkill.m_list.numItems = CommonDataManager.Tables.TblLeagueSkillCountCfg.GetOrDefault(_type).LayerCount; _ui.m_t0.Play(() => { _showEff = true; _ui.m_comSkill.m_list.numItems = CommonDataManager.Tables.TblLeagueSkillCountCfg.GetOrDefault(_type).LayerCount; UpdateView(false); }); } protected override void OnHide() { base.OnHide(); _valueBarController.OnHide(); if (_ui.m_comSkill.m_list.numItems > 0) _ui.m_comSkill.m_list.ScrollToView(0); _ui.m_comSkill.m_list.numItems = 0; _ui.m_t0.Stop(); _ui.m_t1.Stop(); DestroySkillAni(); } private void DestroySkillAni() { for (int i = 0; i < _effectUIs.Count; i++) { EffectUIPool.Recycle(_effectUIs[i]); _effectUIs[i] = null; } _effectUIs.Clear(); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateView); } private void OnBtnBackClick() { ViewManager.GoBackFrom(typeof(LeagueSkillUpView).FullName); } private void OnBtnRightClick() { int index = _ui.m_comSkill.m_list.GetFirstChildInView(); int curPage = index / _ui.m_comSkill.m_list.lineCount; int nextPage = curPage + 1; if (nextPage * _ui.m_comSkill.m_list.lineCount > _ui.m_comSkill.m_list.numItems - 1) return; DestroySkillAni(); saveListPageIndex = nextPage * _ui.m_comSkill.m_list.lineCount; _ui.m_comSkill.m_list.ScrollToView(saveListPageIndex, true); _ui.m_comSkill.m_list.RefreshVirtualList(); Debug.Log("curPage:" + nextPage); } private void OnBtnLeftClick() { int index = _ui.m_comSkill.m_list.GetFirstChildInView(); int curPage = index / _ui.m_comSkill.m_list.lineCount; int lastPage = curPage - 1; if (lastPage * _ui.m_comSkill.m_list.lineCount < 0) return; DestroySkillAni(); saveListPageIndex = lastPage * _ui.m_comSkill.m_list.lineCount; _ui.m_comSkill.m_list.ScrollToView(saveListPageIndex, true); Debug.Log("curPage:" + lastPage); } private void UpdateView() { UpdateView(true); } private void UpdateView(bool showAni) { if (LeagueDataManager.Instance.GetSkillProgressByType(_type) < 100 && LeagueDataManager.Instance.GetSkillProgressByType(_type) > 0) { if (LeagueDataManager.Instance.CurLayer == _ui.m_comSkill.m_list.numItems) //最后一层 { _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1, showAni); } else { bool isActive = true; List skillCfgs = CommonDataManager.Tables.TblLeagueSkillCfg.DataList.Where(a => a.Type == _type && a.Layer == LeagueDataManager.Instance.CurLayer).ToList(); for (int i = 0; i < skillCfgs.Count; i++) { if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillCfgs[i].Id) < 0) { isActive = false; break; } } if (isActive) { _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer, showAni); } else { _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1, showAni); } } // _ui.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1); } _ui.m_comSkill.m_listScore.numItems = 4; _ui.m_comSkill.m_list.RefreshVirtualList(); _ui.m_txtTitle.text = "茶艺-" + CommonDataManager.Tables.TblLeagueSkillCountCfg.GetOrDefault(_type).Name; double progress = LeagueDataManager.Instance.GetSkillProgressByType(_type); _ui.m_txtProgress.SetVar("value", progress.ToString()).FlushVars(); } private void RenderListScoreItem(int index, GObject obj) { UI_ListScoreItem item = UI_ListScoreItem.Proxy(obj); item.m_loaIcon.url = ResPathUtil.GetScorePath(index + 1); item.m_txtProperty.text = LeagueDataManager.Instance.GetSkillScoreByType(_type, index + 1).ToString(); UI_ListScoreItem.ProxyEnd(); } private void RenderListItem(int index, GObject obj) { List skillCfgs = CommonDataManager.Tables.TblLeagueSkillCfg.DataList.Where(a => a.Type == _type && a.Layer == index + 1) .ToList(); UI_ListSkillLayerItem item = UI_ListSkillLayerItem.Proxy(obj); if (item.m_listSkill.data == null) { item.m_listSkill.itemRenderer = RenderListSkillItem; } if (LeagueDataManager.Instance.CurLayer == index + 1) { DestroySkillAni(); } item.m_listSkill.data = skillCfgs; item.m_listSkill.numItems = skillCfgs.Count; UI_ListSkillLayerItem.ProxyEnd(); } private void RenderListSkillItem(int index, GObject obj) { List skillCfgs = obj.parent.data as List; UI_ListSkillItem item = UI_ListSkillItem.Proxy(obj); item.m_loaScore.url = ResPathUtil.GetScorePath(skillCfgs[index].Score); item.m_txtScore.text = "+" + skillCfgs[index].Value.ToString(); item.m_loaIcon.url = string.Format("ui://League/tb_jn_{0}", _type); bool isLock = !SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillCfgs[index].Id) < 0; item.m_imgLock.visible = isLock; bool canActive = true; List lastSkillCfgs = CommonDataManager.Tables.TblLeagueSkillCfg.DataList .Where(a => a.Type == _type && a.Layer == skillCfgs[index].Layer - 1).ToList(); for (int i = 0; i < lastSkillCfgs.Count; i++) { if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(lastSkillCfgs[i].Id) < 0) { canActive = false; break; } } item.m_imgSuo.visible = !canActive; if (_showEff && isLock && canActive && _effectUIs.Count <= index) { EffectUIPool.CreateEffectUI(item.m_holdeLight, "ui_league", "tea_nolearn", onComplete: (effect) => { if (effect != null) { _effectUIs.Add(effect); } }); } if (isLock && canActive) item.m_c1.selectedIndex = 1; else item.m_c1.selectedIndex = 0; ItemUtil.UpdateItemNeedNum(item.m_comCost, skillCfgs[index].Consume[0].ToGfgGameItemParam(), false, "#FFFBF4"); if (item.target.data == null) { item.target.onClick.Add(OnActiveSkill); } item.target.data = skillCfgs[index].Id; UI_ListSkillItem.ProxyEnd(); } private async void OnActiveSkill(EventContext context) { GObject obj = context.sender as GObject; int skillId = (int)obj.data; if (SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) && SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillId) >= 0) { return; } LeagueSkillCfg skillCfg = CommonDataManager.Tables.TblLeagueSkillCfg.GetOrDefault(skillId); List lastSkillCfgs = CommonDataManager.Tables.TblLeagueSkillCfg.DataList .Where(a => a.Type == _type && a.Layer == skillCfg.Layer - 1).ToList(); for (int i = 0; i < lastSkillCfgs.Count; i++) { if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(lastSkillCfgs[i].Id) < 0) { return; } } long needCount = skillCfg.Consume[0].Count; long hasCount = ItemDataManager.GetItemNum(skillCfg.Consume[0].ItemId); if (hasCount < needCount) { PromptController.Instance.ShowFloatTextPrompt("消耗不足"); return; } bool result = await SkillSProxy.ReqActiveSkill(SkillType.LeagueSkill, skillId); if (result) { Vector2 posInSkill = obj.TransformPoint(new Vector2(obj.width / 2, obj.height / 2), _ui.target); _ui.m_holderSkill.position = posInSkill; GObject scoreObj = _ui.m_comSkill.m_listScore.GetChildAt(skillCfg.Score - 1); Vector2 posInScore = scoreObj.TransformPoint(new Vector2(scoreObj.width / 2, scoreObj.height / 2), _ui.target); _ui.m_holderScore.position = posInScore; _ui.m_t1.Play(); UpdateView(true); } } private void OnTouchEndSkillList(EventContext context) { DestroySkillAni(); _ui.m_comSkill.m_list.RefreshVirtualList(); } // private void OnDropDisSkillList(EventContext context) // { // // } } }