LeagueSkillUpView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 GameObject _gameObject0;
  16. private GameObject _gameObject1;
  17. private GameObject _gameObject2;
  18. private GoWrapper _wrapper0;
  19. private GoWrapper _wrapper1;
  20. private GoWrapper _wrapper2;
  21. private int _pageCount;
  22. private int _type;
  23. public override void Dispose()
  24. {
  25. SceneController.DestroyObjectFromView(_gameObject0, _wrapper0);
  26. SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
  27. SceneController.DestroyObjectFromView(_gameObject2, _wrapper2);
  28. if (_valueBarController != null)
  29. {
  30. _valueBarController.Dispose();
  31. _valueBarController = null;
  32. }
  33. if (_ui != null)
  34. {
  35. _ui.Dispose();
  36. _ui = null;
  37. }
  38. base.Dispose();
  39. }
  40. protected override void OnInit()
  41. {
  42. base.OnInit();
  43. packageName = UI_LeagueSkillUpUI.PACKAGE_NAME;
  44. _ui = UI_LeagueSkillUpUI.Create();
  45. this.viewCom = _ui.target;
  46. isfullScreen = true;
  47. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  48. _ui.m_comSkill.m_listScore.itemRenderer = RenderListScoreItem;
  49. _ui.m_comSkill.m_list.itemRenderer = RenderListItem;
  50. _ui.m_comSkill.m_list.SetVirtual();
  51. _ui.m_comSkill.m_list.scrollPane.decelerationRate = 0.8f;
  52. _ui.m_comSkill.m_btnLeft.onClick.Add(OnBtnLeftClick);
  53. _ui.m_comSkill.m_btnRight.onClick.Add(OnBtnRightClick);
  54. _valueBarController = new ValueBarController(_ui.m_comValue);
  55. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("lm_ch_jnbg");
  56. string resPath = ResPathUtil.GetViewEffectPath("ui_league", "TEA");
  57. SceneController.AddObjectToView(null, null, _ui.m_holder, resPath, out _gameObject0, out _wrapper0);
  58. string resPath1 = ResPathUtil.GetViewEffectPath("ui_league", "tea_unlock");
  59. SceneController.AddObjectToView(null, null, _ui.m_holderSkill, resPath1, out _gameObject1, out _wrapper1);
  60. string resPath2 = ResPathUtil.GetViewEffectPath("ui_league", "tea_unlock");
  61. SceneController.AddObjectToView(null, null, _ui.m_holderScore, resPath2, out _gameObject2, out _wrapper2, 90);
  62. }
  63. protected override void AddEventListener()
  64. {
  65. base.AddEventListener();
  66. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateView);
  67. }
  68. protected override void OnShown()
  69. {
  70. base.OnShown();
  71. _type = (int)this.viewData;
  72. _valueBarController.OnShown();
  73. _valueBarController.Controller(11);
  74. _ui.m_comSkill.m_list.numItems = LeagueSkillCountCfgArray.Instance.GetCfg(_type).layerCount;
  75. _ui.m_t0.Play();
  76. UpdateView();
  77. }
  78. protected override void OnHide()
  79. {
  80. base.OnHide();
  81. _valueBarController.OnHide();
  82. if (_ui.m_comSkill.m_list.numItems > 0) _ui.m_comSkill.m_list.ScrollToView(0);
  83. _ui.m_t0.Stop();
  84. _ui.m_t1.Stop();
  85. }
  86. protected override void RemoveEventListener()
  87. {
  88. base.RemoveEventListener();
  89. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateView);
  90. }
  91. private void OnBtnBackClick()
  92. {
  93. ViewManager.GoBackFrom(typeof(LeagueSkillUpView).FullName);
  94. }
  95. private void OnBtnRightClick()
  96. {
  97. int index = _ui.m_comSkill.m_list.GetFirstChildInView();
  98. int curPage = index / _ui.m_comSkill.m_list.lineCount;
  99. int nextPage = curPage + 1;
  100. if (nextPage * _ui.m_comSkill.m_list.lineCount > _ui.m_comSkill.m_list.numItems - 1) return;
  101. _ui.m_comSkill.m_list.ScrollToView(nextPage * _ui.m_comSkill.m_list.lineCount, true);
  102. Debug.Log("curPage:" + nextPage);
  103. }
  104. private void OnBtnLeftClick()
  105. {
  106. int index = _ui.m_comSkill.m_list.GetFirstChildInView();
  107. int curPage = index / _ui.m_comSkill.m_list.lineCount;
  108. int lastPage = curPage - 1;
  109. if (lastPage * _ui.m_comSkill.m_list.lineCount < 0) return;
  110. _ui.m_comSkill.m_list.ScrollToView(lastPage * _ui.m_comSkill.m_list.lineCount, true);
  111. Debug.Log("curPage:" + lastPage);
  112. }
  113. private void UpdateView()
  114. {
  115. if (LeagueDataManager.Instance.GetSkillProgressByType(_type) < 100 && LeagueDataManager.Instance.GetSkillProgressByType(_type) > 0)
  116. {
  117. if (LeagueDataManager.Instance.CurLayer == _ui.m_comSkill.m_list.numItems)
  118. {
  119. _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1);
  120. }
  121. else
  122. {
  123. bool isActive = true;
  124. List<LeagueSkillCfg> skillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, LeagueDataManager.Instance.CurLayer);
  125. for (int i = 0; i < skillCfgs.Count; i++)
  126. {
  127. if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillCfgs[i].id) < 0)
  128. {
  129. isActive = false;
  130. break;
  131. }
  132. }
  133. if (isActive)
  134. {
  135. _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer);
  136. }
  137. else
  138. {
  139. _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1);
  140. }
  141. }
  142. // _ui.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1);
  143. }
  144. _ui.m_comSkill.m_listScore.numItems = 4;
  145. _ui.m_comSkill.m_list.RefreshVirtualList();
  146. _ui.m_txtTitle.text = "茶艺-" + LeagueSkillCountCfgArray.Instance.GetCfg(_type).name;
  147. double progress = LeagueDataManager.Instance.GetSkillProgressByType(_type);
  148. _ui.m_txtProgress.SetVar("value", progress.ToString()).FlushVars();
  149. }
  150. private void RenderListScoreItem(int index, GObject obj)
  151. {
  152. UI_ListScoreItem item = UI_ListScoreItem.Proxy(obj);
  153. item.m_loaIcon.url = ResPathUtil.GetScorePath(index + 1);
  154. item.m_txtProperty.text = LeagueDataManager.Instance.GetSkillScoreByType(_type, index + 1).ToString();
  155. UI_ListScoreItem.ProxyEnd();
  156. }
  157. private void RenderListItem(int index, GObject obj)
  158. {
  159. List<LeagueSkillCfg> skillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, index + 1);
  160. UI_ListSkillLayerItem item = UI_ListSkillLayerItem.Proxy(obj);
  161. if (item.m_listSkill.data == null)
  162. {
  163. item.m_listSkill.itemRenderer = RenderListSkillItem;
  164. }
  165. item.m_listSkill.data = skillCfgs;
  166. item.m_listSkill.numItems = skillCfgs.Count;
  167. UI_ListSkillLayerItem.ProxyEnd();
  168. }
  169. private void RenderListSkillItem(int index, GObject obj)
  170. {
  171. List<LeagueSkillCfg> skillCfgs = obj.parent.data as List<LeagueSkillCfg>;
  172. UI_ListSkillItem item = UI_ListSkillItem.Proxy(obj);
  173. item.m_loaScore.url = ResPathUtil.GetScorePath(skillCfgs[index].score);
  174. item.m_txtScore.text = "+" + skillCfgs[index].value.ToString();
  175. bool isLock = !SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillCfgs[index].id) < 0;
  176. item.m_imgLock.visible = isLock;
  177. bool canActive = true;
  178. List<LeagueSkillCfg> lastSkillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, skillCfgs[index].layer - 1);
  179. for (int i = 0; i < lastSkillCfgs.Count; i++)
  180. {
  181. if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(lastSkillCfgs[i].id) < 0)
  182. {
  183. canActive = false;
  184. break;
  185. }
  186. }
  187. item.m_imgSuo.visible = !canActive;
  188. ItemUtil.UpdateItemNeedNum(item.m_comCost, skillCfgs[index].consumeArr[0], false, "#FFFBF4");
  189. if (item.target.data == null)
  190. {
  191. item.target.onClick.Add(OnActiveSkill);
  192. }
  193. item.target.data = skillCfgs[index].id;
  194. UI_ListSkillItem.ProxyEnd();
  195. }
  196. private async void OnActiveSkill(EventContext context)
  197. {
  198. GObject obj = context.sender as GObject;
  199. int skillId = (int)obj.data;
  200. if (SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) && SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillId) >= 0)
  201. {
  202. return;
  203. }
  204. LeagueSkillCfg skillCfg = LeagueSkillCfgArray.Instance.GetCfg(skillId);
  205. List<LeagueSkillCfg> lastSkillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, skillCfg.layer - 1);
  206. for (int i = 0; i < lastSkillCfgs.Count; i++)
  207. {
  208. if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(lastSkillCfgs[i].id) < 0)
  209. {
  210. return;
  211. }
  212. }
  213. long needCount = skillCfg.consumeArr[0][1];
  214. long hasCount = ItemDataManager.GetItemNum(skillCfg.consumeArr[0][0]);
  215. if (hasCount < needCount)
  216. {
  217. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  218. return;
  219. }
  220. bool result = await SkillSProxy.ReqActiveSkill(SkillType.LeagueSkill, skillId);
  221. if (result)
  222. {
  223. Vector2 posInSkill = obj.TransformPoint(new Vector2(obj.width / 2, obj.height / 2), _ui.target);
  224. _ui.m_holderSkill.position = posInSkill;
  225. GObject scoreObj = _ui.m_comSkill.m_listScore.GetChildAt(skillCfg.score - 1);
  226. Vector2 posInScore = scoreObj.TransformPoint(new Vector2(scoreObj.width / 2, scoreObj.height / 2), _ui.target);
  227. _ui.m_holderScore.position = posInScore;
  228. _ui.m_t1.Play();
  229. UpdateView();
  230. }
  231. }
  232. }
  233. }