"use strict"; cc._RF.push(module, '22ab2ZplHBMDYAT0IZCt9N+', 'cmp.daily.rewards'); // Scripts/mod/task/cmp/cmp.daily.rewards.js "use strict"; var TaskConst = require("task_const"); var TaskEvent = require("task_event"); var TaskController = require("task_controller"); var RoleController = require("role_controller"); var _require = require("define"), PlayerAction = _require.PlayerAction; cc.Class({ "extends": cc.Component, properties: { awards: { "default": [], type: [cc.Node] }, score: { "default": null, type: cc.Label }, score_bar: { "default": null, type: cc.ProgressBar }, nodClose: { "default": null, type: cc.Node } }, // LIFE-CYCLE CALLBACKS: onLoad: function onLoad() { this.cfg_list = []; this.role_vo = RoleController.getInstance().getRoleVo(); this.box_list = [109, 108, 108, 110]; //注册事件 if (this.role_vo != null) { if (this.role_assets_event == null) { this.role_assets_event = this.role_vo.bind(EventId.UPDATE_ROLE_ATTRIBUTE, function (key, value) { if (key == "activity") this.updateActivity(true); }.bind(this)); } } //更新活跃度以及激发活跃宝箱 if (this.update_activity_info == null) { this.update_activity_info = gcore.GlobalEvent.bind(TaskEvent.UpdateActivityInfo, function (_data) { this.updateActivityData(_data); }.bind(this)); } this.initCfg(); }, start: function start() { this.updateActivity(false); }, onDestroy: function onDestroy() { this.tweens.forEach(function (_tween) { _tween.stop(); }); if (this.role_assets_event != null) { if (this.role_vo != null) { this.role_vo.unbind(this.role_assets_event); } this.role_assets_event = null; } if (this.update_activity_info != null) { gcore.GlobalEvent.unbind(this.update_activity_info); this.update_activity_info = null; } }, onEnable: function onEnable() { this.initCfg(); }, initCfg: function initCfg() { var TM = TaskController.getInstance().getModel(); var rewards = []; this.tweens = []; if (TM) { rewards = TM.getActivityData(); } this.rewards = rewards; // console.log( "領取相關" + JSON.stringify( rewards ) ); var dealShow = function dealShow(_nod, _data) { // for (let j in rewards ) { // // nx.gui.setActive( _nod, "tip", parseInt( j ) >= _data ); // nx.gui.setActive( _nod, "got", parseInt( j ) >= _data ); // } }; // nx.gui.setActive( this.awards[i], "got", false ); var len = this.awards.length; for (var i = 0; i < len; i++) { var config = null; if (gdata("activity_data", "data_get", [i + 1]) != null) { config = gdata("activity_data", "data_get", [i + 1]); var target_val = nx.gui.getComponent(this.awards[i], "score/txt", cc.Label); target_val.string = config.activity; this.awards[i].status = TaskConst.action_status.normal; dealShow(this.awards[i], config.activity); var items = nx.gui.getComponent(this.awards[i], "show", "cmp.common.itemlayout"); if (items) { items.rebuild(config.rewards); } nx.gui.setActive(this.awards[i], "show", false); if (nx.dt.objEmpty(rewards)) { nx.gui.setActive(this.awards[i], "got", false); nx.gui.setActive(this.awards[i], "tip", config.activity <= this.role_vo.activity); } else { var reward = rewards[config.activity]; if (reward) { nx.gui.setActive(this.awards[i], "tip", false); nx.gui.setActive(this.awards[i], "got", true); } else { nx.gui.setActive(this.awards[i], "tip", config.activity <= this.role_vo.activity); nx.gui.setActive(this.awards[i], "got", false); } } nx.gui.setActive(this.awards[i], "icon", !nx.gui.find(this.awards[i], "got").active); var nod = nx.gui.find(this.awards[i], "tip"); if (nod.active) { var cnod = nx.gui.find(this.awards[i], "icon"); var tween = cc.tween(cnod).to(0.5, { scale: 0.95, angle: 0 }).to(0.5, { scale: 1, angle: 0 }).union().repeatForever().start(); this.tweens.push(tween); } this.cfg_list.push(config); } } }, touchAwardGet: function touchAwardGet(e) { var _this = this; if (!this.cfg_list[e]) return; var config = this.cfg_list[e]; if (this.role_vo && this.role_vo.activity >= config.activity && !this.rewards[config.activity]) { TaskController.getInstance().requestGetActivityAwards(config.activity); return; } this.cfg_list.forEach(function (_item) { if (_item.index != parseInt(e) + 1) { nx.gui.setActive(_this.awards[_item.index - 1], "show", false); } }); var nod = nx.gui.find(this.awards[e], "show"); nx.gui.setActive(this.awards[e], "show", !nod.active); nx.gui.setActive(this.nodClose, "", nod.active == true); }, updateActivity: function updateActivity(need_update) { this.need_update = need_update; if (this.role_vo != null) { var activity_config = gdata("activity_data", "data_get", [game.configs.activity_data.data_get_length]); var max_activity = 100; if (activity_config != null) max_activity = activity_config.activity; this.score.string = this.role_vo.activity + "/" + max_activity; this.score_bar.progress = this.role_vo.activity / max_activity; if (need_update) this.updateActivityData(TaskController.getInstance().getModel().getActivityData()); } }, updateActivityData: function updateActivityData(data) { if (this.role_vo == null) return; var data_list = data; //判断这个活跃度的宝箱是否已经领取了 var check_activity = function check_activity(activity) { if (data_list == null) return false; return data_list[activity]; }; for (var i in this.awards) { var item = this.awards[i]; var cfg = this.cfg_list[i]; if (item && cfg) { if (check_activity(cfg.activity)) { item.is_show_tips = true; item.status = TaskConst.action_status.finish; } else { if (cfg.activity <= this.role_vo.activity) { item.is_show_tips = false; item.status = TaskConst.action_status.activity; } else { item.is_show_tips = true; item.status = TaskConst.action_status.un_activity; } } // var box_action = PlayerAction.action_1; // if (item.status == TaskConst.action_status.finish){ // box_action = PlayerAction.action_3; // }else if (item.status == TaskConst.action_status.activity){ // box_action = PlayerAction.action_2; // } nx.gui.setActive(item, "tip", !item.is_show_tips); nx.gui.setActive(item, "icon", item.status != TaskConst.action_status.finish); var nod = nx.gui.find(item, "tip"); var cnod = nx.gui.find(item, "icon"); if (nod.active) { var tween = cc.tween(cnod).to(0.5, { scale: 0.95, angle: 2 }).to(0.5, { scale: 1, angle: -3 }).union().repeatForever().start(); this.tweens.push(tween); } else { cc.Tween.stopAllByTarget(cnod); } nx.gui.setActive(item, "got", item.status == TaskConst.action_status.finish); // //宝箱特效 // var effect_nd = nx.gui.find(item,"effect_container"); // let skel = nx.gui.getComponent(effect_nd,"",sp.Skeleton); // if(effect_nd){ // if (skel.skeletonData) { // if (item.box_action != box_action) { // skel.setAnimation(0, box_action, true); // item.box_action = box_action; // } // }else{ // var res_id = gdata("effect_data", "data_effect_info", this.box_list[i]); // var path = cc.js.formatStr("spine/%s/action.atlas", res_id) // this.createEffect(skel, path, box_action); // } // } } } }, //生成宝箱 createEffect: function createEffect(_skeleton, path, box_action) { cc.loader.loadRes(path, sp.SkeletonData, function (res) { _skeleton.skeletonData = res; _skeleton.setAnimation(0, box_action, true); }); } // update (dt) {}, }); cc._RF.pop();