ApproachView.cs 14 KB

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