StoryLevelInfoView.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. EventAgent.AddEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, UpdateVisitNum);
  197. _ui.m_comCostCurrent.visible = true;
  198. _ui.m_btnBg.url = "ui://Main/zcjb_zdgktc";
  199. UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(_ui.m_comCostCurrent);
  200. com.m_c1.selectedIndex = 2;
  201. UpdateVisitNum();
  202. UI_ComCostCurrency.ProxyEnd();
  203. }
  204. else
  205. {
  206. _ui.m_btnBg.url = "ui://Main/zx_jq_dituditu";
  207. }
  208. // _ui.m_txtPowerDesc.SetVar("power", "" + levelCfg.power).FlushVars();
  209. _ui.m_scoreType.url = "ui://CommonGame/kp_sx_" + fightCfg.scoreType;
  210. if (fightCfg.targetName != null && fightCfg.targetName.Length > 0)
  211. {
  212. _ui.m_txtTargetName.text = "挑战对手·" + fightCfg.targetName;
  213. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath(fightCfg.targetRes);
  214. }
  215. else
  216. {
  217. _ui.m_txtTargetName.text = RoleDataManager.roleName;
  218. _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath("self");
  219. }
  220. _bonusList.Clear();
  221. if (InstanceZonesDataManager.CheckLevelPass(_levelID))
  222. {
  223. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, false, true);
  224. _ui.m_groupPass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) >= _quicklyStarCount;
  225. _ui.m_groupUnpass.visible = InstanceZonesDataManager.GetStarCountHistory(_levelID) < _quicklyStarCount;
  226. UpdateBtnFightTimes();
  227. }
  228. else
  229. {
  230. _bonusList = StoryBonusDataCache.GetBonusList(_levelID, true);
  231. _ui.m_groupPass.visible = false;
  232. _ui.m_groupUnpass.visible = true;
  233. _ui.m_txtUnpassTips.SetVar("count", NumberUtil.GetChiniseNumberText(fightCfg.quickFightStart)).FlushVars();
  234. }
  235. _ui.m_listBonus.numItems = _bonusList.Count;
  236. // if (_ui.m_listBonus.numItems > 4)
  237. // {
  238. // _ui.m_listBonus.columnGap = 40;
  239. // }
  240. // else
  241. // {
  242. // _ui.m_listBonus.columnGap = 60;
  243. // }
  244. int score = InstanceZonesDataManager.GetScoreHighest(_levelID);
  245. if (score > 0)
  246. {
  247. string scoreStr = "" + score;
  248. if (score <= fightCfg.score1)
  249. {
  250. scoreStr = "[color=#A28D77]失败 " + scoreStr + "[/color]";
  251. }
  252. _ui.m_txtHighestScore.text = scoreStr;
  253. _ui.m_flower.target.visible = true;
  254. int starCount = InstanceZonesDataManager.GetStarCountHistory(_levelID);
  255. StoryUtil.UpdateStar(starCount, _ui.m_flower.target);
  256. }
  257. else
  258. {
  259. _ui.m_txtHighestScore.text = "--";
  260. _ui.m_flower.target.visible = false;
  261. }
  262. _ui.m_ctrlNeed.selectedIndex = 0;
  263. if (fightCfg.needItemId != 0)
  264. {
  265. _ui.m_ctrlNeed.selectedIndex = 1;
  266. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(fightCfg.needItemId);
  267. _ui.m_txtNeed.text = cfg.name;
  268. }
  269. else if (fightCfg.needSuitId != 0)
  270. {
  271. _ui.m_ctrlNeed.selectedIndex = 1;
  272. SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId);
  273. _ui.m_txtNeed.text = cfg.name;
  274. }
  275. else if (fightCfg.needTagsArr.Length > 0)
  276. {
  277. _ui.m_ctrlNeed.selectedIndex = 2;
  278. _ui.m_listTag.numItems = fightCfg.needTagsArr.Length;
  279. }
  280. else if ((levelCfg.type == ConstInstanceZonesType.Studio && levelCfg.subType == ConstInstanceZonesSubType.Hard3) || levelCfg.type == ConstInstanceZonesType.PureFight)
  281. {
  282. _ui.m_ctrlNeed.selectedIndex = 3;
  283. _ui.m_grpAdditionDesc.visible = false;
  284. // 如果是活动界面,不显示收集进度
  285. if (StudioDataManager.Instance.IsluckyBoxFilingChapter() || levelCfg.type == ConstInstanceZonesType.PureFight)
  286. {
  287. _ui.m_btnAdditionDesc.visible = false;
  288. }
  289. else
  290. {
  291. StudioCfg filingCfg = StudioCfgArray.Instance.GetCfg(StudioDataManager.Instance.filingChapterId);
  292. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(filingCfg.suitId);
  293. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(filingCfg.suitId, out int count, out int totalCount);
  294. _ui.m_txtAdditionDesc.text = string.Format("{0}套装收集进度:{1}/{2}", suitCfg.name, count, totalCount);
  295. _ui.m_btnAdditionDesc.visible = true;
  296. }
  297. float addition = 0;
  298. if (levelCfg.type == ConstInstanceZonesType.PureFight)
  299. {
  300. StudioDataManager.Instance.filingChapterId = levelCfg.chapterId;
  301. addition = StudioDataManager.Instance.GetAddition(ConstInstanceZonesType.PureFight);
  302. }
  303. else
  304. addition = StudioDataManager.Instance.GetAddition();
  305. addition = addition / 10000 * 100;
  306. _ui.m_txtAddition.text = string.Format("{0}%加成", addition);
  307. }
  308. }
  309. private void RenderListTagItem(int index, GObject obj)
  310. {
  311. UI_ComTag item = UI_ComTag.Proxy(obj);
  312. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID);
  313. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  314. string tag = fightCfg.needTagsArr[index];
  315. int tagType = TagCfgArray.Instance.GetCfg(tag).type;
  316. item.m_txtTag.text = tag;
  317. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tagType);
  318. UI_ComTag.ProxyEnd();
  319. }
  320. private void OnBtnAdditionDescClick()
  321. {
  322. _ui.m_grpAdditionDesc.visible = !_ui.m_grpAdditionDesc.visible;
  323. }
  324. //招财进宝活动
  325. private void UpdateVisitNum()
  326. {
  327. UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(_ui.m_comCostCurrent);
  328. RoleLimitData limitData = RoleLimitDataManager.GetLimitData(ActivityFightCfgArray.Instance.GetCfg(61001).limit);
  329. int time = limitData.TotalPlayMax - limitData.PlayTimes;
  330. com.m_limitNum.text = "今日免费次数:" + time + "/" + limitData.TotalPlayMax;
  331. com.m_addBtn.onClick.Add(OnClickAddBtn);
  332. UI_ComCostCurrency.ProxyEnd();
  333. }
  334. private void OnClickAddBtn()
  335. {
  336. string name = ItemCfgArray.Instance.GetCfg(LimitCfgArray.Instance.GetCfg(500).moneyId).name;
  337. string desc = string.Format("是否花费{0}{1}购买{2}次过关次数?", LimitCfgArray.Instance.GetCfg(500).moneyNumArr[0],name, 1);
  338. AlertUI.Show(desc).SetLeftButton(true).SetRightButton(true, "购买", (object data) =>
  339. {
  340. RoleLimitSProxy.ReqBuyLimitPlayTimes(500, 1, 1).Coroutine();
  341. EventAgent.DispatchEvent(ConstMessage.NOTICE_LIMIT_CHANGED);
  342. EventAgent.DispatchEvent(ConstMessage.NUMERIC_CHANGE);
  343. });
  344. }
  345. //******************//
  346. private void CheckGuide(object param)
  347. {
  348. if (
  349. GuideDataManager.IsGuideFinish(ConstGuideId.START_FIGHT) <= 0
  350. || GuideDataManager.IsGuideFinish(ConstGuideId.STUDIO_PORCELAIN) <= 0
  351. || GuideDataManager.IsGuideFinish(ConstGuideId.STUDIO_PROPERTY) <= 0
  352. || GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  353. {
  354. UpdateToCheckGuide(null);
  355. }
  356. else
  357. {
  358. Timers.inst.Remove(CheckGuide);
  359. }
  360. }
  361. protected override void UpdateToCheckGuide(object param)
  362. {
  363. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  364. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.START_FIGHT, 2, "点击开启换装。");
  365. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.BUY_CLOTHING, 2, "");
  366. // GuideController.TryGuide(_ui.m_listTag, ConstGuideId.OPEN_TAGS, 1, "选择相应的关卡标签,可提高分数。", -1, true, _ui.m_btnStart.LocalToGlobal(Vector2.zero).y + _ui.m_btnStart.height + 400, true);
  367. // GuideController.TryCompleteGuide(ConstGuideId.OPEN_TAGS, 1);
  368. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.STUDIO_PORCELAIN, 6, "");
  369. GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.STUDIO_PROPERTY, 5, "");
  370. }
  371. protected override void TryCompleteGuide()
  372. {
  373. // GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC);
  374. //GuideController.TryCompleteGuideIndex(ConstGuideId.CLOTHING_SYNTHETIC, 3);
  375. }
  376. }
  377. }