ApproachView.cs 12 KB

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