StoryLevelInfoView.cs 11 KB

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