StoryLevelInfoView.cs 12 KB

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