LeagueSkillUpView.cs 13 KB

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