ApproachView.cs 12 KB

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