ClothingUpgradeView.cs 9.3 KB

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