消消方块阵换皮表情
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.9 KiB

1 week ago
import { _decorator, Component, Node, Sprite } from 'cc';
import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad';
import { GBundle, GPath } from '../../game/ConfigRes';
const { ccclass, property } = _decorator;
@ccclass('MapGrid')
export class MapGrid extends Component {
@property({ displayName: '是否可以通行' })
isCanWalk: boolean = true;
@property({ displayName: '是否可以放置' })
isCanPutObstacle: boolean = true;
@property({ displayName: '是否可以铲除' })
isCanRemove: boolean = false;
@property({ displayName: '是否可以被雷击' })
isCanBeThunder: boolean = false;
@property({ displayName: '是否最佳摆放点' })
isBestPlace: boolean = false;
/**是否是免费推荐点 */
@property({ displayName: '是否免费推荐点' })
isFreePlace: boolean = false;
//是否是破损状态
@property({ displayName: '是否是破损状态' })
isBroken: boolean = false;
/** 行 */
Row = 0;
/** 列 */
Col = 0;
/** 网格索引 */
Index = 0;
statusSprite: Sprite = null;
removeIcon: Node = null;
ShowGuidePos: boolean = false;
protected onLoad(): void {
this.statusSprite = this.node.getOrAddComponent(Sprite);
}
updateGrid() {
if (gg.game.CurentBattle.IsEdit) {
let name = "格子状态默认";
if (this.isCanPutObstacle) name = "格子状态可放置";
else if (!this.isCanWalk && this.isCanRemove) name = "格子状态已放置";
this.node.getOrAddComponent(SpriteLoad).setSprite(GPath.ObstacleItem(name), GBundle.BattleMap);
this.showRemoveIcon(this.isCanRemove);
} else {
this.showRemoveIcon(false);
this.statusSprite.spriteFrame = null;
}
}
/**显示铲子 */
showRemoveIcon(isShow: boolean) {
if (this.removeIcon?.isValid) {
this.removeIcon.active = isShow;
this.removeIcon.setSiblingIndex(-1);
return;
1 week ago
}
if (!isShow) return;
void this._loadRemoveIcon(true);
}
private async _loadRemoveIcon(isShow: boolean): Promise<void> {
if (!this.node?.isValid) return;
if (this.removeIcon?.isValid) {
this.removeIcon.active = isShow;
this.removeIcon.setSiblingIndex(-1);
return;
}
const n = await gg.res.getNodeAsync(GPath.ObstaclePrefab(''), 'removeIcon', GBundle.BattleMap);
if (!n?.isValid || !this.node?.isValid) {
console.warn('[MapGrid] removeIcon 加载失败');
return;
}
if (this.removeIcon?.isValid) {
gg.res.putNode(n);
this.removeIcon.active = isShow;
this.removeIcon.setSiblingIndex(-1);
return;
}
this.removeIcon = n;
this.node.addChild(n);
n.active = isShow;
n.setSiblingIndex(-1);
1 week ago
}
}