ClothingUpgradeView.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. RedDotController.Instance.SetComRedDot(_ui.m_levelUpBtn, CollectPartDataManager.Instance.CheckPartCanUP(_partIndex),"");
  127. RedDotController.Instance.SetComRedDot(_ui.m_upgradeBtn, CollectPartDataManager.Instance.CheckPartCanUP(_partIndex), "");
  128. string name = CollegeRankCfgArray.Instance.GetCfgByRankPartsIdAndSecondLevelRank(partIndexCommon, level).gradeName;
  129. string partName = CollectPartDataManager.Instance.partNameDic[_partIndex];
  130. _ui.m_desc1Text.text = string.Format("{0}{1}级", name,levelNum);
  131. _ui.m_desc2.text = string.Format("当 前:{0}", partName);
  132. _ui.m_desc2Text.text = string.Format("基础属性+{0}%", AddNum.ToString());
  133. _ui.m_desc3.text = string.Format("下一级:{0}", partName);
  134. _ui.m_desc3Text.text = string.Format("基础属性+{0}%", nextPartData.AddNum);
  135. if(status != 3)
  136. {
  137. _ui.m_c2.selectedIndex = collegeBoostNextCfg.consumeArr.Length;
  138. for (int i=0;i< collegeBoostNextCfg.consumeArr.Length;i++)
  139. {
  140. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(collegeBoostNextCfg.consumeArr[i][0]);
  141. UI_ComItem item = UI_ComItem.Proxy(itemList[i]);
  142. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  143. //item.m_txtCount.SetVar("count", itemData.num.ToString()).FlushVars();
  144. ItemData itemCount;
  145. long count;
  146. if(itemCfg.itemType == ConstItemType.DRESS_UP)
  147. {
  148. count = ItemDataManager.GetItemNum(collegeBoostNextCfg.consumeArr[i][0]);
  149. }
  150. else
  151. {
  152. if (BagDataManager.Instance.GetBagData().TryGetValue(collegeBoostNextCfg.consumeArr[i][0], out itemCount))
  153. {
  154. count = itemCount.num;
  155. }
  156. else
  157. {
  158. count = 0;
  159. }
  160. }
  161. item.m_txtCount.text = count.ToString() + "/" + collegeBoostNextCfg.consumeArr[i][1].ToString();
  162. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  163. item.m_ShowName.selectedIndex = 1;
  164. item.m_txtName.text = itemCfg.name;
  165. if (item.target.data == null)
  166. {
  167. item.target.onClick.Add(OnClickListDressUpItem);
  168. }
  169. item.target.data = collegeBoostNextCfg.consumeArr[i][0];
  170. UI_ComItem.ProxyEnd();
  171. }
  172. }
  173. }
  174. private void InitDate()
  175. {
  176. if (_partIndex != 99)
  177. {
  178. maxRank = CollectPartDataManager.Instance.MaxNormalRank;
  179. partIndexCommon = 0;
  180. }
  181. else
  182. {
  183. maxRank = CollectPartDataManager.Instance.MaxSpecialRank;
  184. partIndexCommon = _partIndex;
  185. }
  186. for (int i = 0; i < 3; i++)
  187. {
  188. GObject item = _ui.target.GetChild(string.Format("item{0}", i));
  189. itemList.Add(item);
  190. }
  191. }
  192. private void OnClickListDressUpItem(EventContext eventContext)
  193. {
  194. int id = (int)(eventContext.sender as GObject).data;
  195. object[] sourceDatas = new object[]
  196. { id, new object[] { typeof(BagView).FullName, this.viewData } };
  197. GoodsItemTipsController.ShowItemTips(id, sourceDatas);
  198. }
  199. private async void OnClickUpgrade()
  200. {
  201. var result = await CollegeSProxy.ReqCollectUpgrade(nextPartData.PartID, nextPartData.LevelID,nextPartData.LevelNum);
  202. }
  203. private void LevelUpSuccessTip()
  204. {
  205. PromptController.Instance.ShowFloatTextPrompt("升级成功!");
  206. }
  207. private void OnClickLevelUp()
  208. {
  209. //晋升先到答题界面,全答对了,晋升
  210. ViewManager.Show<ClothingAnsweringView>( new object[] { _partIndex, nextPartData.LevelID, nextPartData.LevelNum });
  211. }
  212. private void OnClickBtnBack()
  213. {
  214. ViewManager.GoBackFrom(typeof(ClothingUpgradeView).FullName);
  215. }
  216. private void CheckGuide(object param)
  217. {
  218. GRoot.inst.touchable = true;
  219. if (GuideDataManager.IsGuideFinish("ClothingSelectView") <= 0)
  220. UpdateCheckGuide(null);
  221. else
  222. Timers.inst.Remove(CheckGuide);
  223. }
  224. protected void UpdateCheckGuide(object param)
  225. {
  226. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  227. GuideController.TryGuide(null, "ClothingSelectView", 6, "升级部位获得加成。", -1, true, _ui.target.height - 600);
  228. GuideController.TryCompleteGuide("ClothingSelectView", 6);
  229. }
  230. }
  231. }