ApproachView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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
  111. {
  112. listItem.m_txtSourceName.text = "服装店";
  113. }
  114. }
  115. else
  116. {
  117. listItem.m_txtSourceName.text = gameFunctionCfg.name;
  118. }
  119. if (listItem.target.data == null)
  120. {
  121. listItem.m_btnGo.target.onClick.Add(OnClickListApproachItem);
  122. }
  123. listItem.m_btnGo.target.data = infos;
  124. UI_ListSourceItem.ProxyEnd();
  125. }
  126. private void OnClickListApproachItem(EventContext context)
  127. {
  128. GObject btnGo = context.sender as GObject;
  129. string[] infos = btnGo.data as string[];
  130. string functionId = infos[0];
  131. int hasNum = ItemDataManager.GetItemNum(_itemId);
  132. int needCount = 0;
  133. bool isJump = true;
  134. switch (functionId)
  135. {
  136. case ConstFunctionId.FU_ZHUANG_DIAN:
  137. // this.Hide();
  138. needCount = (_needCount - hasNum) <= 0 ? 1 : _needCount - hasNum;
  139. int shopId = int.Parse(infos[1]);
  140. if (shopId == ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID)
  141. {
  142. PromptController.Instance.ShowFloatTextPrompt("活动暂未开启");
  143. break;
  144. }
  145. isJump = ViewManager.Show(ViewName.CLOTHING_SHOP_VIEW, new object[] { shopId, null, _itemId, needCount }, _fromeViewDatas, true, true);
  146. break;
  147. case ConstFunctionId.FU_ZHUANG_DECOMPOSE:
  148. // this.Hide();
  149. isJump = ViewManager.Show<ClothingDecomposeView>(null, _fromeViewDatas);
  150. break;
  151. case ConstFunctionId.SHOP_GIFT_BAG:
  152. // this.Hide();
  153. int giftBagValue = int.Parse(infos[1]);
  154. isJump = ViewManager.Show<RechargeStoreView>(giftBagValue, _fromeViewDatas);
  155. break;
  156. case ConstFunctionId.SHOP_EXCHANGE:
  157. // this.Hide();
  158. int exchangeValue = int.Parse(infos[1]);
  159. isJump = ViewManager.Show<RechargeStoreView>(exchangeValue, _fromeViewDatas);
  160. break;
  161. case ConstFunctionId.JU_QING_GUAN_QIA:
  162. string value = infos[1];
  163. var levelCfgId = int.Parse(value);
  164. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  165. isJump = false;
  166. if (levelCfg.type == ConstInstanceZonesType.Studio)
  167. {
  168. StudioCfg studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  169. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(studioCfg.funId))
  170. {
  171. break;
  172. }
  173. //TO DO
  174. List<StoryLevelCfg> storyLevelCfgs = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(studioCfg.type, studioCfg.subType, studioCfg.id);
  175. StudioDataManager.Instance.IsCanFight(levelCfg.id, out bool canFight, out string content);
  176. if (!canFight)
  177. {
  178. PromptController.Instance.ShowFloatTextPrompt("关卡未开启");
  179. break;
  180. }
  181. if (!TimeUtil.CheckDayOfWeek(studioCfg.timeArr))
  182. {
  183. PromptController.Instance.ShowFloatTextPrompt("不在活动周期内");
  184. break;
  185. }
  186. if (studioCfg.funId == typeof(StudioFilingView).Name)
  187. {
  188. StudioDataManager.Instance.filingChapterId = studioCfg.id;
  189. ViewManager.Show<StudioFilingView>();
  190. MainStoryDataManager.currentLevelCfgId = levelCfg.id;
  191. InstanceZonesController.ShowLevelView(levelCfg.id, StudioDataManager.Instance.OnFinishFilingStoryLevel);
  192. }
  193. else
  194. {
  195. int type = studioCfg.funId == typeof(StudioPropertyView).Name ? 1 : 0;
  196. StudioDataManager.Instance.TYPE_SELECT_INDEX = type;
  197. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = 0;
  198. if (studioCfg.funId == typeof(StudioPropertyView).Name)
  199. {
  200. List<StudioCfg> studioCfgs = StudioCfgArray.Instance.GetCfgsByfunId(typeof(StudioPropertyView).Name);
  201. for (int i = 0; i < studioCfgs.Count; i++)
  202. {
  203. if (studioCfgs[i].id == studioCfg.id)
  204. {
  205. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = i;
  206. break;
  207. }
  208. }
  209. }
  210. string viewName = "GFGGame." + studioCfg.funId;
  211. ViewManager.Show(viewName, new object[] { type, 0 }, _fromeViewDatas);
  212. StudioDataManager.Instance.VIEW_NAME = viewName;
  213. InstanceZonesController.ShowLevelView(levelCfgId, StudioDataManager.Instance.OnFinishStudioStoryLevel, _itemId, _needCount);
  214. isJump = true;
  215. }
  216. break;
  217. }
  218. else
  219. {
  220. // if (levelCfg.type == ConstInstanceZonesType.Story)
  221. // {
  222. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(ViewName.STORY_CHAPTER_VIEW))
  223. {
  224. break;
  225. }
  226. if (!MainStoryDataManager.CheckLevelUnlock(levelCfgId))
  227. {
  228. PromptController.Instance.ShowFloatTextPrompt("关卡未开启");
  229. break;
  230. }
  231. if ((string)_fromeViewDatas[0] == ViewName.DRESS_UP_FIGHT_VIEW)
  232. {
  233. //从战斗换装必需品来源跳转到剧情界面,在剧情界面点返回后直接返回章节界面,无需返回换装界面
  234. _fromeViewDatas = null;
  235. }
  236. isJump = ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, levelCfg.chapterId, _fromeViewDatas, true);
  237. StoryController.ShowLevelView(levelCfgId, _itemId, _needCount);
  238. break;
  239. }
  240. case ConstFunctionId.FU_ZHUANG_HE_CHENG:
  241. isJump = false;
  242. int suitId = SuitCfgManager.Instance.GetItemSuitId(_itemId);
  243. if (suitId > 0)
  244. {
  245. // this.Hide();
  246. isJump = ViewManager.Show(ViewName.CLOTHING_SYNTHETIC_VIEW, new object[] { suitId, _itemId }, _fromeViewDatas);
  247. }
  248. break;
  249. case ConstFunctionId.ZHAI_XING:
  250. // this.Hide();
  251. isJump = ViewManager.Show(ViewName.LUCKY_BOX_VIEW, null, _fromeViewDatas, true);
  252. break;
  253. case ConstFunctionId.TAO_ZHUANG_TU_JIAN:
  254. isJump = false;
  255. if (ViewManager.isViewOpen(ViewName.SUIT_GUIDE_VIEW))
  256. {
  257. // this.Hide();
  258. return;
  259. }
  260. // this.Hide();
  261. isJump = ViewManager.Show(ViewName.SUIT_GUIDE_VIEW, null, _fromeViewDatas);
  262. break;
  263. case ConstFunctionId.TAO_ZHUANG_HE_CHENG:
  264. // this.Hide();
  265. isJump = ViewManager.Show(ViewName.SUIT_SYNTHETIC_LIST_VIEW);
  266. break;
  267. case ConstFunctionId.SUIT_FOSTER:
  268. // this.Hide();
  269. isJump = ViewManager.Show<ClothingListView>(null, _fromeViewDatas);
  270. break;
  271. }
  272. if (isJump)
  273. {
  274. EventAgent.DispatchEvent(ConstMessage.JUMP_TO_SOURCE);
  275. }
  276. }
  277. }
  278. }