LeagueSkillUpView.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using UI.CommonGame;
  6. using UI.League;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. //联盟技能激活
  11. public class LeagueSkillUpView : BaseWindow
  12. {
  13. private UI_LeagueSkillUpUI _ui;
  14. private ValueBarController _valueBarController;
  15. private EffectUI _effectUI1;
  16. private EffectUI _effectUI2;
  17. private EffectUI _effectUI3;
  18. private List<GameObject> _gameObjects = new List<GameObject>();
  19. private List<GoWrapper> _wrappers = new List<GoWrapper>();
  20. private List<GComponent> _items = new List<GComponent>();
  21. private int _pageCount;
  22. private int _type;
  23. public override void Dispose()
  24. {
  25. EffectUIPool.Recycle(_effectUI1);
  26. _effectUI1 = null;
  27. EffectUIPool.Recycle(_effectUI2);
  28. _effectUI2 = null;
  29. EffectUIPool.Recycle(_effectUI3);
  30. _effectUI3 = null;
  31. // for (int i = 0; i < _gameObjects.Count; i++)
  32. // {
  33. // SceneController.DestroyObjectFromView(_gameObjects[i], _wrappers[i]);
  34. // }
  35. if (_valueBarController != null)
  36. {
  37. _valueBarController.Dispose();
  38. _valueBarController = null;
  39. }
  40. if (_ui != null)
  41. {
  42. _ui.Dispose();
  43. _ui = null;
  44. }
  45. base.Dispose();
  46. }
  47. protected override void OnInit()
  48. {
  49. base.OnInit();
  50. packageName = UI_LeagueSkillUpUI.PACKAGE_NAME;
  51. _ui = UI_LeagueSkillUpUI.Create();
  52. this.viewCom = _ui.target;
  53. isfullScreen = true;
  54. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  55. _ui.m_comSkill.m_listScore.itemRenderer = RenderListScoreItem;
  56. _ui.m_comSkill.m_list.itemRenderer = RenderListItem;
  57. _ui.m_comSkill.m_list.SetVirtual();
  58. _ui.m_comSkill.m_list.scrollPane.decelerationRate = 0.8f;
  59. _ui.m_comSkill.m_btnLeft.onClick.Add(OnBtnLeftClick);
  60. _ui.m_comSkill.m_btnRight.onClick.Add(OnBtnRightClick);
  61. _valueBarController = new ValueBarController(_ui.m_comValue);
  62. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("lm_ch_jnbg");
  63. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_league", "TEA");
  64. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderSkill, "ui_league", "tea_unlock");
  65. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_holderScore, "ui_league", "tea_unlock");
  66. }
  67. protected override void AddEventListener()
  68. {
  69. base.AddEventListener();
  70. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateView);
  71. }
  72. protected override void OnShown()
  73. {
  74. base.OnShown();
  75. _type = (int)this.viewData;
  76. _valueBarController.OnShown();
  77. _valueBarController.Controller(11);
  78. _ui.m_t0.Play(() =>
  79. {
  80. _ui.m_comSkill.m_list.numItems = LeagueSkillCountCfgArray.Instance.GetCfg(_type).layerCount;
  81. UpdateView(false);
  82. });
  83. }
  84. protected override void OnHide()
  85. {
  86. base.OnHide();
  87. _valueBarController.OnHide();
  88. if (_ui.m_comSkill.m_list.numItems > 0) _ui.m_comSkill.m_list.ScrollToView(0);
  89. _ui.m_comSkill.m_list.numItems = 0;
  90. _ui.m_t0.Stop();
  91. _ui.m_t1.Stop();
  92. DestroySkillAni();
  93. }
  94. private void DestroySkillAni()
  95. {
  96. for (int i = 0; i < _gameObjects.Count; i++)
  97. {
  98. SceneController.DestroyObjectFromView(_gameObjects[i], _wrappers[i]);
  99. _items[i].RemoveChildAt(4);
  100. }
  101. _gameObjects.Clear();
  102. _wrappers.Clear();
  103. _items.Clear();
  104. }
  105. protected override void RemoveEventListener()
  106. {
  107. base.RemoveEventListener();
  108. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateView);
  109. }
  110. private void OnBtnBackClick()
  111. {
  112. ViewManager.GoBackFrom(typeof(LeagueSkillUpView).FullName);
  113. }
  114. private void OnBtnRightClick()
  115. {
  116. int index = _ui.m_comSkill.m_list.GetFirstChildInView();
  117. int curPage = index / _ui.m_comSkill.m_list.lineCount;
  118. int nextPage = curPage + 1;
  119. if (nextPage * _ui.m_comSkill.m_list.lineCount > _ui.m_comSkill.m_list.numItems - 1) return;
  120. _ui.m_comSkill.m_list.ScrollToView(nextPage * _ui.m_comSkill.m_list.lineCount, true);
  121. Debug.Log("curPage:" + nextPage);
  122. }
  123. private void OnBtnLeftClick()
  124. {
  125. int index = _ui.m_comSkill.m_list.GetFirstChildInView();
  126. int curPage = index / _ui.m_comSkill.m_list.lineCount;
  127. int lastPage = curPage - 1;
  128. if (lastPage * _ui.m_comSkill.m_list.lineCount < 0) return;
  129. _ui.m_comSkill.m_list.ScrollToView(lastPage * _ui.m_comSkill.m_list.lineCount, true);
  130. Debug.Log("curPage:" + lastPage);
  131. }
  132. private void UpdateView()
  133. {
  134. UpdateView(true);
  135. }
  136. private void UpdateView(bool showAni)
  137. {
  138. if (LeagueDataManager.Instance.GetSkillProgressByType(_type) < 100 && LeagueDataManager.Instance.GetSkillProgressByType(_type) > 0)
  139. {
  140. if (LeagueDataManager.Instance.CurLayer == _ui.m_comSkill.m_list.numItems)//最后一层
  141. {
  142. _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1, showAni);
  143. }
  144. else
  145. {
  146. bool isActive = true;
  147. List<LeagueSkillCfg> skillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, LeagueDataManager.Instance.CurLayer);
  148. for (int i = 0; i < skillCfgs.Count; i++)
  149. {
  150. if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillCfgs[i].id) < 0)
  151. {
  152. isActive = false;
  153. break;
  154. }
  155. }
  156. if (isActive)
  157. {
  158. _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer, showAni);
  159. }
  160. else
  161. {
  162. _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1, showAni);
  163. }
  164. }
  165. // _ui.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1);
  166. }
  167. _ui.m_comSkill.m_listScore.numItems = 4;
  168. _ui.m_comSkill.m_list.RefreshVirtualList();
  169. _ui.m_txtTitle.text = "茶艺-" + LeagueSkillCountCfgArray.Instance.GetCfg(_type).name;
  170. double progress = LeagueDataManager.Instance.GetSkillProgressByType(_type);
  171. _ui.m_txtProgress.SetVar("value", progress.ToString()).FlushVars();
  172. }
  173. private void RenderListScoreItem(int index, GObject obj)
  174. {
  175. UI_ListScoreItem item = UI_ListScoreItem.Proxy(obj);
  176. item.m_loaIcon.url = ResPathUtil.GetScorePath(index + 1);
  177. item.m_txtProperty.text = LeagueDataManager.Instance.GetSkillScoreByType(_type, index + 1).ToString();
  178. UI_ListScoreItem.ProxyEnd();
  179. }
  180. private void RenderListItem(int index, GObject obj)
  181. {
  182. List<LeagueSkillCfg> skillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, index + 1);
  183. UI_ListSkillLayerItem item = UI_ListSkillLayerItem.Proxy(obj);
  184. if (item.m_listSkill.data == null)
  185. {
  186. item.m_listSkill.itemRenderer = RenderListSkillItem;
  187. }
  188. if (LeagueDataManager.Instance.CurLayer == index + 1)
  189. {
  190. DestroySkillAni();
  191. }
  192. item.m_listSkill.data = skillCfgs;
  193. item.m_listSkill.numItems = skillCfgs.Count;
  194. UI_ListSkillLayerItem.ProxyEnd();
  195. }
  196. private void RenderListSkillItem(int index, GObject obj)
  197. {
  198. List<LeagueSkillCfg> skillCfgs = obj.parent.data as List<LeagueSkillCfg>;
  199. UI_ListSkillItem item = UI_ListSkillItem.Proxy(obj);
  200. item.m_loaScore.url = ResPathUtil.GetScorePath(skillCfgs[index].score);
  201. item.m_txtScore.text = "+" + skillCfgs[index].value.ToString();
  202. item.m_loaIcon.url = string.Format("ui://League/tb_jn_{0}", _type);
  203. bool isLock = !SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillCfgs[index].id) < 0;
  204. item.m_imgLock.visible = isLock;
  205. bool canActive = true;
  206. List<LeagueSkillCfg> lastSkillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, skillCfgs[index].layer - 1);
  207. for (int i = 0; i < lastSkillCfgs.Count; i++)
  208. {
  209. if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(lastSkillCfgs[i].id) < 0)
  210. {
  211. canActive = false;
  212. break;
  213. }
  214. }
  215. item.m_imgSuo.visible = !canActive;
  216. if (isLock && canActive && _gameObjects.Count <= index)
  217. {
  218. EffectUI _effectUI;
  219. GGraph holder = new GGraph();
  220. holder.SetSize(1, 1);
  221. holder.SetPosition(80, 80, 0);
  222. holder.name = "holder";
  223. item.target.AddChildAt(holder, 4);
  224. _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_league", "tea_nolearn");
  225. EffectUIPool.Recycle(_effectUI);
  226. _effectUI = null;
  227. _items.Add(item.target);
  228. }
  229. GObject gObject = item.target.GetChild("holder");
  230. if (gObject != null)
  231. {
  232. gObject.visible = isLock && canActive;
  233. }
  234. ItemUtil.UpdateItemNeedNum(item.m_comCost, skillCfgs[index].consumeArr[0], false, "#FFFBF4");
  235. if (item.target.data == null)
  236. {
  237. item.target.onClick.Add(OnActiveSkill);
  238. }
  239. item.target.data = skillCfgs[index].id;
  240. UI_ListSkillItem.ProxyEnd();
  241. }
  242. private async void OnActiveSkill(EventContext context)
  243. {
  244. GObject obj = context.sender as GObject;
  245. int skillId = (int)obj.data;
  246. if (SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) && SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillId) >= 0)
  247. {
  248. return;
  249. }
  250. LeagueSkillCfg skillCfg = LeagueSkillCfgArray.Instance.GetCfg(skillId);
  251. List<LeagueSkillCfg> lastSkillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, skillCfg.layer - 1);
  252. for (int i = 0; i < lastSkillCfgs.Count; i++)
  253. {
  254. if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(lastSkillCfgs[i].id) < 0)
  255. {
  256. return;
  257. }
  258. }
  259. long needCount = skillCfg.consumeArr[0][1];
  260. long hasCount = ItemDataManager.GetItemNum(skillCfg.consumeArr[0][0]);
  261. if (hasCount < needCount)
  262. {
  263. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  264. return;
  265. }
  266. bool result = await SkillSProxy.ReqActiveSkill(SkillType.LeagueSkill, skillId);
  267. if (result)
  268. {
  269. Vector2 posInSkill = obj.TransformPoint(new Vector2(obj.width / 2, obj.height / 2), _ui.target);
  270. _ui.m_holderSkill.position = posInSkill;
  271. GObject scoreObj = _ui.m_comSkill.m_listScore.GetChildAt(skillCfg.score - 1);
  272. Vector2 posInScore = scoreObj.TransformPoint(new Vector2(scoreObj.width / 2, scoreObj.height / 2), _ui.target);
  273. _ui.m_holderScore.position = posInScore;
  274. _ui.m_t1.Play();
  275. UpdateView(true);
  276. }
  277. }
  278. }
  279. }