ApproachView.cs 12 KB

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