CardUpLevelView.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using FairyGUI;
  2. using UI.Card;
  3. using System.Collections;
  4. using UnityEngine;
  5. using System;
  6. using System.Collections.Generic;
  7. using UI.CommonGame;
  8. using ET;
  9. namespace GFGGame
  10. {
  11. public class CardUpLevelView : BaseWindow
  12. {
  13. private UI_CardUpLevelUI _ui;
  14. private EffectUI _effectUI1;
  15. private EffectUI _effectUI2;
  16. private int[] upgradeCardItemsArr = GlobalCfgArray.globalCfg.upgradeCardItemsArr;
  17. private CardData _cardData;
  18. private List<int> itemsCount;
  19. private int _countCanUpMaxLevel = 0;
  20. private int _nowCountCanUpLevel = 0;
  21. private long _goldsHasNum = 0;
  22. private int _cumulativeGold = 0;
  23. public override void Dispose()
  24. {
  25. EffectUIPool.Recycle(_effectUI1);
  26. _effectUI1 = null;
  27. EffectUIPool.Recycle(_effectUI2);
  28. _effectUI2 = null;
  29. if (_ui != null)
  30. {
  31. _ui.Dispose();
  32. _ui = null;
  33. }
  34. base.Dispose();
  35. }
  36. protected override void OnInit()
  37. {
  38. base.OnInit();
  39. _ui = UI_CardUpLevelUI.Create();
  40. this.viewCom = _ui.target;
  41. this.viewCom.Center();
  42. this.modal = true;
  43. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  44. _ui.m_btnUse.onClick.Add(OnClickBtnUse);
  45. _ui.m_btnReduce.onClick.Add(OnClickBtnReduce);
  46. _ui.m_btnAdd.onClick.Add(OnClickBtnAdd);
  47. _ui.m_list.itemRenderer = RenderListItem;
  48. _ui.m_slideUpLevel.onChanged.Add(OnChangeUpLevel);
  49. }
  50. private void OnChangeUpLevel()
  51. {
  52. float volumn = (float)_ui.m_slideUpLevel.value / 100;
  53. //UI_UpLevelSlide slider1 = UI_UpLevelSlide.Proxy(_ui.m_slideUpLevel);
  54. //slider1.m_progressBar.fillAmount = volumn;
  55. ////tidyData(_nowCountCanUpLevel);
  56. ////ReferViewInfo();
  57. //UI_UpLevelSlide.ProxyEnd();
  58. }
  59. protected override void OnShown()
  60. {
  61. base.OnShown();
  62. _cardData = (CardData)this.viewData;
  63. AddEffect();
  64. ClearItemsCountList();
  65. int cfgMaxLevel = CardLvlCfgArray.Instance.GetCfgsByrarity(_cardData.itemCfg.rarity).Count - 1;
  66. tidyData(cfgMaxLevel);
  67. _countCanUpMaxLevel = _nowCountCanUpLevel;
  68. tidyData(_cardData.lv);
  69. ReferViewInfo();
  70. }
  71. private void tidyData(int setLevel)
  72. {
  73. _nowCountCanUpLevel = 0;
  74. _goldsHasNum = 0;
  75. _cumulativeGold = 0;
  76. int CumulativeExp = 0;
  77. int needExp = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(_cardData.itemCfg.rarity, setLevel).needExp; //需要升级到的经验值
  78. needExp = needExp - _cardData.exp; //缺的经验值
  79. //先计算出可以升满的最高级别
  80. for (int i = 0; i < upgradeCardItemsArr.Length; i++)
  81. {
  82. int itemId = upgradeCardItemsArr[i];
  83. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  84. int num = 0;
  85. if(setLevel> _cardData.lv)
  86. num = (int)Math.Ceiling((needExp - CumulativeExp) / (decimal)itemCfg.cardUpLvExp); //需要购买的数量
  87. long itemNum = Math.Min(num, ItemDataManager.GetItemNum(itemId)); //物品可购买数量
  88. int[] cardUpLvGolds = ItemCfgArray.Instance.GetCfg(upgradeCardItemsArr[i]).cardUpLvGoldsArr[_cardData.itemCfg.rarity - 1];
  89. _goldsHasNum = ItemDataManager.GetItemNum(cardUpLvGolds[0]);
  90. int goldNum = (int)Math.Floor((_goldsHasNum - _cumulativeGold) / (decimal)cardUpLvGolds[1]);//货币可购买数量
  91. int sumNum = (int)Math.Min(goldNum, itemNum);
  92. itemsCount[i] = sumNum;
  93. CumulativeExp = CumulativeExp + (sumNum * itemCfg.cardUpLvExp);
  94. _cumulativeGold = _cumulativeGold + (sumNum * cardUpLvGolds[1]);
  95. }
  96. _nowCountCanUpLevel = _cardData.lv;
  97. for (int i = _cardData.lv; i < setLevel; i++)
  98. {
  99. int needLevelExp = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(_cardData.itemCfg.rarity, i).needExp;
  100. if (_cardData.exp + CumulativeExp >= needLevelExp)
  101. _nowCountCanUpLevel += 1;
  102. else
  103. break;
  104. }
  105. }
  106. //清理itemsCount
  107. private void ClearItemsCountList()
  108. {
  109. if (itemsCount == null)
  110. {
  111. itemsCount = new List<int>();
  112. }
  113. itemsCount.Clear();
  114. for (int i = 0; i < upgradeCardItemsArr.Length; i++)
  115. {
  116. itemsCount.Add(0);
  117. }
  118. }
  119. protected override void OnHide()
  120. {
  121. base.OnHide();
  122. }
  123. private void AddEffect()
  124. {
  125. //邊框左上角特效
  126. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderLeftTop, "ui_Activity", "Com_window_L_up");
  127. //邊框右下角特效
  128. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderRightDowm, "ui_Activity", "Com_window_R_Down");
  129. }
  130. private void RenderListItem(int index, GObject obj)
  131. {
  132. UI_ComItem listItem = UI_ComItem.Proxy(obj);
  133. CardLvlCfg cardLvCfg = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(_cardData.itemCfg.rarity, _cardData.lv);
  134. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(upgradeCardItemsArr[index]);
  135. listItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  136. listItem.m_CountType.selectedIndex = 1;
  137. listItem.m_txtDecomCount.text = itemsCount[index].ToString();
  138. listItem.m_txtDecomHasCount.text = "/" + ItemDataManager.GetItemNum(itemCfg.id).ToString();
  139. UI_ComItem.ProxyEnd();
  140. }
  141. private void ReferViewInfo()
  142. {
  143. _ui.m_txtChooseLevel.SetVar("value1", _nowCountCanUpLevel.ToString()).FlushVars();
  144. _ui.m_txtChooseLevel.SetVar("value2", _countCanUpMaxLevel.ToString()).FlushVars();
  145. _ui.m_txtCost.SetVar("value1", _cumulativeGold.ToString()).FlushVars();
  146. _ui.m_txtCost.SetVar("value2", _goldsHasNum.ToString()).FlushVars();
  147. _ui.m_list.numItems = upgradeCardItemsArr.Length;
  148. }
  149. private async void OnClickBtnUse()
  150. {
  151. bool result = await CardSProxy.UpgradeCardLvl(_cardData.id, itemsCount);
  152. if (result)
  153. {
  154. this.Hide();
  155. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.CI_PAI, 2);
  156. }
  157. }
  158. private void OnClickBtnReduce()
  159. {
  160. _nowCountCanUpLevel -= 1;
  161. if (_nowCountCanUpLevel < _cardData.lv)
  162. _nowCountCanUpLevel = _cardData.lv;
  163. tidyData(_nowCountCanUpLevel);
  164. ReferViewInfo();
  165. }
  166. private void OnClickBtnAdd()
  167. {
  168. _nowCountCanUpLevel += 1;
  169. if (_nowCountCanUpLevel > _countCanUpMaxLevel)
  170. _nowCountCanUpLevel = _countCanUpMaxLevel;
  171. tidyData(_nowCountCanUpLevel);
  172. ReferViewInfo();
  173. }
  174. }
  175. }