StoryLevelInfoView.cs 12 KB

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