feat(技能盒): 添加技能盒销毁事件与自动排列功能
- 新增 RemoveSkillBox 事件用于技能盒销毁时通知 - 在 SkillBoxComp 销毁时触发 RemoveSkillBox 事件 - 为 MissSkillsComp 实现技能盒槽位管理系统 - 技能盒添加时会自动分配到可用槽位 - 技能盒销毁后会自动重新排列剩余技能盒 - 调整技能盒预制体尺寸和位置以优化显示效果
This commit is contained in:
@@ -105,7 +105,7 @@
|
|||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 40,
|
"y": 35,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
"_lrot": {
|
"_lrot": {
|
||||||
@@ -145,8 +145,8 @@
|
|||||||
},
|
},
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 80,
|
"width": 70,
|
||||||
"height": 80
|
"height": 70
|
||||||
},
|
},
|
||||||
"_anchorPoint": {
|
"_anchorPoint": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
@@ -287,7 +287,7 @@
|
|||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 40,
|
"y": 35,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
"_lrot": {
|
"_lrot": {
|
||||||
@@ -349,8 +349,8 @@
|
|||||||
},
|
},
|
||||||
"_lscale": {
|
"_lscale": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 1,
|
"x": 0.9,
|
||||||
"y": 1,
|
"y": 0.9,
|
||||||
"z": 1
|
"z": 1
|
||||||
},
|
},
|
||||||
"_mobility": 0,
|
"_mobility": 0,
|
||||||
@@ -377,8 +377,8 @@
|
|||||||
},
|
},
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 100,
|
"width": 78,
|
||||||
"height": 100
|
"height": 78
|
||||||
},
|
},
|
||||||
"_anchorPoint": {
|
"_anchorPoint": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
@@ -417,7 +417,7 @@
|
|||||||
"__uuid__": "031877cb-0f3d-4e92-bc5d-e492a0d95a08@f4f28",
|
"__uuid__": "031877cb-0f3d-4e92-bc5d-e492a0d95a08@f4f28",
|
||||||
"__expectedType__": "cc.SpriteFrame"
|
"__expectedType__": "cc.SpriteFrame"
|
||||||
},
|
},
|
||||||
"_type": 0,
|
"_type": 1,
|
||||||
"_fillType": 0,
|
"_fillType": 0,
|
||||||
"_sizeMode": 0,
|
"_sizeMode": 0,
|
||||||
"_fillCenter": {
|
"_fillCenter": {
|
||||||
@@ -463,8 +463,8 @@
|
|||||||
},
|
},
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 78,
|
"width": 68,
|
||||||
"height": 78
|
"height": 68
|
||||||
},
|
},
|
||||||
"_anchorPoint": {
|
"_anchorPoint": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
@@ -623,7 +623,7 @@
|
|||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 40,
|
"y": 35,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
"_lrot": {
|
"_lrot": {
|
||||||
@@ -663,8 +663,8 @@
|
|||||||
},
|
},
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 76,
|
"width": 66,
|
||||||
"height": 76
|
"height": 66
|
||||||
},
|
},
|
||||||
"_anchorPoint": {
|
"_anchorPoint": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
@@ -798,7 +798,7 @@
|
|||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 40,
|
"y": 35,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
"_lrot": {
|
"_lrot": {
|
||||||
@@ -838,8 +838,8 @@
|
|||||||
},
|
},
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 68,
|
"width": 58,
|
||||||
"height": 68
|
"height": 58
|
||||||
},
|
},
|
||||||
"_anchorPoint": {
|
"_anchorPoint": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
@@ -973,7 +973,7 @@
|
|||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": 40,
|
"y": 35,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
"_lrot": {
|
"_lrot": {
|
||||||
@@ -1013,8 +1013,8 @@
|
|||||||
},
|
},
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 80,
|
"width": 70,
|
||||||
"height": 80
|
"height": 70
|
||||||
},
|
},
|
||||||
"_anchorPoint": {
|
"_anchorPoint": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
@@ -1294,8 +1294,8 @@
|
|||||||
},
|
},
|
||||||
"_contentSize": {
|
"_contentSize": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 80,
|
"width": 70,
|
||||||
"height": 80
|
"height": 70
|
||||||
},
|
},
|
||||||
"_anchorPoint": {
|
"_anchorPoint": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -74,4 +74,5 @@ export enum GameEvent {
|
|||||||
GlobalAttrChange = "GlobalAttrChange",
|
GlobalAttrChange = "GlobalAttrChange",
|
||||||
CoinAdd = "CoinAdd",
|
CoinAdd = "CoinAdd",
|
||||||
TriggerSkill = "TriggerSkill", // 瞬间触发施法事件
|
TriggerSkill = "TriggerSkill", // 瞬间触发施法事件
|
||||||
|
RemoveSkillBox = "RemoveSkillBox", // 技能盒销毁事件
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { mLogger } from "../common/Logger";
|
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 { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||||
import { SkillBoxComp } from "./SkillBoxComp";
|
import { SkillBoxComp } from "./SkillBoxComp";
|
||||||
@@ -8,7 +8,12 @@ import { GameEvent } from "../common/config/GameEvent";
|
|||||||
import { smc } from "../common/SingletonModuleComp";
|
import { smc } from "../common/SingletonModuleComp";
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
interface SkillBoxSlot {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
used: boolean;
|
||||||
|
node: Node | null;
|
||||||
|
}
|
||||||
|
|
||||||
/** 视图层对象 */
|
/** 视图层对象 */
|
||||||
@ccclass('MissSkillsComp')
|
@ccclass('MissSkillsComp')
|
||||||
@@ -18,13 +23,62 @@ export class MissSkillsComp extends CCComp {
|
|||||||
@property({type: Prefab})
|
@property({type: Prefab})
|
||||||
private skill_box: Prefab = null;
|
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() {
|
onLoad() {
|
||||||
oops.message.on(GameEvent.UseSkillCard, this.onUseSkillCard, this);
|
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() {
|
onDestroy() {
|
||||||
oops.message.off(GameEvent.UseSkillCard, this.onUseSkillCard, this);
|
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) {
|
private onUseSkillCard(event: string, args: any) {
|
||||||
@@ -40,12 +94,26 @@ export class MissSkillsComp extends CCComp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addSkill(uuid: number, card_lv: number) {
|
addSkill(uuid: number, card_lv: number) {
|
||||||
|
var parent = smc.map.MapView.scene.entityLayer!.node!.getChildByName("SKILL")!;
|
||||||
|
|
||||||
if (!this.skill_box) {
|
if (!this.skill_box) {
|
||||||
mLogger.error(this.debugMode, "MissSkillsComp", "skill_box prefab not set");
|
mLogger.error(this.debugMode, "MissSkillsComp", "skill_box prefab not set");
|
||||||
return;
|
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);
|
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);
|
const comp = node.getComponent(SkillBoxComp) || node.addComponent(SkillBoxComp);
|
||||||
comp.init(uuid, card_lv);
|
comp.init(uuid, card_lv);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ export class SkillBoxComp extends CCComp {
|
|||||||
oops.message.off(GameEvent.MissionEnd, this.onMissionEnd, this);
|
oops.message.off(GameEvent.MissionEnd, this.onMissionEnd, this);
|
||||||
this.node.off(GameEvent.NewWave, this.onNewWave, this);
|
this.node.off(GameEvent.NewWave, this.onNewWave, this);
|
||||||
oops.message.off(GameEvent.NewWave, this.onNewWaveGlobal, this);
|
oops.message.off(GameEvent.NewWave, this.onNewWaveGlobal, this);
|
||||||
|
oops.message.dispatchEvent(GameEvent.RemoveSkillBox, this.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
init(uuid: number, card_lv: number) {
|
init(uuid: number, card_lv: number) {
|
||||||
|
|||||||
Reference in New Issue
Block a user