ClothingUpgradeView.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using UI.CommonGame;
  6. using UI.ClothingUpgrade;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. public class ClothingUpgradeView : BaseWindow
  11. {
  12. private UI_ClothingUpgradeUI _ui;
  13. private int _partIndex;
  14. private int partIndexCommon;
  15. private int maxRank;
  16. private int level;
  17. private int levelNum;
  18. private float AddNum;
  19. private int status = 0;
  20. private CollegeBoostCfg collegegBoostCfg;
  21. private CollegeBoostCfg collegeBoostNextCfg;
  22. private List<GObject> itemList = new List<GObject>();
  23. private CollectPartData nextPartData = new CollectPartData();
  24. public override void Dispose()
  25. {
  26. base.Dispose();
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. packageName = UI_ClothingSelectUI.PACKAGE_NAME;
  32. _ui = UI_ClothingUpgradeUI.Create();
  33. this.viewCom = _ui.target;
  34. isfullScreen = true;
  35. modal = true;
  36. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  37. _ui.m_upgradeBtn.onClick.Add(OnClickUpgrade);
  38. _ui.m_levelUpBtn.onClick.Add(OnClickLevelUp);
  39. }
  40. protected override void OnShown()
  41. {
  42. base.OnShown();
  43. if (this.viewData != null)
  44. {
  45. _partIndex = (int)(this.viewData as object[])[0];
  46. }
  47. _ui.m_bg.url = ResPathUtil.GetBgImgPath("gyp_bg");
  48. InitDate();
  49. //更新数据
  50. Update();
  51. }
  52. protected override void OnHide()
  53. {
  54. itemList.Clear();
  55. base.OnHide();
  56. }
  57. protected override void AddEventListener()
  58. {
  59. base.AddEventListener();
  60. EventAgent.AddEventListener(ConstMessage.COLLEGE_UPGRADE, Update);
  61. EventAgent.AddEventListener(ConstMessage.COLLEGE_UPGRADE, LevelUpSuccessTip);
  62. }
  63. protected override void RemoveEventListener()
  64. {
  65. base.RemoveEventListener();
  66. EventAgent.RemoveEventListener(ConstMessage.COLLEGE_UPGRADE, Update);
  67. EventAgent.RemoveEventListener(ConstMessage.COLLEGE_UPGRADE, LevelUpSuccessTip);
  68. }
  69. private void Update()
  70. {
  71. UpdateData();
  72. UpdateView();
  73. }
  74. private void UpdateData()
  75. {
  76. level = CollectPartDataManager.Instance.CollectPartDataDic[_partIndex][0];
  77. levelNum = CollectPartDataManager.Instance.CollectPartDataDic[_partIndex][1];
  78. if (levelNum > 0)
  79. {
  80. //当前数据
  81. collegegBoostCfg = CollegeBoostCfgArray.Instance.GetCfgBytypePartsAndtypePhaseAndlayer(_partIndex, level, levelNum);
  82. AddNum = (float)collegegBoostCfg.value / CollectPartDataManager.Instance.AddtitionRatio;
  83. //下一级数据
  84. levelNum = CollectPartDataManager.Instance.CollectPartDataDic[_partIndex][1];
  85. nextPartData.PartID = _partIndex;
  86. if (levelNum + 1 > CollectPartDataManager.Instance.MaxLevel)
  87. {
  88. nextPartData.LevelID = level + 1;
  89. nextPartData.LevelNum = 1;
  90. status = 2;
  91. }
  92. else
  93. {
  94. nextPartData.LevelID = level;
  95. nextPartData.LevelNum = levelNum + 1;
  96. status = 1;
  97. }
  98. }
  99. else
  100. {
  101. AddNum = 0;
  102. levelNum = 0;
  103. nextPartData.PartID = _partIndex;
  104. nextPartData.LevelID = level;
  105. nextPartData.LevelNum = levelNum + 1;
  106. status = 1;
  107. }
  108. collegeBoostNextCfg = CollegeBoostCfgArray.Instance.GetCfgBytypePartsAndtypePhaseAndlayer(_partIndex, nextPartData.LevelID, nextPartData.LevelNum);
  109. if(collegeBoostNextCfg == null || collegeBoostNextCfg.value == 0)
  110. {
  111. nextPartData.AddNum = 0;
  112. status = 3;
  113. }
  114. else
  115. {
  116. nextPartData.AddNum = (float)collegeBoostNextCfg.value / CollectPartDataManager.Instance.AddtitionRatio;
  117. }
  118. }
  119. private void UpdateView()
  120. {
  121. _ui.m_c1.selectedIndex = status;
  122. string name = CollegeRankCfgArray.Instance.GetCfgByRankPartsIdAndSecondLevelRank(partIndexCommon, level).gradeName;
  123. string partName = CollectPartDataManager.Instance.partNameDic[_partIndex];
  124. _ui.m_desc1Text.text = string.Format("{0}{1}级", name,levelNum);
  125. _ui.m_desc2.text = string.Format("当 前:{0}", partName);
  126. _ui.m_desc2Text.text = string.Format("基础属性+{0}%", AddNum.ToString());
  127. _ui.m_desc3.text = string.Format("下一级:{0}", partName);
  128. _ui.m_desc3Text.text = string.Format("基础属性+{0}%", nextPartData.AddNum);
  129. if(status != 3)
  130. {
  131. _ui.m_c2.selectedIndex = collegeBoostNextCfg.consumeArr.Length;
  132. for (int i=0;i< collegeBoostNextCfg.consumeArr.Length;i++)
  133. {
  134. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(collegeBoostNextCfg.consumeArr[i][0]);
  135. UI_ComItem item = UI_ComItem.Proxy(itemList[i]);
  136. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  137. //item.m_txtCount.SetVar("count", itemData.num.ToString()).FlushVars();
  138. ItemData itemCount;
  139. long count;
  140. if (BagDataManager.Instance.GetBagData().TryGetValue(collegeBoostNextCfg.consumeArr[i][0], out itemCount))
  141. {
  142. count = itemCount.num;
  143. }
  144. else
  145. {
  146. count = 0;
  147. }
  148. item.m_txtCount.text = count.ToString() + "/" + collegeBoostNextCfg.consumeArr[i][1].ToString();
  149. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  150. item.m_ShowName.selectedIndex = 1;
  151. item.m_txtName.text = itemCfg.name;
  152. if (item.target.data == null)
  153. {
  154. item.target.onClick.Add(OnClickListDressUpItem);
  155. }
  156. item.target.data = collegeBoostNextCfg.consumeArr[i][0];
  157. UI_ComItem.ProxyEnd();
  158. }
  159. }
  160. }
  161. private void InitDate()
  162. {
  163. if (_partIndex != 99)
  164. {
  165. maxRank = CollectPartDataManager.Instance.MaxNormalRank;
  166. partIndexCommon = 0;
  167. }
  168. else
  169. {
  170. maxRank = CollectPartDataManager.Instance.MaxSpecialRank;
  171. partIndexCommon = _partIndex;
  172. }
  173. for (int i = 0; i < 3; i++)
  174. {
  175. GObject item = _ui.target.GetChild(string.Format("item{0}", i));
  176. itemList.Add(item);
  177. }
  178. }
  179. private void OnClickListDressUpItem(EventContext eventContext)
  180. {
  181. int id = (int)(eventContext.sender as GObject).data;
  182. object[] sourceDatas = new object[]
  183. { id, new object[] { typeof(BagView).FullName, this.viewData } };
  184. GoodsItemTipsController.ShowItemTips(id, sourceDatas);
  185. }
  186. private async void OnClickUpgrade()
  187. {
  188. var result = await CollegeSProxy.ReqCollectUpgrade(nextPartData.PartID, nextPartData.LevelID,nextPartData.LevelNum);
  189. }
  190. private void LevelUpSuccessTip()
  191. {
  192. PromptController.Instance.ShowFloatTextPrompt("升级成功!");
  193. }
  194. private void OnClickLevelUp()
  195. {
  196. //晋升先到答题界面,全答对了,晋升
  197. ViewManager.Show<ClothingAnsweringView>( new object[] { _partIndex, nextPartData.LevelID, nextPartData.LevelNum });
  198. }
  199. private void OnClickBtnBack()
  200. {
  201. ViewManager.GoBackFrom(typeof(ClothingUpgradeView).FullName);
  202. }
  203. }
  204. }