123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- using System;
- using System.Collections.Generic;
- 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 GameObject _gameObject0;
- private GameObject _gameObject1;
- private GameObject _gameObject2;
- private GoWrapper _wrapper0;
- private GoWrapper _wrapper1;
- private GoWrapper _wrapper2;
- private List<GameObject> _gameObjects = new List<GameObject>();
- private List<GoWrapper> _wrappers = new List<GoWrapper>();
- private List<GComponent> _items = new List<GComponent>();
- private int _pageCount;
- private int _type;
- public override void Dispose()
- {
- SceneController.DestroyObjectFromView(_gameObject0, _wrapper0);
- SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
- SceneController.DestroyObjectFromView(_gameObject2, _wrapper2);
- // for (int i = 0; i < _gameObjects.Count; i++)
- // {
- // SceneController.DestroyObjectFromView(_gameObjects[i], _wrappers[i]);
- // }
- 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;
- _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_btnLeft.onClick.Add(OnBtnLeftClick);
- _ui.m_comSkill.m_btnRight.onClick.Add(OnBtnRightClick);
- _valueBarController = new ValueBarController(_ui.m_comValue);
- _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("lm_ch_jnbg");
- string resPath = ResPathUtil.GetViewEffectPath("ui_league", "TEA");
- SceneController.AddObjectToView(null, null, _ui.m_holder, resPath, out _gameObject0, out _wrapper0);
- string resPath1 = ResPathUtil.GetViewEffectPath("ui_league", "tea_unlock");
- SceneController.AddObjectToView(null, null, _ui.m_holderSkill, resPath1, out _gameObject1, out _wrapper1);
- string resPath2 = ResPathUtil.GetViewEffectPath("ui_league", "tea_unlock");
- SceneController.AddObjectToView(null, null, _ui.m_holderScore, resPath2, out _gameObject2, out _wrapper2, 90);
- }
- 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);
- _ui.m_t0.Play(() =>
- {
- _ui.m_comSkill.m_list.numItems = LeagueSkillCountCfgArray.Instance.GetCfg(_type).layerCount;
- });
- UpdateView();
- }
- 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 < _gameObjects.Count; i++)
- {
- SceneController.DestroyObjectFromView(_gameObjects[i], _wrappers[i]);
- _items[i].RemoveChildAt(4);
- }
- _gameObjects.Clear();
- _wrappers.Clear();
- _items.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;
- _ui.m_comSkill.m_list.ScrollToView(nextPage * _ui.m_comSkill.m_list.lineCount, true);
- 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;
- _ui.m_comSkill.m_list.ScrollToView(lastPage * _ui.m_comSkill.m_list.lineCount, true);
- Debug.Log("curPage:" + lastPage);
- }
- private void UpdateView()
- {
- 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, true);
- }
- else
- {
- bool isActive = true;
- List<LeagueSkillCfg> skillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, LeagueDataManager.Instance.CurLayer);
- 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, true);
- }
- else
- {
- _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1, true);
- }
- }
- // _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 = "茶艺-" + LeagueSkillCountCfgArray.Instance.GetCfg(_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<LeagueSkillCfg> skillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, index + 1);
- 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<LeagueSkillCfg> skillCfgs = obj.parent.data as List<LeagueSkillCfg>;
- 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<LeagueSkillCfg> lastSkillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, skillCfgs[index].layer - 1);
- 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 (isLock && canActive && _gameObjects.Count <= index)
- {
- GameObject gameObject = null;
- GoWrapper wrapper = null;
- GGraph holder = new GGraph();
- holder.SetSize(1, 1);
- holder.SetPosition(80, 80, 0);
- holder.name = "holder";
- item.target.AddChildAt(holder, 4);
- string resPath = ResPathUtil.GetViewEffectPath("ui_league", "tea_nolearn");
- SceneController.AddObjectToView(gameObject, wrapper, holder, resPath, out gameObject, out wrapper, 100);
- _gameObjects.Add(gameObject);
- _wrappers.Add(wrapper);
- _items.Add(item.target);
- }
- GObject gObject = item.target.GetChild("holder");
- if (gObject != null)
- {
- gObject.visible = isLock && canActive;
- }
- ItemUtil.UpdateItemNeedNum(item.m_comCost, skillCfgs[index].consumeArr[0], 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 = LeagueSkillCfgArray.Instance.GetCfg(skillId);
- List<LeagueSkillCfg> lastSkillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, skillCfg.layer - 1);
- 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.consumeArr[0][1];
- long hasCount = ItemDataManager.GetItemNum(skillCfg.consumeArr[0][0]);
- 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();
- }
- }
- }
- }
|