ApproachView.cs 20 KB

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