LeagueSkillUpView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. UpdateView(false);
  85. });
  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. UpdateView(true);
  138. }
  139. private void UpdateView(bool showAni)
  140. {
  141. if (LeagueDataManager.Instance.GetSkillProgressByType(_type) < 100 && LeagueDataManager.Instance.GetSkillProgressByType(_type) > 0)
  142. {
  143. if (LeagueDataManager.Instance.CurLayer == _ui.m_comSkill.m_list.numItems)//最后一层
  144. {
  145. _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1, showAni);
  146. }
  147. else
  148. {
  149. bool isActive = true;
  150. List<LeagueSkillCfg> skillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, LeagueDataManager.Instance.CurLayer);
  151. for (int i = 0; i < skillCfgs.Count; i++)
  152. {
  153. if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillCfgs[i].id) < 0)
  154. {
  155. isActive = false;
  156. break;
  157. }
  158. }
  159. if (isActive)
  160. {
  161. _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer, showAni);
  162. }
  163. else
  164. {
  165. _ui.m_comSkill.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1, showAni);
  166. }
  167. }
  168. // _ui.m_list.ScrollToView(LeagueDataManager.Instance.CurLayer - 1);
  169. }
  170. _ui.m_comSkill.m_listScore.numItems = 4;
  171. _ui.m_comSkill.m_list.RefreshVirtualList();
  172. _ui.m_txtTitle.text = "茶艺-" + LeagueSkillCountCfgArray.Instance.GetCfg(_type).name;
  173. double progress = LeagueDataManager.Instance.GetSkillProgressByType(_type);
  174. _ui.m_txtProgress.SetVar("value", progress.ToString()).FlushVars();
  175. }
  176. private void RenderListScoreItem(int index, GObject obj)
  177. {
  178. UI_ListScoreItem item = UI_ListScoreItem.Proxy(obj);
  179. item.m_loaIcon.url = ResPathUtil.GetScorePath(index + 1);
  180. item.m_txtProperty.text = LeagueDataManager.Instance.GetSkillScoreByType(_type, index + 1).ToString();
  181. UI_ListScoreItem.ProxyEnd();
  182. }
  183. private void RenderListItem(int index, GObject obj)
  184. {
  185. List<LeagueSkillCfg> skillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, index + 1);
  186. UI_ListSkillLayerItem item = UI_ListSkillLayerItem.Proxy(obj);
  187. if (item.m_listSkill.data == null)
  188. {
  189. item.m_listSkill.itemRenderer = RenderListSkillItem;
  190. }
  191. if (LeagueDataManager.Instance.CurLayer == index + 1)
  192. {
  193. DestroySkillAni();
  194. }
  195. item.m_listSkill.data = skillCfgs;
  196. item.m_listSkill.numItems = skillCfgs.Count;
  197. UI_ListSkillLayerItem.ProxyEnd();
  198. }
  199. private void RenderListSkillItem(int index, GObject obj)
  200. {
  201. List<LeagueSkillCfg> skillCfgs = obj.parent.data as List<LeagueSkillCfg>;
  202. UI_ListSkillItem item = UI_ListSkillItem.Proxy(obj);
  203. item.m_loaScore.url = ResPathUtil.GetScorePath(skillCfgs[index].score);
  204. item.m_txtScore.text = "+" + skillCfgs[index].value.ToString();
  205. item.m_loaIcon.url = string.Format("ui://League/tb_jn_{0}", _type);
  206. bool isLock = !SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillCfgs[index].id) < 0;
  207. item.m_imgLock.visible = isLock;
  208. bool canActive = true;
  209. List<LeagueSkillCfg> lastSkillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, skillCfgs[index].layer - 1);
  210. for (int i = 0; i < lastSkillCfgs.Count; i++)
  211. {
  212. if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(lastSkillCfgs[i].id) < 0)
  213. {
  214. canActive = false;
  215. break;
  216. }
  217. }
  218. item.m_imgSuo.visible = !canActive;
  219. if (isLock && canActive && _gameObjects.Count <= index)
  220. {
  221. GameObject gameObject = null;
  222. GoWrapper wrapper = null;
  223. GGraph holder = new GGraph();
  224. holder.SetSize(1, 1);
  225. holder.SetPosition(80, 80, 0);
  226. holder.name = "holder";
  227. item.target.AddChildAt(holder, 4);
  228. string resPath = ResPathUtil.GetViewEffectPath("ui_league", "tea_nolearn");
  229. SceneController.AddObjectToView(gameObject, wrapper, holder, resPath, out gameObject, out wrapper, 100);
  230. _gameObjects.Add(gameObject);
  231. _wrappers.Add(wrapper);
  232. _items.Add(item.target);
  233. }
  234. GObject gObject = item.target.GetChild("holder");
  235. if (gObject != null)
  236. {
  237. gObject.visible = isLock && canActive;
  238. }
  239. ItemUtil.UpdateItemNeedNum(item.m_comCost, skillCfgs[index].consumeArr[0], false, "#FFFBF4");
  240. if (item.target.data == null)
  241. {
  242. item.target.onClick.Add(OnActiveSkill);
  243. }
  244. item.target.data = skillCfgs[index].id;
  245. UI_ListSkillItem.ProxyEnd();
  246. }
  247. private async void OnActiveSkill(EventContext context)
  248. {
  249. GObject obj = context.sender as GObject;
  250. int skillId = (int)obj.data;
  251. if (SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) && SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(skillId) >= 0)
  252. {
  253. return;
  254. }
  255. LeagueSkillCfg skillCfg = LeagueSkillCfgArray.Instance.GetCfg(skillId);
  256. List<LeagueSkillCfg> lastSkillCfgs = LeagueSkillCfgArray.Instance.GetCfgsBytypeAndlayer(_type, skillCfg.layer - 1);
  257. for (int i = 0; i < lastSkillCfgs.Count; i++)
  258. {
  259. if (!SkillDataManager.Instance.LeagueSkillDatas.ContainsKey(_type) || SkillDataManager.Instance.LeagueSkillDatas[_type].IndexOf(lastSkillCfgs[i].id) < 0)
  260. {
  261. return;
  262. }
  263. }
  264. long needCount = skillCfg.consumeArr[0][1];
  265. long hasCount = ItemDataManager.GetItemNum(skillCfg.consumeArr[0][0]);
  266. if (hasCount < needCount)
  267. {
  268. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  269. return;
  270. }
  271. bool result = await SkillSProxy.ReqActiveSkill(SkillType.LeagueSkill, skillId);
  272. if (result)
  273. {
  274. Vector2 posInSkill = obj.TransformPoint(new Vector2(obj.width / 2, obj.height / 2), _ui.target);
  275. _ui.m_holderSkill.position = posInSkill;
  276. GObject scoreObj = _ui.m_comSkill.m_listScore.GetChildAt(skillCfg.score - 1);
  277. Vector2 posInScore = scoreObj.TransformPoint(new Vector2(scoreObj.width / 2, scoreObj.height / 2), _ui.target);
  278. _ui.m_holderScore.position = posInScore;
  279. _ui.m_t1.Play();
  280. UpdateView(true);
  281. }
  282. }
  283. }
  284. }