ApproachView.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. using System.Collections.Generic;
  2. using FairyGUI;
  3. using UI.CommonGame;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public class ApproachView
  8. {
  9. private UI_ComTipsApproach _ui;
  10. private object[] _viewData;
  11. private int _itemId;
  12. private object[] _fromeViewDatas;
  13. private int _needCount;//需求总量
  14. private List<string[]> _approachDatas = new List<string[]>();
  15. public void Dispose()
  16. {
  17. if (_ui != null)
  18. {
  19. _ui.Dispose();
  20. _ui = null;
  21. }
  22. UI_ComTipsApproach.ProxyEnd();
  23. }
  24. public void OnHide()
  25. {
  26. // _ui.m_list.onClickItem.Remove(OnClickListApproachItem);
  27. if (_ui.m_list.numItems > 0)
  28. {
  29. _ui.m_list.ScrollToView(0);
  30. _ui.m_list.numItems = 0;
  31. }
  32. _approachDatas.Clear();
  33. _fromeViewDatas = null;
  34. }
  35. public void OnInit(GComponent component)
  36. {
  37. _ui = UI_ComTipsApproach.Proxy(component);
  38. _ui.m_list.itemRenderer = ListApproachItemRenderer;
  39. }
  40. public void OnShow(object[] viewData)
  41. {
  42. _viewData = viewData;
  43. _itemId = (int)viewData[0];
  44. _fromeViewDatas = viewData[1] as object[];
  45. // _needCount = viewData.Length > 2 ? (int)viewData[2] : 0;
  46. int needCount = viewData.Length > 2 ? (int)viewData[2] : 0;
  47. _needCount = (int)needCount;
  48. SetData();
  49. UpdateView();
  50. }
  51. private void SetData()
  52. {
  53. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
  54. if (string.IsNullOrEmpty(itemCfg.approach)) return;
  55. string[] approachStrs = itemCfg.approach.Split(';');
  56. foreach (string approachStr in approachStrs)
  57. {
  58. if (string.IsNullOrEmpty(approachStr)) continue;
  59. string[] infos = approachStr.Split('=');
  60. _approachDatas.Add(infos);
  61. }
  62. }
  63. private void UpdateView()
  64. {
  65. _ui.m_txtNone.visible = _approachDatas.Count == 0;
  66. _ui.m_list.numItems = _approachDatas.Count;
  67. _ui.m_list.data = _approachDatas;
  68. }
  69. private void ListApproachItemRenderer(int index, GObject item)
  70. {
  71. UI_ListSourceItem listItem = UI_ListSourceItem.Proxy(item);
  72. string[] infos = _approachDatas[index];
  73. string functionId = infos[0];
  74. GameFunctionCfg gameFunctionCfg = GameFunctionCfgArray.Instance.GetCfg(functionId);
  75. // FunctionOpenCfg functionOpenCfg = FunctionOpenCfgArray.Instance.GetCfg(gameFunctionCfg.functionId);
  76. // listItem.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(functionOpenCfg.res);
  77. if (functionId == ConstFunctionId.JU_QING_GUAN_QIA)
  78. {
  79. var levelCfgId = int.Parse(infos[1]);
  80. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  81. if (levelCfg.type == ConstInstanceZonesType.Story)
  82. {
  83. var chapterCfg = StoryChapterCfgArray.Instance.GetCfg(levelCfg.chapterId);
  84. string chapter = NumberUtil.GetChiniseNumberText(chapterCfg.order);
  85. string level = NumberUtil.GetChiniseNumberText(levelCfg.order);
  86. if (levelCfg.subType == ConstInstanceZonesSubType.Normal)
  87. {
  88. listItem.m_txtSourceName.text = string.Format(gameFunctionCfg.name, chapter, level);
  89. }
  90. else if (levelCfg.subType == ConstInstanceZonesSubType.Hard)
  91. {
  92. listItem.m_txtSourceName.text = string.Format("精英" + gameFunctionCfg.name, chapter, level);
  93. }
  94. }
  95. else if (levelCfg.type == ConstInstanceZonesType.Studio)
  96. {
  97. var studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  98. listItem.m_txtSourceName.text = levelCfg.name;
  99. }
  100. }
  101. else if (functionId == ConstFunctionId.FU_ZHUANG_DIAN)
  102. {
  103. int shopId = int.Parse(infos[1]);
  104. if (shopId == ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID)
  105. {
  106. listItem.m_txtSourceName.text = "活动商店";
  107. }
  108. else if (shopId == ConstStoreId.LUCKY_BOX_STORE_ID)
  109. {
  110. listItem.m_txtSourceName.text = "落星商店";
  111. }
  112. else if (shopId == ConstStoreId.GALLERY_STORE_ID)
  113. {
  114. listItem.m_txtSourceName.text = "画廊商店";
  115. }
  116. else
  117. {
  118. listItem.m_txtSourceName.text = "服装店";
  119. }
  120. }
  121. else if (functionId == ConstFunctionId.STORE)
  122. {
  123. int storeTabId = int.Parse(infos[1]);
  124. int storeSubId = int.Parse(infos[2]);
  125. listItem.m_txtSourceName.text = StoreTabCfgArray.Instance.GetCfg(storeTabId).subTabArr[storeSubId][0];
  126. }
  127. else
  128. {
  129. listItem.m_txtSourceName.text = gameFunctionCfg.name;
  130. }
  131. if (listItem.target.data == null)
  132. {
  133. listItem.m_btnGo.target.onClick.Add(OnClickListApproachItem);
  134. }
  135. listItem.m_btnGo.target.data = infos;
  136. UI_ListSourceItem.ProxyEnd();
  137. }
  138. private void OnClickListApproachItem(EventContext context)
  139. {
  140. GObject btnGo = context.sender as GObject;
  141. string[] infos = btnGo.data as string[];
  142. string functionId = infos[0];
  143. long hasNum = ItemDataManager.GetItemNum(_itemId);
  144. long needCount = 0;
  145. bool isJump = true;
  146. switch (functionId)
  147. {
  148. case ConstFunctionId.FU_ZHUANG_DIAN:
  149. // this.Hide();
  150. needCount = (_needCount - hasNum) <= 0 ? 1 : _needCount - hasNum;
  151. int shopId = int.Parse(infos[1]);
  152. // if (shopId == ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID)
  153. // {
  154. // PromptController.Instance.ShowFloatTextPrompt("活动暂未开启");
  155. // isJump = false;
  156. // break;
  157. // }
  158. isJump = ViewManager.Show<ClothingShopView>(new object[] { shopId, null, _itemId, needCount }, _fromeViewDatas, true, true);
  159. break;
  160. case ConstFunctionId.FU_ZHUANG_DECOMPOSE:
  161. // this.Hide();
  162. isJump = ViewManager.Show<ClothingDecomposeView>(null, _fromeViewDatas);
  163. break;
  164. case ConstFunctionId.STORE:
  165. int storeTabId = int.Parse(infos[1]);
  166. int storeSubId = int.Parse(infos[2]);
  167. isJump = ViewManager.Show<StoreView>(new object[] { storeTabId, storeSubId });
  168. return;
  169. // case ConstFunctionId.SHOP_GIFT_BAG:
  170. // // this.Hide();
  171. // int giftBagValue = int.Parse(infos[1]);
  172. // isJump = ViewManager.Show<StoreView>(new object[] { ConstFunctionId.STORE_CHARGE, giftBagValue }, _fromeViewDatas);
  173. // break;
  174. // case ConstFunctionId.SHOP_EXCHANGE:
  175. // // this.Hide();
  176. // int exchangeValue = int.Parse(infos[1]);
  177. // isJump = ViewManager.Show<StoreView>(new object[] { ConstFunctionId.STORE_CHARGE, exchangeValue }, _fromeViewDatas);
  178. // break;
  179. case ConstFunctionId.JU_QING_GUAN_QIA:
  180. string value = infos[1];
  181. var levelCfgId = int.Parse(value);
  182. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  183. isJump = false;
  184. if (levelCfg.type == ConstInstanceZonesType.Studio)
  185. {
  186. StudioCfg studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  187. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(studioCfg.funId))
  188. {
  189. break;
  190. }
  191. //TO DO
  192. List<StoryLevelCfg> storyLevelCfgs = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(studioCfg.type, studioCfg.subType, studioCfg.id);
  193. StudioDataManager.Instance.IsCanFight(levelCfg.id, out bool canFight, out string content);
  194. if (!canFight)
  195. {
  196. PromptController.Instance.ShowFloatTextPrompt("关卡未开启");
  197. break;
  198. }
  199. if (!TimeUtil.CheckDayOfWeek(studioCfg.timeArr))
  200. {
  201. PromptController.Instance.ShowFloatTextPrompt("不在活动周期内");
  202. break;
  203. }
  204. if (studioCfg.funId == typeof(StudioFilingView).Name)
  205. {
  206. StudioDataManager.Instance.filingChapterId = studioCfg.id;
  207. ViewManager.Show<StudioFilingView>(null, _fromeViewDatas);
  208. MainStoryDataManager.currentLevelCfgId = levelCfg.id;
  209. InstanceZonesController.ShowLevelView(levelCfg.id, StudioDataManager.Instance.OnFinishFilingStoryLevel, _itemId, _needCount);
  210. isJump = true;
  211. }
  212. else
  213. {
  214. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = 0;
  215. if (studioCfg.funId == typeof(StudioPropertyView).Name)
  216. {
  217. List<StudioCfg> studioCfgs = StudioCfgArray.Instance.GetCfgsByfunId(typeof(StudioPropertyView).Name);
  218. for (int i = 0; i < studioCfgs.Count; i++)
  219. {
  220. if (studioCfgs[i].id == studioCfg.id)
  221. {
  222. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = i;
  223. break;
  224. }
  225. }
  226. }
  227. string viewName = "GFGGame." + studioCfg.funId;
  228. ViewManager.Show(viewName, StudioDataManager.Instance.PROPERTY_SELECT_INDEX, _fromeViewDatas);
  229. StudioDataManager.Instance.VIEW_NAME = viewName;
  230. InstanceZonesController.ShowLevelView(levelCfgId, StudioDataManager.Instance.OnFinishStudioStoryLevel, _itemId, _needCount);
  231. isJump = true;
  232. }
  233. break;
  234. }
  235. else
  236. {
  237. // if (levelCfg.type == ConstInstanceZonesType.Story)
  238. // {
  239. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(ViewName.STORY_CHAPTER_VIEW))
  240. {
  241. break;
  242. }
  243. if (!MainStoryDataManager.CheckLevelUnlock(levelCfgId))
  244. {
  245. PromptController.Instance.ShowFloatTextPrompt("关卡未开启");
  246. break;
  247. }
  248. if ((string)_fromeViewDatas[0] == ViewName.DRESS_UP_FIGHT_VIEW)
  249. {
  250. //从战斗换装必需品来源跳转到剧情界面,在剧情界面点返回后直接返回章节界面,无需返回换装界面
  251. _fromeViewDatas = null;
  252. }
  253. isJump = ViewManager.Show<StoryChapterView>(levelCfg.chapterId, _fromeViewDatas, true);
  254. StoryController.ShowLevelView(levelCfgId, _itemId, _needCount);
  255. break;
  256. }
  257. case ConstFunctionId.FU_ZHUANG_HE_CHENG:
  258. isJump = false;
  259. int suitId = SuitCfgArray.Instance.GetSuitIdOfItem(_itemId);
  260. if (suitId > 0)
  261. {
  262. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  263. bool isPass = InstanceZonesDataManager.CheckLevelPass(suitCfg.syntheticStoryLevelId);
  264. if (suitCfg.syntheticStoryLevelId > 0 && !isPass)
  265. {
  266. isJump = ViewManager.Show<SuitSyntheticView>(suitId, _fromeViewDatas);
  267. }
  268. else
  269. {
  270. isJump = ViewManager.Show<ClothingSyntheticView>(new object[] { suitId, _itemId }, _fromeViewDatas);
  271. }
  272. }
  273. break;
  274. case ConstFunctionId.ZHAI_XING:
  275. // this.Hide();
  276. isJump = ViewManager.Show<LuckyBoxView>(null, _fromeViewDatas, true);
  277. break;
  278. case ConstFunctionId.TAO_ZHUANG_TU_JIAN:
  279. isJump = false;
  280. if (ViewManager.isViewOpen(ViewName.SUIT_GUIDE_VIEW))
  281. {
  282. return;
  283. }
  284. isJump = ViewManager.Show<SuitGuideView>(null, _fromeViewDatas);
  285. break;
  286. case ConstFunctionId.TAO_ZHUANG_HE_CHENG:
  287. isJump = ViewManager.Show<SuitSyntheticView>();
  288. break;
  289. case ConstFunctionId.SUIT_FOSTER:
  290. isJump = ViewManager.Show<ClothingListView>(null, _fromeViewDatas);
  291. break;
  292. case ConstFunctionId.DAILY_TASK:
  293. isJump = ViewManager.Show<TaskView>(null, _fromeViewDatas);
  294. break;
  295. case ConstFunctionId.WEEKLY_TASK:
  296. isJump = ViewManager.Show<TaskView>(new object[] { 1 }, _fromeViewDatas);
  297. break;
  298. case ConstFunctionId.LEAGUE_PRAY:
  299. isJump = ViewManager.Show<LeaguePrayView>(null, _fromeViewDatas);
  300. break;
  301. case ConstFunctionId.LEAGUE_ANSWER:
  302. if (LeagueDataManager.Instance.Type == LeagueJoinType.Join)
  303. {
  304. ViewManager.Show<LeagueView>(null, _fromeViewDatas);
  305. isJump = ViewManager.Show<LeagueAnswerView>();
  306. }
  307. else
  308. {
  309. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(nameof(LeagueView))) return;
  310. PromptController.Instance.ShowFloatTextPrompt("暂未加入雅集");
  311. }
  312. break;
  313. }
  314. if (isJump)
  315. {
  316. EventAgent.DispatchEvent(ConstMessage.JUMP_TO_SOURCE);
  317. }
  318. }
  319. }
  320. }