StoryLevelInfoView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. using FairyGUI;
  2. using UI.Main;
  3. using System.Collections.Generic;
  4. using UI.CommonGame;
  5. using System;
  6. using ET;
  7. using UI_ListRewardItem = UI.Main.UI_ListRewardItem;
  8. using UnityEngine;
  9. namespace GFGGame
  10. {
  11. public class StoryLevelInfoView : BaseWindow
  12. {
  13. private const int _quicklyStarCount = 2;//达到2星可快速挑战
  14. private UI_StoryLevelInfoUI _ui;
  15. private int _levelID;
  16. private int _needItemId;
  17. private int _needItemCount;
  18. private int _type;
  19. private int _storyType;
  20. private List<ItemData> _bonusList = new List<ItemData>();
  21. public override void Dispose()
  22. {
  23. if (_ui != null)
  24. {
  25. _ui.Dispose();
  26. _ui = null;
  27. }
  28. base.Dispose();
  29. }
  30. protected override void OnInit()
  31. {
  32. base.OnInit();
  33. _ui = UI_StoryLevelInfoUI.Create();
  34. this.viewCom = _ui.target;
  35. this.viewCom.Center();
  36. this.modal = true;
  37. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  38. _ui.m_listBonus.itemRenderer = UpdateBonusItem;
  39. // _ui.m_listBonus.onClickItem.Add(OnClickListBonusItem);
  40. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  41. _ui.m_btnFightOnce.onClick.Add(OnClickBtnFightOnce);
  42. _ui.m_btnFightTimes.onClick.Add(OnClickBtnFightTimes);
  43. _ui.m_btnAdditionDesc.onClick.Add(OnBtnAdditionDescClick);
  44. _ui.m_btnGuide.onClick.Add(this.Hide);
  45. _ui.m_listTag.itemRenderer = RenderListTagItem;
  46. }
  47. protected override void AddEventListener()
  48. {
  49. base.AddEventListener();
  50. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  51. }
  52. protected override void OnShown()
  53. {
  54. base.OnShown();
  55. ViewManager.SetMaskAlpha(0.8f);
  56. _levelID = (int)(viewData as object[])[0];
  57. _needItemId = (int)(viewData as object[])[1];
  58. _needItemCount = (int)(viewData as object[])[2];
  59. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  60. _type = levelCfg.type;
  61. _storyType = levelCfg.subType;
  62. _ui.m_btnStart.touchable = true;
  63. UpdateView();
  64. Timers.inst.AddUpdate(CheckGuide);
  65. }
  66. protected override void OnHide()
  67. {
  68. base.OnHide();
  69. ViewManager.SetMaskAlpha(0.6f);
  70. Timers.inst.Remove(CheckGuide);
  71. }
  72. protected override void RemoveEventListener()
  73. {
  74. base.RemoveEventListener();
  75. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  76. }
  77. private void OnClickBtnStart()
  78. {
  79. // int time = InstanceZonesDataManager.GetCanFightTime(_levelID);
  80. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  81. if (times > 0)
  82. {
  83. ViewManager.Show(ViewName.DRESS_UP_FIGHT_VIEW, _levelID, null, true);
  84. }
  85. else
  86. {
  87. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  88. if (RoleDataManager.power < levelCfg.power)
  89. {
  90. ItemUtil.AddPower("体力不足", OnClickBtnStart);
  91. }
  92. else
  93. {
  94. if (levelCfg.type == ConstInstanceZonesType.Studio)
  95. {
  96. ViewManager.Show<StudioBuyNumView>(levelCfg.chapterId);
  97. }
  98. else
  99. {
  100. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  101. }
  102. }
  103. }
  104. }
  105. private void OnClickBtnFightOnce()
  106. {
  107. // int time = InstanceZonesDataManager.GetCanFightTime(_levelID);
  108. int starCount = InstanceZonesDataManager.GetStarCountHistory(_levelID);
  109. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  110. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  111. if (starCount < fightCfg.quickFightStart)
  112. {
  113. PromptController.Instance.ShowFloatTextPrompt("挑战星数不足");
  114. return;
  115. }
  116. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  117. if (times > 0)
  118. {
  119. ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, new object[] { 1, _needItemId, _needItemCount }, new object[] { typeof(StoryLevelInfoView).FullName, this.viewData });
  120. this.Hide();
  121. }
  122. else
  123. {
  124. if (RoleDataManager.power < levelCfg.power)
  125. {
  126. ItemUtil.AddPower("体力不足", OnClickBtnFightOnce);
  127. }
  128. else
  129. {
  130. if (levelCfg.type == ConstInstanceZonesType.Studio)
  131. {
  132. ViewManager.Show<StudioBuyNumView>(levelCfg.chapterId);
  133. }
  134. else
  135. {
  136. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  137. }
  138. }
  139. }
  140. }
  141. private void OnClickBtnFightTimes()
  142. {
  143. //只要按钮显示说明一定可以速刷多次
  144. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  145. ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, new object[] { times, _needItemId, _needItemCount }, new object[] { typeof(StoryLevelInfoView).FullName, this.viewData });
  146. this.Hide();
  147. }
  148. private void UpdateBonusItem(int index, GObject item)
  149. {
  150. ItemData itemData = _bonusList[index] as ItemData;
  151. UI_ListRewardItem listItem = UI_ListRewardItem.Proxy(item);
  152. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  153. listItem.m_txtName.text = cfg.name;
  154. listItem.m_txtOwner.text = string.Format("已拥有:{0}", ItemDataManager.GetItemNum(itemData.id));
  155. if (item.data == null)
  156. {
  157. item.data = new ItemView(listItem.m_comItem as GComponent);
  158. }
  159. (item.data as ItemView).SetData(itemData);
  160. List<ItemData> bonusOnceData = StoryBonusDataCache.GetBonusData(_levelID).bonusOnce;
  161. (item.data as ItemView).ImgShouTongVisable = !InstanceZonesDataManager.CheckLevelPass(_levelID) && index < bonusOnceData.Count;
  162. UI_ListRewardItem.ProxyEnd();
  163. }
  164. private void UpdateBtnFightTimes()
  165. {
  166. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  167. _ui.m_btnFightTimes.title = title;
  168. _ui.m_btnFightTimes.visible = times > 1;
  169. }
  170. private void UpdateView()
  171. {
  172. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  173. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  174. var title = levelCfg.name;
  175. switch (levelCfg.type)
  176. {
  177. case ConstInstanceZonesType.Story:
  178. title = MainStoryDataManager.CurrentChapterOrder + "-" + InstanceZonesDataManager.currentLevelOrder + " " + levelCfg.name;
  179. break;
  180. }
  181. _ui.m_txtTitle.text = title;
  182. _ui.m_txtLevelDesc.text = levelCfg.desc;
  183. _ui.m_txtPowerDesc.SetVar("power", "" + levelCfg.power).FlushVars();
  184. _ui.m_scoreType.url = "ui://CommonGame/kp_sx_" + fightCfg.scoreType;
  185. if (fightCfg.targetName != null && fightCfg.targetName.Length > 0)
  186. {
  187. _ui.m_txtTargetName.text = "挑战对手·" + fightCfg.targetName;
  188. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath(fightCfg.targetRes);
  189. }
  190. else
  191. {
  192. _ui.m_txtTargetName.text = RoleDataManager.roleName;
  193. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath("self");
  194. }
  195. _bonusList.Clear();
  196. if (InstanceZonesDataManager.CheckLevelPass(_levelID))
  197. {
  198. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, false, true);
  199. _ui.m_groupPass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) >= _quicklyStarCount;
  200. _ui.m_groupUnpass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) < _quicklyStarCount;
  201. UpdateBtnFightTimes();
  202. }
  203. else
  204. {
  205. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, true);
  206. _ui.m_groupPass.visible = false;
  207. _ui.m_groupUnpass.visible = true;
  208. _ui.m_txtUnpassTips.SetVar("count", NumberUtil.GetChiniseNumberText(fightCfg.quickFightStart)).FlushVars();
  209. }
  210. _ui.m_listBonus.numItems = _bonusList.Count;
  211. // if (_ui.m_listBonus.numItems > 4)
  212. // {
  213. // _ui.m_listBonus.columnGap = 40;
  214. // }
  215. // else
  216. // {
  217. // _ui.m_listBonus.columnGap = 60;
  218. // }
  219. int score = InstanceZonesDataManager.GetScoreHighest(_levelID);
  220. if (score > 0)
  221. {
  222. string scoreStr = "" + score;
  223. if (score <= fightCfg.score1)
  224. {
  225. scoreStr = "[color=#A28D77]失败 " + scoreStr + "[/color]";
  226. }
  227. _ui.m_txtHighestScore.text = scoreStr;
  228. _ui.m_flower.target.visible = true;
  229. int starCount = InstanceZonesDataManager.GetStarCountHistory(_levelID);
  230. StoryUtil.UpdateStar(starCount, _ui.m_flower.target);
  231. }
  232. else
  233. {
  234. _ui.m_txtHighestScore.text = "--";
  235. _ui.m_flower.target.visible = false;
  236. }
  237. _ui.m_ctrlNeed.selectedIndex = 0;
  238. if (fightCfg.needItemId != 0)
  239. {
  240. _ui.m_ctrlNeed.selectedIndex = 1;
  241. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(fightCfg.needItemId);
  242. _ui.m_txtNeed.text = cfg.name;
  243. }
  244. else if (fightCfg.needSuitId != 0)
  245. {
  246. _ui.m_ctrlNeed.selectedIndex = 1;
  247. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  248. _ui.m_txtNeed.text = cfg.name;
  249. }
  250. else if (fightCfg.needTagsArr.Length > 0)
  251. {
  252. _ui.m_ctrlNeed.selectedIndex = 2;
  253. _ui.m_listTag.numItems = fightCfg.needTagsArr.Length;
  254. }
  255. else if (levelCfg.type == ConstInstanceZonesType.Studio && levelCfg.subType == ConstInstanceZonesSubType.Hard3)
  256. {
  257. _ui.m_ctrlNeed.selectedIndex = 3;
  258. StudioCfg filingCfg = StudioCfgArray.Instance.GetCfg(StudioDataManager.Instance.filingChapterId);
  259. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(filingCfg.suitId);
  260. float addition = StudioDataManager.Instance.GetAdditionBySuitId(filingCfg.suitId);
  261. addition = addition / 10000 * 100;
  262. _ui.m_txtAddition.text = string.Format("{0}%加成", addition);
  263. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(filingCfg.suitId, out int count, out int totalCount);
  264. _ui.m_txtAdditionDesc.text = string.Format("{0}套装收集进度:{1}/{2}", suitCfg.name, count, totalCount);
  265. _ui.m_grpAdditionDesc.visible = false;
  266. }
  267. }
  268. private void RenderListTagItem(int index, GObject obj)
  269. {
  270. UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
  271. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  272. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  273. string tag = fightCfg.needTagsArr[index];
  274. int tagType = TagCfgArray.Instance.GetCfg(tag).type;
  275. item.m_txtTag.text = tag;
  276. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tagType);
  277. UI_ListTagItem.ProxyEnd();
  278. }
  279. private void OnBtnAdditionDescClick()
  280. {
  281. _ui.m_grpAdditionDesc.visible = !_ui.m_grpAdditionDesc.visible;
  282. }
  283. private void CheckGuide(object param)
  284. {
  285. if (
  286. GuideDataManager.IsGuideFinish(ConstGuideId.START_FIGHT) <= 0
  287. || GuideDataManager.IsGuideFinish(ConstGuideId.OPEN_TAGS) <= 0
  288. || GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  289. {
  290. UpdateToCheckGuide(null);
  291. }
  292. else
  293. {
  294. Timers.inst.Remove(CheckGuide);
  295. }
  296. }
  297. protected override void UpdateToCheckGuide(object param)
  298. {
  299. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  300. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.START_FIGHT, 2, "点击开启换装。");
  301. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.BUY_CLOTHING, 2, "");
  302. GuideController.TryGuide(_ui.m_listTag, ConstGuideId.OPEN_TAGS, 1, "选择相应的关卡标签,可提高分数。", -1, true, _ui.m_btnStart.LocalToGlobal(Vector2.zero).y + _ui.m_btnStart.height + 400, true);
  303. GuideController.TryCompleteGuide(ConstGuideId.OPEN_TAGS, 1);
  304. }
  305. protected override void TryCompleteGuide()
  306. {
  307. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC);
  308. GuideController.TryCompleteGuideIndex(cfg.id, 3);
  309. }
  310. }
  311. }