|
|
@@ -4,6 +4,7 @@
|
|
|
*/
|
|
|
|
|
|
import { GuideStep } from "./GuideStep";
|
|
|
+import { _decorator, Component, Node, Button, Label, find, Vec2, Vec3, UITransform, EventTouch, Sprite, Color, tween, Tween } from 'cc';
|
|
|
|
|
|
/**
|
|
|
* 点击引导步骤
|
|
|
@@ -11,7 +12,7 @@ import { GuideStep } from "./GuideStep";
|
|
|
*/
|
|
|
export class ClickGuideStep extends GuideStep {
|
|
|
private _targetNodePath: string;
|
|
|
- private _targetNode: cc.Node;
|
|
|
+ private _targetNode: Node;
|
|
|
private _clickHandler: () => void;
|
|
|
|
|
|
constructor(stepId: string, targetNodePath: string) {
|
|
|
@@ -34,13 +35,15 @@ export class ClickGuideStep extends GuideStep {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 显示手指指向动画
|
|
|
+ // 显示手指指向动画 - 使用步骤索引让GuideUIController使用配置的节点
|
|
|
const uiController = this._manager.getUIController();
|
|
|
- const worldPos = this._targetNode.convertToWorldSpaceAR(cc.Vec2.ZERO);
|
|
|
- uiController.createPointingAnimation("guild_1", worldPos);
|
|
|
+ // 传入步骤索引,让GuideUIController使用配置的fingerStartNodes和fingerTargetNodes
|
|
|
+ // 从stepId中提取数字索引,如果没有数字则使用0
|
|
|
+ const stepIndex = parseInt(this._stepId.replace(/\D/g, '')) || 0;
|
|
|
+ uiController.createPointingAnimation("guild_1", undefined, stepIndex);
|
|
|
|
|
|
// 添加点击监听
|
|
|
- this._targetNode.on(cc.Node.EventType.TOUCH_END, this._clickHandler, this);
|
|
|
+ this._targetNode.on(Node.EventType.TOUCH_END, this._clickHandler, this);
|
|
|
|
|
|
// 创建高亮效果
|
|
|
uiController.createHighlightEffect(this._targetNode);
|
|
|
@@ -50,9 +53,8 @@ export class ClickGuideStep extends GuideStep {
|
|
|
if (this._targetNode) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- // 根据路径查找节点
|
|
|
- this._targetNode = cc.find(this._targetNodePath);
|
|
|
+ // 使用 find 函数查找节点
|
|
|
+ this._targetNode = find(this._targetNodePath);
|
|
|
}
|
|
|
|
|
|
private onTargetClick(): void {
|
|
|
@@ -63,7 +65,7 @@ export class ClickGuideStep extends GuideStep {
|
|
|
protected onComplete(): void {
|
|
|
// 移除点击监听
|
|
|
if (this._targetNode) {
|
|
|
- this._targetNode.off(cc.Node.EventType.TOUCH_END, this._clickHandler, this);
|
|
|
+ this._targetNode.off(Node.EventType.TOUCH_END, this._clickHandler, this);
|
|
|
}
|
|
|
|
|
|
// 隐藏引导UI
|
|
|
@@ -80,8 +82,8 @@ export class ClickGuideStep extends GuideStep {
|
|
|
export class DragGuideStep extends GuideStep {
|
|
|
private _sourceNodePath: string;
|
|
|
private _targetNodePath: string;
|
|
|
- private _sourceNode: cc.Node;
|
|
|
- private _targetNode: cc.Node;
|
|
|
+ private _sourceNode: Node;
|
|
|
+ private _targetNode: Node;
|
|
|
private _isDragging: boolean = false;
|
|
|
|
|
|
constructor(stepId: string, sourceNodePath: string, targetNodePath: string) {
|
|
|
@@ -113,10 +115,10 @@ export class DragGuideStep extends GuideStep {
|
|
|
|
|
|
private findNodes(): void {
|
|
|
if (!this._sourceNode) {
|
|
|
- this._sourceNode = cc.find(this._sourceNodePath);
|
|
|
+ this._sourceNode = find(this._sourceNodePath);
|
|
|
}
|
|
|
if (!this._targetNode) {
|
|
|
- this._targetNode = cc.find(this._targetNodePath);
|
|
|
+ this._targetNode = find(this._targetNodePath);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -124,64 +126,69 @@ export class DragGuideStep extends GuideStep {
|
|
|
const uiController = this._manager.getUIController();
|
|
|
|
|
|
// 在源节点位置显示手指
|
|
|
- const sourceWorldPos = this._sourceNode.convertToWorldSpaceAR(cc.Vec2.ZERO);
|
|
|
+ const sourceUITransform = this._sourceNode.getComponent(UITransform);
|
|
|
+ const sourceWorldPos = sourceUITransform ? sourceUITransform.convertToWorldSpaceAR(Vec3.ZERO) : this._sourceNode.worldPosition;
|
|
|
uiController.setGuideUIPosition("guild_1", sourceWorldPos);
|
|
|
uiController.showGuideUI("guild_1", "tap");
|
|
|
|
|
|
// 创建拖拽路径动画
|
|
|
- const targetWorldPos = this._targetNode.convertToWorldSpaceAR(cc.Vec2.ZERO);
|
|
|
+ const targetUITransform = this._targetNode.getComponent(UITransform);
|
|
|
+ const targetWorldPos = targetUITransform ? targetUITransform.convertToWorldSpaceAR(Vec3.ZERO) : this._targetNode.worldPosition;
|
|
|
const guideNode = uiController.getGuideNode("guild_1");
|
|
|
if (guideNode) {
|
|
|
- const moveAction = cc.repeatForever(
|
|
|
- cc.sequence(
|
|
|
- cc.moveTo(1.0, targetWorldPos),
|
|
|
- cc.moveTo(0.1, sourceWorldPos)
|
|
|
- )
|
|
|
- );
|
|
|
- guideNode.runAction(moveAction);
|
|
|
+ const moveAction = tween(guideNode)
|
|
|
+ .repeatForever(
|
|
|
+ tween(guideNode)
|
|
|
+ .to(1.0, { position: targetWorldPos })
|
|
|
+ .to(0.1, { position: sourceWorldPos })
|
|
|
+ );
|
|
|
+ moveAction.start();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private addDragListeners(): void {
|
|
|
- this._sourceNode.on(cc.Node.EventType.TOUCH_START, this.onDragStart, this);
|
|
|
- this._sourceNode.on(cc.Node.EventType.TOUCH_MOVE, this.onDragMove, this);
|
|
|
- this._sourceNode.on(cc.Node.EventType.TOUCH_END, this.onDragEnd, this);
|
|
|
+ this._sourceNode.on(Node.EventType.TOUCH_START, this.onDragStart, this);
|
|
|
+ this._sourceNode.on(Node.EventType.TOUCH_MOVE, this.onDragMove, this);
|
|
|
+ this._sourceNode.on(Node.EventType.TOUCH_END, this.onDragEnd, this);
|
|
|
}
|
|
|
|
|
|
- private onDragStart(event: cc.Event.EventTouch): void {
|
|
|
+ private onDragStart(event: EventTouch): void {
|
|
|
this._isDragging = true;
|
|
|
}
|
|
|
|
|
|
- private onDragMove(event: cc.Event.EventTouch): void {
|
|
|
+ private onDragMove(event: EventTouch): void {
|
|
|
if (!this._isDragging) return;
|
|
|
|
|
|
// 检查是否拖拽到目标区域
|
|
|
const touchPos = event.getLocation();
|
|
|
- const targetBoundingBox = this._targetNode.getBoundingBoxToWorld();
|
|
|
-
|
|
|
- if (targetBoundingBox.contains(touchPos)) {
|
|
|
- // 拖拽到目标区域,完成引导
|
|
|
- this.complete();
|
|
|
+ const targetUITransform = this._targetNode.getComponent(UITransform);
|
|
|
+ if (targetUITransform) {
|
|
|
+ const targetBoundingBox = targetUITransform.getBoundingBoxToWorld();
|
|
|
+
|
|
|
+ if (targetBoundingBox.contains(new Vec2(touchPos.x, touchPos.y))) {
|
|
|
+ // 拖拽到目标区域,完成引导
|
|
|
+ this.complete();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private onDragEnd(event: cc.Event.EventTouch): void {
|
|
|
+ private onDragEnd(event: EventTouch): void {
|
|
|
this._isDragging = false;
|
|
|
}
|
|
|
|
|
|
protected onComplete(): void {
|
|
|
// 移除拖拽监听
|
|
|
if (this._sourceNode) {
|
|
|
- this._sourceNode.off(cc.Node.EventType.TOUCH_START, this.onDragStart, this);
|
|
|
- this._sourceNode.off(cc.Node.EventType.TOUCH_MOVE, this.onDragMove, this);
|
|
|
- this._sourceNode.off(cc.Node.EventType.TOUCH_END, this.onDragEnd, this);
|
|
|
+ this._sourceNode.off(Node.EventType.TOUCH_START, this.onDragStart, this);
|
|
|
+ this._sourceNode.off(Node.EventType.TOUCH_MOVE, this.onDragMove, this);
|
|
|
+ this._sourceNode.off(Node.EventType.TOUCH_END, this.onDragEnd, this);
|
|
|
}
|
|
|
|
|
|
// 隐藏引导UI
|
|
|
const uiController = this._manager.getUIController();
|
|
|
const guideNode = uiController.getGuideNode("guild_1");
|
|
|
if (guideNode) {
|
|
|
- guideNode.stopAllActions();
|
|
|
+ Tween.stopAllByTarget(guideNode);
|
|
|
}
|
|
|
uiController.hideGuideUI("guild_1");
|
|
|
}
|
|
|
@@ -245,7 +252,7 @@ export class WaitConditionGuideStep extends GuideStep {
|
|
|
*/
|
|
|
export class DialogGuideStep extends GuideStep {
|
|
|
private _dialogText: string;
|
|
|
- private _dialogNode: cc.Node;
|
|
|
+ private _dialogNode: Node;
|
|
|
|
|
|
constructor(stepId: string, dialogText: string) {
|
|
|
super(stepId);
|
|
|
@@ -262,31 +269,37 @@ export class DialogGuideStep extends GuideStep {
|
|
|
|
|
|
private showDialog(): void {
|
|
|
// 创建对话框节点
|
|
|
- this._dialogNode = new cc.Node("guide_dialog");
|
|
|
- const canvas = cc.find("Canvas");
|
|
|
+ this._dialogNode = new Node("guide_dialog");
|
|
|
+ const canvas = find("Canvas");
|
|
|
if (canvas) {
|
|
|
canvas.addChild(this._dialogNode);
|
|
|
- this._dialogNode.zIndex = 1001;
|
|
|
+ this._dialogNode.setSiblingIndex(1001);
|
|
|
}
|
|
|
|
|
|
// 添加背景
|
|
|
- const bg = new cc.Node("bg");
|
|
|
- bg.addComponent(cc.Sprite);
|
|
|
- bg.color = cc.Color.BLACK;
|
|
|
- bg.opacity = 128;
|
|
|
+ const bg = new Node("bg");
|
|
|
+ const bgSprite = bg.addComponent(Sprite);
|
|
|
+ bg.addComponent(UITransform);
|
|
|
+ bgSprite.color = Color.BLACK;
|
|
|
+ const bgUITransform = bg.getComponent(UITransform);
|
|
|
+ if (bgUITransform) {
|
|
|
+ bgUITransform.setContentSize(800, 600);
|
|
|
+ }
|
|
|
this._dialogNode.addChild(bg);
|
|
|
|
|
|
// 添加文本
|
|
|
- const textNode = new cc.Node("text");
|
|
|
- const label = textNode.addComponent(cc.Label);
|
|
|
+ const textNode = new Node("text");
|
|
|
+ const label = textNode.addComponent(Label);
|
|
|
label.string = this._dialogText;
|
|
|
label.fontSize = 24;
|
|
|
+ textNode.addComponent(UITransform);
|
|
|
this._dialogNode.addChild(textNode);
|
|
|
|
|
|
// 添加确定按钮
|
|
|
- const btnNode = new cc.Node("btn_ok");
|
|
|
- const button = btnNode.addComponent(cc.Button);
|
|
|
- btnNode.on(cc.Node.EventType.TOUCH_END, () => {
|
|
|
+ const btnNode = new Node("btn_ok");
|
|
|
+ const button = btnNode.addComponent(Button);
|
|
|
+ btnNode.addComponent(UITransform);
|
|
|
+ btnNode.on(Node.EventType.TOUCH_END, () => {
|
|
|
this.complete();
|
|
|
});
|
|
|
this._dialogNode.addChild(btnNode);
|