StoryLevelInfoView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. (item.data as ItemView).ShowTxtCount = false;
  161. List<ItemData> bonusOnceData = StoryBonusDataCache.GetBonusData(_levelID).bonusOnce;
  162. (item.data as ItemView).ImgShouTongVisable = !InstanceZonesDataManager.CheckLevelPass(_levelID) && index < bonusOnceData.Count;
  163. UI_ListRewardItem.ProxyEnd();
  164. }
  165. private void UpdateBtnFightTimes()
  166. {
  167. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  168. _ui.m_btnFightTimes.title = title;
  169. _ui.m_btnFightTimes.visible = times > 1;
  170. }
  171. private void UpdateView()
  172. {
  173. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  174. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  175. var title = levelCfg.name;
  176. switch (levelCfg.type)
  177. {
  178. case ConstInstanceZonesType.Story:
  179. title = MainStoryDataManager.CurrentChapterOrder + "-" + InstanceZonesDataManager.currentLevelOrder + " " + levelCfg.name;
  180. break;
  181. }
  182. _ui.m_txtTitle.text = title;
  183. _ui.m_txtLevelDesc.text = levelCfg.desc;
  184. _ui.m_txtPowerDesc.SetVar("power", "" + levelCfg.power).FlushVars();
  185. _ui.m_scoreType.url = "ui://CommonGame/kp_sx_" + fightCfg.scoreType;
  186. if (fightCfg.targetName != null && fightCfg.targetName.Length > 0)
  187. {
  188. _ui.m_txtTargetName.text = "挑战对手·" + fightCfg.targetName;
  189. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath(fightCfg.targetRes);
  190. }
  191. else
  192. {
  193. _ui.m_txtTargetName.text = RoleDataManager.roleName;
  194. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath("self");
  195. }
  196. _bonusList.Clear();
  197. if (InstanceZonesDataManager.CheckLevelPass(_levelID))
  198. {
  199. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, false, true);
  200. _ui.m_groupPass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) >= _quicklyStarCount;
  201. _ui.m_groupUnpass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) < _quicklyStarCount;
  202. UpdateBtnFightTimes();
  203. }
  204. else
  205. {
  206. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, true);
  207. _ui.m_groupPass.visible = false;
  208. _ui.m_groupUnpass.visible = true;
  209. _ui.m_txtUnpassTips.SetVar("count", NumberUtil.GetChiniseNumberText(fightCfg.quickFightStart)).FlushVars();
  210. }
  211. _ui.m_listBonus.numItems = _bonusList.Count;
  212. // if (_ui.m_listBonus.numItems > 4)
  213. // {
  214. // _ui.m_listBonus.columnGap = 40;
  215. // }
  216. // else
  217. // {
  218. // _ui.m_listBonus.columnGap = 60;
  219. // }
  220. int score = InstanceZonesDataManager.GetScoreHighest(_levelID);
  221. if (score > 0)
  222. {
  223. string scoreStr = "" + score;
  224. if (score <= fightCfg.score1)
  225. {
  226. scoreStr = "[color=#A28D77]失败 " + scoreStr + "[/color]";
  227. }
  228. _ui.m_txtHighestScore.text = scoreStr;
  229. _ui.m_flower.target.visible = true;
  230. int starCount = InstanceZonesDataManager.GetStarCountHistory(_levelID);
  231. StoryUtil.UpdateStar(starCount, _ui.m_flower.target);
  232. }
  233. else
  234. {
  235. _ui.m_txtHighestScore.text = "--";
  236. _ui.m_flower.target.visible = false;
  237. }
  238. _ui.m_ctrlNeed.selectedIndex = 0;
  239. if (fightCfg.needItemId != 0)
  240. {
  241. _ui.m_ctrlNeed.selectedIndex = 1;
  242. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(fightCfg.needItemId);
  243. _ui.m_txtNeed.text = cfg.name;
  244. }
  245. else if (fightCfg.needSuitId != 0)
  246. {
  247. _ui.m_ctrlNeed.selectedIndex = 1;
  248. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  249. _ui.m_txtNeed.text = cfg.name;
  250. }
  251. else if (fightCfg.needTagsArr.Length > 0)
  252. {
  253. _ui.m_ctrlNeed.selectedIndex = 2;
  254. _ui.m_listTag.numItems = fightCfg.needTagsArr.Length;
  255. }
  256. else if (levelCfg.type == ConstInstanceZonesType.Studio && levelCfg.subType == ConstInstanceZonesSubType.Hard3)
  257. {
  258. _ui.m_ctrlNeed.selectedIndex = 3;
  259. StudioCfg filingCfg = StudioCfgArray.Instance.GetCfg(StudioDataManager.Instance.filingChapterId);
  260. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(filingCfg.suitId);
  261. float addition = StudioDataManager.Instance.GetAdditionBySuitId(filingCfg.suitId);
  262. addition = addition / 10000 * 100;
  263. _ui.m_txtAddition.text = string.Format("{0}%加成", addition);
  264. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(filingCfg.suitId, out int count, out int totalCount);
  265. _ui.m_txtAdditionDesc.text = string.Format("{0}套装收集进度:{1}/{2}", suitCfg.name, count, totalCount);
  266. _ui.m_grpAdditionDesc.visible = false;
  267. }
  268. }
  269. private void RenderListTagItem(int index, GObject obj)
  270. {
  271. UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
  272. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  273. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  274. string tag = fightCfg.needTagsArr[index];
  275. int tagType = TagCfgArray.Instance.GetCfg(tag).type;
  276. item.m_txtTag.text = tag;
  277. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tagType);
  278. UI_ListTagItem.ProxyEnd();
  279. }
  280. private void OnBtnAdditionDescClick()
  281. {
  282. _ui.m_grpAdditionDesc.visible = !_ui.m_grpAdditionDesc.visible;
  283. }
  284. private void CheckGuide(object param)
  285. {
  286. if (
  287. GuideDataManager.IsGuideFinish(ConstGuideId.START_FIGHT) <= 0
  288. || GuideDataManager.IsGuideFinish(ConstGuideId.OPEN_TAGS) <= 0
  289. || GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  290. {
  291. UpdateToCheckGuide(null);
  292. }
  293. else
  294. {
  295. Timers.inst.Remove(CheckGuide);
  296. }
  297. }
  298. protected override void UpdateToCheckGuide(object param)
  299. {
  300. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  301. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.START_FIGHT, 2, "点击开启换装。");
  302. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.BUY_CLOTHING, 2, "");
  303. GuideController.TryGuide(_ui.m_listTag, ConstGuideId.OPEN_TAGS, 1, "选择相应的关卡标签,可提高分数。", -1, true, _ui.m_btnStart.LocalToGlobal(Vector2.zero).y + _ui.m_btnStart.height + 400, true);
  304. GuideController.TryCompleteGuide(ConstGuideId.OPEN_TAGS, 1);
  305. }
  306. protected override void TryCompleteGuide()
  307. {
  308. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC);
  309. GuideController.TryCompleteGuideIndex(cfg.id, 3);
  310. }
  311. }
  312. }