ClothingUpgradeView.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. UI_ComItem000 item = UI_ComItem000.Proxy(itemList[i]);
  135. int id = collegeBoostNextCfg.consumeArr[i][0];
  136. int count = collegeBoostNextCfg.consumeArr[i][1];
  137. ItemData itemDate = ItemUtil.createItemData(id, count);
  138. ItemView itemView = new ItemView(item.target);
  139. itemView.SetData(itemDate);
  140. if(item.target.data == null)
  141. {
  142. item.target.onClick.Add(OnClickListDressUpItem);
  143. }
  144. item.target.data = id;
  145. UI_ComItem000.ProxyEnd();
  146. }
  147. }
  148. }
  149. private void InitDate()
  150. {
  151. if (_partIndex != 99)
  152. {
  153. maxRank = CollectPartDataManager.Instance.MaxNormalRank;
  154. partIndexCommon = 0;
  155. }
  156. else
  157. {
  158. maxRank = CollectPartDataManager.Instance.MaxSpecialRank;
  159. partIndexCommon = _partIndex;
  160. }
  161. for (int i = 0; i < 3; i++)
  162. {
  163. GObject item = _ui.target.GetChild(string.Format("item{0}", i));
  164. itemList.Add(item);
  165. }
  166. }
  167. private void OnClickListDressUpItem(EventContext eventContext)
  168. {
  169. int id = (int)(eventContext.sender as GObject).data;
  170. object[] goBackDatas = ViewManager.GetGoBackDatas(typeof(ClothingUpgradeView).Name);
  171. object[] sourceDatas = new object[] { id, goBackDatas, 1 };
  172. GoodsItemTipsController.ShowItemTips(id, sourceDatas);
  173. }
  174. private async void OnClickUpgrade()
  175. {
  176. var result = await CollegeSProxy.ReqCollectUpgrade(nextPartData.PartID, nextPartData.LevelID,nextPartData.LevelNum);
  177. }
  178. private void LevelUpSuccessTip()
  179. {
  180. PromptController.Instance.ShowFloatTextPrompt("升级成功!");
  181. }
  182. private void OnClickLevelUp()
  183. {
  184. //晋升先到答题界面,全答对了,晋升
  185. ViewManager.Show<ClothingAnsweringView>( new object[] { _partIndex, nextPartData.LevelID, nextPartData.LevelNum });
  186. }
  187. private void OnClickBtnBack()
  188. {
  189. ViewManager.GoBackFrom(typeof(ClothingUpgradeView).FullName);
  190. }
  191. }
  192. }