CardUpView.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_listProperty.itemRenderer = RenderListPropertyItem;
  40. _ui.m_listLastProperty.itemRenderer = RenderListLastPropertyItem;
  41. }
  42. protected override void OnShown()
  43. {
  44. base.OnShown();
  45. _scores = (Dictionary<int, int>)(viewData as object[])[0];
  46. _type = (string)(viewData as object[])[1];
  47. _lastNum = (int)(viewData as object[])[2];
  48. _curNum = (int)(viewData as object[])[3];
  49. _cardId = (int)(viewData as object[])[4];
  50. _ui.m_listProperty.numItems = _scores.Count;
  51. if (_type == "lv")
  52. {
  53. _ui.m_c1.selectedIndex = 0;
  54. _ui.m_txtLast.text = string.Format("{0}级", _lastNum);
  55. _ui.m_txtNow.text = string.Format("{0}级", _curNum);
  56. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cardId);
  57. _cardLvCfg = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(itemCfg.rarity, _lastNum);
  58. _cardStarCfg = null;
  59. _itemCfgMainScore = itemCfg.mainScore;
  60. _mainScore = 0;
  61. _otherScore = 0;
  62. for (int i = _lastNum; i < _curNum; i++)
  63. {
  64. CardLvlCfg cardLvCfg = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(itemCfg.rarity, i);
  65. _mainScore += cardLvCfg.mainScore;
  66. _otherScore += cardLvCfg.otherScore;
  67. }
  68. }
  69. else if (_type == "star")
  70. {
  71. _ui.m_c1.selectedIndex = 1;
  72. _ui.m_txtLast.text = string.Format("{0}星", _lastNum / 5);
  73. _ui.m_txtNow.text = string.Format("{0}星", _curNum / 5);
  74. _cardStarCfg = CardStarCfgArray.Instance.GetCfgBycardIdAndstarLvl(_cardId, _lastNum);
  75. _cardLvCfg = null;
  76. }
  77. else {
  78. _ui.m_c1.selectedIndex = 2;
  79. _cardStarCfg = CardStarCfgArray.Instance.GetCfgBycardIdAndstarLvl(_cardId, _lastNum);
  80. _cardLvCfg = null;
  81. }
  82. _ui.m_listLastProperty.numItems = _scores.Count;
  83. Timers.inst.AddUpdate(CheckGuide);
  84. }
  85. private void RenderListLastPropertyItem(int index, GObject obj)
  86. {
  87. UI_ListScoreItem listItem = UI_ListScoreItem.Proxy(obj);
  88. int score = 0;
  89. if (_cardStarCfg != null)
  90. {
  91. if (index == 0)
  92. score = _scores[index + 1] - _cardStarCfg.score1;
  93. else if (index == 1)
  94. score = _scores[index + 1] - _cardStarCfg.score2;
  95. else if (index == 2)
  96. score = _scores[index + 1] - _cardStarCfg.score3;
  97. else if (index == 3)
  98. score = _scores[index + 1] - _cardStarCfg.score4;
  99. }
  100. else {
  101. if ((index + 1) == _itemCfgMainScore)
  102. score = _scores[index + 1] - _mainScore;
  103. else
  104. score = _scores[index + 1] - _otherScore;
  105. }
  106. listItem.m_txtProperty.text = score.ToString();
  107. listItem.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (index + 1));
  108. UI_ListScoreItem.ProxyEnd();
  109. }
  110. private void RenderListPropertyItem(int index, GObject obj)
  111. {
  112. UI_ListScoreItem listItem = UI_ListScoreItem.Proxy(obj);
  113. listItem.m_txtProperty.text = _scores[index + 1].ToString();
  114. listItem.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (index + 1));
  115. UI_ListScoreItem.ProxyEnd();
  116. }
  117. protected override void OnHide()
  118. {
  119. base.OnHide();
  120. Timers.inst.Remove(CheckGuide);
  121. }
  122. private void CheckGuide(object param)
  123. {
  124. if (GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_LV) <= 0
  125. || GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_STAR) <= 0)
  126. {
  127. UpdateToCheckGuide(null);
  128. }
  129. else
  130. {
  131. Timers.inst.Remove(CheckGuide);
  132. }
  133. }
  134. protected override void UpdateToCheckGuide(object param)
  135. {
  136. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  137. GuideController.TryGuide(null, ConstGuideId.UP_CARD_LV, 6, "升级成功啦", -1, true, 1500);
  138. GuideController.TryGuide(null, ConstGuideId.UP_CARD_STAR, 6, "升星成功啦", -1, true, 1500);
  139. }
  140. }
  141. }