ApproachView.cs 14 KB

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