import Gamecfg from "../../common/gameCfg"; import GameDataCenter from "../../data/GameDataCenter"; import ResSprite from "../../frameWork/compment/ResSprite"; import UEBase from "../../frameWork/compment/UEBase"; import EventMng from "../../manager/EventMng"; import { GridEvent } from "./GridEvent"; const { ccclass, property } = cc._decorator; export enum E_CubeType { None = 0,//无物品 Material = 2,//材料 Emitter = 3,//发射器 Monster = 50,//怪物 MergeEquip = 4,//装备 } export interface I_CubeData { /** 物品类型 */ type: E_CubeType; /** 物品ID */ id: number; /** 层级 */ zIndex: number; /** 解锁条件 */ unlock: number } @ccclass export default class UECube extends UEBase { static readonly BundleKey: string = "gridMap"; static readonly PrefabUrl: string = "UECube"; static readonly CLS: string = "UECube"; @property(cc.Node) private itemNode: cc.Node = null!; @property(cc.Label) private lbt_num: cc.Label = null!; @property(cc.Label) private lbt_key: cc.Label = null!; @property(ResSprite) private sp_item: ResSprite = null!; originalPos: cc.Vec3 = cc.Vec3.ZERO; cubeData: I_CubeData = null!; Init(cubeData: I_CubeData) { this.cubeData = cubeData; this.SetZIndex(cubeData.zIndex); this.originalPos = cc.v3(this.node.x, this.node.y); if (cubeData.type == E_CubeType.Emitter) { let mergePropCfg = Gamecfg.emitterInfo.getItem(cubeData.id.toString()); this.sp_item.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg.icon}`); } else if (cubeData.type == E_CubeType.Material) { let mergePropCfg = Gamecfg.mergePropInfo.getItem(cubeData.id.toString()); this.sp_item.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg.icon}`); } else if (cubeData.type == E_CubeType.MergeEquip) { let mergePropCfg = Gamecfg.equipInfo.getItem(cubeData.id.toString()); this.sp_item.setSpriteFrame('gridMap', `mergeEquip/${mergePropCfg.icon}`); } this.lbt_key.string = `${cubeData.type}_${cubeData.id}`; } /** 触发点击 */ TriggerClick() { if (this.cubeData.type == E_CubeType.Emitter) { CC_PREVIEW && console.log("触发点击发射器"); GameDataCenter.gridMap.sendEmitter(this.cubeData.zIndex); } else if (this.cubeData.type == E_CubeType.Monster) { CC_PREVIEW && console.log("点击怪物开始战斗"); } else if (this.cubeData.type == E_CubeType.MergeEquip) { } } GetCubeData(): I_CubeData { return this.cubeData; } SetZIndex(zIndex: number) { this.node.zIndex = zIndex; this.cubeData.zIndex = zIndex; this.lbt_num.string = zIndex.toString(); } /** 是否有物品可以拖动 */ CanDrag(): boolean { return true; } StartDrag(): void { this.node.zIndex = 1000; } UpdateDragPosition(pos: cc.Vec3): void { this.node.position = pos.sub(this.node.position); } EndDrag(): void { this.node.zIndex = this.cubeData.zIndex; } ClearCell() { } /** 回到原来位置 */ BackToOriginalPos(needMove: boolean) { if (needMove) { cc.tween(this.node) .to(0.15, { position: this.originalPos }) .call(() => { this.EndDrag(); this.PlayJellyAnim(); }) .start(); } else { this.itemNode.setPosition(this.originalPos.clone()); this.EndDrag(); this.PlayJellyAnim(); } } /** 播放果冻效果 */ PlayJellyAnim() { cc.tween(this.itemNode) .to(0.1, { scale: 1.3 }) .to(0.1, { scale: 0.9 }) .to(0.08, { scale: 1 }) .start(); } /** 播放合成动画 */ PlayMergeAnim() { cc.tween(this.itemNode) .by(0.1, { position: cc.v3(0, 40) }) .by(0.1, { position: cc.v3(0, -40) }) .by(0.1, { position: cc.v3(0, 10) }) .by(0.1, { position: cc.v3(0, -10) }) .start(); } /** 移动到新的位置 */ MoveToNewPos(newPos: cc.Vec3, duration: number = 0.2) { cc.tween(this.node) .to(duration, { position: newPos }) .call(() => { this.EndDrag(); this.PlayJellyAnim(); }) .start(); this.originalPos = newPos.clone(); } private UpdateItemDisplay(): void { // 根据 itemType 和 itemLevel 更新物品显示 if (this.itemNode) { this.itemNode.active = true; // TODO: 更新物品的具体显示效果 } } public unUse() { this.node.destroy(); } }