feat(技能盒): 添加技能盒销毁事件与自动排列功能
- 新增 RemoveSkillBox 事件用于技能盒销毁时通知 - 在 SkillBoxComp 销毁时触发 RemoveSkillBox 事件 - 为 MissSkillsComp 实现技能盒槽位管理系统 - 技能盒添加时会自动分配到可用槽位 - 技能盒销毁后会自动重新排列剩余技能盒 - 调整技能盒预制体尺寸和位置以优化显示效果
This commit is contained in:
@@ -74,4 +74,5 @@ export enum GameEvent {
|
||||
GlobalAttrChange = "GlobalAttrChange",
|
||||
CoinAdd = "CoinAdd",
|
||||
TriggerSkill = "TriggerSkill", // 瞬间触发施法事件
|
||||
RemoveSkillBox = "RemoveSkillBox", // 技能盒销毁事件
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { mLogger } from "../common/Logger";
|
||||
import { _decorator, Node, Prefab, instantiate } from "cc";
|
||||
import { _decorator, Node, Prefab, instantiate, 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 { SkillBoxComp } from "./SkillBoxComp";
|
||||
@@ -8,7 +8,12 @@ import { GameEvent } from "../common/config/GameEvent";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
|
||||
interface SkillBoxSlot {
|
||||
x: number;
|
||||
y: number;
|
||||
used: boolean;
|
||||
node: Node | null;
|
||||
}
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('MissSkillsComp')
|
||||
@@ -18,13 +23,62 @@ export class MissSkillsComp extends CCComp {
|
||||
@property({type: Prefab})
|
||||
private skill_box: Prefab = null;
|
||||
|
||||
private slots: SkillBoxSlot[] = [
|
||||
{ x: -320, y: 220, used: false, node: null },
|
||||
{ x: -240, y: 220, used: false, node: null },
|
||||
{ x: -160, y: 220, used: false, node: null },
|
||||
{ x: -80, y: 220, used: false, node: null },
|
||||
{ x: 0, y: 220, used: false, node: null },
|
||||
{ x: -320, y: 300, used: false, node: null },
|
||||
{ x: -240, y: 300, used: false, node: null },
|
||||
{ x: -160, y: 300, used: false, node: null },
|
||||
{ x: -80, y: 300, used: false, node: null },
|
||||
{ x: 0, y: 300, used: false, node: null },
|
||||
];
|
||||
|
||||
onLoad() {
|
||||
oops.message.on(GameEvent.UseSkillCard, this.onUseSkillCard, this);
|
||||
this.node.parent=smc.map.MapView.scene.entityLayer!.node!
|
||||
oops.message.on(GameEvent.RemoveSkillBox, this.onRemoveSkillBox, this);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
oops.message.off(GameEvent.UseSkillCard, this.onUseSkillCard, this);
|
||||
oops.message.off(GameEvent.RemoveSkillBox, this.onRemoveSkillBox, this);
|
||||
}
|
||||
|
||||
private onRemoveSkillBox(event: string, args: any) {
|
||||
const node = args as Node;
|
||||
let removed = false;
|
||||
for (let i = 0; i < this.slots.length; i++) {
|
||||
if (this.slots[i].node === node) {
|
||||
this.slots[i].used = false;
|
||||
this.slots[i].node = null;
|
||||
removed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (removed) {
|
||||
this.rearrangeSlots();
|
||||
}
|
||||
}
|
||||
|
||||
private rearrangeSlots() {
|
||||
const validNodes: Node[] = [];
|
||||
for (let i = 0; i < this.slots.length; i++) {
|
||||
if (this.slots[i].used && this.slots[i].node && this.slots[i].node.isValid) {
|
||||
validNodes.push(this.slots[i].node);
|
||||
}
|
||||
this.slots[i].used = false;
|
||||
this.slots[i].node = null;
|
||||
}
|
||||
|
||||
for (let i = 0; i < validNodes.length; i++) {
|
||||
if (i < this.slots.length) {
|
||||
this.slots[i].used = true;
|
||||
this.slots[i].node = validNodes[i];
|
||||
validNodes[i].setPosition(new Vec3(this.slots[i].x, this.slots[i].y, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private onUseSkillCard(event: string, args: any) {
|
||||
@@ -40,12 +94,26 @@ export class MissSkillsComp extends CCComp {
|
||||
}
|
||||
|
||||
addSkill(uuid: number, card_lv: number) {
|
||||
var parent = smc.map.MapView.scene.entityLayer!.node!.getChildByName("SKILL")!;
|
||||
|
||||
if (!this.skill_box) {
|
||||
mLogger.error(this.debugMode, "MissSkillsComp", "skill_box prefab not set");
|
||||
return;
|
||||
}
|
||||
|
||||
const emptyIndex = this.slots.findIndex(slot => !slot.used);
|
||||
if (emptyIndex === -1) {
|
||||
mLogger.warn(this.debugMode, "MissSkillsComp", "skill_box slots are full");
|
||||
return;
|
||||
}
|
||||
|
||||
const node = instantiate(this.skill_box);
|
||||
node.parent = this.node;
|
||||
node.parent = parent;
|
||||
node.setPosition(new Vec3(this.slots[emptyIndex].x, this.slots[emptyIndex].y, 0));
|
||||
|
||||
this.slots[emptyIndex].used = true;
|
||||
this.slots[emptyIndex].node = node;
|
||||
|
||||
const comp = node.getComponent(SkillBoxComp) || node.addComponent(SkillBoxComp);
|
||||
comp.init(uuid, card_lv);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ export class SkillBoxComp extends CCComp {
|
||||
oops.message.off(GameEvent.MissionEnd, this.onMissionEnd, this);
|
||||
this.node.off(GameEvent.NewWave, this.onNewWave, this);
|
||||
oops.message.off(GameEvent.NewWave, this.onNewWaveGlobal, this);
|
||||
oops.message.dispatchEvent(GameEvent.RemoveSkillBox, this.node);
|
||||
}
|
||||
|
||||
init(uuid: number, card_lv: number) {
|
||||
|
||||
Reference in New Issue
Block a user