|
|
@@ -1,6 +1,7 @@
|
|
|
-import { _decorator, Component, Node, Prefab, resources, instantiate, Label, Sprite, SpriteFrame, Button, ProgressBar, ScrollView, Vec2, Vec3, UITransform } from 'cc';
|
|
|
+import { _decorator, Component, Node, Prefab, resources, instantiate, Label, Sprite, SpriteFrame, Button, ProgressBar, ScrollView, Vec2, Vec3, UITransform, tween, Color } from 'cc';
|
|
|
import { PersistentSkillManager } from './PersistentSkillManager';
|
|
|
import { SaveDataManager } from '../../LevelSystem/SaveDataManager';
|
|
|
+import EventBus, { GameEvents } from '../../Core/EventBus';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
/**
|
|
|
@@ -64,14 +65,20 @@ export class SkillNodeGenerator extends Component {
|
|
|
// 持久化技能管理器
|
|
|
private skillManager: PersistentSkillManager | null = null;
|
|
|
|
|
|
- // 存档管理器
|
|
|
+ // 保存数据管理器引用
|
|
|
private saveDataManager: SaveDataManager | null = null;
|
|
|
|
|
|
+ // 闪烁动画相关
|
|
|
+ private blinkingNodes: Set<Node> = new Set(); // 正在闪烁的节点集合
|
|
|
+
|
|
|
start() {
|
|
|
console.log('SkillNodeGenerator 初始化开始');
|
|
|
this.skillManager = PersistentSkillManager.getInstance();
|
|
|
this.saveDataManager = SaveDataManager.getInstance();
|
|
|
|
|
|
+ // 监听货币变化事件
|
|
|
+ EventBus.getInstance().on(GameEvents.CURRENCY_CHANGED, this.onCurrencyChanged, this);
|
|
|
+
|
|
|
// 生成所有技能节点
|
|
|
this.generateSkillNodes();
|
|
|
console.log(`技能节点生成完成,共 ${this.skillNodes.length} 个节点`);
|
|
|
@@ -87,6 +94,12 @@ export class SkillNodeGenerator extends Component {
|
|
|
this.scrollToLatestUnlockedSkill();
|
|
|
}, 0.1);
|
|
|
|
|
|
+ // 更新钻石UI显示
|
|
|
+ this.updateDiamondUI();
|
|
|
+
|
|
|
+ // 初始化闪烁状态
|
|
|
+ this.updateBlinkingNodes();
|
|
|
+
|
|
|
console.log('SkillNodeGenerator 初始化完成');
|
|
|
}
|
|
|
|
|
|
@@ -171,12 +184,6 @@ export class SkillNodeGenerator extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 设置节点位置(从下到上排列)
|
|
|
- // 每个节点垂直间距150,从最下方开始排列
|
|
|
- const yPosition = -totalIndex * 150;
|
|
|
- skillNode.setPosition(0, yPosition, 0);
|
|
|
- console.log(`Created skill node at position Y: ${yPosition}, totalIndex: ${totalIndex}`);
|
|
|
-
|
|
|
// 添加到当前节点(content节点)
|
|
|
this.node.addChild(skillNode);
|
|
|
|
|
|
@@ -216,8 +223,6 @@ export class SkillNodeGenerator extends Component {
|
|
|
|
|
|
// 初始化为未点亮状态
|
|
|
this.updateSkillNodeVisual(skillNodeData);
|
|
|
-
|
|
|
- console.log(`Created skill node: ${skillName}, Cost: ${cost}, Group: ${group}, Position: (0, ${yPosition}, 0)`);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -250,6 +255,11 @@ export class SkillNodeGenerator extends Component {
|
|
|
const currentDiamonds = this.saveDataManager ? this.saveDataManager.getDiamonds() : 0;
|
|
|
if (currentDiamonds < skillNodeData.cost) {
|
|
|
console.log(`钻石不足Need: ${skillNodeData.cost}, Have: ${currentDiamonds}`);
|
|
|
+ // 发送Toast提示事件
|
|
|
+ EventBus.getInstance().emit(GameEvents.SHOW_TOAST, {
|
|
|
+ message: `钻石不足,需要${skillNodeData.cost}钻石`,
|
|
|
+ duration: 2.0
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -283,6 +293,11 @@ export class SkillNodeGenerator extends Component {
|
|
|
this.updateProgressBar();
|
|
|
this.updateDiamondUI();
|
|
|
|
|
|
+ // 延迟更新闪烁状态,确保所有状态更新完成
|
|
|
+ this.scheduleOnce(() => {
|
|
|
+ this.updateBlinkingNodes();
|
|
|
+ }, 0.1);
|
|
|
+
|
|
|
// 输出技能解锁信息,包含数组索引
|
|
|
console.log(`技能已解锁: ${this.getSkillTypeString(skillNodeData.skillIndex)} Group ${skillNodeData.group}, 索引[${nodeIndex}/${this.skillNodes.length-1}]`);
|
|
|
|
|
|
@@ -339,6 +354,9 @@ export class SkillNodeGenerator extends Component {
|
|
|
playerData.diamonds = amount;
|
|
|
this.saveDataManager.savePlayerData();
|
|
|
this.updateDiamondUI();
|
|
|
+
|
|
|
+ // 更新闪烁状态
|
|
|
+ this.updateBlinkingNodes();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -359,6 +377,9 @@ export class SkillNodeGenerator extends Component {
|
|
|
} else {
|
|
|
console.warn('Diamond number node not assigned in inspector');
|
|
|
}
|
|
|
+
|
|
|
+ // 更新闪烁状态
|
|
|
+ this.updateBlinkingNodes();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -397,9 +418,7 @@ export class SkillNodeGenerator extends Component {
|
|
|
|
|
|
// 更新进度条
|
|
|
this.updateProgressBar();
|
|
|
-
|
|
|
- console.log(`已加载技能解锁状态,当前解锁索引: ${this.currentUnlockIndex}/${this.skillNodes.length-1}`);
|
|
|
-
|
|
|
+
|
|
|
// 输出已解锁技能的数组信息
|
|
|
this.logUnlockedSkills();
|
|
|
}
|
|
|
@@ -688,5 +707,118 @@ export class SkillNodeGenerator extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新闪烁节点状态
|
|
|
+ * 检查哪些节点可以升级并开始闪烁动画
|
|
|
+ */
|
|
|
+ private updateBlinkingNodes() {
|
|
|
+ // 停止所有当前的闪烁动画
|
|
|
+ this.stopAllBlinking();
|
|
|
+
|
|
|
+ // 获取当前钻石数量
|
|
|
+ const currentDiamonds = this.saveDataManager ? this.saveDataManager.getDiamonds() : 0;
|
|
|
+
|
|
|
+ // 找到下一个可解锁的节点
|
|
|
+ const nextUnlockIndex = this.currentUnlockIndex + 1;
|
|
|
+
|
|
|
+ if (nextUnlockIndex < this.skillNodes.length) {
|
|
|
+ const nextNode = this.skillNodes[nextUnlockIndex];
|
|
|
+ console.log(`[闪烁检查] 下一个节点 - 组别: ${nextNode.group}, 技能: ${this.getSkillTypeString(nextNode.skillIndex)}, 费用: ${nextNode.cost}, 已解锁: ${nextNode.isUnlocked}, 当前钻石: ${currentDiamonds}`);
|
|
|
+
|
|
|
+ // 检查是否有足够钻石且节点未解锁
|
|
|
+ if (!nextNode.isUnlocked && currentDiamonds >= nextNode.cost) {
|
|
|
+ this.startBlinking(nextNode.node);
|
|
|
+ } else {
|
|
|
+ console.log(`[闪烁检查] 节点不满足闪烁条件`);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.log(`[闪烁检查] 已达到最后一个节点,无需闪烁`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开始节点闪烁动画
|
|
|
+ * @param node 要闪烁的节点
|
|
|
+ */
|
|
|
+ private startBlinking(node: Node) {
|
|
|
+ if (this.blinkingNodes.has(node)) {
|
|
|
+ return; // 已经在闪烁中
|
|
|
+ }
|
|
|
+
|
|
|
+ this.blinkingNodes.add(node);
|
|
|
+
|
|
|
+ // 创建闪烁动画:透明度在0.5和1.0之间循环
|
|
|
+ const blinkTween = tween(node)
|
|
|
+ .to(0.5, { scale: new Vec3(1.1, 1.1, 1.1) }, { easing: 'sineInOut' })
|
|
|
+ .to(0.5, { scale: new Vec3(1.0, 1.0, 1.0) }, { easing: 'sineInOut' })
|
|
|
+ .union()
|
|
|
+ .repeatForever();
|
|
|
+
|
|
|
+ blinkTween.start();
|
|
|
+
|
|
|
+ // 将tween存储到节点上,方便后续停止
|
|
|
+ node['_blinkTween'] = blinkTween;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 停止节点闪烁动画
|
|
|
+ * @param node 要停止闪烁的节点
|
|
|
+ */
|
|
|
+ private stopBlinking(node: Node) {
|
|
|
+ if (!this.blinkingNodes.has(node)) {
|
|
|
+ return; // 没有在闪烁
|
|
|
+ }
|
|
|
+
|
|
|
+ this.blinkingNodes.delete(node);
|
|
|
+
|
|
|
+ // 停止tween动画
|
|
|
+ if (node['_blinkTween']) {
|
|
|
+ node['_blinkTween'].stop();
|
|
|
+ node['_blinkTween'] = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重置节点状态
|
|
|
+ node.setScale(1, 1, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 停止所有闪烁动画
|
|
|
+ */
|
|
|
+ private stopAllBlinking() {
|
|
|
+ for (const node of this.blinkingNodes) {
|
|
|
+ if (node['_blinkTween']) {
|
|
|
+ node['_blinkTween'].stop();
|
|
|
+ node['_blinkTween'] = null;
|
|
|
+ }
|
|
|
+ node.setScale(1, 1, 1);
|
|
|
+ }
|
|
|
+ this.blinkingNodes.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当钻石数量变化时调用,更新闪烁状态
|
|
|
+ */
|
|
|
+ public onDiamondsChanged() {
|
|
|
+ this.updateBlinkingNodes();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 货币变化事件处理
|
|
|
+ */
|
|
|
+ private onCurrencyChanged() {
|
|
|
+ console.log('[SkillNodeGenerator] 检测到货币变化,更新钻石UI和闪烁状态');
|
|
|
+ this.updateDiamondUI();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组件销毁时清理资源
|
|
|
+ */
|
|
|
+ onDestroy() {
|
|
|
+ // 取消事件监听
|
|
|
+ EventBus.getInstance().off(GameEvents.CURRENCY_CHANGED, this.onCurrencyChanged, this);
|
|
|
+
|
|
|
+ // 停止所有闪烁动画
|
|
|
+ this.stopAllBlinking();
|
|
|
+ }
|
|
|
|
|
|
}
|