46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
import JCWallet from "../JCWallet";
|
|
import ButtonGroup from "./ButtonGroup";
|
|
import TextBtn from "./TextBtn";
|
|
|
|
const {ccclass, property} = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class ChainTab extends cc.Component {
|
|
private wallet: JCWallet
|
|
|
|
@property({
|
|
type: ButtonGroup
|
|
})
|
|
btnGroup: ButtonGroup = null
|
|
|
|
@property({
|
|
type: cc.Prefab
|
|
})
|
|
btnPreb: cc.Prefab = null
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {}
|
|
|
|
start () {
|
|
this.wallet = new JCWallet()
|
|
this.updateChains()
|
|
}
|
|
|
|
// update (dt) {}
|
|
|
|
updateChains() {
|
|
const chains = this.wallet.chainList
|
|
if (!chains || chains.length === 0) {
|
|
return;
|
|
}
|
|
this.node.removeAllChildren()
|
|
for (const chain of chains) {
|
|
const btn = cc.instantiate(this.btnPreb)
|
|
const btnM: TextBtn = btn.getComponent(TextBtn)
|
|
this.node.addChild(btn)
|
|
btnM.title = chain.name
|
|
btnM.selected = this.wallet.currentChain.id === chain.id
|
|
}
|
|
}
|
|
}
|