123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- 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 { HcType } from "../../shared/hc/PtlHcInfo";
- import { GridEvent } from "./GridEvent";
- const { ccclass, property } = cc._decorator;
- export interface I_CubeData {
- /** 物品类型 */
- type: HcType;
- /** 物品ID */
- id: number;
- /** 层级 */
- zIndex: 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!;
- cubeData: I_CubeData = null!;
- quality: number = 0;
- Init(cubeData: I_CubeData) {
- this.cubeData = cubeData;
- this.SetZIndex(cubeData.zIndex);
- if (cubeData.type == HcType.emitter) {
- let mergePropCfg = Gamecfg.emitterInfo.getItem(cubeData.id.toString());
- this.sp_item.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg.icon}`);
- // this.quality = mergePropCfg.
- } else if (cubeData.type == HcType.material) {
- let mergePropCfg = Gamecfg.mergePropInfo.getItem(cubeData.id.toString());
- this.sp_item.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg.icon}`);
- this.quality = mergePropCfg.quality;
- } else if (cubeData.type == HcType.equip) {
- let mergePropCfg = Gamecfg.equipInfo.getItem(cubeData.id.toString());
- this.sp_item.setSpriteFrame('gridMap', `mergeEquip/${mergePropCfg.icon}`);
- // this.quality = mergePropCfg.quality;
- }
- this.lbt_key.string = `${cubeData.type}_${cubeData.id}`;
- }
- /** 获取品质 */
- GetQuality() {
- return this.quality;
- }
- /** 触发点击 */
- TriggerClick() {
- if (this.cubeData.type == HcType.emitter) {
- CC_PREVIEW && console.log("触发点击发射器");
- GameDataCenter.gridMap.sendEmitter(this.cubeData.zIndex);
- } else if (this.cubeData.type == HcType.monster) {
- CC_PREVIEW && console.log("点击怪物开始战斗");
- } else if (this.cubeData.type == HcType.equip) {
- }
- }
- 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) {
- let originalPos = GameDataCenter.gridMap.GetPosByIdx(this.cubeData.zIndex);
- if (needMove) {
- cc.tween(this.node)
- .to(0.15, { position: originalPos })
- .call(() => {
- this.EndDrag();
- this.PlayJellyAnim();
- })
- .start();
- } else {
- this.itemNode.setPosition(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();
- }
- private UpdateItemDisplay(): void {
- // 根据 itemType 和 itemLevel 更新物品显示
- if (this.itemNode) {
- this.itemNode.active = true;
- // TODO: 更新物品的具体显示效果
- }
- }
- public unUse() {
- this.node.destroy();
- }
- }
|