ApproachView.cs 20 KB

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