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