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; } if (!isShow) return; void this._loadRemoveIcon(true); } private async _loadRemoveIcon(isShow: boolean): Promise { 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); } }