StoryLevelInfoView.cs 13 KB

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