import SKUIUtil from "./gear_2.3.4/util/SKUIUtil"; import FGUtil from "./gear_2.3.4/fgui/FGUtil"; import MsgAlert from "./game/msg/MsgAlert"; import GameModel from "./core/GameModel"; import SKDataUtil from "./gear_2.3.4/util/SKDataUtil"; const { ccclass, property } = cc._decorator; @ccclass export default class GameMap extends cc.Component { /** * 單例實例 */ public static Instance: GameMap = null; /** * 主面板 */ mainPanel: fgui.GComponent = null; aboveMapNode: cc.Node = null; mapId: number = 0; onLoad() { if (GameMap.Instance === null) { GameMap.Instance = this; } else { this.destroy(); return; } } openMapPanel() { if (!SKUIUtil.isFGUIValid(this.mainPanel)) { this.mainPanel = FGUtil.create("main_ui", "big_map_panel"); FGUtil.root().addChild(this.mainPanel); this.mainPanel.makeFullScreen(); FGUtil.getButton(this.mainPanel, "n5").onClick(this.closeMapPanel, this); for (let i = 0; i < 10; i++) { let item = FGUtil.getButton(this.mainPanel, `alert/b100${i}`); item.node["idx"] = `100${i}`; item.onClick(this.clickMapLabel, this); } for (let i = 10; i < 21; i++) { let item = FGUtil.getButton(this.mainPanel, `alert/b10${i}`); item.node["idx"] = `10${i}`; item.onClick(this.clickMapLabel, this); } } } clickMapLabel(e: Event) { if (!SKDataUtil.hasProperty(e.target, "idx")) return this.showAboveNode(parseInt(e.target["idx"])) } showAboveNode(mapid) { this.aboveMapNode.destroyAllChildren(); this.mapId = mapid; // let pPos = this.getPlayerPos(); // this.roleNode.setPosition(pPos); // this.roleNode.active = false; // this.unschedule(this.checkPlayerMove); // for (let j = 0; j < this.moveNodes.length; j++) { // this.moveNodes[j].active = false; // } // this.endNode.active = false; // if (this.mapId == GameModel.player.mapid) { // this.roleNode.active = true; // this.unschedule(this.checkPlayerMove); // for (let j = 0; j < this.moveNodes.length; j++) { // this.moveNodes[j].active = true; // } // if (this.moveNodes.length > 0) { // this.endNode.active = true; // } // this.schedule(this.checkPlayerMove, 0.02, cc.macro.REPEAT_FOREVER); // } // let self = this; // let mapres = GameModel.conf_map[this.mapId].mapid; // cc.loader.loadRes(`Map/map/${mapres}`, cc.SpriteFrame, function (err, frame) { // if (!err) { // self.aboveMapNode.getComponent(cc.Sprite).spriteFrame = frame; // self.aboveLayer.active = true; // self.scheduleOnce(() => { // self.aboveCloseNode.x = self.aboveMapNode.width / 2; // self.aboveLayer.getChildByName('mapbg').width = self.aboveMapNode.width + 110; // self.aboveLayer.getChildByName('titleline').width = self.aboveMapNode.width + 120; // self.aboveLayer.getChildByName('pos').getComponent(cc.Label).string = GameModel.conf_map[mapid].map_name; // self.addMapNode(); // }, 0); // } // else { // self.node.active = false; // } // }); } closeMapPanel() { FGUtil.dispose(this.mainPanel) this.mainPanel = null } }