ApproachView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. int hasNum = ItemDataManager.GetItemNum(_itemId);
  136. int 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. break;
  148. }
  149. isJump = ViewManager.Show(ViewName.CLOTHING_SHOP_VIEW, new object[] { shopId, null, _itemId, needCount }, _fromeViewDatas, true, true);
  150. break;
  151. case ConstFunctionId.FU_ZHUANG_DECOMPOSE:
  152. // this.Hide();
  153. isJump = ViewManager.Show<ClothingDecomposeView>(null, _fromeViewDatas);
  154. break;
  155. case ConstFunctionId.SHOP_GIFT_BAG:
  156. // this.Hide();
  157. int giftBagValue = int.Parse(infos[1]);
  158. isJump = ViewManager.Show<RechargeStoreView>(giftBagValue, _fromeViewDatas);
  159. break;
  160. case ConstFunctionId.SHOP_EXCHANGE:
  161. // this.Hide();
  162. int exchangeValue = int.Parse(infos[1]);
  163. isJump = ViewManager.Show<RechargeStoreView>(exchangeValue, _fromeViewDatas);
  164. break;
  165. case ConstFunctionId.JU_QING_GUAN_QIA:
  166. string value = infos[1];
  167. var levelCfgId = int.Parse(value);
  168. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  169. isJump = false;
  170. if (levelCfg.type == ConstInstanceZonesType.Studio)
  171. {
  172. StudioCfg studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  173. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(studioCfg.funId))
  174. {
  175. break;
  176. }
  177. //TO DO
  178. List<StoryLevelCfg> storyLevelCfgs = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(studioCfg.type, studioCfg.subType, studioCfg.id);
  179. StudioDataManager.Instance.IsCanFight(levelCfg.id, out bool canFight, out string content);
  180. if (!canFight)
  181. {
  182. PromptController.Instance.ShowFloatTextPrompt("关卡未开启");
  183. break;
  184. }
  185. if (!TimeUtil.CheckDayOfWeek(studioCfg.timeArr))
  186. {
  187. PromptController.Instance.ShowFloatTextPrompt("不在活动周期内");
  188. break;
  189. }
  190. if (studioCfg.funId == typeof(StudioFilingView).Name)
  191. {
  192. StudioDataManager.Instance.filingChapterId = studioCfg.id;
  193. ViewManager.Show<StudioFilingView>(null, _fromeViewDatas);
  194. MainStoryDataManager.currentLevelCfgId = levelCfg.id;
  195. InstanceZonesController.ShowLevelView(levelCfg.id, StudioDataManager.Instance.OnFinishFilingStoryLevel);
  196. isJump = true;
  197. }
  198. else
  199. {
  200. int type = studioCfg.funId == typeof(StudioPropertyView).Name ? 1 : 0;
  201. StudioDataManager.Instance.TYPE_SELECT_INDEX = type;
  202. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = 0;
  203. if (studioCfg.funId == typeof(StudioPropertyView).Name)
  204. {
  205. List<StudioCfg> studioCfgs = StudioCfgArray.Instance.GetCfgsByfunId(typeof(StudioPropertyView).Name);
  206. for (int i = 0; i < studioCfgs.Count; i++)
  207. {
  208. if (studioCfgs[i].id == studioCfg.id)
  209. {
  210. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = i;
  211. break;
  212. }
  213. }
  214. }
  215. string viewName = "GFGGame." + studioCfg.funId;
  216. ViewManager.Show(viewName, new object[] { type, 0 }, _fromeViewDatas);
  217. StudioDataManager.Instance.VIEW_NAME = viewName;
  218. InstanceZonesController.ShowLevelView(levelCfgId, StudioDataManager.Instance.OnFinishStudioStoryLevel, _itemId, _needCount);
  219. isJump = true;
  220. }
  221. break;
  222. }
  223. else
  224. {
  225. // if (levelCfg.type == ConstInstanceZonesType.Story)
  226. // {
  227. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(ViewName.STORY_CHAPTER_VIEW))
  228. {
  229. break;
  230. }
  231. if (!MainStoryDataManager.CheckLevelUnlock(levelCfgId))
  232. {
  233. PromptController.Instance.ShowFloatTextPrompt("关卡未开启");
  234. break;
  235. }
  236. if ((string)_fromeViewDatas[0] == ViewName.DRESS_UP_FIGHT_VIEW)
  237. {
  238. //从战斗换装必需品来源跳转到剧情界面,在剧情界面点返回后直接返回章节界面,无需返回换装界面
  239. _fromeViewDatas = null;
  240. }
  241. isJump = ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, levelCfg.chapterId, _fromeViewDatas, true);
  242. StoryController.ShowLevelView(levelCfgId, _itemId, _needCount);
  243. break;
  244. }
  245. case ConstFunctionId.FU_ZHUANG_HE_CHENG:
  246. isJump = false;
  247. int suitId = SuitCfgManager.Instance.GetItemSuitId(_itemId);
  248. if (suitId > 0)
  249. {
  250. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  251. bool isPass = InstanceZonesDataManager.CheckLevelPass(suitCfg.syntheticStoryLevelId);
  252. if (suitCfg.syntheticStoryLevelId > 0 && !isPass)
  253. {
  254. isJump = ViewManager.Show(ViewName.SUIT_SYNTHETIC_LIST_VIEW, suitId, _fromeViewDatas);
  255. }
  256. else
  257. {
  258. isJump = ViewManager.Show(ViewName.CLOTHING_SYNTHETIC_VIEW, new object[] { suitId, _itemId }, _fromeViewDatas);
  259. }
  260. }
  261. break;
  262. case ConstFunctionId.ZHAI_XING:
  263. // this.Hide();
  264. isJump = ViewManager.Show(ViewName.LUCKY_BOX_VIEW, null, _fromeViewDatas, true);
  265. break;
  266. case ConstFunctionId.TAO_ZHUANG_TU_JIAN:
  267. isJump = false;
  268. if (ViewManager.isViewOpen(ViewName.SUIT_GUIDE_VIEW))
  269. {
  270. // this.Hide();
  271. return;
  272. }
  273. // this.Hide();
  274. isJump = ViewManager.Show(ViewName.SUIT_GUIDE_VIEW, null, _fromeViewDatas);
  275. break;
  276. case ConstFunctionId.TAO_ZHUANG_HE_CHENG:
  277. // this.Hide();
  278. isJump = ViewManager.Show(ViewName.SUIT_SYNTHETIC_LIST_VIEW);
  279. break;
  280. case ConstFunctionId.SUIT_FOSTER:
  281. // this.Hide();
  282. isJump = ViewManager.Show<ClothingListView>(null, _fromeViewDatas);
  283. break;
  284. }
  285. if (isJump)
  286. {
  287. EventAgent.DispatchEvent(ConstMessage.JUMP_TO_SOURCE);
  288. }
  289. }
  290. }
  291. }