var NetManage = require('NetManage'); var gameConfig = require('gameConfig'); var Utils = require('Utils'); const { uimanger, UIManger } = require('./UIManger'); const { KeyanMain } = require('./Academy/UIKeyanMain'); const Config = require('../Config'); const { default: Loading } = require('../gif/Loading'); const { GuestLoginTip } = require('../tips/GuestLoginTip'); const { LogoutTip } = require('../tips/LogoutTip'); const { operation, OperationType } = require('../Operation/Operation'); const jcgamelog = require('../jcfw/service/jcgamelog'); const { InviteTip } = require('../tips/InviteTip'); var playerData = require('playerData'); const { MulitLoginTip } = require('../tips/MulitLoginTip'); cc.Class({ extends: cc.Component, properties: { pb_chat: { default: null, type: cc.Prefab, }, pb_chose: { default: null, type: cc.Prefab, }, pb_chosehero: { default: null, type: cc.Prefab, }, pb_teammatch: { default: null, type: cc.Prefab, }, pb_hero: { default: null, type: cc.Prefab, }, pb_heroInfo: { default: null, type: cc.Prefab, }, pb_herobuy: { default: null, type: cc.Prefab, }, pb_xp: { default: null, type: cc.Prefab, }, pb_bag: { default: null, type: cc.Prefab, }, pb_top: { default: null, type: cc.Prefab, }, pb_season: { default: null, type: cc.Prefab, }, pb_editname: { default: null, type: cc.Prefab, }, pb_rank: { default: null, type: cc.Prefab, }, pb_userinfo: { default: null, type: cc.Prefab, }, pb_task: { default: null, type: cc.Prefab, }, pb_gun: { default: null, type: cc.Prefab, }, pb_seasoncard: { default: null, type: cc.Prefab, }, lb_name: { default: null, type: cc.Label, }, lb_lv: { default: null, type: cc.Label, }, sp_head: { default: null, type: cc.Sprite, }, sp_head_back: { default: null, type: cc.Sprite, }, lb_gold: { default: null, type: cc.Label, }, lb_diamond: { default: null, type: cc.Label, }, spine_hero: { default: null, type: sp.Skeleton, }, pr_progress: { default: null, type: cc.ProgressBar, }, pb_reward1: { default: null, type: cc.Prefab, }, pb_shop: { default: null, type: cc.Prefab, }, pb_keyan: { default: null, type: cc.Prefab, }, nd_accountNode: { default: null, type: cc.Node, }, nd_connectwalletBtn: { default: null, type: cc.Node, }, nd_editName: { default: null, type: cc.Node, }, nd_linkNode: { default: null, type: cc.Node, }, nd_splitLine: { default: null, type: cc.Node, }, nd_eventNode: { default: null, type: cc.Node, }, pb_friend: { default: null, type: cc.Prefab, }, friendRedPoint: { default: null, type: cc.Node, }, updateinfo: { default: null, type: cc.Node, }, btn_task: { default: null, type: cc.Node, }, btn_shop: { default: null, type: cc.Node, }, btn_acdemy: { default: null, type: cc.Node, }, }, onLoad() { cc.audioEngine.stopAll(); NetManage.getOptionSwitch((res) => { console.log('get switch' + JSON.stringify(res)); if (res.open_list.includes(2)) { this.btn_acdemy.active = true; this.btn_shop.active = true; } }); }, start() { //test this.nd_linkNode.active = !Config.isTest; this.nd_splitLine.active = !Config.isTest; // cc.uiMain = this; cc.Notifier.on( 'showFriendRedPoint', this, this.updateRedPoint.bind(this) ); cc.Notifier.on('openSelfPlayerInfoUI', this, this.callInfo.bind(this)); cc.Notifier.on('joinTeamRoom', this, this.joinTeamRoom.bind(this)); // cc.Notifier.on("openheroinfo", this, this.openheroinfo.bind(this)); cc.Notifier.on('buyitem', this, this.buyitem.bind(this)); cc.Notifier.on( 'refreshBaseInfo', this, this.refreshBaseInfo.bind(this) ); cc.Notifier.on('getreward', this, this.callreward.bind(this)); cc.Notifier.on( 'hasConnectWallet', this, this.getwalletEvent.bind(this) ); cc.Notifier.on('SMCustomMsgNotify', this, this.getCustomMsg.bind(this)); cc.Notifier.on('multipointlogin', this, this.multipointout.bind(this)); this.refreshBaseInfo(); NetManage.getItemList(); NetManage.getHeroList(); NetManage.getSkinList(); // this.nd_connectwalletBtn.active = !Config.isTest; if (window.hasWallet) { this.nd_connectwalletBtn.active = false; this.nd_accountNode.active = true; this.nd_accountNode.getComponent(cc.Label).string = this.replacepos( window.account, 7, 37 ); } // // // this.calleditname(90001); // if (window.canrename && window.hasWallet) { window.canrename = false; this.nd_editName.active = true; } }, multipointout() { jcgamelog.addOperation(OperationType.LOGIN, 'multipointout'); uimanger.showUI(MulitLoginTip.prefabPath); }, getCustomMsg(msg) { if (!cc.find('Canvas').getComponentInChildren('GameUI')) { uimanger.showUI(InviteTip.prefabPath, msg); } }, getwalletEvent() { this.nd_connectwalletBtn.active = false; this.nd_accountNode.active = true; this.nd_accountNode.getComponent(cc.Label).string = this.replacepos( window.account, 7, 37 ); }, replacepos(text, start, stop) { var mid = '*****'; let mystr = text.toString().substr(0, start - 1) + mid + text.toString().substr(stop + 1); return mystr; }, onDestroy() { cc.Notifier.off('openSelfPlayerInfoUI', this); cc.Notifier.off('joinTeamRoom', this); // cc.Notifier.off("openheroinfo", this); cc.Notifier.off('buyitem', this); cc.Notifier.off('refreshBaseInfo', this); cc.Notifier.off('getreward', this); cc.Notifier.off('hasConnectWallet', this); cc.Notifier.off( 'showFriendRedPoint', this, this.updateRedPoint.bind(this) ); cc.Notifier.off('multipointlogin', this, this.multipointout.bind(this)); }, updateRedPoint(msg) { if (playerData.friend_red == 1) { this.friendRedPoint.active = true; } else { this.friendRedPoint.active = false; } }, refreshBaseInfo() { NetManage.getUserMainInfo((res) => { this.lb_gold.string = res.info.gold; }); var pdata = cc.playerData; this.lb_name.string = pdata.name; this.lb_lv.string = 'LV.' + pdata.level; // this.lb_gold.string = pdata.gold; this.lb_diamond.string = pdata.diamond; this.pr_progress.progress = pdata.exp / pdata.max_exp; if (this.nowheadid != pdata.head_id) { this.nowheadid = pdata.head_id; Utils.setitem(this, this.nowheadid, this.sp_head); } if (this.nowheroid != pdata.hero_id) { this.nowheroid = pdata.hero_id; var skinres = cc.playerData.getheroSkinbyId(this.nowheroid, 0); cc.loader.loadRes( 'spine/heropic/pic_hero' + skinres, sp.SkeletonData, function (err, sp) { this.spine_hero.skeletonData = sp; this.spine_hero._updateSkeletonData(); this.spine_hero.setAnimation(0, 'animation', true); }.bind(this) ); } if (this.nowkuang != pdata.head_frame) { this.nowkuang = pdata.head_frame; Utils.setitem(this, this.nowkuang, this.sp_head_back); } }, joinTeamRoom(v) { var self = this; var cb = function (v) { if (v.errcode == 0) { self.callteammatch(v); } else { cc.uiHelper.showTips(v.errmsg); } }; NetManage.joinTeam(v, cb); // this.callteammatch(v) }, onClickOfficial() { this.openUrlinNative('https://www.cebg.games/'); }, onClickTwitter() { this.openUrlinNative('https://twitter.com/CEBG_GAME'); }, onClickTelegram() { this.openUrlinNative('https://t.me/CEBG_official'); }, onClickDiscord() { this.openUrlinNative('https://discord.gg/8dWX6jpcME'); }, openUrlinNative(url) { jcgamelog.addOperation(OperationType.BUTTON, 'openurl', url); if (cc.sys.os == cc.sys.OS_ANDROID) { jsb.reflection.callStaticMethod( 'org/cocos2dx/javascript/AppActivity', 'openSocialUrl', '(Ljava/lang/String;)V', url ); } else if (cc.sys.os == cc.sys.OS_IOS) { jsb.reflection.callStaticMethod( 'AppController', 'openSocialUrl:', url ); } }, onClickUpdateInfo() { this.updateinfo.active = true; }, onCloseUpdateInfo() { this.updateinfo.active = false; }, callreward(v) { var nd = cc.instantiate(this.pb_reward1); nd.getComponent('UIReward').initdata(v); this.node.addChild(nd); }, callBattle() { jcgamelog.addOperation(OperationType.BUTTON, 'intobattle'); if (cc.sys.isNative) { if (Config.isTest) { var nd = cc.instantiate(this.pb_chose); this.node.addChild(nd); } else { // debug if (!window.hasWallet) { uimanger.showUI(GuestLoginTip.prefabPath); return; } var nd = cc.instantiate(this.pb_chose); this.node.addChild(nd); } } else { // browser var nd = cc.instantiate(this.pb_chose); this.node.addChild(nd); } }, callChat() { jcgamelog.addOperation(OperationType.BUTTON, 'intochat'); var nd = cc.instantiate(this.pb_chat); this.node.addChild(nd); }, callbattlechosehero(opt) { var nd = cc.instantiate(this.pb_chosehero); nd.getComponent('UIChoseHero').initdata(opt); this.node.addChild(nd); }, callteammatch(teamid) { var nd = cc.instantiate(this.pb_teammatch); nd.getComponent('UITeamMatch').initdata(teamid); this.node.addChild(nd); }, onclickinfo() { this.callInfo(NetManage.account_id); }, callInfo(v) { jcgamelog.addOperation(OperationType.BUTTON, 'into userinfo'); NetManage.getUeserInfo(v, (data) => { if (data.errcode == 0) { var nd = cc.instantiate(this.pb_userinfo); nd.getComponent('UIRoleInfo').initdata(data.info); this.node.addChild(nd); } }); }, callbag() { var nd = cc.instantiate(this.pb_bag); this.node.addChild(nd); }, callgunskin() {}, callxinpian() { NetManage.gettalentList(() => { var nd = cc.instantiate(this.pb_xp); this.node.addChild(nd); }); }, callrole() { NetManage.getHeroList((data) => { var nd = cc.instantiate(this.pb_hero); nd.getComponent('UIHero').initdata(data); this.node.addChild(nd); }); }, // openheroinfo(v) { // var nd = cc.instantiate(this.pb_heroInfo); // nd.getComponent('UIHeroInfo').initdata(v.hero_id); // this.node.addChild(nd); // }, buyitem(v) { var nd = cc.instantiate(this.pb_herobuy); nd.getComponent('UIHeroBuy').initdata(v); this.node.addChild(nd); }, calltop(fnode) { var nd = cc.instantiate(this.pb_top); fnode.addChild(nd); }, callseason() { NetManage.getSeasonInfo(() => { var nd = cc.instantiate(this.pb_season); this.node.addChild(nd); }); }, calleditname(itemid) { var nd = cc.instantiate(this.pb_editname); nd.getComponent('UINameCard').initdata(itemid); this.node.addChild(nd); }, callrank() { NetManage.getactivityRankingList(1, (data) => { var nd = cc.instantiate(this.pb_rank); nd.getComponent('UIRank').init(JSON.stringify(data)); this.node.addChild(nd); }); }, calltask() { if (!window.hasWallet && cc.isNative) { uimanger.showUI(GuestLoginTip.prefabPath); return; } NetManage.missionList(1, (data) => { var nd = cc.instantiate(this.pb_task); nd.getComponent('UITask').initdata(data); this.node.addChild(nd); }); }, callGuns() { // NetManage.UpdateVersion((data) => { // console.log(data); // }); NetManage.gunList((data) => { var nd = cc.instantiate(this.pb_gun); nd.getComponent('UIGuns').initdata(data); this.node.addChild(nd); }); }, callShop() { NetManage.getShopGoodsInfo((data) => { var nd = cc.instantiate(this.pb_shop); this.node.addChild(nd); nd.getComponent('UIShop').init(data); }); }, callKeyan() { // NetManage.getShopGoodsInfo((data) => { // console.log(data); // }); var nd = cc.instantiate(this.pb_keyan); this.node.addChild(nd); }, callseasoncard() { NetManage.seasonCard((data) => { var nd = cc.instantiate(this.pb_seasoncard); nd.getComponent('UISeasonCard').initdata(data); this.node.addChild(nd); }); }, callFriend() { var nd = cc.instantiate(this.pb_friend); this.node.addChild(nd); this.friendRedPoint.active = false; }, callEvent() { this.nd_eventNode.active = true; }, closeEvent() { this.nd_eventNode.active = false; }, logout() { jcgamelog.addOperation(OperationType.BUTTON, 'logout'); uimanger.showUI(LogoutTip.prefabPath); }, connectwalletinmain() { jcgamelog.addOperation( OperationType.BUTTON, 'clickwalletconnectinmain' ); localStorage.removeItem('walletaccount'); window.hasWallet = false; cc.game.restart(); }, });