整合,清理掉很多冗余的东西

This commit is contained in:
walkpan
2025-11-02 10:34:18 +08:00
parent b24f0e2afc
commit f35d755b74
41 changed files with 99 additions and 1798 deletions

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "c7b87b89-72d6-4bf8-9ed2-ead66b613984",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,220 +0,0 @@
import { _decorator, director, Node } from "cc";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { GuideConfig, GuideConfigArray, GuideStepType, IGuideStep, findGuideByEndEvent, findGuideById, findGuideIndexById, findGuideByNumberId, finishCurrGuide, startGuide } from "../common/config/Guide";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { UIID } from "../common/config/GameUIConfig";
import { GameEvent } from "../common/config/GameEvent";
import { smc } from "../common/SingletonModuleComp";
const { ccclass } = _decorator;
/** 新手引导组件 */
@ccclass('GuideConComp')
export class GuideConComp extends CCComp {
/** Cocos Creator 组件生命周期方法 */
onLoad() {
console.log("[GuideConComp] onLoad 被调用");
this.on(GameEvent.GuideStart, this.GuideStart, this);
this.on(GameEvent.GuideEnd, this.GuideEnd, this);
}
start() {
this.init();
}
/** 初始化引导管理器 */
init() {
console.log("[GuideConComp] init");
this.initializeGuideProgress();
// 移除自动启动第一个引导,所有引导都变成触发式
// this.checkFirstGuide();
}
/** 初始化引导进度数组 */
private initializeGuideProgress() {
// 确保 smc.guides 存在且长度匹配
if (!smc.guides || smc.guides.length !== GuideConfigArray.length) {
smc.guides = new Array(GuideConfigArray.length).fill(0);
smc.syncGuide()
console.log("[GuideCon] 初始化 smc.guides 为全0");
}
}
GuideStart(e: any, data: any) {
console.log("[GuideCon] 监听到开始引导 key: ", data);
smc.current_guide=data
if(this.isAllGuidesCompleted()) return
const guide = findGuideByNumberId(data);
if (guide) this.displayStep(guide);
}
GuideEnd(e: any, data: any) {
console.log("[GuideCon] 监听到结束引导 key: ", data);
this.completeGuide(data)
}
/** 显示引导步骤 */
private displayStep(step: IGuideStep) {
console.log("[Tutorial] 根据step类型显示引导", step);
switch (step.type) {
case GuideStepType.TIP:
this.showTip(step);
break;
case GuideStepType.CLICK:
this.showClickGuide(step);
break;
case GuideStepType.DRAG:
this.showDragGuide(step);
break;
case GuideStepType.WAIT:
this.showWaitGuide(step);
break;
}
}
/** 信息引导 */
private showTip(step: IGuideStep) {
this.showGuideStepUI(step);
this.scheduleOnce(() => {
this.onStepCompleted(step);
}, step.waitTime ?? 2000);
}
/** 点击引导 */
private showClickGuide(step: IGuideStep) {
console.log("[Tutorial] 显示点击引导", step);
// if (!step.targetPath) {
// console.error("[Tutorial] 点击引导缺少目标路径");
// return;
// }
// const targetNode = this.findTargetNode(step.targetPath);
// if (!targetNode) {
// console.error(`[Tutorial] 找不到目标节点: ${step.targetPath}`);
// return;
// }
// let tipParent:Node|null=null;
// if(step.tipParent){
// tipParent = this.findTargetNode(step.tipParent);
// }else{
// tipParent=targetNode;
// }
// console.log("[Tutorial] 开始点击引导UI", step.targetPath);
this.showGuideStepUI(step);
}
/** 显示拖拽引导 */
private showDragGuide(step: IGuideStep) {
console.log("[Tutorial] 显示拖拽引导:", step.id);
this.showGuideStepUI(step);
}
/** 显示等待引导 */
private showWaitGuide(step: IGuideStep) {
console.log("[Tutorial] 显示等待引导:", step.id);
this.showGuideStepUI(step);
this.scheduleOnce(() => {
this.onStepCompleted(step);
}, step.waitTime ?? 2);
// 触摸监听器现在由 GuideSetpComp 管理
}
/** 步骤完成回调 */
private onStepCompleted(step: IGuideStep) {
console.log(`[Tutorial] 步骤完成: ${step.id}`);
// 检查是否有下一个引导
if (step.nextStep && step.nextStep.trim() !== "") {
const nextGuide = findGuideById(step.nextStep);
if (nextGuide && !this.isGuideCompleted(nextGuide.id)) {
console.log(`[GuideCon] 自动开始下一个引导: ${nextGuide.id}`);
startGuide(nextGuide.key)
return;
}
}
// 引导完成关闭UI
this.closeGuideStepUI();
}
private completeAllGuide(){
smc.guides = new Array(GuideConfigArray.length).fill(1);
smc.syncGuide()
}
/** 完成指定引导 */
private completeGuide(key:any) {
smc.finishGuide(key);
this.closeGuideStepUI()
console.log(`[GuideCon] 引导 ${key} 已完成,进度数组: ${JSON.stringify(smc.guides)}`);
}
/** 判断指定引导是否已完成 */
private isGuideCompleted(guideId: string): boolean {
const guideIndex = findGuideIndexById(guideId);
if (guideIndex !== -1 && guideIndex < GuideConfigArray.length) {
return smc.guides[guideIndex] === 1;
}
return false;
}
/** 判断所有引导是否已完成 */
private isAllGuidesCompleted(): boolean {
return smc.guides.every(stepStatus => stepStatus === 1);
}
/** 打开引导UI */
private showGuideStepUI(step: IGuideStep) {
console.log(`[GuideCon] 开始打开UI: ${step.id}, uiId: ${UIID.Guide}`);
// 关闭之前的引导UI
if (oops.gui.has(UIID.Guide)) {
oops.gui.remove(UIID.Guide);
console.log("[Tutorial] 关闭之前的引导UI", UIID.Guide);
}
this.doOpenGuideStepUI(step);
}
doOpenGuideStepUI(step: IGuideStep) {
try {
console.log("[Tutorial] 打开新的引导UI", UIID.Guide);
oops.gui.open(UIID.Guide, {
step: step,
stepIndex: 0,
totalSteps: 1,
callbacks: {
onStepComplete: this.onStepCompleted.bind(this),
onComplete: this.completeAllGuide.bind(this)
}
});
console.log(`[GuideCon] 成功打开引导步骤UI: ${UIID.Guide}`);
} catch (error) {
console.error(`[GuideCon] 打开引导步骤UI失败: ${UIID.Guide}`, error);
oops.gui.toast(step.tipText );
}
}
/** 关闭引导步骤UI */
private closeGuideStepUI() {
console.log("[GuideCon] 关闭引导步骤UI", UIID.Guide);
oops.gui.remove(UIID.Guide);
}
/** 重置引导 */
resetGuide() {
// 重置进度数组为全0
smc.guides = new Array(GuideConfigArray.length).fill(0);
smc.syncGuide()
console.log("[GuideCon] 重置引导,进度数组重置为:", JSON.stringify(smc.guides));
}
/** 组件销毁时清理 */
reset() {
// this.guideProgress = []; // This line is removed
oops.gui.remove(UIID.Guide);
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "1e280c31-a416-42c8-8239-f7f6782b904b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,268 +0,0 @@
import { _decorator, BlockInputEvents, Button, director, Label, Node, UITransform, Vec3 } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { IGuideStep, GuideStepType } from "../common/config/Guide";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
const { ccclass, property } = _decorator;
/** 引导步骤UI组件 - 完整的引导UI容器 */
@ccclass('GuideSetpComp')
@ecs.register('GuideSetp', false)
export class GuideSetpComp extends CCComp {
@property(Label)
private tipLabel: Label = null!;
@property(Node)
private tipNode: Node = null!;
@property(Node)
private handNode: Node = null!;
@property(Button)
private skipButton: Button = null!;
/** 当前引导步骤数据 */
private currentStep: IGuideStep | null = null;
/** 当前步骤索引 */
private currentStepIndex: number = 0;
/** 总步骤数 */
private totalSteps: number = 0;
/** 目标节点 */
private _targetNode: Node | null = null;
/** 提示父节点 */
private _tipParent: Node | null = null;
private _showTip: boolean = false;
private _showHand: boolean = false;
private _callback: any = null;
private _noInput: any = null;
/** 触摸监听器标志位 */
private _hasTouchListener: boolean = false;
/** 添加触摸监听器 */
private addTouchListener() {
// 如果已经有监听器,不要重复添加
if (this._hasTouchListener) {
console.log("[GuideSetpComp] 触摸监听器已存在,跳过添加");
return;
}
// 直接监听当前节点的触摸事件
this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
this._hasTouchListener = true;
console.log("[GuideSetpComp] 已添加触摸监听器到当前节点,等待用户点击");
}
/** 触摸开始事件处理 */
private onTouchStart(event: any) {
// 检查是否当前有等待引导在运行
if (!this.currentStep || this.currentStep.type !== GuideStepType.WAIT) {
return; // 如果没有等待引导,不处理触摸事件
}
console.log("[GuideSetpComp] 检测到触摸事件,完成等待引导");
// 移除触摸监听器
this.removeTouchListener();
// 完成当前引导
if (this._callback && this._callback.onStepComplete) {
this._callback.onStepComplete(this.currentStep);
}
}
/** 移除触摸监听器 */
private removeTouchListener() {
// 如果没有监听器,直接返回
if (!this._hasTouchListener) {
return;
}
// 直接从当前节点移除触摸事件监听
this.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this);
this._hasTouchListener = false;
console.log("[GuideSetpComp] 已移除触摸监听器");
}
/** 组件初始化 */
start() {
console.log("[GuideSetpComp] start", this.node);
}
onAdded(args: any) {
console.log("[GuideSetpComp] onAdded", this.node);
this.initUI();
this._noInput=this.node.getComponent(BlockInputEvents);
this._noInput.enabled=false;
// 如有传入的参数,直接处理
if (args && args.step) {
this.handleStepInfo(args);
}
}
protected onEnable(): void {
console.log("[GuideSetpComp] onEnable", this.node);
}
/** 处理步骤信息 */
private handleStepInfo(data: any) {
const { step, stepIndex, totalSteps,callbacks } = data;
const targetNode=this.findTargetNode(step.targetPath);
this._noInput.enabled=step.noInput??false;
this._callback=callbacks;
if(targetNode){
this._targetNode=targetNode;
this._showTip=true;
this._showHand=true;
}else{
this._targetNode=this.node;
this._showTip=true;
this._showHand=false;
}
if(step.tipParent){
this._tipParent=this.findTargetNode(step.tipParent);
}else{
this._tipParent=this._targetNode;
}
console.log("[GuideSetpComp] 处理步骤信息:", step);
// 显示步骤
this.showStep(step, stepIndex, totalSteps,targetNode,this._tipParent);
// 如果有手指位置,直接设置
// this.setHandPosition(this._targetNode);
}
/** 初始化UI */
private initUI() {
// 设置初始状态
this.node.active = false;
this.node.setSiblingIndex(1000);
this.tipNode.active = false;
this.handNode.active = false;
}
/** 显示引导步骤 */
showStep(step: IGuideStep, stepIndex: number, totalSteps: number,targetNode: Node,tipParent: Node) {
this.currentStep = step;
this.currentStepIndex = stepIndex;
this.totalSteps = totalSteps;
// 将handNode和tipNode从当前父节点移除
this.handNode.parent=this._targetNode;
// if(this._tipParent){
// this.tipNode.parent=this._tipParent;
// }else{
// this.tipNode.parent=this._targetNode;
// }
this.handNode.setPosition(this.currentStep?.handOffset?.x || 0, this.currentStep?.handOffset?.y || 0);
// this.tipNode.setPosition(this.currentStep?.tipOffset?.x || 0, this.currentStep?.tipOffset?.y || 0);
// 设置setSiblingIndex最大
this.handNode.setSiblingIndex(this._targetNode.children.length - 1);
// this.tipNode.setSiblingIndex(this._targetNode.children.length - 1);
// 更新UI内容
this.updateStepContent()
// 显示组件
this.show();
// 如果是等待引导,添加触摸监听器
if (step.type === GuideStepType.WAIT) {
this.addTouchListener();
}
}
/** 更新步骤内容 */
private updateStepContent() {
if (!this.currentStep || !this._targetNode) return;
// 根据目标节点调整tipNode的位置
// 假设tipNode相对于目标节点是固定的偏移
// 更新提示文本
if (this.tipLabel) {
this.tipLabel.string = this.currentStep.tipText ||"";
}
// 控制跳过按钮显示
}
/** 显示组件 */
private show() {
this.node.active = true;
if (this.tipLabel.string!="") {
this.tipNode.active = true;
}
if (this.handNode) {
this.handNode.active = true;
}
}
/** 查找目标节点 */
private findTargetNode(path: string): Node | null {
console.log(`[GuideCon] 开始查找目标节点: ${path}`);
const pathParts = path.split('/');
let currentNode: any = director.getScene();
for (const part of pathParts) {
if (!currentNode || !currentNode.getChildByName) {
console.error(`[GuideCon] 节点 ${part} 不存在或没有getChildByName方法`);
break;
}
const childNode = currentNode.getChildByName(part);
if (!childNode) {
console.error(`[GuideCon] 找不到子节点: ${part}`);
console.log(`[GuideCon] 当前节点 ${currentNode.name} 的子节点:`, currentNode.children.map(c => c.name));
break;
}
currentNode = childNode;
console.log("[GuideCon] 当前节点:", currentNode)
}
if (currentNode) {
console.log(`[GuideCon] 目标节点查找成功:`, currentNode.position, currentNode.getWorldPosition());
return currentNode as Node;
} else {
console.error(`[GuideCon] 目标节点查找失败: ${path}`);
return null;
}
}
/** 跳过按钮点击事件 */
private onSkipButtonClick() {
console.log("[GuideSetpComp] 跳过按钮点击事件");
this.tipNode.destroy();
this.handNode.destroy();
// oops.gui.removeByNode(this.node);
this._callback.onComplete();
}
/** 清理资源 */
private cleanup() {
// 移除触摸监听器
this.removeTouchListener();
this.currentStep = null;
this.currentStepIndex = 0;
this.totalSteps = 0;
}
/** 组件销毁时清理 */
reset() {
this.cleanup();
this.node.active = false;
}
/** 组件销毁时清理 */
onDestroy() {
// 清理资源
this.removeTouchListener();
this.tipNode.destroy();
this.handNode.destroy();
console.log("[GuideSetpComp] 监听onDestroy", this.node);
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "afbf476b-b77b-4ca9-979f-ada073411c72",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,26 +0,0 @@
// 开始战斗
function startBattle() {
const battle = new BattleManager();
battle.add(BattleManagerComp);
oops.message.dispatchEvent("BattleStart");
}
// 结束战斗
function endBattle() {
const battle = ecs.query(ecs.allOf(BattleManager))[0];
if (battle) {
battle.destroy();
}
}
// 点击开始战斗按钮
function onBattleStartClick(missionId: number) {
BattleManager.instance.startBattle(missionId);
}
// 角色死亡时检测
function checkHeroDeath() {
if (heroView.hp <= 0) {
BattleManager.instance.endBattle();
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "3748c53e-6b9b-479f-aba0-87fc123ce161",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -3,7 +3,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { smc } from "../common/SingletonModuleComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { FightSet} from "../common/config/Mission";
import { FightSet} from "../common/config/GameSet";
import { GameEvent } from "../common/config/GameEvent";
import { HeroViewComp } from "../hero/HeroViewComp";
import { UIID } from "../common/config/GameUIConfig";
@@ -99,7 +99,7 @@ export class MissionComp extends CCComp {
to_fight(){
smc.mission.in_fight=true
oops.message.dispatchEvent(GameEvent.FightStart) //MissionMonComp 监听刷怪
oops.message.dispatchEvent(GameEvent.FightStart) //GameSetMonComp 监听刷怪
}

View File

@@ -1,7 +1,7 @@
import { _decorator, Component, Label, Node, tween, v3 } from 'cc';
import { GameEvent } from '../common/config/GameEvent';
import { smc } from '../common/SingletonModuleComp';
import { BoxSet, NumberFormatter } from '../common/config/BoxSet';
import { BoxSet, NumberFormatter } from '../common/config/GameSet';
import { oops } from 'db://oops-framework/core/Oops';
const { ccclass, property } = _decorator;

View File

@@ -4,8 +4,6 @@ import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/modu
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { smc } from "../common/SingletonModuleComp";
import { GameEvent } from "../common/config/GameEvent";
import { ItemComp } from "./ItemComp";
import { startGuide } from "../common/config/Guide";
import { it } from "node:test";
const { ccclass, property } = _decorator;

View File

@@ -2,7 +2,7 @@ import { v3, Vec3, _decorator ,Prefab,instantiate,JsonAsset} from "cc";
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { smc } from "../../common/SingletonModuleComp";
import { BoxSet } from "../../common/config/BoxSet";
import { BoxSet } from "../../common/config/GameSet";
import { MapViewScene } from "./MapViewScene";
import { Timer } from "../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";

View File

@@ -7,7 +7,7 @@
import { Component, Node, Prefab, _decorator ,instantiate} from 'cc';
import { Timer } from '../../../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer';
import {oops} from "../../../../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { BoxSet } from '../../../../common/config/BoxSet';
import { BoxSet } from '../../../../common/config/GameSet';
const { ccclass, property } = _decorator;
/**