You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
307 lines
11 KiB
307 lines
11 KiB
import { Component, director, Node } from "cc";
|
|
import { PREVIEW } from "cc/env";
|
|
import { MainConfig } from "../../Launch/_MainConfig";
|
|
import { EGlobalEvent } from "../MesEvent/EGlobalEvent";
|
|
import MesMgr from "../MesEvent/MesMgr";
|
|
import { LocalDataMgr } from "../Mgr_LocalData/LocalDataMgr";
|
|
import UIMgr from "../Mgr_UI/UIMgr";
|
|
import { GuideConfig, GuideConfigType, GuideFlagConfig } from "./GuideConfig";
|
|
import GuideData from "./GuideData";
|
|
import { clickChildSetpData, ClickSetpData, EventSetpData, FingerSetpData, GType } from "./GuideEnum";
|
|
import GuideUIView from "./GuideUIView";
|
|
import { TDAnalyticsMgr } from "../Mgr_Ge/TDAnalyticsMgr";
|
|
import { GEData } from "../Mgr_Ge/GeDifine";
|
|
import { TXSDKMgr } from "../Mgr_Ge/TXSDKMgr";
|
|
|
|
//#region 引导数据管理
|
|
|
|
// 该脚本主要处理 引导是遮罩移动与遮罩聚焦 设置按钮点击时的处理
|
|
|
|
//#endregion
|
|
|
|
export default class GuideDataMgr extends Component {
|
|
private static _ins: GuideDataMgr = null;
|
|
public static get ins(): GuideDataMgr {
|
|
if (!this._ins) {
|
|
let tNode = new Node("GuideDataMgr")
|
|
tNode.addComponent(GuideDataMgr);
|
|
director.addPersistRootNode(tNode);
|
|
}
|
|
return this._ins;
|
|
}
|
|
|
|
init() {
|
|
//ConsoleEx.Log("初始化GuideDataMgr")
|
|
if (PREVIEW) {
|
|
window["GuideDataMgr"] = GuideDataMgr;
|
|
}
|
|
}
|
|
|
|
protected onLoad(): void {
|
|
GuideDataMgr._ins = this;
|
|
GuideData.isGuide = false;
|
|
/**引导中的Key */
|
|
GuideData.guideKey = "";
|
|
/**当前引导数据 */
|
|
GuideData.curGuideConfig = null;
|
|
GuideData.stepIndex = 0;
|
|
if(!LocalDataMgr.Guide.isAllGuideDone){
|
|
MesMgr.on(EGlobalEvent.E_TRY_EXECUTE_GUIDE, this.TryExecuteGuide, this);
|
|
MesMgr.on(EGlobalEvent.E_GUIDE_TO_NEXT, this.tickGuide, this);
|
|
MesMgr.on(EGlobalEvent.E_UPDATE_TOKEN, this.TryExecuteGuide, this);
|
|
}
|
|
}
|
|
|
|
protected onDestroy(): void {
|
|
MesMgr.offAllCaller(this)
|
|
GuideDataMgr._ins = null;
|
|
}
|
|
|
|
getGuideEventID(guide) {
|
|
return GuideFlagConfig[guide] || 0;
|
|
}
|
|
|
|
TryExecuteGuide() {
|
|
let guide = this.TryGetGuide();
|
|
if ((!GuideData.guideKey || !GuideData.curGuideConfig) && guide) {
|
|
let guideCnf = GuideConfig[guide];
|
|
if (guideCnf) {
|
|
if (guideCnf.uiName && guideCnf.uiName.length) {
|
|
if (!UIMgr.Ins.getUIFrom(guideCnf.uiName)) {
|
|
return;
|
|
}
|
|
}
|
|
UIMgr.Ins.CloseAllUIByType();
|
|
this.setGuide(guide);
|
|
}
|
|
}
|
|
}
|
|
|
|
setExecuteGuide(guide: GuideConfigType) {
|
|
if (!this.hasGuide(guide)) {
|
|
if ((!GuideData.guideKey || !GuideData.curGuideConfig) && guide) {
|
|
let guideCnf = GuideConfig[guide];
|
|
if (guideCnf) {
|
|
if(guide === GuideConfigType.第一次查看任务){
|
|
TXSDKMgr.ins.onTutorial_start();
|
|
}
|
|
if (guideCnf.uiName && guideCnf.uiName.length) {
|
|
if (!UIMgr.Ins.getUIFrom(guideCnf.uiName)) {
|
|
return;
|
|
}
|
|
}
|
|
//UIMgr.Ins.CloseOtherUI();
|
|
this.setGuide(guide);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**尝试获取引导 */
|
|
TryGetGuide() {
|
|
|
|
if (MainConfig.ShieldingGuidanceSteps || LocalDataMgr.Guide.isAllGuideDone) {
|
|
return null;
|
|
}
|
|
|
|
// if(this.hasGuide(GuideConfigType.失败免费获取奖励)){
|
|
// if(!this.hasGuide(GuideConfigType.点击升级)){
|
|
// return GuideConfigType.点击升级;
|
|
// }
|
|
// }
|
|
|
|
return GuideConfig[LocalDataMgr.Guide.curguidetype];
|
|
}
|
|
|
|
/**执行引导 */
|
|
tickGuide() {
|
|
if (GuideData.stepIndex < GuideData.curGuideConfig.steps.length) {
|
|
let data = GuideData.curGuideConfig.steps[GuideData.stepIndex];
|
|
GuideData.stepIndex++;
|
|
this.dispose(data);
|
|
return;
|
|
}
|
|
/**引导结束 */
|
|
this.finishGuide(GuideData.guideKey);
|
|
/**自动检测下一个引导 */
|
|
if (GuideData.curGuideConfig.next && GuideConfig[GuideData.curGuideConfig.next]) {
|
|
let next = GuideData.curGuideConfig.next;
|
|
this.Stop();
|
|
this.setGuide(next);
|
|
return;
|
|
}
|
|
this.Stop();
|
|
}
|
|
|
|
private Stop() {
|
|
GuideData.guideKey = "";
|
|
GuideData.curGuideConfig = null;
|
|
GuideData.stepIndex = 0;
|
|
GuideData.isGuide = false;
|
|
}
|
|
|
|
hasGuide(guide: string) {
|
|
return LocalDataMgr.Guide.isGuideisOK(guide)
|
|
}
|
|
|
|
public finishGuide(guide: string) {
|
|
ConsoleEx.Log("完成引导", guide);
|
|
// if(guide == GuideConfigType.失败免费获取奖励){
|
|
// LocalStorage.isNewUser = false;
|
|
// }
|
|
let gFlag = this.getGuideEventID(guide);
|
|
LocalDataMgr.Guide.finishCurGuide(guide);
|
|
MesMgr.event(EGlobalEvent.GUIDE_COMPLETE_EVENT, guide);
|
|
let time = LocalDataMgr.Guide.curfinishtime;
|
|
/**完成 */
|
|
if(guide === GuideConfigType.第一次查看任务){
|
|
ConsoleEx.Log("完成第一个引导,发送onTutorialFinish");
|
|
TXSDKMgr.ins.onTutorialFinish();
|
|
}
|
|
//TDAnalyticsMgr.ins.TrySendtrack(GEData.GEeventName.guide_end, { id: gFlag, duration: time })
|
|
}
|
|
|
|
setGuide(guide: string) {
|
|
let guideCnf = GuideConfig[guide]
|
|
if (!GuideData.curGuideConfig && guideCnf) {
|
|
/**不是引导的目标场景 不执行 */
|
|
if (guideCnf.scene && guideCnf.scene != "") {
|
|
return;
|
|
}
|
|
this.Stop();
|
|
GuideData.isGuide = true;
|
|
GuideData.guideKey = guide;
|
|
GuideData.curGuideConfig = guideCnf;
|
|
/**开始 */
|
|
let gFlag = this.getGuideEventID(guide);
|
|
ConsoleEx.Log("触发引导", guide);
|
|
//TDAnalyticsMgr.ins.TrySendtrack(GEData.GEeventName.guide, { id: gFlag })
|
|
this.tickGuide();
|
|
}
|
|
return;
|
|
}
|
|
|
|
dispose(setp: any) {
|
|
switch (setp.gType) {
|
|
case GType.notice:
|
|
this.dispose_notice(setp);
|
|
break;
|
|
case GType.clickBtn:
|
|
this.dispose_clickBtn(setp);
|
|
break;
|
|
case GType.clickChild:
|
|
this.dispose_clickChild(setp);
|
|
break;
|
|
case GType.showSceneMask:
|
|
break;
|
|
case GType.UIFrom:
|
|
break;
|
|
default:
|
|
ConsoleEx.Warn("未找到相关引导类型", setp)
|
|
break;
|
|
}
|
|
}
|
|
|
|
delaydispose(setp: any) {
|
|
this.scheduleOnce(() => { this.dispose(setp); }, 0.1);
|
|
}
|
|
|
|
/**事件派发处理 */
|
|
dispose_notice(setp: EventSetpData) {
|
|
let type = typeof setp.onEventType;
|
|
PREVIEW && !["number", "string"].includes(type) && ConsoleEx.Error("类型错误", setp);
|
|
if (type == "string") {
|
|
MesMgr.once(setp.onEventType, this.onEventTypeCheck.bind(this, setp), this);
|
|
}
|
|
/**发送事件 */
|
|
setp.sendEventType && MesMgr.event(setp.sendEventType, setp.Param1, setp.Param2, setp.Param3, setp.Param4);
|
|
if (type == "number") {
|
|
setp.onEventType == 0 ? this.tickGuide() : this.scheduleOnce(this.tickGuide.bind(this), setp.onEventType as number)
|
|
}
|
|
}
|
|
|
|
onEventTypeCheck(setp: EventSetpData, value: string) {
|
|
if (setp.checkValue) {
|
|
if (setp.checkValue == value) {
|
|
this.tickGuide();
|
|
} else {
|
|
MesMgr.once(setp.onEventType, this.onEventTypeCheck.bind(this, setp), this);
|
|
}
|
|
} else {
|
|
this.tickGuide();
|
|
}
|
|
}
|
|
|
|
/**按钮点击处理 */
|
|
dispose_clickBtn(setp: ClickSetpData) {
|
|
/**检测UI是否存在 */
|
|
if (!UIMgr.Ins.hasUIFrom(setp.uiName)) {
|
|
ConsoleEx.Log("UI不存在", setp.uiName);
|
|
/**监听UI打开 触发再次寻找 */
|
|
MesMgr.once(EGlobalEvent.E_UI_OPEN_CALL_BACK, () => {
|
|
this.dispose(setp)
|
|
}, this);
|
|
return;
|
|
}
|
|
let baseUiForm = UIMgr.Ins.getUIFrom(setp.uiName);
|
|
let nodeList = CNodeUtils.getNodeEx(baseUiForm.node, setp.clickPath, true)
|
|
/**未找到目标节点 */
|
|
if (!nodeList || nodeList.length < 1) {
|
|
this.delaydispose(setp);
|
|
return;
|
|
}
|
|
setp.maskOpactiy < 2 ? GuideUIView.ins.setGuideParent(baseUiForm.node) : GuideUIView.ins.setGuideOrgParent();
|
|
GuideUIView.ins.setGuideNode(nodeList[0], setp.clickNum, setp.des, setp.maskOpactiy, setp.offsetX, setp.offsetY);
|
|
}
|
|
|
|
|
|
/**子组件点击处理 */
|
|
dispose_clickChild(setp: clickChildSetpData) {
|
|
/**检测UI是否存在 */
|
|
if (!UIMgr.Ins.hasUIFrom(setp.uiName)) {
|
|
ConsoleEx.Log("UI不存在", setp.uiName);
|
|
/**监听UI打开 触发再次寻找 */
|
|
MesMgr.once(EGlobalEvent.E_UI_OPEN_CALL_BACK, () => {
|
|
this.dispose(setp)
|
|
}, this);
|
|
return;
|
|
}
|
|
let baseUiForm = UIMgr.Ins.getUIFrom(setp.uiName);
|
|
let nodeList = CNodeUtils.getNodeEx(baseUiForm.node, setp.clickPath, true)//baseUiForm.node.getChildByPath(setp.clickPath)
|
|
/**未找到目标节点 */
|
|
if (!nodeList || nodeList.length < 1) {
|
|
this.delaydispose(setp);
|
|
return;
|
|
}
|
|
let clickChild = nodeList[0]//.children[setp.childidx];
|
|
if (!clickChild) {
|
|
this.delaydispose(setp);
|
|
return;
|
|
}
|
|
setp.maskOpactiy < 2 ? GuideUIView.ins.setGuideParent(baseUiForm.node) : GuideUIView.ins.setGuideOrgParent();
|
|
GuideUIView.ins.setGuideNode(clickChild, setp.clickNum, setp.des, setp.maskOpactiy, setp.offsetX, setp.offsetY);
|
|
}
|
|
|
|
/**设置手指提示 */
|
|
public setFinger(setp: FingerSetpData) {
|
|
/**检测UI是否存在 */
|
|
if (!UIMgr.Ins.hasUIFrom(setp.uiName)) {
|
|
ConsoleEx.Log("UI不存在", setp.uiName);
|
|
return;
|
|
}
|
|
let baseUiForm = UIMgr.Ins.getUIFrom(setp.uiName);
|
|
let View = baseUiForm.views.get("View");
|
|
let nodeList = CNodeUtils.getNodeEx(baseUiForm.node, setp.nodeName, true)
|
|
/**未找到目标节点 */
|
|
if (!nodeList || nodeList.length < 1 || !View) {
|
|
ConsoleEx.Log("UI.nodeName不存在", setp.nodeName);
|
|
return;
|
|
}
|
|
nodeList[0].once(Node.EventType.TOUCH_END, () => {
|
|
MesMgr.event(EGlobalEvent.GUIDE_HIDE_FINGER);
|
|
});
|
|
GuideUIView.ins.showFinger(View,nodeList[0], setp.desc, setp.offsetX, setp.offsetY);
|
|
}
|
|
|
|
}
|