LeagueSkillUpView.cs 12 KB

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