StoryLevelInfoView.cs 14 KB

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