CardUpLevelView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. using FairyGUI;
  2. using UI.Card;
  3. using System.Collections;
  4. using UnityEngine;
  5. using System;
  6. using System.Collections.Generic;
  7. using cfg.GfgCfg;
  8. using UI.CommonGame;
  9. using ET;
  10. namespace GFGGame
  11. {
  12. public class CardUpLevelView : BaseWindow
  13. {
  14. private UI_CardUpLevelUI _ui;
  15. private EffectUI _effectUI1;
  16. private EffectUI _effectUI2;
  17. private List<int> upgradeCardItemsArr = CommonDataManager.Tables.TblGlobalCfg.UpgradeCardItems;
  18. private CardData _cardData;
  19. private List<int> itemsCount;
  20. private Dictionary<int,int> _listItemChose = new Dictionary<int, int>();
  21. private List<GObject> _listItemObj = new List<GObject>();
  22. private int _countCanUpMaxLevel = 0;
  23. private int _nowCountCanUpLevel = 0;
  24. private int _oldCanUpLevel = 0;
  25. private long _goldsHasNum = 0;
  26. private int _cumulativeGold = 0;
  27. private int _cfgMaxLevel = 0;
  28. public override void Dispose()
  29. {
  30. EffectUIPool.Recycle(_effectUI1);
  31. _effectUI1 = null;
  32. EffectUIPool.Recycle(_effectUI2);
  33. _effectUI2 = null;
  34. if (_ui != null)
  35. {
  36. _ui.Dispose();
  37. _ui = null;
  38. }
  39. base.Dispose();
  40. }
  41. protected override void OnInit()
  42. {
  43. base.OnInit();
  44. _ui = UI_CardUpLevelUI.Create();
  45. this.viewCom = _ui.target;
  46. this.viewCom.Center();
  47. this.modal = true;
  48. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  49. _ui.m_btnUse.onClick.Add(OnClickBtnUse);
  50. _ui.m_btnReduce.onClick.Add(OnClickBtnReduce);
  51. _ui.m_btnAdd.onClick.Add(OnClickBtnAdd);
  52. _ui.m_list.itemRenderer = RenderListItem;
  53. _ui.m_slideUpLevel.onChanged.Add(OnChangeUpLevel);
  54. }
  55. protected override void OnShown()
  56. {
  57. base.OnShown();
  58. //防止引导检测之前触发点击事件
  59. GRoot.inst.touchable = false;
  60. _cardData = (CardData)this.viewData;
  61. AddEffect();
  62. ClearItemsCountList();
  63. _oldCanUpLevel = _cardData.lv;
  64. _cfgMaxLevel = CommonDataManager.Tables.TblCardLvlCfg.GetGroup1ByRarity(_cardData.itemCfg.Rarity).Count;
  65. tidyData(_cfgMaxLevel, "Max");
  66. _ui.m_slideUpLevel.value = 100;
  67. tidyData(_countCanUpMaxLevel); // _cardData.lv
  68. ReferViewInfo();
  69. Timers.inst.AddUpdate(CheckGuide);
  70. }
  71. private void tidyData(int setLevel,string tidyType = "")
  72. {
  73. _goldsHasNum = 0;
  74. _cumulativeGold = 0;
  75. int CumulativeExp = 0;
  76. long needExp = 0;
  77. long allNeedLevelExp = 0;
  78. if (setLevel > 0){
  79. for (int i = _cardData.lv; i < setLevel; i++)
  80. {
  81. allNeedLevelExp += CommonDataManager.Tables.TblCardLvlCfg.Get(_cardData.itemCfg.Rarity, i).NeedExp;
  82. }
  83. needExp = allNeedLevelExp - _cardData.exp; //缺的经验值
  84. }
  85. //先计算出可以升满的最高级别
  86. for (int i = 0; i < upgradeCardItemsArr.Count; i++)
  87. {
  88. ItemParamProto cardUpLvGolds = CommonDataManager.Tables.TblItemCfg.GetOrDefault(upgradeCardItemsArr[i]).CardUpLvGolds[_cardData.itemCfg.Rarity - 1].ToGfgGameItemParam();
  89. _goldsHasNum = ItemDataManager.GetItemNum(cardUpLvGolds.ItemId);
  90. if (!_listItemChose.ContainsKey(i) || _listItemChose[i] == 1)
  91. {
  92. int itemId = upgradeCardItemsArr[i];
  93. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemId);
  94. int num = 0;
  95. if (setLevel > _cardData.lv)
  96. num = (int)Math.Ceiling((needExp - CumulativeExp) / (decimal)itemCfg.CardUpLvExp); //需要购买的数量
  97. long itemNum = Math.Min(num, ItemDataManager.GetItemNum(itemId)); //物品可购买数量
  98. int goldNum = (int)Math.Floor((_goldsHasNum - _cumulativeGold) / (decimal)cardUpLvGolds.Count);//货币可购买数量
  99. int sumNum = (int)Math.Min(goldNum, itemNum);
  100. itemsCount[i] = sumNum;
  101. CumulativeExp = CumulativeExp + (sumNum * itemCfg.CardUpLvExp);
  102. _cumulativeGold = _cumulativeGold + (sumNum * cardUpLvGolds.Count);
  103. }
  104. }
  105. if(tidyType == "Max")
  106. _countCanUpMaxLevel = _cardData.lv;
  107. else
  108. _nowCountCanUpLevel = _cardData.lv;
  109. allNeedLevelExp = _cardData.exp + CumulativeExp;
  110. int lvLimit = CommonDataManager.Tables.TblRoleLevelCfg.GetOrDefault(RoleDataManager.lvl).CardLeverLimit;
  111. for (int i = _cardData.lv; i < setLevel; i++)
  112. {
  113. int needLevelExp = CommonDataManager.Tables.TblCardLvlCfg.Get(_cardData.itemCfg.Rarity, i).NeedExp;
  114. allNeedLevelExp -= needLevelExp;
  115. if (allNeedLevelExp >= 0)
  116. {
  117. if (tidyType == "Max") {
  118. if (_countCanUpMaxLevel < lvLimit)
  119. _countCanUpMaxLevel += 1;
  120. }
  121. else {
  122. if (_nowCountCanUpLevel < lvLimit)
  123. _nowCountCanUpLevel += 1;
  124. }
  125. }
  126. else
  127. break;
  128. }
  129. }
  130. private void OnChangeUpLevel()
  131. {
  132. float volumn = (float)_ui.m_slideUpLevel.value / 100;
  133. _nowCountCanUpLevel = _cardData.lv + (int)(volumn * (_countCanUpMaxLevel - _cardData.lv));
  134. tidyData(_nowCountCanUpLevel);
  135. ReferViewInfo();
  136. }
  137. private void ReferSlide()
  138. {
  139. _ui.m_slideUpLevel.value = (float)(_nowCountCanUpLevel - _cardData.lv) / (_countCanUpMaxLevel - _cardData.lv) * 100;
  140. }
  141. //清理itemsCount
  142. private void ClearItemsCountList()
  143. {
  144. if (itemsCount == null)
  145. {
  146. itemsCount = new List<int>();
  147. }
  148. itemsCount.Clear();
  149. for (int i = 0; i < upgradeCardItemsArr.Count; i++)
  150. {
  151. itemsCount.Add(0);
  152. }
  153. }
  154. protected override void OnHide()
  155. {
  156. GRoot.inst.touchable = true;
  157. base.OnHide();
  158. Timers.inst.Remove(CheckGuide);
  159. }
  160. private void AddEffect()
  161. {
  162. //边框左上角特效
  163. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderLeftTop, "ui_Activity", "Com_window_L_up");
  164. //边框右下角特效
  165. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderRightDowm, "ui_Activity", "Com_window_R_Down");
  166. }
  167. private void RenderListItem(int index, GObject obj)
  168. {
  169. UI_ComItem listItem = UI_ComItem.Proxy(obj);
  170. _listItemObj.Add(obj);
  171. CardLvlCfg cardLvCfg = CommonDataManager.Tables.TblCardLvlCfg.Get(_cardData.itemCfg.Rarity, _cardData.lv);
  172. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(upgradeCardItemsArr[index]);
  173. listItem.m_ButtonType.selectedIndex = 4;
  174. if (!_listItemChose.ContainsKey(index))
  175. _listItemChose.Add(index,1);
  176. listItem.m_ImgpinkGot.visible = (_listItemChose[index] != 0);
  177. listItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  178. if (listItem.target.data == null)
  179. listItem.target.onClick.Add(OnListItemClick);
  180. listItem.target.data = index;
  181. listItem.m_CountType.selectedIndex = 1;
  182. listItem.m_txtDecomCount.text = itemsCount[index].ToString();
  183. listItem.m_txtDecomHasCount.text = "/" + ItemDataManager.GetItemNum(itemCfg.Id).ToString();
  184. UI_ComItem.ProxyEnd();
  185. }
  186. private void OnListItemClick(EventContext context)
  187. {
  188. int index = (int)(context.sender as GObject).data;
  189. UI_ComItem listItem = UI_ComItem.Proxy(_listItemObj[index]);
  190. if (_listItemChose[index] == 0)
  191. _listItemChose[index] = 1;
  192. else
  193. _listItemChose[index] = 0;
  194. listItem.m_ImgpinkGot.visible = (_listItemChose[index] != 0);
  195. UI_ComItem.ProxyEnd();
  196. ClearItemsCountList();
  197. tidyData(_cfgMaxLevel, "Max");
  198. tidyData(_nowCountCanUpLevel);
  199. ReferViewInfo();
  200. ReferSlide();
  201. }
  202. private void ReferViewInfo()
  203. {
  204. _ui.m_txtChooseLevel.SetVar("value1", _nowCountCanUpLevel.ToString()).FlushVars();
  205. _ui.m_txtChooseLevel.SetVar("value2", _countCanUpMaxLevel.ToString()).FlushVars();
  206. _ui.m_txtCost.SetVar("value1", _cumulativeGold.ToString()).FlushVars();
  207. _ui.m_txtCost.SetVar("value2", _goldsHasNum.ToString()).FlushVars();
  208. _listItemObj.Clear();
  209. _ui.m_list.numItems = upgradeCardItemsArr.Count;
  210. }
  211. private async void OnClickBtnUse()
  212. {
  213. bool result = await CardSProxy.UpgradeCardLvl(_cardData.id, itemsCount);
  214. if (result)
  215. {
  216. this.Hide();
  217. if (_cardData.lv - _oldCanUpLevel >= 1)
  218. {
  219. ViewManager.Show<CardUpView>(new object[] { _cardData.scores, "lv", _oldCanUpLevel, _cardData.lv, _cardData.id });
  220. }
  221. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.CI_PAI, 2);
  222. }
  223. }
  224. private void OnClickBtnReduce()
  225. {
  226. _nowCountCanUpLevel -= 1;
  227. if (_nowCountCanUpLevel < _cardData.lv)
  228. _nowCountCanUpLevel = _cardData.lv;
  229. tidyData(_nowCountCanUpLevel);
  230. ReferViewInfo();
  231. ReferSlide();
  232. }
  233. private void OnClickBtnAdd()
  234. {
  235. _nowCountCanUpLevel += 1;
  236. if (_nowCountCanUpLevel > _countCanUpMaxLevel)
  237. _nowCountCanUpLevel = _countCanUpMaxLevel;
  238. tidyData(_nowCountCanUpLevel);
  239. ReferViewInfo();
  240. ReferSlide();
  241. }
  242. private void CheckGuide(object param)
  243. {
  244. GRoot.inst.touchable = true;
  245. if (GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_LV) <= 0)
  246. {
  247. UpdateToCheckGuide(null);
  248. }
  249. else
  250. {
  251. Timers.inst.Remove(CheckGuide);
  252. }
  253. }
  254. protected override void UpdateToCheckGuide(object param)
  255. {
  256. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  257. GuideController.TryGuide(_ui.m_btnUse, ConstGuideId.UP_CARD_LV, 5, "");
  258. }
  259. }
  260. }