ApproachView.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.CommonGame;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class ApproachView
  9. {
  10. private UI_ComTipsApproach _ui;
  11. private object[] _viewData;
  12. private int _itemId;
  13. private object[] _fromViewDatas;
  14. private int _needCount;//需求总量
  15. private List<string[]> _approachDatas = new List<string[]>();
  16. public void Dispose()
  17. {
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. UI_ComTipsApproach.ProxyEnd();
  24. }
  25. public void OnHide()
  26. {
  27. // _ui.m_list.onClickItem.Remove(OnClickListApproachItem);
  28. if (_ui.m_list.numItems > 0)
  29. {
  30. _ui.m_list.ScrollToView(0);
  31. _ui.m_list.numItems = 0;
  32. }
  33. _approachDatas.Clear();
  34. _fromViewDatas = null;
  35. }
  36. public void OnInit(GComponent component)
  37. {
  38. _ui = UI_ComTipsApproach.Proxy(component);
  39. _ui.m_list.itemRenderer = ListApproachItemRenderer;
  40. }
  41. public void OnShow(object[] viewData)
  42. {
  43. _viewData = viewData;
  44. _itemId = (int)viewData[0];
  45. _fromViewDatas = viewData[1] as object[];
  46. // _needCount = viewData.Length > 2 ? (int)viewData[2] : 0;
  47. int needCount = viewData.Length > 2 ? (int)viewData[2] : 0;
  48. _needCount = (int)needCount;
  49. SetData();
  50. UpdateView();
  51. }
  52. private void SetData()
  53. {
  54. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
  55. if (string.IsNullOrEmpty(itemCfg.approach)) return;
  56. string[] approachStrs = itemCfg.approach.Split(';');
  57. foreach (string approachStr in approachStrs)
  58. {
  59. if (string.IsNullOrEmpty(approachStr)) continue;
  60. string[] infos = approachStr.Split('=');
  61. if(infos[0] == ConstFunctionId.STORE)
  62. {
  63. if (CheckStoreItem(infos))
  64. {
  65. _approachDatas.Add(infos);
  66. }
  67. }
  68. else
  69. {
  70. _approachDatas.Add(infos);
  71. }
  72. }
  73. }
  74. /// <summary>
  75. /// 去除未上架的商品
  76. /// </summary>
  77. /// <param name="infos"></param>
  78. /// <returns></returns>
  79. private bool CheckStoreItem(string[] infos)
  80. {
  81. int storeTabId = int.Parse(infos[1]);
  82. int storeSubId = int.Parse(infos[2]);
  83. List<ShopCfg> storyActivityCfg = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(storeTabId, storeSubId);
  84. storyActivityCfg = ShopDataManager.Instance.RemoveNotOpenCfg(storyActivityCfg);
  85. foreach (var v in storyActivityCfg)
  86. {
  87. if (v.itemId == _itemId)
  88. {
  89. return true;
  90. }
  91. }
  92. return false;
  93. }
  94. private void UpdateView()
  95. {
  96. _ui.m_txtNone.visible = _approachDatas.Count == 0;
  97. _ui.m_list.numItems = _approachDatas.Count;
  98. _ui.m_list.data = _approachDatas;
  99. }
  100. private void ListApproachItemRenderer(int index, GObject item)
  101. {
  102. UI_ListSourceItem listItem = UI_ListSourceItem.Proxy(item);
  103. string[] infos = _approachDatas[index];
  104. string functionId = infos[0];
  105. GameFunctionCfg gameFunctionCfg = GameFunctionCfgArray.Instance.GetCfg(functionId);
  106. // FunctionOpenCfg functionOpenCfg = FunctionOpenCfgArray.Instance.GetCfg(gameFunctionCfg.functionId);
  107. // listItem.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(functionOpenCfg.res);
  108. if (functionId == ConstFunctionId.JU_QING_GUAN_QIA)
  109. {
  110. var levelCfgId = int.Parse(infos[1]);
  111. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  112. if (levelCfg.type == ConstInstanceZonesType.Story)
  113. {
  114. var chapterCfg = StoryChapterCfgArray.Instance.GetCfg(levelCfg.chapterId);
  115. if (chapterCfg != null) {
  116. string chapter = NumberUtil.GetChiniseNumberText(chapterCfg.order);
  117. string level = NumberUtil.GetChiniseNumberText(levelCfg.order);
  118. if (levelCfg.subType == ConstInstanceZonesSubType.Normal)
  119. {
  120. listItem.m_txtSourceName.text = string.Format(gameFunctionCfg.name, chapter, level);
  121. }
  122. else if (levelCfg.subType == ConstInstanceZonesSubType.Hard)
  123. {
  124. listItem.m_txtSourceName.text = string.Format("精英" + gameFunctionCfg.name, chapter, level);
  125. }
  126. }
  127. }
  128. else if (levelCfg.type == ConstInstanceZonesType.Studio)
  129. {
  130. var studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  131. listItem.m_txtSourceName.text = levelCfg.name;
  132. }
  133. }
  134. else if (functionId == ConstFunctionId.FU_ZHUANG_DIAN)
  135. {
  136. int shopId = int.Parse(infos[1]);
  137. if (shopId == ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID)
  138. {
  139. listItem.m_txtSourceName.text = "活动商店";
  140. }
  141. else if (shopId == ConstStoreId.LUCKY_BOX_STORE_ID)
  142. {
  143. listItem.m_txtSourceName.text = "落星商店";
  144. }
  145. else if (shopId == ConstStoreId.GALLERY_STORE_ID)
  146. {
  147. listItem.m_txtSourceName.text = "画廊商店";
  148. }
  149. else
  150. {
  151. listItem.m_txtSourceName.text = "服装店";
  152. }
  153. }
  154. else if (functionId == ConstFunctionId.STORE)
  155. {
  156. int storeTabId = int.Parse(infos[1]);
  157. int storeSubId = int.Parse(infos[2]);
  158. listItem.m_txtSourceName.text = StoreTabCfgArray.Instance.GetCfg(storeTabId).subTabArr[storeSubId][0];
  159. }
  160. else
  161. {
  162. listItem.m_txtSourceName.text = gameFunctionCfg.name;
  163. }
  164. if (listItem.target.data == null)
  165. {
  166. listItem.m_btnGo.target.onClick.Add(OnClickListApproachItem);
  167. }
  168. listItem.m_btnGo.target.data = infos;
  169. UI_ListSourceItem.ProxyEnd();
  170. }
  171. private void OnClickListApproachItem(EventContext context)
  172. {
  173. GObject btnGo = context.sender as GObject;
  174. string[] infos = btnGo.data as string[];
  175. string functionId = infos[0];
  176. GameFunctionCfg gameFunctionCfg = GameFunctionCfgArray.Instance.GetCfg(functionId);
  177. if (gameFunctionCfg.activityIdArr.Length > 0)
  178. {
  179. ActivityOpenCfg _activityCfg = ActivityOpenCfgArray.Instance.GetCfg(gameFunctionCfg.activityIdArr[0]);
  180. long openTime = TimeUtil.DateTimeToTimestamp(_activityCfg.openTime);
  181. long endTime = TimeUtil.DateTimeToTimestamp(_activityCfg.endTime);
  182. long curTime = TimeHelper.ServerNow();
  183. if (openTime > curTime || curTime > endTime) {
  184. PromptController.Instance.ShowFloatTextPrompt("活动已过期");
  185. return;
  186. }
  187. }
  188. long hasNum = ItemDataManager.GetItemNum(_itemId);
  189. long needCount = 0;
  190. bool isJump = true;
  191. switch (functionId)
  192. {
  193. case ConstFunctionId.FU_ZHUANG_DIAN:
  194. // this.Hide();
  195. needCount = (_needCount - hasNum) <= 0 ? 1 : _needCount - hasNum;
  196. int shopId = int.Parse(infos[1]);
  197. // if (shopId == ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID)
  198. // {
  199. // PromptController.Instance.ShowFloatTextPrompt("活动暂未开启");
  200. // isJump = false;
  201. // break;
  202. // }
  203. isJump = ViewManager.Show<ClothingShopView>(new object[] { shopId, null, _itemId, needCount }, false);
  204. break;
  205. case ConstFunctionId.FU_ZHUANG_DECOMPOSE:
  206. // this.Hide();
  207. isJump = ViewManager.Show<ClothingDecomposeView>();
  208. break;
  209. case ConstFunctionId.ARENA:
  210. if (!ArenaDataManager.Instance.IsSeasonOpen)
  211. {
  212. PromptController.Instance.ShowFloatTextPrompt("赛季未开始");
  213. return;
  214. }
  215. isJump = ViewManager.Show<ArenaView>();
  216. break;
  217. case ConstFunctionId.STORE:
  218. int storeTabId = int.Parse(infos[1]);
  219. int storeSubId = int.Parse(infos[2]);
  220. if (storeTabId == ConstStoreTabId.STORE_GIFT_BAG) {
  221. List<ShopCfg> shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_GIFT_BAG, ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY);
  222. }
  223. isJump = ViewManager.Show<StoreView>(new object[] { storeTabId, storeSubId });
  224. break;
  225. // case ConstFunctionId.SHOP_GIFT_BAG:
  226. // // this.Hide();
  227. // int giftBagValue = int.Parse(infos[1]);
  228. // isJump = ViewManager.Show<StoreView>(new object[] { ConstFunctionId.STORE_CHARGE, giftBagValue }, _fromeViewDatas);
  229. // break;
  230. // case ConstFunctionId.SHOP_EXCHANGE:
  231. // // this.Hide();
  232. // int exchangeValue = int.Parse(infos[1]);
  233. // isJump = ViewManager.Show<StoreView>(new object[] { ConstFunctionId.STORE_CHARGE, exchangeValue }, _fromeViewDatas);
  234. // break;
  235. case ConstFunctionId.JU_QING_GUAN_QIA:
  236. string value = infos[1];
  237. var levelCfgId = int.Parse(value);
  238. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  239. isJump = false;
  240. if (levelCfg.type == ConstInstanceZonesType.Studio)
  241. {
  242. StudioCfg studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  243. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(studioCfg.funId))
  244. {
  245. break;
  246. }
  247. //TO DO
  248. List<StoryLevelCfg> storyLevelCfgs = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(studioCfg.type, studioCfg.subType, studioCfg.id);
  249. StudioDataManager.Instance.IsCanFight(levelCfg.id, out bool canFight, out string content);
  250. if (!canFight)
  251. {
  252. PromptController.Instance.ShowFloatTextPrompt("关卡未开启");
  253. break;
  254. }
  255. if (!TimeUtil.CheckDayOfWeek(studioCfg.timeArr))
  256. {
  257. PromptController.Instance.ShowFloatTextPrompt("不在活动周期内");
  258. break;
  259. }
  260. if (studioCfg.funId == typeof(StudioFilingView).Name)
  261. {
  262. StudioDataManager.Instance.filingChapterId = studioCfg.id;
  263. StudioDataManager.Instance.npcFilingChapterId = studioCfg.id;
  264. if (StudioDataManager.Instance.IsluckyBoxFilingChapter())
  265. {
  266. ViewManager.Show<StudioActivityView>();
  267. }
  268. else
  269. {
  270. ViewManager.Show<StudioFilingView>();
  271. }
  272. MainStoryDataManager.currentLevelCfgId = levelCfg.id;
  273. InstanceZonesController.ShowLevelView(levelCfg.id, StudioDataManager.Instance.OnFinishFilingStoryLevel, _itemId, _needCount);
  274. isJump = true;
  275. }
  276. else
  277. {
  278. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = 0;
  279. if (studioCfg.funId == typeof(StudioPropertyView).Name)
  280. {
  281. List<StudioCfg> studioCfgs = StudioCfgArray.Instance.GetCfgsByfunId(typeof(StudioPropertyView).Name);
  282. for (int i = 0; i < studioCfgs.Count; i++)
  283. {
  284. if (studioCfgs[i].id == studioCfg.id)
  285. {
  286. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = i;
  287. break;
  288. }
  289. }
  290. }
  291. string viewName = "GFGGame." + studioCfg.funId;
  292. if (studioCfg.funId == "StudioActivityView") {
  293. var activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitLuckyBox);
  294. if (activityId <= 0)
  295. {
  296. PromptController.Instance.ShowFloatTextPrompt("不在活动周期内");
  297. break;
  298. }
  299. }
  300. ViewManager.Show(viewName, StudioDataManager.Instance.PROPERTY_SELECT_INDEX);
  301. StudioDataManager.Instance.VIEW_NAME = viewName;
  302. InstanceZonesController.ShowLevelView(levelCfgId, StudioDataManager.Instance.OnFinishStudioStoryLevel, _itemId, _needCount);
  303. isJump = true;
  304. }
  305. break;
  306. }
  307. else
  308. {
  309. // if (levelCfg.type == ConstInstanceZonesType.Story)
  310. // {
  311. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(typeof(StoryChapterView).FullName))
  312. {
  313. break;
  314. }
  315. if (!MainStoryDataManager.CheckLevelUnlock(levelCfgId))
  316. {
  317. PromptController.Instance.ShowFloatTextPrompt("关卡未开启");
  318. break;
  319. }
  320. if ((string)_fromViewDatas[0] == typeof(DressUpFightView).FullName)
  321. {
  322. //从战斗换装必需品来源跳转到剧情界面,在剧情界面点返回后直接返回章节界面,无需返回换装界面
  323. _fromViewDatas = null;
  324. }
  325. isJump = ViewManager.Show<StoryChapterView>(levelCfg.chapterId, false);
  326. StoryController.ShowLevelView(levelCfgId, _itemId, _needCount);
  327. break;
  328. }
  329. case ConstFunctionId.FU_ZHUANG_HE_CHENG:
  330. isJump = false;
  331. int suitId = SuitCfgArray.Instance.GetSuitIdOfItem(_itemId);
  332. if (suitId > 0)
  333. {
  334. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  335. bool isPass = InstanceZonesDataManager.CheckLevelPass(suitCfg.syntheticStoryLevelId);
  336. if (suitCfg.syntheticStoryLevelId > 0 && !isPass)
  337. {
  338. isJump = ViewManager.Show<SuitSyntheticView>(suitId);
  339. }
  340. else
  341. {
  342. isJump = ViewManager.Show<ClothingSyntheticView>(new object[] { suitId, _itemId });
  343. }
  344. }
  345. break;
  346. case ConstFunctionId.ZHAI_XING:
  347. // this.Hide();
  348. isJump = ViewManager.Show<LuckyBoxView>(null, true);
  349. break;
  350. case ConstFunctionId.TAO_ZHUANG_TU_JIAN:
  351. isJump = false;
  352. if (ViewManager.isViewOpen(typeof(SuitGuideView).FullName))
  353. {
  354. return;
  355. }
  356. isJump = ViewManager.Show<SuitGuideView>();
  357. break;
  358. case ConstFunctionId.TAO_ZHUANG_HE_CHENG:
  359. isJump = ViewManager.Show<SuitSyntheticView>();
  360. break;
  361. case ConstFunctionId.SUIT_FOSTER:
  362. isJump = ViewManager.Show<ClothingListView>();
  363. break;
  364. case ConstFunctionId.DAILY_TASK:
  365. isJump = ViewManager.Show<TaskView>();
  366. break;
  367. case ConstFunctionId.WEEKLY_TASK:
  368. isJump = ViewManager.Show<TaskView>(new object[] { 1 });
  369. break;
  370. case ConstFunctionId.LEAGUE_PRAY:
  371. if (LeagueDataManager.Instance.Type == LeagueJoinType.Join)
  372. {
  373. ViewManager.Show<LeagueView>();
  374. isJump = ViewManager.Show<LeaguePrayView>();
  375. }
  376. else
  377. {
  378. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(nameof(LeagueView))) return;
  379. PromptController.Instance.ShowFloatTextPrompt("暂未加入雅集");
  380. }
  381. break;
  382. case ConstFunctionId.LEAGUE_ANSWER:
  383. if (LeagueDataManager.Instance.Type == LeagueJoinType.Join)
  384. {
  385. ViewManager.Show<LeagueView>();
  386. isJump = ViewManager.Show<LeagueAnswerView>();
  387. }
  388. else
  389. {
  390. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(nameof(LeagueView))) return;
  391. PromptController.Instance.ShowFloatTextPrompt("暂未加入雅集");
  392. }
  393. break;
  394. case ConstFunctionId.SKILLBOOK:
  395. ViewManager.Show<ExchangeGoodsView>(_itemId);
  396. break;
  397. case ConstFunctionId.HEAVEN_SMALL_GAMW:
  398. ViewManager.Show<GameStartView>();
  399. break;
  400. case ConstFunctionId.OPEN_SERVER_FIGHT:
  401. ViewManager.Show<OpenServerFightView>(ConstLimitTimeActivityType.ActLimitStlyc);
  402. break;
  403. case ConstFunctionId.ACTIVITY_GET_YUAN_XIAO_TASK:
  404. ViewManager.Show<ActivityGetYuanXiaoEntryView>();
  405. ViewManager.Show($"GFGGame.{gameFunctionCfg.functionId}");
  406. break;
  407. case ConstFunctionId.ACTIVITY_GET_YUAN_XIAO:
  408. ViewManager.Show($"GFGGame.{gameFunctionCfg.functionId}");
  409. break;
  410. }
  411. if (isJump)
  412. {
  413. EventAgent.DispatchEvent(ConstMessage.JUMP_TO_SOURCE);
  414. }
  415. }
  416. }
  417. }