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"); 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_iosChooseWalletNode: { 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, }, }, onLoad() { cc.audioEngine.stopAll(); }, start() { //test this.nd_linkNode.active = !Config.isTest; this.nd_splitLine.active = !Config.isTest; // cc.uiMain = 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) ); 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 == true) { window.canrename = false; this.nd_editName.active = true; } }, 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.on("hasConnectWallet", this); }, refreshBaseInfo() { 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 ); } }, 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); }); // type 10 时常rank // NetManage.getRankList(10, () => { // var nd = cc.instantiate(this.pb_rank); // this.node.addChild(nd); // }); }, calltask() { 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) => { console.log(data); var nd = cc.instantiate(this.pb_shop); this.node.addChild(nd); }); }, 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); }, 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(); }, });