GuideController.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using FairyGUI;
  2. using UI.DressUp;
  3. using UI.Main;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UI.ClothingSynthetic;
  7. using ET;
  8. namespace GFGGame
  9. {
  10. public class GuideController
  11. {
  12. public static bool IsGuide()
  13. {
  14. if (!GameGlobal.isEnterGame) return false;//未进入游戏
  15. bool isAllGuideFinish = false;
  16. for (int i = 0; i < GuideCfgArray.Instance.dataArray.Length; i++)
  17. {
  18. if (GuideDataManager.IsGuideFinish(GuideCfgArray.Instance.dataArray[i].key) <= 0)
  19. {
  20. isAllGuideFinish = false;
  21. break;
  22. }
  23. isAllGuideFinish = true;
  24. }
  25. bool isGuide = GameGlobal.skipGuide == false && !isAllGuideFinish;
  26. return isGuide;
  27. }
  28. /// <summary>
  29. /// 检测当前角色等级是否有引导开启,若有则返回引导id
  30. /// </summary>
  31. /// <returns></returns>
  32. public static string CheckHasRoleLvGuideOpen()
  33. {
  34. GuideCfg[] guideCfgs = GuideCfgArray.Instance.dataArray;
  35. for (int i = 0; i < guideCfgs.Length; i++)
  36. {
  37. if (guideCfgs[i].roleLv <= 0) continue;
  38. bool isFinishCurId = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_GUIDE + guideCfgs[i].id) > 0;
  39. if (!isFinishCurId && guideCfgs[i].roleLv <= RoleDataManager.lvl)
  40. {
  41. return guideCfgs[i].viewName;
  42. }
  43. }
  44. return "";
  45. }
  46. /// <summary>
  47. /// 是否特殊条件开启
  48. /// </summary>
  49. /// <returns></returns>
  50. private static bool CheckSpecialGuideOpen(GuideCfg cfg)
  51. {
  52. if (cfg.special <= 0) return false;
  53. if (cfg.guideKey == ConstGuideId.SUIT_LIST_VIEW)
  54. {
  55. return FunctionOpenDataManager.Instance.CheckIsFunOpenById(typeof(ClothingListView).Name, false);
  56. }
  57. return false;
  58. }
  59. private static GList targetList = null;
  60. public static bool TryGuide(GComponent target, string guideKey, int index, string guideStr = null, int listIndex = -1, bool checkPriorIndex = true, float yTxt = 0, bool justHint = false, bool noTips = false)
  61. {
  62. if (!GameGlobal.PreDataInited)
  63. {
  64. return false;
  65. }
  66. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  67. if (cfg == null || GuideDataManager.currentGuideId != 0 && GuideDataManager.currentGuideId != cfg.id) return false;
  68. bool isPass = InstanceZonesDataManager.CheckLevelPass(cfg.storyLevelId);
  69. // if (guideKey == ConstGuideId.ARENA_OPEN)
  70. // {
  71. // return false;//临时屏蔽
  72. // }
  73. if (guideKey == ConstGuideId.ARENA_OPEN && (isPass || ArenaDataManager.Instance.IsArenaClearing))
  74. {
  75. return false;//竞技场结算中或已通关指定开启关卡,不引导
  76. }
  77. GRoot.inst.touchable = false;
  78. bool isStoryLevelGuide = cfg.storyLevelId > 0;
  79. bool isFinishCurId = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_GUIDE + cfg.id) > 0;//当前引导未完成
  80. bool isFinishPriorId = cfg.priorId <= 0 || StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_GUIDE + cfg.priorId) > 0;//前置引导已完成
  81. bool isFinishCurIndex = GuideDataManager.IsGuideIndexFinish(cfg.id, index) == true;//当前index未完成
  82. bool isFinishPriorIndex = !checkPriorIndex || checkPriorIndex && GuideDataManager.IsGuideIndexFinish(cfg.id, index - 1) == true;//前置index已完成
  83. // ET.Log.Debug("storyLevelId:" + cfg.storyLevelId + " time:" + TimeHelper.ClientNowSeconds());
  84. bool isCfgChapterOpen = MainStoryDataManager.CheckLevelUnlock(cfg.storyLevelId, false);//引导配置关卡已开启
  85. bool isCfgChapter = MainStoryDataManager.currentLevelCfgId == 0 || MainStoryDataManager.currentLevelCfgId == cfg.storyLevelId;//无选择(进入游戏时无选择)或当前所选择为配置关卡
  86. if (isStoryLevelGuide && isPass && !isFinishCurId)
  87. {
  88. GuideDataManager.currentGuideId = cfg.id;
  89. TryCompleteGuide(guideKey);
  90. return false;
  91. }
  92. bool isRoleLvGuide = cfg.roleLv > 0;
  93. bool iscurRoleLv = RoleDataManager.lvl >= cfg.roleLv;
  94. bool isSpecial = cfg.special > 0; //特殊条件开启的引导
  95. bool specialOpen = CheckSpecialGuideOpen(cfg);
  96. bool noneType = !isStoryLevelGuide && !isFinishCurId && isFinishPriorId && !isFinishCurIndex && isFinishPriorIndex && !isRoleLvGuide && !isSpecial;
  97. bool storyType = isStoryLevelGuide && !isFinishCurId && isFinishPriorId && !isFinishCurIndex && isFinishPriorIndex && isCfgChapterOpen && isCfgChapter;
  98. bool roleLvType = isRoleLvGuide && !isFinishCurId && isFinishPriorId && !isFinishCurIndex && isFinishPriorIndex && iscurRoleLv;
  99. bool specialType = isSpecial && !isFinishCurId && isFinishPriorId && !isFinishCurIndex && isFinishPriorIndex && specialOpen;
  100. if (storyType || roleLvType || specialType || noneType)
  101. {
  102. GuideDataManager.currentGuideId = cfg.id;
  103. GuideDataManager.currentGuideIdIndex = index;
  104. GuideDataManager.SetGuideIndex(cfg.id, index);
  105. if (listIndex >= 0)
  106. {
  107. if (target.asList.numItems > 0)
  108. {
  109. GComponent item = (target.asList).GetChildAt(listIndex).asCom;
  110. if (item != null)
  111. {
  112. targetList = target as GList;
  113. targetList.ScrollToView(listIndex);
  114. if (targetList.scrollPane != null)
  115. {
  116. targetList.scrollPane.touchEffect = false;//引导中禁止拖动
  117. }
  118. target = item;
  119. // target.asList.ScrollToView(listIndex);
  120. }
  121. }
  122. else
  123. {
  124. GRoot.inst.touchable = true;
  125. return false;
  126. }
  127. }
  128. ShowGuideByIndex(target, guideKey, guideStr, GuideDataManager.currentGuideId, GuideDataManager.currentGuideIdIndex, yTxt, justHint, noTips);
  129. if (!checkPriorIndex)
  130. {
  131. for (int i = 1; i < index; i++)
  132. {
  133. GuideDataManager.TryCompleteGuideIndex(cfg.id, i, false);
  134. }
  135. }
  136. return true;
  137. }
  138. GRoot.inst.touchable = true;
  139. MainDataManager.Instance.CanSwipe = true;
  140. return false;
  141. }
  142. private static void ShowGuideByIndex(GObject target, string guideKey, string guideStr = null, int guideId = 0, int index = 0, float yTxt = 0, bool justHint = false, bool noTips = false)
  143. {
  144. HideGuide();
  145. if (GameGlobal.skipGuide)
  146. {
  147. return;
  148. }
  149. LogServerHelper.SendNodeLog(GuideDataManager.currentGuideId * 100 + 1);
  150. ViewManager.Show<GuideView>(new List<object> { target, guideKey, guideStr, guideId, index, yTxt, justHint, noTips });
  151. }
  152. public static bool TryCompleteGuideIndex(string guideKey, int index)
  153. {
  154. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  155. if (cfg == null) return false;
  156. HideGuide();
  157. if (GuideDataManager.TryCompleteGuideIndex(cfg.id, index))
  158. {
  159. if (targetList != null && targetList.scrollPane != null)
  160. {
  161. targetList.scrollPane.touchEffect = true;
  162. targetList = null;
  163. }
  164. MainDataManager.Instance.CanSwipe = true;
  165. EventAgent.DispatchEvent(ConstMessage.FINSH_GUIDE_INDEX);
  166. return true;
  167. }
  168. return false;
  169. }
  170. public static async void TryCompleteGuide(string guideKey, int count)
  171. {
  172. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  173. if (cfg == null) return;
  174. if (!GuideDataManager.CheckAllIndexFinish(cfg.id, count)) return;
  175. TryCompleteGuide(guideKey);
  176. }
  177. private static async void TryCompleteGuide(string guideKey)
  178. {
  179. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  180. bool result = await GuideDataManager.TryCompleteGuide(cfg.id);
  181. if (result)
  182. {
  183. if (targetList != null && targetList.scrollPane != null)
  184. {
  185. targetList.scrollPane.touchEffect = true;
  186. targetList = null;
  187. }
  188. MainDataManager.Instance.CanSwipe = true;
  189. LogServerHelper.SendNodeLog(GuideDataManager.currentGuideId * 100 + 2);
  190. GuideDataManager.currentGuideId = 0;
  191. HideGuide();
  192. }
  193. }
  194. public static void HideGuide()
  195. {
  196. ViewManager.Hide<GuideView>();
  197. }
  198. }
  199. }