"use strict"; cc._RF.push(module, 'b0083RN9fdDjrjyF0bsR+xw', 'cmp.main.ui.top'); // Scripts/mod/mainui/cmp/cmp.main.ui.top.js "use strict"; /****************************************************************** * Copyright(C) 2019 - 2020 Nx Studio * * 主界面 --- 顶部栏 * * ******************************************************************/ var RoleController = require("role_controller"); var ExchangeController = require("exchange_controller"); var ExchangeEvent = require("exchange_event"); var ActMod = require("acts.mod"); var ActDefine = require("acts.define"); var TDefine = require("trace.define"); var TTT = TDefine.TraceType; var _require = require("define"), SCENE_TAG = _require.SCENE_TAG; var FID = require("bridge.function.ids"); cc.Class({ "extends": cc.Component, properties: { nodAvatar: { "default": null, type: cc.Node }, progExp: { "default": null, type: cc.ProgressBar }, lstActs: { "default": null, type: cc.Node } }, // 加载 onLoad: function onLoad() { // GM界面 if (nx.bridge.vget("gm")) { var GmCmd = require("gmcmd"); GmCmd.show(); } // 金币红点 var tipCoin = nx.gui.find(this, "coin/add/tip"); if (tipCoin) { tipCoin.active = false; this.handler_coin = gcore.GlobalEvent.bind(ExchangeEvent.Extra_Reward, function (data) { tipCoin.active = ExchangeController.getInstance().getModel().getRedStatus(); }.bind(this)); } // 经验条 this.exp_bar = nx.gui.find(this, "infos/exp/bar"); // 角色属性监听 this.role_vo = RoleController.getInstance().getRoleVo(); if (this.role_vo) { this.handler_role = this.role_vo.bind(EventId.UPDATE_ROLE_ATTRIBUTE, function (key, val) { switch (key) { case "face_id": this.updateRoleHead(); break; case "avatar_base_id": this.updateRoleHeadFrame(); break; case "exp": this.updateRoleExp(); break; case "exp_max": this.updateRoleExp(); break; // case "hero_exp": this.updateRoleExp(); break; default: break; } }, this); } this.onInit(); }, // 展示 onInit: function onInit() { var _this = this; this.updateRoleHead(); this.updateRoleHeadFrame(); this.updateRoleExp(); // 活动监听 ActMod.getInstance().vbind(this, [["themes", this.onActThemesChanged.bind(this)], ["pushPopup", this.onActPushChanged.bind(this)]]); // 计时器 this.schedule(function () { _this.cdThemes(); }, 1, cc.macro.REPEAT_FOREVER); // 今日推送 if (this.role_vo.lev >= game.configs.source_data.data_source_data[FID.ActFirst].lev_limit[1]) { // ActMod.getInstance().reqPushPopup(); } }, // 销毁 onDestroy: function onDestroy() { // 计时器 this.unscheduleAllCallbacks(); if (this.tween) { this.tween.stop(); } // 监听解除 if (this.handler_coin) { gcore.GlobalEvent.unbind(this.handler_coin); this.handler_coin = null; } // 监听解除 if (this.handler_role && this.role_vo) { this.role_vo.unbind(this.handler_role); this.handler_role = null; this.role_vo = null; } if (window.nx && nx.bridge.ui && nx.gui.find(nx.bridge.ui.getSceneNode(SCENE_TAG.msg), "gm")) { var nod = nx.gui.find(nx.bridge.ui.getSceneNode(SCENE_TAG.msg), "gm"); nod.destroy(); } // 活动监听解除 ActMod.getInstance().vunbind(this); }, // 头像更新 updateRoleHead: function updateRoleHead() { nx.bridge.setIcon(this.nodAvatar, "mask/img", this.role_vo.face_id); }, // 头像框更新 updateRoleHeadFrame: function updateRoleHeadFrame() { var path = cc.path.join("resDB/aframes", this.role_vo.avatar_base_id); nx.gui.setSpriteFrame(this.nodAvatar, "frame", path); }, // 经验更新 updateRoleExp: function updateRoleExp() { var pro = 0; if (this.role_vo && nx.dt.numGood(this.role_vo.exp) && nx.dt.numGood(this.role_vo.exp_max)) { pro = this.role_vo.exp / this.role_vo.exp_max; } this.progExp.progress = pro; }, // ======================================================================== // 活动 // ======================================================================== // 活动主题刷新 onActThemesChanged: function onActThemesChanged(_themes) { // 重复过滤 if (nx.dt.strNEmpty(this.tsTheme)) { var ids = []; _themes.forEach(function (_tm) { ids.push(_tm.theme_id); }); var ts = ids.toString(); if (ts == this.tsTheme) { return; } this.tsTheme = ts; } // 空主题 if (nx.dt.arrEmpty(_themes)) { nx.gui.setActive(this.lstActs, "", false); return; } var chds = this.lstActs.children; nx.gui.setActive(this.lstActs, "", true); nx.gui.gocChildren(this.lstActs, "", _themes.length, chds[0]); for (var i = 0; i < _themes.length; ++i) { var entry = nx.gui.getComponent(chds[i], "", "cmp.main.theme.entry"); if (entry) { if (chds[i]) { chds[i].active = true; } entry.setTheme(_themes[i]); } else { nx.error("Top:\u4E3B\u9898\u5165\u53E3\u7EC4\u4EF6\u7F3A\u5931!"); if (chds[i]) { chds[i].active = false; } } } }, // 主题活动时间刷新 cdThemes: function cdThemes() { var chds = this.lstActs.children; chds.forEach(function (node) { var entry = nx.gui.getComponent(node, "", "cmp.main.theme.entry"); if (entry && node.active && entry.theme) { entry.tick(); } }); }, // 活动推送弹窗 onActPushChanged: function onActPushChanged(_id) { if (!nx.dt.numPositive(_id, false)) { return; } this.scheduleOnce(function () { nx.bridge.createPanel("WndActPop" + _id, { id: _id }); }, 1); } }); cc._RF.pop();