151 lines
4.6 KiB
JavaScript
151 lines
4.6 KiB
JavaScript
var http = require('./utils/http');
|
|
var onfire = require('./utils/onfire');
|
|
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;
|
|
http.get('http://192.168.100.228:7456/res/import/4d/4d364e42-855d-4e28-abe4-0221d8b6c47b.json', {} )
|
|
.then(res => {
|
|
console.log(res);
|
|
})
|
|
.catch(err => {
|
|
console.error(err);
|
|
});
|
|
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);
|
|
});
|
|
this.longPressListener = onfire.on('longPressed', this.longPressed.bind(this));
|
|
},
|
|
|
|
start () {
|
|
},
|
|
onDestroy: function () {
|
|
onfire.un(this.topMenuListener);
|
|
onfire.un(this.longPressListener);
|
|
},
|
|
// 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);
|
|
},
|
|
longPressed(data) {
|
|
console.log(data);
|
|
switch (data.target) {
|
|
case 'qr_wechat':
|
|
window.location.href = 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzU0MTk4MzkyNQ==&scene=124#wechat_redirect';
|
|
break;
|
|
case 'qr_qq':
|
|
window.location.href = 'http://qm.qq.com/cgi-bin/qm/qr?k=9OEVDuOyP1BZ_cXOApidE9P2ea8daCVF';
|
|
break;
|
|
}
|
|
}
|
|
});
|