StoryLevelInfoView.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. EventAgent.RemoveEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, UpdateVisitNum);
  77. }
  78. private void OnClickBtnStart()
  79. {
  80. // int time = InstanceZonesDataManager.GetCanFightTime(_levelID);
  81. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  82. if (times > 0)
  83. {
  84. DressUpFightType dressUpFightType = new DressUpFightType();
  85. dressUpFightType.levelID = _levelID;
  86. dressUpFightType.teaPartID = 0;
  87. ViewManager.Show<DressUpFightView>(dressUpFightType,true);
  88. this.Hide();
  89. }
  90. else
  91. {
  92. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  93. if (RoleDataManager.power < levelCfg.power)
  94. {
  95. ItemUtil.AddPower(OnClickBtnStart);
  96. }
  97. else
  98. {
  99. if (levelCfg.type == ConstInstanceZonesType.Studio && levelCfg.chapterId != StudioDataManager.Instance.GetLuckyBoxActivityID())
  100. {
  101. var studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  102. ViewManager.Show<StudioBuyNumView>(studioCfg.limit);
  103. }
  104. else
  105. {
  106. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  107. }
  108. }
  109. }
  110. }
  111. private void OnClickBtnFightOnce()
  112. {
  113. // int time = InstanceZonesDataManager.GetCanFightTime(_levelID);
  114. int starCount = InstanceZonesDataManager.GetStarCountHistory(_levelID);
  115. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  116. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  117. if (starCount < fightCfg.quickFightStart)
  118. {
  119. PromptController.Instance.ShowFloatTextPrompt("挑战星数不足");
  120. return;
  121. }
  122. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  123. if (times > 0)
  124. {
  125. ViewManager.Show<StoryFightQuicklyView>(new object[] { 1, _needItemId, _needItemCount });
  126. this.Hide();
  127. }
  128. else
  129. {
  130. if (RoleDataManager.power < levelCfg.power)
  131. {
  132. ItemUtil.AddPower(OnClickBtnFightOnce);
  133. }
  134. else
  135. {
  136. if (levelCfg.type == ConstInstanceZonesType.Studio && levelCfg.chapterId != StudioDataManager.Instance.GetLuckyBoxActivityID())
  137. {
  138. var studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  139. ViewManager.Show<StudioBuyNumView>(studioCfg.limit);
  140. }
  141. else
  142. {
  143. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  144. }
  145. }
  146. }
  147. }
  148. private void OnClickBtnFightTimes()
  149. {
  150. //只要按钮显示说明一定可以速刷多次
  151. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  152. ViewManager.Show<StoryFightQuicklyView>(new object[] { times, _needItemId, _needItemCount });
  153. this.Hide();
  154. }
  155. private void UpdateBonusItem(int index, GObject item)
  156. {
  157. ItemData itemData = _bonusList[index] as ItemData;
  158. UI_ListRewardItem listItem = UI_ListRewardItem.Proxy(item);
  159. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  160. listItem.m_txtName.text = cfg.name;
  161. listItem.m_txtOwner.text = string.Format("已拥有:{0}", ItemDataManager.GetItemNum(itemData.id));
  162. if (item.data == null)
  163. {
  164. item.data = new ItemView(listItem.m_comItem as GComponent);
  165. }
  166. (item.data as ItemView).SetData(itemData);
  167. //(item.data as ItemView).ShowTxtCount = false;
  168. List<ItemData> bonusOnceData = StoryBonusDataCache.GetBonusData(_levelID).bonusOnce;
  169. (item.data as ItemView).ImgShouTongVisable = !InstanceZonesDataManager.CheckLevelPass(_levelID) && index < bonusOnceData.Count;
  170. UI_ListRewardItem.ProxyEnd();
  171. }
  172. private void UpdateBtnFightTimes()
  173. {
  174. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  175. _ui.m_btnFightTimes.title = title;
  176. _ui.m_btnFightTimes.visible = times > 1;
  177. }
  178. private void UpdateView()
  179. {
  180. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  181. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  182. var title = levelCfg.name;
  183. switch (levelCfg.type)
  184. {
  185. case ConstInstanceZonesType.Story:
  186. title = MainStoryDataManager.CurrentChapterOrder + "-" + InstanceZonesDataManager.currentLevelOrder + " " + levelCfg.name;
  187. break;
  188. }
  189. _ui.m_txtTitle.text = title;
  190. _ui.m_txtLevelDesc.text = levelCfg.desc;
  191. ItemUtil.UpdateItemNeedNum(_ui.m_comCostCurrent, ConstItemID.POWER, levelCfg.power);
  192. _ui.m_comCostCurrent.visible = levelCfg.power > 0;
  193. //招财进宝活动
  194. if(levelCfg.subType == 1 && levelCfg.type == 6)
  195. {
  196. _ui.m_ctrlNeed.selectedIndex = 0;
  197. EventAgent.AddEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, UpdateVisitNum);
  198. _ui.m_comCostCurrent.visible = true;
  199. _ui.m_btnBg.url = "ui://Main/zcjb_zdgktc";
  200. UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(_ui.m_comCostCurrent);
  201. com.m_c1.selectedIndex = 2;
  202. UpdateVisitNum();
  203. UI_ComCostCurrency.ProxyEnd();
  204. }
  205. else
  206. {
  207. _ui.m_btnBg.url = "ui://Main/zx_jq_dituditu";
  208. }
  209. // _ui.m_txtPowerDesc.SetVar("power", "" + levelCfg.power).FlushVars();
  210. _ui.m_scoreType.url = "ui://CommonGame/kp_sx_" + fightCfg.scoreType;
  211. if (fightCfg.targetName != null && fightCfg.targetName.Length > 0)
  212. {
  213. _ui.m_txtTargetName.text = "挑战对手·" + fightCfg.targetName;
  214. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath(fightCfg.targetRes);
  215. }
  216. else
  217. {
  218. _ui.m_txtTargetName.text = RoleDataManager.roleName;
  219. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath("self");
  220. }
  221. _bonusList.Clear();
  222. if (InstanceZonesDataManager.CheckLevelPass(_levelID))
  223. {
  224. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, false, true);
  225. _ui.m_groupPass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) >= _quicklyStarCount;
  226. _ui.m_groupUnpass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) < _quicklyStarCount;
  227. UpdateBtnFightTimes();
  228. }
  229. else
  230. {
  231. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, true);
  232. _ui.m_groupPass.visible = false;
  233. _ui.m_groupUnpass.visible = true;
  234. _ui.m_txtUnpassTips.SetVar("count", NumberUtil.GetChiniseNumberText(fightCfg.quickFightStart)).FlushVars();
  235. }
  236. _ui.m_listBonus.numItems = _bonusList.Count;
  237. // if (_ui.m_listBonus.numItems > 4)
  238. // {
  239. // _ui.m_listBonus.columnGap = 40;
  240. // }
  241. // else
  242. // {
  243. // _ui.m_listBonus.columnGap = 60;
  244. // }
  245. int score = InstanceZonesDataManager.GetScoreHighest(_levelID);
  246. if (score > 0)
  247. {
  248. string scoreStr = "" + score;
  249. if (score <= fightCfg.score1)
  250. {
  251. scoreStr = "[color=#A28D77]失败 " + scoreStr + "[/color]";
  252. }
  253. _ui.m_txtHighestScore.text = scoreStr;
  254. _ui.m_flower.target.visible = true;
  255. int starCount = InstanceZonesDataManager.GetStarCountHistory(_levelID);
  256. StoryUtil.UpdateStar(starCount, _ui.m_flower.target);
  257. }
  258. else
  259. {
  260. _ui.m_txtHighestScore.text = "--";
  261. _ui.m_flower.target.visible = false;
  262. }
  263. _ui.m_ctrlNeed.selectedIndex = 0;
  264. if (fightCfg.needItemId != 0)
  265. {
  266. _ui.m_ctrlNeed.selectedIndex = 1;
  267. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(fightCfg.needItemId);
  268. _ui.m_txtNeed.text = cfg.name;
  269. }
  270. else if (fightCfg.needSuitId != 0)
  271. {
  272. _ui.m_ctrlNeed.selectedIndex = 1;
  273. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  274. _ui.m_txtNeed.text = cfg.name;
  275. }
  276. else if (fightCfg.needTagsArr.Length > 0)
  277. {
  278. _ui.m_ctrlNeed.selectedIndex = 2;
  279. _ui.m_listTag.numItems = fightCfg.needTagsArr.Length;
  280. }
  281. else if ((levelCfg.type == ConstInstanceZonesType.Studio && levelCfg.subType == ConstInstanceZonesSubType.Hard3) || levelCfg.type == ConstInstanceZonesType.PureFight)
  282. {
  283. _ui.m_ctrlNeed.selectedIndex = 3;
  284. _ui.m_grpAdditionDesc.visible = false;
  285. // 如果是活动界面,不显示收集进度
  286. if (StudioDataManager.Instance.IsluckyBoxFilingChapter() || levelCfg.type == ConstInstanceZonesType.PureFight)
  287. {
  288. _ui.m_btnAdditionDesc.visible = false;
  289. }
  290. else
  291. {
  292. StudioCfg filingCfg = StudioCfgArray.Instance.GetCfg(StudioDataManager.Instance.filingChapterId);
  293. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(filingCfg.suitId);
  294. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(filingCfg.suitId, out int count, out int totalCount);
  295. _ui.m_txtAdditionDesc.text = string.Format("{0}套装收集进度:{1}/{2}", suitCfg.name, count, totalCount);
  296. _ui.m_btnAdditionDesc.visible = true;
  297. }
  298. float addition = 0;
  299. if (levelCfg.type == ConstInstanceZonesType.PureFight)
  300. {
  301. StudioDataManager.Instance.filingChapterId = levelCfg.chapterId;
  302. addition = StudioDataManager.Instance.GetAddition(ConstInstanceZonesType.PureFight);
  303. }
  304. else
  305. addition = StudioDataManager.Instance.GetAddition();
  306. addition = addition / 10000 * 100;
  307. _ui.m_txtAddition.text = string.Format("{0}%加成", addition);
  308. }
  309. //招财进宝活动
  310. if (levelCfg.subType == 1 && levelCfg.type == 6)
  311. {
  312. _ui.m_ctrlNeed.selectedIndex = 0;
  313. }
  314. }
  315. private void RenderListTagItem(int index, GObject obj)
  316. {
  317. UI_ComTag item = UI_ComTag.Proxy(obj);
  318. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  319. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  320. string tag = fightCfg.needTagsArr[index];
  321. int tagType = TagCfgArray.Instance.GetCfg(tag).type;
  322. item.m_txtTag.text = tag;
  323. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tagType);
  324. UI_ComTag.ProxyEnd();
  325. }
  326. private void OnBtnAdditionDescClick()
  327. {
  328. _ui.m_grpAdditionDesc.visible = !_ui.m_grpAdditionDesc.visible;
  329. }
  330. //招财进宝活动
  331. private void UpdateVisitNum()
  332. {
  333. UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(_ui.m_comCostCurrent);
  334. RoleLimitData limitData = RoleLimitDataManager.GetLimitData(ActivityFightCfgArray.Instance.GetCfg(61001).limit);
  335. int time = limitData.TotalPlayMax - limitData.PlayTimes;
  336. com.m_limitNum.text = "今日免费次数:" + time + "/" + limitData.TotalPlayMax;
  337. com.m_addBtn.onClick.Add(OnClickAddBtn);
  338. UI_ComCostCurrency.ProxyEnd();
  339. }
  340. private void OnClickAddBtn()
  341. {
  342. string name = ItemCfgArray.Instance.GetCfg(LimitCfgArray.Instance.GetCfg(500).moneyId).name;
  343. string desc = string.Format("是否花费{0}{1}购买{2}次过关次数?", LimitCfgArray.Instance.GetCfg(500).moneyNumArr[0],name, 1);
  344. AlertUI.Show(desc).SetLeftButton(true).SetRightButton(true, "购买", (object data) =>
  345. {
  346. RoleLimitSProxy.ReqBuyLimitPlayTimes(500, 1, 1).Coroutine();
  347. EventAgent.DispatchEvent(ConstMessage.NOTICE_LIMIT_CHANGED);
  348. EventAgent.DispatchEvent(ConstMessage.NUMERIC_CHANGE);
  349. });
  350. }
  351. //******************//
  352. private void CheckGuide(object param)
  353. {
  354. if (
  355. GuideDataManager.IsGuideFinish(ConstGuideId.START_FIGHT) <= 0
  356. || GuideDataManager.IsGuideFinish(ConstGuideId.STUDIO_PORCELAIN) <= 0
  357. || GuideDataManager.IsGuideFinish(ConstGuideId.STUDIO_PROPERTY) <= 0
  358. || GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  359. {
  360. UpdateToCheckGuide(null);
  361. }
  362. else
  363. {
  364. Timers.inst.Remove(CheckGuide);
  365. }
  366. }
  367. protected override void UpdateToCheckGuide(object param)
  368. {
  369. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  370. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.START_FIGHT, 2, "点击开启换装。");
  371. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.BUY_CLOTHING, 2, "");
  372. // GuideController.TryGuide(_ui.m_listTag, ConstGuideId.OPEN_TAGS, 1, "选择相应的关卡标签,可提高分数。", -1, true, _ui.m_btnStart.LocalToGlobal(Vector2.zero).y + _ui.m_btnStart.height + 400, true);
  373. // GuideController.TryCompleteGuide(ConstGuideId.OPEN_TAGS, 1);
  374. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.STUDIO_PORCELAIN, 6, "");
  375. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.STUDIO_PROPERTY, 5, "");
  376. }
  377. protected override void TryCompleteGuide()
  378. {
  379. // GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC);
  380. //GuideController.TryCompleteGuideIndex(ConstGuideId.CLOTHING_SYNTHETIC, 3);
  381. }
  382. }
  383. }