a3ffad93-c091-4eb7-88ed-b3d48c250cae.js 5.25 KB
"use strict";
cc._RF.push(module, 'a3ffa2TwJFOt4jts9SMJQyu', 'PageViewIndicatorEx');
// script/game/ui/PageViewIndicatorEx.ts

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const CCDummyObjects_1 = require("../../common/CCDummyObjects");
const { ccclass, property } = cc._decorator;
let PageViewIndicatorEx = /** @class */ (() => {
    let PageViewIndicatorEx = class PageViewIndicatorEx extends cc.Component {
        constructor() {
            super(...arguments);
            this.unselectSpriteFrame = CCDummyObjects_1.DummySpriteFrame;
            this.selectSpriteFrame = CCDummyObjects_1.DummySpriteFrame;
            this.handlerPageView = CCDummyObjects_1.DummyPageView;
            this.touchEnable = false;
            this.curPageSelectIndex = 0;
            this.cellWidth = 20;
            this.cellHeight = 20;
            this.autoRefresh = false;
            this.autoRefreshDuration = 5000;
            this._nodeReady = false;
            this._indicatorArr = [];
            this._timeTicker = -1;
            this.onIndicatorClick = (index) => {
                if (!this.handlerPageView) {
                    return;
                }
                this.handlerPageView.setCurrentPageIndex(index);
            };
            this.selectIndex = (index) => {
                for (let i = 0; i < this._indicatorArr.length; i++) {
                    let spr = this._indicatorArr[i].getComponent(cc.Sprite);
                    spr.spriteFrame = i === index ? this.selectSpriteFrame : this.unselectSpriteFrame;
                }
                this.curPageSelectIndex = index;
            };
        }
        onLoad() {
            if (!this.handlerPageView) {
                return;
            }
            this._createIndicator();
            this.selectIndex(this.curPageSelectIndex);
        }
        _createIndicator() {
            let pagesNum = this.handlerPageView.getPages().length;
            this.node.removeAllChildren(true);
            for (let i = 0; i < pagesNum; i++) {
                let node = new cc.Node();
                let sprite = node.addComponent(cc.Sprite);
                sprite.spriteFrame = this.unselectSpriteFrame;
                sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
                node.width = this.cellWidth;
                node.height = this.cellHeight;
                if (this.touchEnable) {
                    node.off('click');
                    node.addComponent(cc.Button);
                    node.on('click', () => {
                        this.onIndicatorClick(i);
                    });
                }
                this.node.addChild(node);
                this._indicatorArr.push(node);
            }
            this._nodeReady = true;
        }
        start() {
            if (this.autoRefresh) {
                if (this._timeTicker !== (-1)) {
                    clearInterval(this._timeTicker);
                }
                this._timeTicker = setInterval(() => {
                    this.onIndicatorClick((this.curPageSelectIndex + 1) % this.handlerPageView.getPages().length);
                }, this.autoRefreshDuration);
            }
        }
        handlerPageViewChangeIndex() {
            if (!this.handlerPageView) {
                return;
            }
            let curIndex = this.handlerPageView.getCurrentPageIndex();
            if (curIndex === this.curPageSelectIndex) {
                return;
            }
            this.selectIndex(curIndex);
        }
        update(dt) {
            if (!this._nodeReady) {
                return;
            }
            this.handlerPageViewChangeIndex();
        }
    };
    __decorate([
        property(cc.SpriteFrame)
    ], PageViewIndicatorEx.prototype, "unselectSpriteFrame", void 0);
    __decorate([
        property(cc.SpriteFrame)
    ], PageViewIndicatorEx.prototype, "selectSpriteFrame", void 0);
    __decorate([
        property(cc.PageView)
    ], PageViewIndicatorEx.prototype, "handlerPageView", void 0);
    __decorate([
        property
    ], PageViewIndicatorEx.prototype, "touchEnable", void 0);
    __decorate([
        property
    ], PageViewIndicatorEx.prototype, "curPageSelectIndex", void 0);
    __decorate([
        property
    ], PageViewIndicatorEx.prototype, "cellWidth", void 0);
    __decorate([
        property
    ], PageViewIndicatorEx.prototype, "cellHeight", void 0);
    __decorate([
        property
    ], PageViewIndicatorEx.prototype, "autoRefresh", void 0);
    __decorate([
        property
    ], PageViewIndicatorEx.prototype, "autoRefreshDuration", void 0);
    PageViewIndicatorEx = __decorate([
        ccclass
    ], PageViewIndicatorEx);
    return PageViewIndicatorEx;
})();
exports.default = PageViewIndicatorEx;

cc._RF.pop();