StoryLevelInfoView.cs 13 KB

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