ClothingUpgradeView.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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(partIndexCommon, 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(partIndexCommon, 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_desc2Text.text = string.Format("当 前:{0}基础属性+{1}%", partName, AddNum.ToString());
  126. _ui.m_desc3Text.text = string.Format("下一级:{0}基础属性+{1}%", partName, nextPartData.AddNum);
  127. if(status != 3)
  128. {
  129. _ui.m_c2.selectedIndex = collegeBoostNextCfg.consumeArr.Length;
  130. for (int i=0;i< collegeBoostNextCfg.consumeArr.Length;i++)
  131. {
  132. UI_ComItem000 item = UI_ComItem000.Proxy(itemList[i]);
  133. int id = collegeBoostNextCfg.consumeArr[i][0];
  134. int count = collegeBoostNextCfg.consumeArr[i][1];
  135. ItemData itemDate = ItemUtil.createItemData(id, count);
  136. ItemView itemView = new ItemView(item.target);
  137. itemView.SetData(itemDate);
  138. UI_ComItem000.ProxyEnd();
  139. }
  140. }
  141. }
  142. private void InitDate()
  143. {
  144. if (_partIndex != 99)
  145. {
  146. maxRank = CollectPartDataManager.Instance.MaxNormalRank;
  147. partIndexCommon = 0;
  148. }
  149. else
  150. {
  151. maxRank = CollectPartDataManager.Instance.MaxSpecialRank;
  152. partIndexCommon = 99;
  153. }
  154. for (int i = 0; i < 3; i++)
  155. {
  156. GObject item = _ui.target.GetChild(string.Format("item{0}", i));
  157. itemList.Add(item);
  158. }
  159. }
  160. private async void OnClickUpgrade()
  161. {
  162. var result = await CollegeSProxy.ReqCollectUpgrade(nextPartData.PartID, nextPartData.LevelID,nextPartData.LevelNum);
  163. }
  164. private void LevelUpSuccessTip()
  165. {
  166. string exitTip = "恭喜!升级成功!";
  167. AlertUI.Show(exitTip)
  168. .SetLeftButton(false, "取消", (object data) =>
  169. {
  170. })
  171. .SetRightButton(true, "确定", (object data) =>
  172. {
  173. });
  174. }
  175. private void OnClickLevelUp()
  176. {
  177. //晋升先到答题界面,全答对了,晋升
  178. ViewManager.Show<ClothingAnsweringView>( new object[] { _partIndex, nextPartData.LevelID, nextPartData.LevelNum });
  179. }
  180. private void OnClickBtnBack()
  181. {
  182. ViewManager.GoBackFrom(typeof(ClothingUpgradeView).FullName);
  183. }
  184. }
  185. }