StoryLevelInfoView.cs 10 KB

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