129 lines
3.7 KiB
JavaScript

cc.Class({
extends: cc.Component,
properties: {
scrollContent: {
default: null,
type: cc.Node
},
scrollView: {
default: null,
type: cc.ScrollView
},
mainScrollPrefab: {
default: null,
type: cc.Prefab
},
topMenuBtn: {
default: null,
type: cc.Button
},
mainScrollContent: {
default: null,
type: cc.Node
},
topMenuPrefab: {
default: null,
type: cc.Prefab
},
infoMenuPrefab: {
default: null,
type: cc.Prefab
},
inviteMenuPrefab: {
default: null,
type: cc.Prefab
},
rulePrefab: {
default: null,
type: cc.Prefab
},
resultPrefab: {
default: null,
type: cc.Prefab
},
menuContentPrefab: {
default: null,
type: cc.Prefab
},
topMenu: {
default: null,
type: cc.Node
},
partsY: []
},
// LIFE-CYCLE CALLBACKS:
onLoad () {
let self = this;
this.partsY = [0, 1560, 2920, 3666, 4686];
this.mainScrollContent = cc.instantiate(this.mainScrollPrefab);
this.scrollContent.addChild(this.mainScrollContent);
this.mainScrollContent.getComponent('scrollContent').joinBtn.on('click', function () {
self.showInfoMenu();
});
this.mainScrollContent.getComponent('scrollContent').inviteBtn.on('click', function () {
self.showInviteMenu();
});
this.mainScrollContent.getComponent('scrollContent').ruleBtn.on('click', function () {
self.showRuleMenu();
});
let topHeader = cc.instantiate(this.topMenuPrefab);
this.node.addChild(topHeader, 10);
topHeader.getComponent('topMenu').menuBtn.on('click', function () {
self.showTopMenu();
});
this.scrollView.node.on('scroll-ended', function (e) {
// let offsetY = self.scrollView.getScrollOffset().y;
// console.log('getScrollOffset: ' + offsetY);
});
},
start () {
},
onDestroy: function () {
onfire.un(this.topMenuListener);
},
// update (dt) {},
showTopMenu() {
let offsetY = this.scrollView.getScrollOffset().y;
let menuNo = 0;
for(let i = 0; i < this.partsY.length; i++) {
if (offsetY >= this.partsY[i]) {
menuNo= i;
}
}
if (!this.topMenu) {
this.topMenu = cc.instantiate(this.menuContentPrefab);
this.node.addChild(this.topMenu, 9);
this.topMenuListener = onfire.on("topMenuClick", this.onTopMenuClick.bind(this));
} else {
this.topMenu.active = !this.topMenu.active ;
}
this.topMenu.getComponent('topMenuContent').updateMenuShow(menuNo);
},
onTopMenuClick: function (idx) {
console.log(idx);
let y = this.partsY[idx];
this.topMenu.getComponent('topMenuContent').updateMenuShow(idx);
this.scrollView.scrollToOffset(cc.v2(0, y), 0.1);
this.topMenu.active = false;
},
showInfoMenu() {
let infoMenu = cc.instantiate(this.infoMenuPrefab);
infoMenu.getComponent('infoMenu').top = this;
this.node.addChild(infoMenu, 11);
},
showInviteMenu() {
let inviteMenu = cc.instantiate(this.inviteMenuPrefab);
this.node.addChild(inviteMenu, 11);
},
showRuleMenu() {
let ruleMenu = cc.instantiate(this.rulePrefab);
this.node.addChild(ruleMenu, 11);
}
});