StoryLevelInfoView.cs 13 KB

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