StoryLevelInfoView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. var studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  97. ViewManager.Show<StudioBuyNumView>(studioCfg.limit);
  98. }
  99. else
  100. {
  101. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  102. }
  103. }
  104. }
  105. }
  106. private void OnClickBtnFightOnce()
  107. {
  108. // int time = InstanceZonesDataManager.GetCanFightTime(_levelID);
  109. int starCount = InstanceZonesDataManager.GetStarCountHistory(_levelID);
  110. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  111. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  112. if (starCount < fightCfg.quickFightStart)
  113. {
  114. PromptController.Instance.ShowFloatTextPrompt("挑战星数不足");
  115. return;
  116. }
  117. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  118. if (times > 0)
  119. {
  120. ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, new object[] { 1, _needItemId, _needItemCount }, new object[] { typeof(StoryLevelInfoView).FullName, this.viewData });
  121. this.Hide();
  122. }
  123. else
  124. {
  125. if (RoleDataManager.power < levelCfg.power)
  126. {
  127. ItemUtil.AddPower("体力不足", OnClickBtnFightOnce);
  128. }
  129. else
  130. {
  131. if (levelCfg.type == ConstInstanceZonesType.Studio)
  132. {
  133. var studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  134. ViewManager.Show<StudioBuyNumView>(studioCfg.limit);
  135. }
  136. else
  137. {
  138. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  139. }
  140. }
  141. }
  142. }
  143. private void OnClickBtnFightTimes()
  144. {
  145. //只要按钮显示说明一定可以速刷多次
  146. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  147. ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, new object[] { times, _needItemId, _needItemCount }, new object[] { typeof(StoryLevelInfoView).FullName, this.viewData });
  148. this.Hide();
  149. }
  150. private void UpdateBonusItem(int index, GObject item)
  151. {
  152. ItemData itemData = _bonusList[index] as ItemData;
  153. UI_ListRewardItem listItem = UI_ListRewardItem.Proxy(item);
  154. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  155. listItem.m_txtName.text = cfg.name;
  156. listItem.m_txtOwner.text = string.Format("已拥有:{0}", ItemDataManager.GetItemNum(itemData.id));
  157. if (item.data == null)
  158. {
  159. item.data = new ItemView(listItem.m_comItem as GComponent);
  160. }
  161. (item.data as ItemView).SetData(itemData);
  162. (item.data as ItemView).ShowTxtCount = false;
  163. List<ItemData> bonusOnceData = StoryBonusDataCache.GetBonusData(_levelID).bonusOnce;
  164. (item.data as ItemView).ImgShouTongVisable = !InstanceZonesDataManager.CheckLevelPass(_levelID) && index < bonusOnceData.Count;
  165. UI_ListRewardItem.ProxyEnd();
  166. }
  167. private void UpdateBtnFightTimes()
  168. {
  169. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  170. _ui.m_btnFightTimes.title = title;
  171. _ui.m_btnFightTimes.visible = times > 1;
  172. }
  173. private void UpdateView()
  174. {
  175. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  176. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  177. var title = levelCfg.name;
  178. switch (levelCfg.type)
  179. {
  180. case ConstInstanceZonesType.Story:
  181. title = MainStoryDataManager.CurrentChapterOrder + "-" + InstanceZonesDataManager.currentLevelOrder + " " + levelCfg.name;
  182. break;
  183. }
  184. _ui.m_txtTitle.text = title;
  185. _ui.m_txtLevelDesc.text = levelCfg.desc;
  186. ItemUtil.UpdateItemNeedNum(_ui.m_comCostCurrent, ConstItemID.POWER, levelCfg.power);
  187. _ui.m_comCostCurrent.visible = levelCfg.power > 0;
  188. // _ui.m_txtPowerDesc.SetVar("power", "" + levelCfg.power).FlushVars();
  189. _ui.m_scoreType.url = "ui://CommonGame/kp_sx_" + fightCfg.scoreType;
  190. if (fightCfg.targetName != null && fightCfg.targetName.Length > 0)
  191. {
  192. _ui.m_txtTargetName.text = "挑战对手·" + fightCfg.targetName;
  193. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath(fightCfg.targetRes);
  194. }
  195. else
  196. {
  197. _ui.m_txtTargetName.text = RoleDataManager.roleName;
  198. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath("self");
  199. }
  200. _bonusList.Clear();
  201. if (InstanceZonesDataManager.CheckLevelPass(_levelID))
  202. {
  203. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, false, true);
  204. _ui.m_groupPass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) >= _quicklyStarCount;
  205. _ui.m_groupUnpass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) < _quicklyStarCount;
  206. UpdateBtnFightTimes();
  207. }
  208. else
  209. {
  210. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, true);
  211. _ui.m_groupPass.visible = false;
  212. _ui.m_groupUnpass.visible = true;
  213. _ui.m_txtUnpassTips.SetVar("count", NumberUtil.GetChiniseNumberText(fightCfg.quickFightStart)).FlushVars();
  214. }
  215. _ui.m_listBonus.numItems = _bonusList.Count;
  216. // if (_ui.m_listBonus.numItems > 4)
  217. // {
  218. // _ui.m_listBonus.columnGap = 40;
  219. // }
  220. // else
  221. // {
  222. // _ui.m_listBonus.columnGap = 60;
  223. // }
  224. int score = InstanceZonesDataManager.GetScoreHighest(_levelID);
  225. if (score > 0)
  226. {
  227. string scoreStr = "" + score;
  228. if (score <= fightCfg.score1)
  229. {
  230. scoreStr = "[color=#A28D77]失败 " + scoreStr + "[/color]";
  231. }
  232. _ui.m_txtHighestScore.text = scoreStr;
  233. _ui.m_flower.target.visible = true;
  234. int starCount = InstanceZonesDataManager.GetStarCountHistory(_levelID);
  235. StoryUtil.UpdateStar(starCount, _ui.m_flower.target);
  236. }
  237. else
  238. {
  239. _ui.m_txtHighestScore.text = "--";
  240. _ui.m_flower.target.visible = false;
  241. }
  242. _ui.m_ctrlNeed.selectedIndex = 0;
  243. if (fightCfg.needItemId != 0)
  244. {
  245. _ui.m_ctrlNeed.selectedIndex = 1;
  246. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(fightCfg.needItemId);
  247. _ui.m_txtNeed.text = cfg.name;
  248. }
  249. else if (fightCfg.needSuitId != 0)
  250. {
  251. _ui.m_ctrlNeed.selectedIndex = 1;
  252. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  253. _ui.m_txtNeed.text = cfg.name;
  254. }
  255. else if (fightCfg.needTagsArr.Length > 0)
  256. {
  257. _ui.m_ctrlNeed.selectedIndex = 2;
  258. _ui.m_listTag.numItems = fightCfg.needTagsArr.Length;
  259. }
  260. else if (levelCfg.type == ConstInstanceZonesType.Studio && levelCfg.subType == ConstInstanceZonesSubType.Hard3)
  261. {
  262. _ui.m_ctrlNeed.selectedIndex = 3;
  263. StudioCfg filingCfg = StudioCfgArray.Instance.GetCfg(StudioDataManager.Instance.filingChapterId);
  264. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(filingCfg.suitId);
  265. float addition = StudioDataManager.Instance.GetAdditionBySuitId(filingCfg.suitId);
  266. addition = addition / 10000 * 100;
  267. _ui.m_txtAddition.text = string.Format("{0}%加成", addition);
  268. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(filingCfg.suitId, out int count, out int totalCount);
  269. _ui.m_txtAdditionDesc.text = string.Format("{0}套装收集进度:{1}/{2}", suitCfg.name, count, totalCount);
  270. _ui.m_grpAdditionDesc.visible = false;
  271. }
  272. }
  273. private void RenderListTagItem(int index, GObject obj)
  274. {
  275. UI_ComTag item = UI_ComTag.Proxy(obj);
  276. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  277. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  278. string tag = fightCfg.needTagsArr[index];
  279. int tagType = TagCfgArray.Instance.GetCfg(tag).type;
  280. item.m_txtTag.text = tag;
  281. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tagType);
  282. UI_ComTag.ProxyEnd();
  283. }
  284. private void OnBtnAdditionDescClick()
  285. {
  286. _ui.m_grpAdditionDesc.visible = !_ui.m_grpAdditionDesc.visible;
  287. }
  288. private void CheckGuide(object param)
  289. {
  290. if (
  291. GuideDataManager.IsGuideFinish(ConstGuideId.START_FIGHT) <= 0
  292. || GuideDataManager.IsGuideFinish(ConstGuideId.STUDIO_PORCELAIN) <= 0
  293. || GuideDataManager.IsGuideFinish(ConstGuideId.STUDIO_PROPERTY) <= 0
  294. || GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  295. {
  296. UpdateToCheckGuide(null);
  297. }
  298. else
  299. {
  300. Timers.inst.Remove(CheckGuide);
  301. }
  302. }
  303. protected override void UpdateToCheckGuide(object param)
  304. {
  305. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  306. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.START_FIGHT, 2, "点击开启换装。");
  307. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.BUY_CLOTHING, 2, "");
  308. // GuideController.TryGuide(_ui.m_listTag, ConstGuideId.OPEN_TAGS, 1, "选择相应的关卡标签,可提高分数。", -1, true, _ui.m_btnStart.LocalToGlobal(Vector2.zero).y + _ui.m_btnStart.height + 400, true);
  309. // GuideController.TryCompleteGuide(ConstGuideId.OPEN_TAGS, 1);
  310. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.STUDIO_PORCELAIN, 6, "");
  311. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.STUDIO_PROPERTY, 5, "");
  312. }
  313. protected override void TryCompleteGuide()
  314. {
  315. // GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC);
  316. GuideController.TryCompleteGuideIndex(ConstGuideId.CLOTHING_SYNTHETIC, 3);
  317. }
  318. }
  319. }