StoryLevelInfoView.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. using FairyGUI;
  2. using UI.Main;
  3. using System.Collections.Generic;
  4. using UI.CommonGame;
  5. using System;
  6. using cfg.GfgCfg;
  7. using ET;
  8. using UI_ListRewardItem = UI.Main.UI_ListRewardItem;
  9. using UnityEngine;
  10. namespace GFGGame
  11. {
  12. public class StoryLevelInfoView : BaseWindow
  13. {
  14. private const int _quicklyStarCount = 2;//达到2星可快速挑战
  15. private UI_StoryLevelInfoUI _ui;
  16. private int _levelID;
  17. private int _needItemId;
  18. private int _needItemCount;
  19. private int _type;
  20. private int _storyType;
  21. private List<ItemData> _bonusList = new List<ItemData>();
  22. public override void Dispose()
  23. {
  24. if (_ui != null)
  25. {
  26. _ui.Dispose();
  27. _ui = null;
  28. }
  29. base.Dispose();
  30. }
  31. protected override void OnInit()
  32. {
  33. base.OnInit();
  34. _ui = UI_StoryLevelInfoUI.Create();
  35. this.viewCom = _ui.target;
  36. this.viewCom.Center();
  37. this.modal = true;
  38. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  39. _ui.m_listBonus.itemRenderer = UpdateBonusItem;
  40. // _ui.m_listBonus.onClickItem.Add(OnClickListBonusItem);
  41. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  42. _ui.m_btnFightOnce.onClick.Add(OnClickBtnFightOnce);
  43. _ui.m_btnFightTimes.onClick.Add(OnClickBtnFightTimes);
  44. _ui.m_btnAdditionDesc.onClick.Add(OnBtnAdditionDescClick);
  45. _ui.m_btnGuide.onClick.Add(this.Hide);
  46. _ui.m_listTag.itemRenderer = RenderListTagItem;
  47. }
  48. protected override void AddEventListener()
  49. {
  50. base.AddEventListener();
  51. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  52. EventAgent.AddEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, UpdateBtnFightTimes);
  53. }
  54. protected override void OnShown()
  55. {
  56. base.OnShown();
  57. ViewManager.SetMaskAlpha(0.8f);
  58. _levelID = (int)(viewData as object[])[0];
  59. _needItemId = (int)(viewData as object[])[1];
  60. _needItemCount = (int)(viewData as object[])[2];
  61. StoryLevelCfg levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(_levelID);
  62. _type = levelCfg.Type;
  63. _storyType = levelCfg.SubType;
  64. _ui.m_btnStart.touchable = true;
  65. UpdateView();
  66. Timers.inst.AddUpdate(CheckGuide);
  67. }
  68. protected override void OnHide()
  69. {
  70. base.OnHide();
  71. ViewManager.SetMaskAlpha(0.6f);
  72. Timers.inst.Remove(CheckGuide);
  73. }
  74. protected override void RemoveEventListener()
  75. {
  76. base.RemoveEventListener();
  77. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes);
  78. EventAgent.RemoveEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, UpdateVisitNum);
  79. EventAgent.RemoveEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, UpdateBtnFightTimes);
  80. }
  81. private void OnClickBtnStart()
  82. {
  83. // int time = InstanceZonesDataManager.GetCanFightTime(_levelID);
  84. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  85. if (times > 0)
  86. {
  87. DressUpFightType dressUpFightType = new DressUpFightType();
  88. dressUpFightType.levelID = _levelID;
  89. dressUpFightType.teaPartID = 0;
  90. ViewManager.Show<DressUpFightView>(dressUpFightType,true,false);
  91. this.Hide();
  92. }
  93. else
  94. {
  95. var levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(_levelID);
  96. if (RoleDataManager.power < levelCfg.Power)
  97. {
  98. ItemUtil.AddPower(OnClickBtnStart);
  99. }
  100. else
  101. {
  102. if (levelCfg.Type == ConstInstanceZonesType.Studio && levelCfg.ChapterId != StudioDataManager.Instance.GetLuckyBoxActivityID())
  103. {
  104. var studioCfg = CommonDataManager.Tables.TblStudioCfg.GetOrDefault(levelCfg.ChapterId);
  105. ViewManager.Show<StudioBuyNumView>(studioCfg.Limit);
  106. }
  107. else
  108. {
  109. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  110. }
  111. }
  112. }
  113. }
  114. private void OnClickBtnFightOnce()
  115. {
  116. // int time = InstanceZonesDataManager.GetCanFightTime(_levelID);
  117. int starCount = InstanceZonesDataManager.GetStarCountHistory(_levelID);
  118. StoryLevelCfg levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(_levelID);
  119. StoryFightCfg fightCfg = CommonDataManager.Tables.TblStoryFightCfg.GetOrDefault(int.Parse(levelCfg.FightID));
  120. if (starCount < fightCfg.QuickFightStart)
  121. {
  122. PromptController.Instance.ShowFloatTextPrompt("挑战星数不足");
  123. return;
  124. }
  125. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  126. if (times > 0)
  127. {
  128. ViewManager.Show<StoryFightQuicklyView>(new object[] { 1, _needItemId, _needItemCount });
  129. this.Hide();
  130. }
  131. else
  132. {
  133. if (RoleDataManager.power < levelCfg.Power)
  134. {
  135. ItemUtil.AddPower(OnClickBtnFightOnce);
  136. }
  137. else
  138. {
  139. if (levelCfg.Type == ConstInstanceZonesType.Studio && levelCfg.ChapterId != StudioDataManager.Instance.GetLuckyBoxActivityID())
  140. {
  141. var studioCfg = CommonDataManager.Tables.TblStudioCfg.GetOrDefault(levelCfg.ChapterId);
  142. ViewManager.Show<StudioBuyNumView>(studioCfg.Limit);
  143. }
  144. else
  145. {
  146. PromptController.Instance.ShowFloatTextPrompt("挑战次数不足");
  147. }
  148. }
  149. }
  150. }
  151. private void OnClickBtnFightTimes()
  152. {
  153. //只要按钮显示说明一定可以速刷多次
  154. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  155. ViewManager.Show<StoryFightQuicklyView>(new object[] { times, _needItemId, _needItemCount });
  156. this.Hide();
  157. }
  158. private void UpdateBonusItem(int index, GObject item)
  159. {
  160. ItemData itemData = _bonusList[index] as ItemData;
  161. UI_ListRewardItem listItem = UI_ListRewardItem.Proxy(item);
  162. ItemCfg cfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemData.id);
  163. listItem.m_txtName.text = cfg.Name;
  164. listItem.m_txtOwner.text = string.Format("已拥有:{0}", ItemDataManager.GetItemNum(itemData.id));
  165. if (item.data == null)
  166. {
  167. item.data = new ItemView(listItem.m_comItem as GComponent);
  168. }
  169. (item.data as ItemView).SetData(itemData);
  170. //(item.data as ItemView).ShowTxtCount = false;
  171. List<ItemData> bonusOnceData = StoryBonusDataCache.GetBonusData(_levelID).bonusOnce;
  172. (item.data as ItemView).ImgShouTongVisable = !InstanceZonesDataManager.CheckLevelPass(_levelID) && index < bonusOnceData.Count;
  173. UI_ListRewardItem.ProxyEnd();
  174. }
  175. private void UpdateBtnFightTimes()
  176. {
  177. InstanceZonesDataManager.GetCanFightTime(_type, _storyType, _levelID, out int times, out string title);
  178. _ui.m_btnFightTimes.title = title;
  179. _ui.m_btnFightTimes.visible = times > 1;
  180. }
  181. private void UpdateView()
  182. {
  183. StoryLevelCfg levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(_levelID);
  184. StoryFightCfg fightCfg = CommonDataManager.Tables.TblStoryFightCfg.GetOrDefault(int.Parse(levelCfg.FightID));
  185. var title = levelCfg.Name;
  186. switch (levelCfg.Type)
  187. {
  188. case ConstInstanceZonesType.Story:
  189. title = MainStoryDataManager.CurrentChapterOrder + "-" + InstanceZonesDataManager.currentLevelOrder + " " + levelCfg.Name;
  190. break;
  191. }
  192. _ui.m_txtTitle.text = title;
  193. _ui.m_txtLevelDesc.text = levelCfg.Desc;
  194. ItemUtil.UpdateItemNeedNum(_ui.m_comCostCurrent, ConstItemID.POWER, levelCfg.Power);
  195. _ui.m_comCostCurrent.visible = levelCfg.Power > 0;
  196. //招财进宝活动
  197. if(levelCfg.SubType == 1 && levelCfg.Type == 6)
  198. {
  199. _ui.m_ctrlNeed.selectedIndex = 0;
  200. EventAgent.AddEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, UpdateVisitNum);
  201. _ui.m_comCostCurrent.visible = true;
  202. _ui.m_btnBg.url = "ui://Main/zcjb_zdgktc";
  203. UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(_ui.m_comCostCurrent);
  204. com.m_c1.selectedIndex = 2;
  205. UpdateVisitNum();
  206. UI_ComCostCurrency.ProxyEnd();
  207. }
  208. else if(levelCfg.SubType == 1 && levelCfg.Type == 1)
  209. {
  210. _ui.m_ctrlNeed.selectedIndex = 0;
  211. EventAgent.AddEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, UpdateVisitNum);
  212. _ui.m_comCostCurrent.visible = true;
  213. _ui.m_btnBg.url = "ui://Main/zx_jq_dituditu";
  214. UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(_ui.m_comCostCurrent);
  215. com.m_c1.selectedIndex = 3;
  216. UpdateVisitNum();
  217. UI_ComCostCurrency.ProxyEnd();
  218. }
  219. else
  220. {
  221. _ui.m_btnBg.url = "ui://Main/zx_jq_dituditu";
  222. }
  223. // _ui.m_txtPowerDesc.SetVar("power", "" + levelCfg.power).FlushVars();
  224. _ui.m_scoreType.url = "ui://CommonGame/kp_sx_" + fightCfg.ScoreType;
  225. if (fightCfg.TargetName != null && fightCfg.TargetName.Length > 0)
  226. {
  227. _ui.m_txtTargetName.text = "挑战对手·" + fightCfg.TargetName;
  228. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath(fightCfg.TargetRes);
  229. }
  230. else
  231. {
  232. _ui.m_txtTargetName.text = RoleDataManager.roleName;
  233. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath("self");
  234. }
  235. _bonusList.Clear();
  236. if (InstanceZonesDataManager.CheckLevelPass(_levelID))
  237. {
  238. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, false, true);
  239. _ui.m_groupPass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) >= _quicklyStarCount;
  240. _ui.m_groupUnpass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) < _quicklyStarCount;
  241. UpdateBtnFightTimes();
  242. }
  243. else
  244. {
  245. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, true);
  246. _ui.m_groupPass.visible = false;
  247. _ui.m_groupUnpass.visible = true;
  248. _ui.m_txtUnpassTips.SetVar("count", NumberUtil.GetChiniseNumberText(fightCfg.QuickFightStart)).FlushVars();
  249. }
  250. _ui.m_listBonus.numItems = _bonusList.Count;
  251. // if (_ui.m_listBonus.numItems > 4)
  252. // {
  253. // _ui.m_listBonus.columnGap = 40;
  254. // }
  255. // else
  256. // {
  257. // _ui.m_listBonus.columnGap = 60;
  258. // }
  259. int score = InstanceZonesDataManager.GetScoreHighest(_levelID);
  260. if (score > 0)
  261. {
  262. string scoreStr = "" + score;
  263. if (score <= fightCfg.Score1)
  264. {
  265. scoreStr = "[color=#A28D77]失败 " + scoreStr + "[/color]";
  266. }
  267. _ui.m_txtHighestScore.text = scoreStr;
  268. _ui.m_flower.target.visible = true;
  269. int starCount = InstanceZonesDataManager.GetStarCountHistory(_levelID);
  270. StoryUtil.UpdateStar(starCount, _ui.m_flower.target);
  271. }
  272. else
  273. {
  274. _ui.m_txtHighestScore.text = "--";
  275. _ui.m_flower.target.visible = false;
  276. }
  277. _ui.m_ctrlNeed.selectedIndex = 0;
  278. if (fightCfg.NeedItemId != 0)
  279. {
  280. _ui.m_ctrlNeed.selectedIndex = 1;
  281. ItemCfg cfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(fightCfg.NeedItemId);
  282. _ui.m_txtNeed.text = cfg.Name;
  283. }
  284. else if (fightCfg.NeedSuitId != 0)
  285. {
  286. _ui.m_ctrlNeed.selectedIndex = 1;
  287. SuitCfg cfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(fightCfg.NeedSuitId);
  288. _ui.m_txtNeed.text = cfg.Name;
  289. }
  290. else if (fightCfg.NeedTags.Count > 0)
  291. {
  292. _ui.m_ctrlNeed.selectedIndex = 2;
  293. _ui.m_listTag.numItems = fightCfg.NeedTags.Count;
  294. }
  295. else if ((levelCfg.Type == ConstInstanceZonesType.Studio && levelCfg.SubType == ConstInstanceZonesSubType.Hard3) || levelCfg.Type == ConstInstanceZonesType.PureFight)
  296. {
  297. _ui.m_ctrlNeed.selectedIndex = 3;
  298. _ui.m_grpAdditionDesc.visible = false;
  299. // 如果是活动界面,不显示收集进度
  300. if (StudioDataManager.Instance.IsluckyBoxFilingChapter() || levelCfg.Type == ConstInstanceZonesType.PureFight)
  301. {
  302. _ui.m_btnAdditionDesc.visible = false;
  303. }
  304. else
  305. {
  306. StudioCfg filingCfg = CommonDataManager.Tables.TblStudioCfg.GetOrDefault(StudioDataManager.Instance.filingChapterId);
  307. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(filingCfg.SuitId);
  308. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(filingCfg.SuitId, out int count, out int totalCount);
  309. _ui.m_txtAdditionDesc.text = string.Format("{0}套装收集进度:{1}/{2}", suitCfg.Name, count, totalCount);
  310. _ui.m_btnAdditionDesc.visible = true;
  311. }
  312. float addition = 0;
  313. if (levelCfg.Type == ConstInstanceZonesType.PureFight)
  314. {
  315. StudioDataManager.Instance.filingChapterId = levelCfg.ChapterId;
  316. addition = StudioDataManager.Instance.GetAddition(ConstInstanceZonesType.PureFight);
  317. }
  318. else
  319. addition = StudioDataManager.Instance.GetAddition();
  320. addition = addition / 10000 * 100;
  321. _ui.m_txtAddition.text = string.Format("{0}%加成", addition);
  322. }
  323. //招财进宝活动
  324. if (levelCfg.SubType == 1 && levelCfg.Type == 6)
  325. {
  326. _ui.m_ctrlNeed.selectedIndex = 0;
  327. }
  328. }
  329. private void RenderListTagItem(int index, GObject obj)
  330. {
  331. UI_ComTag item = UI_ComTag.Proxy(obj);
  332. StoryLevelCfg levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(_levelID);
  333. StoryFightCfg fightCfg = CommonDataManager.Tables.TblStoryFightCfg.GetOrDefault(int.Parse(levelCfg.FightID));
  334. string tag = fightCfg.NeedTags[index];
  335. int tagType = CommonDataManager.Tables.TblTagCfg.GetOrDefault(tag).Type;
  336. item.m_txtTag.text = tag;
  337. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tagType);
  338. UI_ComTag.ProxyEnd();
  339. }
  340. private void OnBtnAdditionDescClick()
  341. {
  342. _ui.m_grpAdditionDesc.visible = !_ui.m_grpAdditionDesc.visible;
  343. }
  344. //招财进宝活动
  345. private void UpdateVisitNum()
  346. {
  347. UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(_ui.m_comCostCurrent);
  348. RoleLimitData limitData;
  349. int limitID;
  350. if (_type == 1 && _storyType == 1)
  351. {
  352. limitData = RoleLimitDataManager.GetLimitData(50);
  353. limitID = 50;
  354. }
  355. else
  356. {
  357. limitData = RoleLimitDataManager.GetLimitData( CommonDataManager.Tables.TblActivityFightCfg.GetOrDefault(ActivityDataManager.Instance.activityZCJBId).Limit);
  358. limitID = CommonDataManager.Tables.TblActivityFightCfg.GetOrDefault(ActivityDataManager.Instance.activityZCJBId).Limit;
  359. }
  360. int time = limitData.TotalPlayMax - limitData.PlayTimes;
  361. com.m_limitNum.text = string.Format("今日免费次数:{0}/{1}", limitData.TotalPlayMax - limitData.PlayTimes, limitData.MaxStorageCount);
  362. if(com.m_addBtn.data == null)
  363. {
  364. com.m_addBtn.onClick.Add(OnClickAddBtn);
  365. }
  366. com.m_addBtn.data = limitID;
  367. UI_ComCostCurrency.ProxyEnd();
  368. }
  369. private void OnClickAddBtn(EventContext context)
  370. {
  371. // GObject obj, int type
  372. GObject sender = context.sender as GObject;
  373. int id = (int)sender.data;
  374. string name = CommonDataManager.Tables.TblItemCfg.GetOrDefault( CommonDataManager.Tables.TblLimitCfg.GetOrDefault(id).MoneyId).Name;
  375. string desc = string.Format("是否花费{0}{1}购买{2}次过关次数?", CommonDataManager.Tables.TblLimitCfg.GetOrDefault(id).MoneyNum[0],name, 1);
  376. ViewManager.Show<ZCJBBuyTipsView>(new object[] { desc, id });
  377. }
  378. //******************//
  379. private void CheckGuide(object param)
  380. {
  381. if (
  382. GuideDataManager.IsGuideFinish(ConstGuideId.START_FIGHT) <= 0
  383. || GuideDataManager.IsGuideFinish(ConstGuideId.STUDIO_PORCELAIN) <= 0
  384. || GuideDataManager.IsGuideFinish(ConstGuideId.STUDIO_PROPERTY) <= 0
  385. || GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  386. {
  387. UpdateToCheckGuide(null);
  388. }
  389. else
  390. {
  391. Timers.inst.Remove(CheckGuide);
  392. }
  393. }
  394. protected override void UpdateToCheckGuide(object param)
  395. {
  396. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  397. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.START_FIGHT, 2, "点击开启换装。");
  398. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.BUY_CLOTHING, 2, "");
  399. // GuideController.TryGuide(_ui.m_listTag, ConstGuideId.OPEN_TAGS, 1, "选择相应的关卡标签,可提高分数。", -1, true, _ui.m_btnStart.LocalToGlobal(Vector2.zero).y + _ui.m_btnStart.height + 400, true);
  400. // GuideController.TryCompleteGuide(ConstGuideId.OPEN_TAGS, 1);
  401. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.STUDIO_PORCELAIN, 6, "");
  402. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.STUDIO_PROPERTY, 5, "");
  403. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.ENTER_CHAPTER_2, 7, "", -1, true, 0, false, false, true);
  404. }
  405. protected override void TryCompleteGuide()
  406. {
  407. // GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC);
  408. //GuideController.TryCompleteGuideIndex(ConstGuideId.CLOTHING_SYNTHETIC, 3);
  409. GuideController.TryCompleteGuideIndex(ConstGuideId.ENTER_CHAPTER_2, 7);
  410. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_2, 7);
  411. }
  412. }
  413. }