import { ZError } from "../common/ZError"; const {ccclass, property} = cc._decorator; @ccclass export default class MenuPanel extends cc.Component { @property(cc.Prefab) btnPreb: cc.Prefab = null; @property(cc.Node) contentNode: cc.Node = null; @property({ type: [cc.SpriteFrame] }) icons: cc.SpriteFrame[] = [] inited = false btns = [ {title: 'Add Account', callback: this.onAddAccount.bind(this)}, {title: 'Import Account', callback: this.onImportAccount.bind(this)}, {title: 'Export Account', callback: this.onExportAccount.bind(this)}, {title: 'Backup Wallet', callback: this.onBackupWallet.bind(this)}, {title: 'Restore Wallet', callback: this.onRestoreWallet.bind(this)}, {title: 'Activity', callback: this.onActivity.bind(this)}, ] // LIFE-CYCLE CALLBACKS: // onLoad () {} start () { this.layoutBtns() } // update (dt) {} onCloseClick() { this.node.active = false } layoutBtns() { if (this.inited) { return } this.contentNode.removeAllChildren() let count = Math.min(this.btns.length, this.icons.length) for (let i = 0; i < count; i++) { this.addOneBtn(this.btns[i], this.icons[i]) } this.inited = true } addOneBtn(data: any, icon: cc.SpriteFrame) { let btn = cc.instantiate(this.btnPreb) btn.getComponent('IconBtn').init(data.title, icon) btn.getComponent('IconBtn').bindCallback(this.onIconBtnClicked.bind(this)) this.contentNode.addChild(btn) } onIconBtnClicked(title: string) { let obj = this.btns.find(o => o.title === title) obj && obj.callback && obj.callback() } onAddAccount() { console.log(this.inited) console.log('onAddAccount: ') } onImportAccount() { console.log('onImportAccount: ') } onExportAccount() { console.log('onExportAccount: ') } onBackupWallet() { console.log('onBackupWallet: ') } onRestoreWallet() { console.log('onRestoreWallet: ') } onActivity() { console.log('onActivity: ') } }