CardUpView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using FairyGUI;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UI.Card;
  5. using UI.CommonGame;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class CardUpView : BaseWindow
  10. {
  11. private UI_CardUpUI _ui;
  12. private Dictionary<int, int> _scores;
  13. private string _type;
  14. private int _lastNum;
  15. private int _curNum;
  16. private int _cardId;
  17. private CardLvlCfg _cardLvCfg;
  18. private CardStarCfg _cardStarCfg;
  19. private int _mainScore = 0;
  20. private int _otherScore = 0;
  21. private int _itemCfgMainScore = 0;
  22. public override void Dispose()
  23. {
  24. if (_ui != null)
  25. {
  26. _ui.Dispose();
  27. _ui = null;
  28. }
  29. base.Dispose();
  30. }
  31. protected override void OnInit()
  32. {
  33. base.OnInit();
  34. _ui = UI_CardUpUI.Create();
  35. this.viewCom = _ui.target;
  36. this.viewCom.Center();
  37. this.modal = true;
  38. //MakeFullScreen(_ui);
  39. _ui.m_bgTouch.onClick.Add(OnBackClick);
  40. _ui.m_listProperty.itemRenderer = RenderListPropertyItem;
  41. _ui.m_listLastProperty.itemRenderer = RenderListLastPropertyItem;
  42. _ui.m_listCardProperty.itemRenderer = RenderListCardPropertyItem;
  43. _ui.m_listLastCardProperty.itemRenderer = RenderListLastCardPropertyItem;
  44. }
  45. private void OnBackClick()
  46. {
  47. this.Hide();
  48. }
  49. protected override void OnShown()
  50. {
  51. base.OnShown();
  52. _scores = (Dictionary<int, int>)(viewData as object[])[0];
  53. _type = (string)(viewData as object[])[1];
  54. _lastNum = (int)(viewData as object[])[2];
  55. _curNum = (int)(viewData as object[])[3];
  56. _cardId = (int)(viewData as object[])[4];
  57. if (_type == "lv")
  58. {
  59. _ui.m_c1.selectedIndex = 0;
  60. _ui.m_txtLast.text = string.Format("{0}级", _lastNum);
  61. _ui.m_txtNow.text = string.Format("{0}级", _curNum);
  62. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cardId);
  63. _cardLvCfg = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(itemCfg.rarity, _lastNum);
  64. _cardStarCfg = null;
  65. _itemCfgMainScore = itemCfg.mainScore;
  66. _mainScore = 0;
  67. _otherScore = 0;
  68. for (int i = _lastNum; i < _curNum; i++)
  69. {
  70. CardLvlCfg cardLvCfg = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(itemCfg.rarity, i);
  71. _mainScore += cardLvCfg.mainScore;
  72. _otherScore += cardLvCfg.otherScore;
  73. }
  74. _ui.m_listProperty.numItems = _scores.Count;
  75. _ui.m_listLastProperty.numItems = _scores.Count;
  76. }
  77. else if (_type == "star")
  78. {
  79. _ui.m_c1.selectedIndex = 1;
  80. _ui.m_txtLast.text = string.Format("{0}星", _lastNum / 5);
  81. _ui.m_txtNow.text = string.Format("{0}星", _curNum / 5);
  82. _cardStarCfg = CardStarCfgArray.Instance.GetCfgBycardIdAndstarLvl(_cardId, _lastNum);
  83. if (_cardStarCfg == null)
  84. ET.Log.Error("RenderListCardPropertyItemd _cardStarCfg 1 is null=" + _cardId + "==" + _lastNum);
  85. _cardLvCfg = null;
  86. _ui.m_listCardProperty.numItems = 1;
  87. _ui.m_listLastCardProperty.numItems = 1;
  88. }
  89. else {
  90. _ui.m_c1.selectedIndex = 2;
  91. _cardStarCfg = CardStarCfgArray.Instance.GetCfgBycardIdAndstarLvl(_cardId, _lastNum);
  92. if (_cardStarCfg == null)
  93. ET.Log.Error("RenderListCardPropertyItemd _cardStarCfg 2 is null=" + _cardId + "==" + _lastNum);
  94. _cardLvCfg = null;
  95. _ui.m_listCardProperty.numItems = 1;
  96. _ui.m_listLastCardProperty.numItems = 1;
  97. }
  98. Timers.inst.AddUpdate(CheckGuide);
  99. }
  100. private void RenderListLastCardPropertyItem(int index, GObject obj)
  101. {
  102. UI_ListScoreItem2 listItem = UI_ListScoreItem2.Proxy(obj);
  103. int score = 0;
  104. int typeIndex = 1;
  105. listItem.m_ArrowsType.selectedIndex = 2;
  106. if (_cardStarCfg.score1 > 0) {
  107. typeIndex = 1;
  108. score = _scores[typeIndex] - _cardStarCfg.score1;
  109. }
  110. else if (_cardStarCfg.score2 > 0)
  111. {
  112. typeIndex = 2;
  113. score = _scores[typeIndex] - _cardStarCfg.score2;
  114. }
  115. else if (_cardStarCfg.score3 > 0)
  116. {
  117. typeIndex = 3;
  118. score = _scores[typeIndex] - _cardStarCfg.score3;
  119. }
  120. else if (_cardStarCfg.score4 > 0)
  121. {
  122. typeIndex = 4;
  123. score = _scores[typeIndex] - _cardStarCfg.score4;
  124. }
  125. listItem.m_txtProperty.text = score.ToString();
  126. listItem.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (typeIndex));
  127. UI_ListScoreItem2.ProxyEnd();
  128. }
  129. private void RenderListLastPropertyItem(int index, GObject obj)
  130. {
  131. UI_ListScoreItem2 listItem = UI_ListScoreItem2.Proxy(obj);
  132. int score = 0;
  133. listItem.m_ArrowsType.selectedIndex = 1;
  134. if ((index + 1) == _itemCfgMainScore)
  135. score = _scores[index + 1] - _mainScore;
  136. else
  137. score = _scores[index + 1] - _otherScore;
  138. listItem.m_txtProperty.text = score.ToString();
  139. listItem.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (index + 1));
  140. UI_ListScoreItem2.ProxyEnd();
  141. }
  142. private void RenderListPropertyItem(int index, GObject obj)
  143. {
  144. UI_ListScoreItem2 listItem = UI_ListScoreItem2.Proxy(obj);
  145. listItem.m_txtProperty.text = _scores[index + 1].ToString();
  146. listItem.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (index + 1));
  147. UI_ListScoreItem2.ProxyEnd();
  148. }
  149. private void RenderListCardPropertyItem(int index, GObject obj)
  150. {
  151. UI_ListScoreItem2 listItem = UI_ListScoreItem2.Proxy(obj);
  152. if (_cardStarCfg == null)
  153. ET.Log.Error("RenderListCardPropertyItemd _cardStarCfg is null");
  154. int typeIndex = 1;
  155. if (_cardStarCfg.score1 > 0)
  156. typeIndex = 1;
  157. else if (_cardStarCfg.score2 > 0)
  158. typeIndex = 2;
  159. else if (_cardStarCfg.score3 > 0)
  160. typeIndex = 3;
  161. else if (_cardStarCfg.score4 > 0)
  162. typeIndex = 4;
  163. _scores.TryGetValue(typeIndex, out var scoresValue);
  164. listItem.m_txtProperty.text = scoresValue.ToString();
  165. listItem.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + typeIndex);
  166. UI_ListScoreItem2.ProxyEnd();
  167. }
  168. protected override void OnHide()
  169. {
  170. base.OnHide();
  171. Timers.inst.Remove(CheckGuide);
  172. }
  173. private void CheckGuide(object param)
  174. {
  175. if (GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_LV) <= 0
  176. || GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_STAR) <= 0)
  177. {
  178. UpdateToCheckGuide(null);
  179. }
  180. else
  181. {
  182. Timers.inst.Remove(CheckGuide);
  183. }
  184. }
  185. protected override void UpdateToCheckGuide(object param)
  186. {
  187. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  188. GuideController.TryGuide(null, ConstGuideId.UP_CARD_LV, 6, "升级成功啦", -1, true, 1500);
  189. GuideController.TryGuide(null, ConstGuideId.UP_CARD_STAR, 6, "升星成功啦", -1, true, 1500);
  190. }
  191. }
  192. }