StoryLevelInfoView.cs 13 KB

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