12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /** @format */
- import {idNum} from '../proto/typedef'
- import {ccUtils} from '../utils/ccUtils'
- import {Mgr} from '../GameControl'
- /** @format */
- const {ccclass, property, executeInEditMode, requireComponent} = cc._decorator
- @ccclass
- @executeInEditMode
- @requireComponent(cc.Layout)
- export class CenterGridCell extends cc.Component {
- @property(cc.Node)
- rawLay: cc.Node = null
- @property({displayName: '最大行数'})
- maxRaw: number = 0
- @property({displayName: '最大列数'})
- maxCol: number = 0
- protected onLoad() {
- this.checkNode()
- }
- checkNode() {
- let check = true
- if (!this.rawLay) {
- this.rawLay = this.node.children[0]
- if (!this.rawLay || !this.rawLay.children[0]) {
- check = false
- console.error('CenterGridCell:layout or children is null')
- }
- }
- return check
- }
- init(num: number): cc.Node[] {
- let nodes: cc.Node[] = []
- if (!this.checkNode()) return nodes
- let min = Math.min(num, this.maxRaw * this.maxCol)
- let realRow = Math.ceil(min / this.maxCol)
- let allRawLay = ccUtils.instantChildren(this.rawLay, realRow)
- for (let i = 0; i < allRawLay.length; i++) {
- let tmp = ccUtils.instantChildren(
- allRawLay[i].children[0],
- i == allRawLay.length - 1 ? min - this.maxCol * (allRawLay.length - 1) : this.maxCol,
- )
- nodes = nodes.concat(tmp)
- }
- return nodes
- }
- getMaxNum() {
- return this.maxRaw * this.maxCol
- }
- }
|