GuideController.cs 9.7 KB

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