StoryLevelInfoView.cs 15 KB

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