12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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.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`);
- }
- }
- SetLock() {
- this.node_lock.active = this.cellData.unlock == HcUnlock.off;
- }
- GetZIndex() {
- return this.cellData.zIndex;
- }
- SetSelect(isSelect: boolean) {
- this.node_select.active = isSelect;
- }
- /** 是否有物品可以拖动 */
- CanDrag(): boolean {
- return !this.IsEmpty();
- }
- 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());
- }
- }
|