import ResSprite from "../../frameWork/compment/ResSprite"; import UEBase from "../../frameWork/compment/UEBase"; import { HcUnlock } from "../../shared/hc/PtlHcInfo"; import UECube from "./UECube"; const { ccclass, property } = cc._decorator; export interface I_CellData { zIndex: number; ueCube: UECube; unlock: HcUnlock; } @ccclass export default class UECell extends UEBase { static readonly BundleKey: string = "gridMap"; static readonly PrefabUrl: string = "UECell"; static readonly CLS: string = "UECell"; @property(cc.Node) private node_select: cc.Node = null!; @property(ResSprite) private sp_quality: ResSprite = null; @property(cc.Node) private node_lock: cc.Node = null; cellData: I_CellData = null!; Init(cellData: I_CellData) { this.cellData = cellData; this.node.zIndex = cellData.zIndex; this.SetQuality(); this.SetLock(); } SetCube(cube: UECube) { this.cellData.ueCube = cube; this.SetQuality(); } SetQuality() { if (this.cellData.ueCube && !this.IsLock()) { this.cellData.ueCube.SetZIndex(this.cellData.zIndex); let quality = this.cellData.ueCube.GetQuality(); this.sp_quality.setSpriteFrame('gridMap', `qualityBg/Img_zjm_diban0${quality}`); } else { this.sp_quality.setSpriteFrame('gridMap', `qualityBg/Img_zjm_diban00`); } } IsLock(): boolean { return this.cellData.unlock == HcUnlock.off; } SetLock() { if (this.cellData.unlock == HcUnlock.off) { this.node_lock.active = true; if (this.cellData.ueCube) { this.cellData.ueCube.node.active = false; } } else { this.node_lock.active = false; if (this.cellData.ueCube) { this.cellData.ueCube.node.active = true; } } } GetZIndex() { return this.cellData.zIndex; } SetSelect(isSelect: boolean) { this.node_select.active = isSelect; } /** 是否有物品可以拖动 */ CanDrag(): boolean { return !this.IsEmpty() && this.cellData.ueCube.CanDrag() && !this.IsLock(); } GetCube(): UECube { return this.cellData.ueCube; } /** 该棋格是否是空的 */ IsEmpty(): boolean { return this.cellData.ueCube == null; } /** 清空棋格里的棋子 */ ClearCube() { this.cellData.ueCube.unUse(); this.cellData.ueCube = null; this.SetQuality(); } MoveCubeToCell(toCell: UECell) { this.cellData.ueCube.MoveToNewPos(toCell.node.position.clone()); } }