a3ffad93-c091-4eb7-88ed-b3d48c250cae.js
5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"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();