|
@@ -11,8 +11,9 @@ import UECube from "./UECube";
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
|
|
export interface I_CellData {
|
|
|
+ x: number,
|
|
|
+ y: number,
|
|
|
idx: number;
|
|
|
- ueCube: UECube;
|
|
|
unlock: HcUnlock;
|
|
|
}
|
|
|
@ccclass
|
|
@@ -27,12 +28,13 @@ export default class UECell extends UEBase {
|
|
|
private sp_quality: ResSprite = null;
|
|
|
@property(cc.Node)
|
|
|
private node_lock: cc.Node = null;
|
|
|
-
|
|
|
+ @property(cc.Prefab)
|
|
|
+ cubePrefab: cc.Prefab = null!;
|
|
|
cellData: I_CellData = null!;
|
|
|
+ ueCube: UECube = null;
|
|
|
Init(cellData: I_CellData) {
|
|
|
this.cellData = cellData;
|
|
|
this.node.zIndex = cellData.idx;
|
|
|
- this.SetQuality();
|
|
|
this.SetLock();
|
|
|
EventMng.on(GridEvent.HC_CELL_CHANGE, this.OnHcCellChange, this);
|
|
|
EventMng.on(GridEvent.HC_CELL_SELECT, this.OnHcCellSelect, this);
|
|
@@ -58,26 +60,35 @@ export default class UECell extends UEBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /** 创建格子 */
|
|
|
- CreateCell(i: number, j: number) {
|
|
|
- // let cell = cc.instantiate(this.cellPrefab).getComponent(UECell);
|
|
|
- // this.cellLayer.addChild(cell.node);
|
|
|
- // cell.node.width = GridConstant.CELL_WIDTH;
|
|
|
- // cell.node.height = GridConstant.CELL_WIDTH;
|
|
|
- // let pos = GameDataCenter.gridMap.GetPosByVec(i, j);
|
|
|
- // cell.node.setPosition(pos);
|
|
|
- // return cell;
|
|
|
+ /** 创建棋子 */
|
|
|
+ CreateCube(info: HcInfoGeziInfo) {
|
|
|
+ let cube = cc.instantiate(this.cubePrefab).getComponent(UECube);
|
|
|
+ GameDataCenter.gridMap.ueGridMap.GetCubeLayer().addChild(cube.node);
|
|
|
+ cube.node.width = GridConstant.CELL_WIDTH;
|
|
|
+ cube.node.height = GridConstant.CELL_WIDTH;
|
|
|
+ let pos = GameDataCenter.gridMap.GetPosByVec(this.cellData.x, this.cellData.y);
|
|
|
+ cube.node.setPosition(pos);
|
|
|
+ let idx = (this.cellData.x + 1) * 10 + (this.cellData.y + 1);
|
|
|
+ cube.Init({
|
|
|
+ type: info.type,
|
|
|
+ id: info.correlationId,
|
|
|
+ idx: idx
|
|
|
+ })
|
|
|
+ this.ueCube = cube;
|
|
|
+ this.SetQuality();
|
|
|
+ this.SetLock();
|
|
|
+ return cube;
|
|
|
}
|
|
|
|
|
|
SetCube(cube: UECube) {
|
|
|
- this.cellData.ueCube = cube;
|
|
|
+ this.ueCube = cube;
|
|
|
this.SetQuality();
|
|
|
}
|
|
|
|
|
|
SetQuality() {
|
|
|
- if (this.cellData.ueCube && !this.IsLock()) {
|
|
|
- this.cellData.ueCube.SetZIndex(this.cellData.idx);
|
|
|
- let quality = this.cellData.ueCube.GetQuality();
|
|
|
+ if (this.ueCube && !this.IsLock()) {
|
|
|
+ this.ueCube.SetZIndex(this.cellData.idx);
|
|
|
+ let quality = this.ueCube.GetQuality();
|
|
|
this.sp_quality.setSpriteFrame('gridMap', `qualityBg/Img_zjm_diban0${quality}`);
|
|
|
} else {
|
|
|
this.sp_quality.setSpriteFrame('gridMap', `qualityBg/Img_zjm_diban00`);
|
|
@@ -96,13 +107,13 @@ export default class UECell extends UEBase {
|
|
|
SetLock() {
|
|
|
if (this.cellData.unlock == HcUnlock.off) {
|
|
|
this.node_lock.active = true;
|
|
|
- if (this.cellData.ueCube) {
|
|
|
- this.cellData.ueCube.node.active = false;
|
|
|
+ if (this.ueCube) {
|
|
|
+ this.ueCube.node.active = false;
|
|
|
}
|
|
|
} else {
|
|
|
this.node_lock.active = false;
|
|
|
- if (this.cellData.ueCube) {
|
|
|
- this.cellData.ueCube.node.active = true;
|
|
|
+ if (this.ueCube) {
|
|
|
+ this.ueCube.node.active = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -119,27 +130,27 @@ export default class UECell extends UEBase {
|
|
|
|
|
|
/** 是否有物品可以拖动 */
|
|
|
CanDrag(): boolean {
|
|
|
- return !this.IsEmpty() && this.cellData.ueCube.CanDrag() && !this.IsLock();
|
|
|
+ return !this.IsEmpty() && this.ueCube.CanDrag() && !this.IsLock();
|
|
|
}
|
|
|
|
|
|
GetCube(): UECube {
|
|
|
- return this.cellData.ueCube;
|
|
|
+ return this.ueCube;
|
|
|
}
|
|
|
|
|
|
/** 该棋格是否是空的 */
|
|
|
IsEmpty(): boolean {
|
|
|
- return this.cellData.ueCube == null;
|
|
|
+ return this.ueCube == null;
|
|
|
}
|
|
|
|
|
|
/** 清空棋格里的棋子 */
|
|
|
ClearCube() {
|
|
|
- this.cellData.ueCube.unUse();
|
|
|
- this.cellData.ueCube = null;
|
|
|
+ this.ueCube.unUse();
|
|
|
+ this.ueCube = null;
|
|
|
this.SetQuality();
|
|
|
}
|
|
|
|
|
|
MoveCubeToCell(toCell: UECell) {
|
|
|
- this.cellData.ueCube.MoveToNewPos(toCell.node.position.clone());
|
|
|
+ this.ueCube.MoveToNewPos(toCell.node.position.clone());
|
|
|
}
|
|
|
|
|
|
}
|