StoryLevelInfoView.cs 13 KB

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