CardUpView.cs 8.0 KB

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