ClothingUpgradeView.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using System;
  2. using System.Collections.Generic;
  3. using cfg.GfgCfg;
  4. using ET;
  5. using FairyGUI;
  6. using UI.CommonGame;
  7. using UI.ClothingUpgrade;
  8. using UnityEngine;
  9. namespace GFGGame
  10. {
  11. public class ClothingUpgradeView : BaseWindow
  12. {
  13. private UI_ClothingUpgradeUI _ui;
  14. private int _partIndex;
  15. private int partIndexCommon;
  16. private int maxRank;
  17. private int level;
  18. private int levelNum;
  19. private float AddNum;
  20. private int status = 0;
  21. private CollegeBoostCfg collegegBoostCfg;
  22. private CollegeBoostCfg collegeBoostNextCfg;
  23. private List<GObject> itemList = new List<GObject>();
  24. private CollectPartData nextPartData = new CollectPartData();
  25. public override void Dispose()
  26. {
  27. base.Dispose();
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. packageName = UI_ClothingSelectUI.PACKAGE_NAME;
  33. _ui = UI_ClothingUpgradeUI.Create();
  34. this.viewCom = _ui.target;
  35. isfullScreen = true;
  36. modal = true;
  37. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  38. _ui.m_upgradeBtn.onClick.Add(OnClickUpgrade);
  39. _ui.m_levelUpBtn.onClick.Add(OnClickLevelUp);
  40. }
  41. protected override void OnShown()
  42. {
  43. base.OnShown();
  44. if (this.viewData != null)
  45. {
  46. _partIndex = (int)(this.viewData as object[])[0];
  47. }
  48. _ui.m_bg.url = ResPathUtil.GetBgImgPath("gyp_bg");
  49. InitDate();
  50. //更新数据
  51. Update();
  52. Timers.inst.AddUpdate(CheckGuide);
  53. }
  54. protected override void OnHide()
  55. {
  56. itemList.Clear();
  57. base.OnHide();
  58. Timers.inst.Remove(CheckGuide);
  59. }
  60. protected override void AddEventListener()
  61. {
  62. base.AddEventListener();
  63. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, Update);
  64. EventAgent.AddEventListener(ConstMessage.COLLEGE_UPGRADE, Update);
  65. EventAgent.AddEventListener(ConstMessage.COLLEGE_UPGRADE, LevelUpSuccessTip);
  66. }
  67. protected override void RemoveEventListener()
  68. {
  69. base.RemoveEventListener();
  70. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, Update);
  71. EventAgent.RemoveEventListener(ConstMessage.COLLEGE_UPGRADE, Update);
  72. EventAgent.RemoveEventListener(ConstMessage.COLLEGE_UPGRADE, LevelUpSuccessTip);
  73. }
  74. private void Update()
  75. {
  76. UpdateData();
  77. UpdateView();
  78. }
  79. private void UpdateData()
  80. {
  81. level = CollectPartDataManager.Instance.CollectPartDataDic[_partIndex][0];
  82. levelNum = CollectPartDataManager.Instance.CollectPartDataDic[_partIndex][1];
  83. if (levelNum > 0)
  84. {
  85. //当前数据
  86. collegegBoostCfg = CommonDataManager.Tables.TblCollegeBoostCfg.Get(_partIndex, level, levelNum);
  87. AddNum = (float)collegegBoostCfg.Value / CollectPartDataManager.Instance.AddtitionRatio;
  88. //下一级数据
  89. levelNum = CollectPartDataManager.Instance.CollectPartDataDic[_partIndex][1];
  90. nextPartData.PartID = _partIndex;
  91. if (levelNum + 1 > CollectPartDataManager.Instance.MaxLevel)
  92. {
  93. nextPartData.LevelID = level + 1;
  94. nextPartData.LevelNum = 1;
  95. status = 2;
  96. }
  97. else
  98. {
  99. nextPartData.LevelID = level;
  100. nextPartData.LevelNum = levelNum + 1;
  101. status = 1;
  102. }
  103. }
  104. else
  105. {
  106. AddNum = 0;
  107. levelNum = 0;
  108. nextPartData.PartID = _partIndex;
  109. nextPartData.LevelID = level;
  110. nextPartData.LevelNum = levelNum + 1;
  111. status = 1;
  112. }
  113. collegeBoostNextCfg = CommonDataManager.Tables.TblCollegeBoostCfg.Get(_partIndex, nextPartData.LevelID, nextPartData.LevelNum);
  114. if(collegeBoostNextCfg == null || collegeBoostNextCfg.Value == 0)
  115. {
  116. nextPartData.AddNum = 0;
  117. status = 3;
  118. }
  119. else
  120. {
  121. nextPartData.AddNum = (float)collegeBoostNextCfg.Value / CollectPartDataManager.Instance.AddtitionRatio;
  122. }
  123. }
  124. private void UpdateView()
  125. {
  126. _ui.m_c1.selectedIndex = status;
  127. RedDotController.Instance.SetComRedDot(_ui.m_levelUpBtn, CollectPartDataManager.Instance.CheckPartCanUP(_partIndex),"");
  128. RedDotController.Instance.SetComRedDot(_ui.m_upgradeBtn, CollectPartDataManager.Instance.CheckPartCanUP(_partIndex), "");
  129. string name = CommonDataManager.Tables.TblCollegeRankCfg.Get(partIndexCommon, level).GradeName;
  130. string partName = CollectPartDataManager.Instance.partNameDic[_partIndex];
  131. _ui.m_desc1Text.text = string.Format("{0}{1}级", name,levelNum);
  132. _ui.m_desc2.text = string.Format("当 前:{0}", partName);
  133. _ui.m_desc2Text.text = string.Format("基础属性+{0}%", AddNum.ToString());
  134. _ui.m_desc3.text = string.Format("下一级:{0}", partName);
  135. _ui.m_desc3Text.text = string.Format("基础属性+{0}%", nextPartData.AddNum);
  136. if(status != 3)
  137. {
  138. _ui.m_c2.selectedIndex = collegeBoostNextCfg.Consume.Count;
  139. for (int i=0;i< collegeBoostNextCfg.Consume.Count;i++)
  140. {
  141. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(collegeBoostNextCfg.Consume[i].ItemId);
  142. UI_ComItem item = UI_ComItem.Proxy(itemList[i]);
  143. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  144. //item.m_txtCount.SetVar("count", itemData.num.ToString()).FlushVars();
  145. ItemData itemCount;
  146. long count;
  147. if(itemCfg.ItemType == ConstItemType.DRESS_UP)
  148. {
  149. count = ItemDataManager.GetItemNum(collegeBoostNextCfg.Consume[i].ItemId);
  150. }
  151. else
  152. {
  153. if (BagDataManager.Instance.GetBagData().TryGetValue(collegeBoostNextCfg.Consume[i].ItemId, out itemCount))
  154. {
  155. count = itemCount.num;
  156. }
  157. else
  158. {
  159. count = 0;
  160. }
  161. }
  162. item.m_txtCount.text = count.ToString() + "/" + collegeBoostNextCfg.Consume[i].Count.ToString();
  163. item.m_QualityType.selectedIndex = itemCfg.Rarity - 1;
  164. item.m_ShowName.selectedIndex = 1;
  165. item.m_txtName.text = itemCfg.Name;
  166. if (item.target.data == null)
  167. {
  168. item.target.onClick.Add(OnClickListDressUpItem);
  169. }
  170. item.target.data = collegeBoostNextCfg.Consume[i].ItemId;
  171. UI_ComItem.ProxyEnd();
  172. }
  173. }
  174. }
  175. private void InitDate()
  176. {
  177. if (_partIndex != 99)
  178. {
  179. maxRank = CollectPartDataManager.Instance.MaxNormalRank;
  180. partIndexCommon = 0;
  181. }
  182. else
  183. {
  184. maxRank = CollectPartDataManager.Instance.MaxSpecialRank;
  185. partIndexCommon = _partIndex;
  186. }
  187. for (int i = 0; i < 3; i++)
  188. {
  189. GObject item = _ui.target.GetChild(string.Format("item{0}", i));
  190. itemList.Add(item);
  191. }
  192. }
  193. private void OnClickListDressUpItem(EventContext eventContext)
  194. {
  195. int id = (int)(eventContext.sender as GObject).data;
  196. object[] sourceDatas = new object[]
  197. { id, new object[] { typeof(ClothingUpgradeView).FullName, this.viewData } };
  198. GoodsItemTipsController.ShowItemTips(id, sourceDatas);
  199. }
  200. private async void OnClickUpgrade()
  201. {
  202. var result = await CollegeSProxy.ReqCollectUpgrade(nextPartData.PartID, nextPartData.LevelID,nextPartData.LevelNum);
  203. }
  204. private void LevelUpSuccessTip()
  205. {
  206. PromptController.Instance.ShowFloatTextPrompt("升级成功!");
  207. }
  208. private void OnClickLevelUp()
  209. {
  210. //晋升先到答题界面,全答对了,晋升
  211. ViewManager.Show<ClothingAnsweringView>( new object[] { _partIndex, nextPartData.LevelID, nextPartData.LevelNum });
  212. }
  213. private void OnClickBtnBack()
  214. {
  215. ViewManager.GoBackFrom(typeof(ClothingUpgradeView).FullName);
  216. }
  217. private void CheckGuide(object param)
  218. {
  219. GRoot.inst.touchable = true;
  220. if (GuideDataManager.IsGuideFinish("ClothingSelectView") <= 0)
  221. UpdateCheckGuide(null);
  222. else
  223. Timers.inst.Remove(CheckGuide);
  224. }
  225. protected void UpdateCheckGuide(object param)
  226. {
  227. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  228. GuideController.TryGuide(null, "ClothingSelectView", 6, "升级部位获得加成。", -1, true, _ui.target.height - 600);
  229. GuideController.TryCompleteGuide("ClothingSelectView", 6);
  230. }
  231. }
  232. }