GuideController.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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)
  61. {
  62. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  63. if (GuideDataManager.currentGuideId != 0 && GuideDataManager.currentGuideId != cfg.id) return false;
  64. GRoot.inst.touchable = false;
  65. bool isStoryLevelGuide = cfg.storyLevelId > 0;
  66. bool isFinishCurId = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_GUIDE + cfg.id) > 0;//当前引导未完成
  67. bool isFinishPriorId = cfg.priorId <= 0 || StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_GUIDE + cfg.priorId) > 0;//前置引导已完成
  68. bool isFinishCurIndex = GuideDataManager.IsGuideIndexFinish(cfg.id, index) == true;//当前index未完成
  69. bool isFinishPriorIndex = !checkPriorIndex || checkPriorIndex && GuideDataManager.IsGuideIndexFinish(cfg.id, index - 1) == true;//前置index已完成
  70. // ET.Log.Debug("storyLevelId:" + cfg.storyLevelId + " time:" + TimeHelper.ClientNowSeconds());
  71. bool isCfgChapterOpen = MainStoryDataManager.CheckLevelUnlock(cfg.storyLevelId, false);//引导配置关卡已开启
  72. bool isCfgChapter = MainStoryDataManager.currentLevelCfgId == 0 || MainStoryDataManager.currentLevelCfgId == cfg.storyLevelId;//无选择(进入游戏时无选择)或当前所选择为配置关卡
  73. bool isRoleLvGuide = cfg.roleLv > 0;
  74. bool iscurRoleLv = RoleDataManager.lvl >= cfg.roleLv;
  75. bool isSpecial = cfg.special > 0; //特殊条件开启的引导
  76. bool specialOpen = CheckSpecialGuideOpen(cfg);
  77. bool noneType = !isStoryLevelGuide && !isFinishCurId && isFinishPriorId && !isFinishCurIndex && isFinishPriorIndex && !isRoleLvGuide && !isSpecial;
  78. bool storyType = isStoryLevelGuide && !isFinishCurId && isFinishPriorId && !isFinishCurIndex && isFinishPriorIndex && isCfgChapterOpen && isCfgChapter;
  79. bool roleLvType = isRoleLvGuide && !isFinishCurId && isFinishPriorId && !isFinishCurIndex && isFinishPriorIndex && iscurRoleLv;
  80. bool specialType = isSpecial && !isFinishCurId && isFinishPriorId && !isFinishCurIndex && isFinishPriorIndex && specialOpen;
  81. if (storyType || roleLvType || specialType || noneType)
  82. {
  83. GuideDataManager.currentGuideId = cfg.id;
  84. GuideDataManager.currentGuideIdIndex = index;
  85. GuideDataManager.SetGuideIndex(cfg.id, index);
  86. if (listIndex >= 0)
  87. {
  88. if (target.asList.numItems > 0)
  89. {
  90. GComponent item = (target.asList).GetChildAt(listIndex).asCom;
  91. if (item != null)
  92. {
  93. targetList = target as GList;
  94. targetList.ScrollToView(listIndex);
  95. if (targetList.scrollPane != null)
  96. {
  97. targetList.scrollPane.touchEffect = false;//引导中禁止拖动
  98. }
  99. target = item;
  100. // target.asList.ScrollToView(listIndex);
  101. }
  102. }
  103. else
  104. {
  105. GRoot.inst.touchable = true;
  106. return false;
  107. }
  108. }
  109. ShowGuideByIndex(target, guideStr, GuideDataManager.currentGuideId, GuideDataManager.currentGuideIdIndex, yTxt, justHint);
  110. if (!checkPriorIndex)
  111. {
  112. for (int i = 1; i < index; i++)
  113. {
  114. GuideDataManager.TryCompleteGuideIndex(cfg.id, i, false);
  115. }
  116. }
  117. return true;
  118. }
  119. GRoot.inst.touchable = true;
  120. MainDataManager.Instance.CanSwipe = true;
  121. return false;
  122. }
  123. private static void ShowGuideByIndex(GObject target, string guideStr = null, int guideId = 0, int index = 0, float yTxt = 0, bool justHint = false)
  124. {
  125. HideGuide();
  126. if (GameGlobal.skipGuide)
  127. {
  128. return;
  129. }
  130. LogServerHelper.SendNodeLog(GuideDataManager.currentGuideId * 100 + 1);
  131. ViewManager.Show(ViewName.GUIDE_VIEW, new List<object> { target, guideStr, guideId, index, yTxt, justHint });
  132. }
  133. public static bool TryCompleteGuideIndex(int guideId, int index)
  134. {
  135. HideGuide();
  136. if (GuideDataManager.TryCompleteGuideIndex(guideId, index))
  137. {
  138. if (targetList != null && targetList.scrollPane != null)
  139. {
  140. targetList.scrollPane.touchEffect = true;
  141. targetList = null;
  142. }
  143. MainDataManager.Instance.CanSwipe = true;
  144. EventAgent.DispatchEvent(ConstMessage.FINSH_GUIDE_INDEX);
  145. return true;
  146. }
  147. return false;
  148. }
  149. public static async void TryCompleteGuide(string guideKey, int count)
  150. {
  151. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  152. bool result = false;
  153. if (!GuideDataManager.CheckAllIndexFinish(cfg.id, count)) return;
  154. result = await GuideDataManager.TryCompleteGuide(cfg.id);
  155. if (result)
  156. {
  157. if (targetList != null && targetList.scrollPane != null)
  158. {
  159. targetList.scrollPane.touchEffect = true;
  160. targetList = null;
  161. }
  162. MainDataManager.Instance.CanSwipe = true;
  163. GuideDataManager.currentGuideId = 0;
  164. HideGuide();
  165. }
  166. }
  167. public static void HideGuide()
  168. {
  169. ViewManager.Hide(ViewName.GUIDE_VIEW);
  170. }
  171. }
  172. }