ClothingUpgradeView.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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.ITEM_CHANGED, Update);
  61. EventAgent.AddEventListener(ConstMessage.COLLEGE_UPGRADE, Update);
  62. EventAgent.AddEventListener(ConstMessage.COLLEGE_UPGRADE, LevelUpSuccessTip);
  63. }
  64. protected override void RemoveEventListener()
  65. {
  66. base.RemoveEventListener();
  67. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, Update);
  68. EventAgent.RemoveEventListener(ConstMessage.COLLEGE_UPGRADE, Update);
  69. EventAgent.RemoveEventListener(ConstMessage.COLLEGE_UPGRADE, LevelUpSuccessTip);
  70. }
  71. private void Update()
  72. {
  73. UpdateData();
  74. UpdateView();
  75. }
  76. private void UpdateData()
  77. {
  78. level = CollectPartDataManager.Instance.CollectPartDataDic[_partIndex][0];
  79. levelNum = CollectPartDataManager.Instance.CollectPartDataDic[_partIndex][1];
  80. if (levelNum > 0)
  81. {
  82. //当前数据
  83. collegegBoostCfg = CollegeBoostCfgArray.Instance.GetCfgBytypePartsAndtypePhaseAndlayer(_partIndex, level, levelNum);
  84. AddNum = (float)collegegBoostCfg.value / CollectPartDataManager.Instance.AddtitionRatio;
  85. //下一级数据
  86. levelNum = CollectPartDataManager.Instance.CollectPartDataDic[_partIndex][1];
  87. nextPartData.PartID = _partIndex;
  88. if (levelNum + 1 > CollectPartDataManager.Instance.MaxLevel)
  89. {
  90. nextPartData.LevelID = level + 1;
  91. nextPartData.LevelNum = 1;
  92. status = 2;
  93. }
  94. else
  95. {
  96. nextPartData.LevelID = level;
  97. nextPartData.LevelNum = levelNum + 1;
  98. status = 1;
  99. }
  100. }
  101. else
  102. {
  103. AddNum = 0;
  104. levelNum = 0;
  105. nextPartData.PartID = _partIndex;
  106. nextPartData.LevelID = level;
  107. nextPartData.LevelNum = levelNum + 1;
  108. status = 1;
  109. }
  110. collegeBoostNextCfg = CollegeBoostCfgArray.Instance.GetCfgBytypePartsAndtypePhaseAndlayer(_partIndex, nextPartData.LevelID, nextPartData.LevelNum);
  111. if(collegeBoostNextCfg == null || collegeBoostNextCfg.value == 0)
  112. {
  113. nextPartData.AddNum = 0;
  114. status = 3;
  115. }
  116. else
  117. {
  118. nextPartData.AddNum = (float)collegeBoostNextCfg.value / CollectPartDataManager.Instance.AddtitionRatio;
  119. }
  120. }
  121. private void UpdateView()
  122. {
  123. _ui.m_c1.selectedIndex = status;
  124. string name = CollegeRankCfgArray.Instance.GetCfgByRankPartsIdAndSecondLevelRank(partIndexCommon, level).gradeName;
  125. string partName = CollectPartDataManager.Instance.partNameDic[_partIndex];
  126. _ui.m_desc1Text.text = string.Format("{0}{1}级", name,levelNum);
  127. _ui.m_desc2.text = string.Format("当 前:{0}", partName);
  128. _ui.m_desc2Text.text = string.Format("基础属性+{0}%", AddNum.ToString());
  129. _ui.m_desc3.text = string.Format("下一级:{0}", partName);
  130. _ui.m_desc3Text.text = string.Format("基础属性+{0}%", nextPartData.AddNum);
  131. if(status != 3)
  132. {
  133. _ui.m_c2.selectedIndex = collegeBoostNextCfg.consumeArr.Length;
  134. for (int i=0;i< collegeBoostNextCfg.consumeArr.Length;i++)
  135. {
  136. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(collegeBoostNextCfg.consumeArr[i][0]);
  137. UI_ComItem item = UI_ComItem.Proxy(itemList[i]);
  138. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  139. //item.m_txtCount.SetVar("count", itemData.num.ToString()).FlushVars();
  140. ItemData itemCount;
  141. long count;
  142. if(itemCfg.itemType == ConstItemType.DRESS_UP)
  143. {
  144. count = ItemDataManager.GetItemNum(collegeBoostNextCfg.consumeArr[i][0]);
  145. }
  146. else
  147. {
  148. if (BagDataManager.Instance.GetBagData().TryGetValue(collegeBoostNextCfg.consumeArr[i][0], out itemCount))
  149. {
  150. count = itemCount.num;
  151. }
  152. else
  153. {
  154. count = 0;
  155. }
  156. }
  157. item.m_txtCount.text = count.ToString() + "/" + collegeBoostNextCfg.consumeArr[i][1].ToString();
  158. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  159. item.m_ShowName.selectedIndex = 1;
  160. item.m_txtName.text = itemCfg.name;
  161. if (item.target.data == null)
  162. {
  163. item.target.onClick.Add(OnClickListDressUpItem);
  164. }
  165. item.target.data = collegeBoostNextCfg.consumeArr[i][0];
  166. UI_ComItem.ProxyEnd();
  167. }
  168. }
  169. }
  170. private void InitDate()
  171. {
  172. if (_partIndex != 99)
  173. {
  174. maxRank = CollectPartDataManager.Instance.MaxNormalRank;
  175. partIndexCommon = 0;
  176. }
  177. else
  178. {
  179. maxRank = CollectPartDataManager.Instance.MaxSpecialRank;
  180. partIndexCommon = _partIndex;
  181. }
  182. for (int i = 0; i < 3; i++)
  183. {
  184. GObject item = _ui.target.GetChild(string.Format("item{0}", i));
  185. itemList.Add(item);
  186. }
  187. }
  188. private void OnClickListDressUpItem(EventContext eventContext)
  189. {
  190. int id = (int)(eventContext.sender as GObject).data;
  191. object[] sourceDatas = new object[]
  192. { id, new object[] { typeof(BagView).FullName, this.viewData } };
  193. GoodsItemTipsController.ShowItemTips(id, sourceDatas);
  194. }
  195. private async void OnClickUpgrade()
  196. {
  197. var result = await CollegeSProxy.ReqCollectUpgrade(nextPartData.PartID, nextPartData.LevelID,nextPartData.LevelNum);
  198. }
  199. private void LevelUpSuccessTip()
  200. {
  201. PromptController.Instance.ShowFloatTextPrompt("升级成功!");
  202. }
  203. private void OnClickLevelUp()
  204. {
  205. //晋升先到答题界面,全答对了,晋升
  206. ViewManager.Show<ClothingAnsweringView>( new object[] { _partIndex, nextPartData.LevelID, nextPartData.LevelNum });
  207. }
  208. private void OnClickBtnBack()
  209. {
  210. ViewManager.GoBackFrom(typeof(ClothingUpgradeView).FullName);
  211. }
  212. }
  213. }