"use strict"; cc._RF.push(module, 'c895agsG3tCSocgeZGd0NIG', 'cmp.library.wnd'); // Scripts/mod/home/library/cmps/cmp.library.wnd.js "use strict"; /****************************************************************** * * 派遣选择界面 * ******************************************************************/ var BridgeWindow = require("bridge.window"); var FxTogs = require("nx.fx.togs"); var ModLibrary = require("library.mod"); cc.Class({ "extends": BridgeWindow, properties: { togMain: { "default": null, type: FxTogs }, togSub: { "default": null, type: FxTogs }, nodPhotos: { "default": null, type: cc.Node }, nodDesc: { "default": null, type: cc.Node }, nodTasks: { "default": null, type: cc.Node }, nodPicture: { "default": null, type: cc.Node } }, // 重载:参数打开 onOpenConfigs: function onOpenConfigs(_params) { this.library = ModLibrary.getInstance(); this.buildTogMain(); // // 参数判定 // if( nx.dt.objEmpty( _params ) || // nx.dt.objEmpty( _params.config ) ) { // nx.error( "派遣选择界面参数为空!" ); // this.scheduleOnce( () => { // this.close(); // }, 0.01 ); // return; // } // this.order = _params; // this.config = _params.config; // this.selects = []; // // 基础刷新 // this.freshBase(); // Tog监听 this.curTog = -1; this.togMain.posTog = this.onTogMain.bind(this); this.togSub.posTog = this.onTogSub.bind(this); nx.lw = this; }, // 重载:关闭前 onPreClosed: function onPreClosed() {}, // ------------------------------------------------------------- // 大类相关 // ------------------------------------------------------------- // 大类重建 buildTogMain: function buildTogMain() { var tags = this.library.tags; for (var tag in tags) { var ifo = tags[tag]; var id = parseInt(tag); var name = nx.text.getKey(ifo.name); var node = this.togMain.togs[id - 1]; node.idTag = id; nx.gui.setString(node, "on/txt", name); nx.gui.setString(node, "off/txt", name); var tip = nx.gui.getComponent(node, "off/tip", "nx.vb.visible"); tip.setTarget(nx.mTip, "home.library.tag" + tag); } // 默认 this.togMain.togTo(0); this.onTogMain(0); }, // 大类切换 onTogMain: function onTogMain(_index) { var idx = parseInt(_index) || 0; nx.debug("\u5927\u7C7B\u5207\u6362:" + this.curTog + " -> " + idx); var tag = this.togMain.togs[idx].idTag; var info = this.library.tags[tag]; if (!info) { return; } // 小类重建 this.buildTogSub(tag, info.subs); }, // ------------------------------------------------------------- // 小类相关 // ------------------------------------------------------------- // 小类重建 buildTogSub: function buildTogSub(_tag, _subs) { if (nx.dt.arrEmpty(_subs)) { this.togSub.node.active = false; return; } this.togSub.node.active = true; for (var i = 0; i < this.togSub.togs.length; ++i) { var tog = this.togSub.togs[i]; var sub = _subs[i]; if (!sub) { tog.active = false; continue; } tog.active = true; tog.idTag = sub.id; var name = nx.text.getKey(sub.name); nx.gui.setString(tog, "on/txt", name); nx.gui.setString(tog, "off/txt", name); var tip = nx.gui.getComponent(tog, "off/tip", "nx.vb.visible"); tip.setTarget(nx.mTip, "home.library.tag" + _tag + "." + sub.id); } // 默认 this.togSub.togTo(0); this.onTogSub(0); }, // 小类切换 onTogSub: function onTogSub(_index) { var idx = parseInt(_index) || 0; nx.debug("\u5C0F\u7C7B\u5207\u6362:" + idx); // 更新页面 var gid = this.togSub.togs[idx].idTag; this.showGroup(gid); }, // ------------------------------------------------------------- // 页面展示 // ------------------------------------------------------------- // 显示指定组别 showGroup: function showGroup(_gid) { var gp = this.library.groups[_gid]; if (!gp) { nx.error("\u65E0\u6548\u7EC4\u522B:" + _gid); return; } // 收集页 if (nx.dt.arrNEmpty(gp.partners)) { this.showTaskPage(gp); return; } // 描述页 if (nx.dt.arrNEmpty(gp.content)) { this.showDescPage(gp); return; } nx.error("\u672A\u5904\u7406\u7EC4\u522B:" + _gid); }, // 展示收集页 showTaskPage: function showTaskPage(_infos) { this.nodDesc.active = false; this.nodPicture.active = false; this.nodPhotos.active = true; this.nodTasks.active = true; // 排序 var partners = _infos.partners; partners.sort(function (a, b) { if (a.statu == b.statu) { return -1; } ; if (a.statu == 1) { return -1; } if (b.statu == 1) { return 1; } if (a.statu == 0) { return -1; } if (b.statu == 0) { return 1; } return -1; }); // 照片墙 var chds = this.nodPhotos.children; nx.gui.gocChildren(this.nodPhotos, "", partners.length, chds[0]); for (var i = 0; i < partners.length; ++i) { var pt = partners[i]; var node = chds[i]; var path = cc.path.join("prefab/home/library/photos", pt.photo_name); var mat = cc.Material.getBuiltinMaterial(pt.statu == 0 ? '2d-gray-sprite' : '2d-sprite'); var sp = nx.gui.setSpriteFrame(node, "", path); if (sp) { sp.setMaterial(0, mat); } node.x = pt.pos[0]; node.y = pt.pos[1]; node.partner = pt; nx.tween.fadeIn(node, "", 0.1); } // 总奖励 var header = nx.gui.getComponent(this.nodTasks, "head", "cmp.library.task.header"); if (header) { header.rebuild(_infos); } // 子奖励 var lst = nx.gui.find(this.nodTasks, "task/view/content"); nx.gui.gocChildren(lst, "", partners.length, lst.children[0]); for (var _i = 0; _i < partners.length; ++_i) { var _pt = partners[_i]; var _node2 = lst.children[_i]; var item = nx.gui.getComponent(_node2, "", "cmp.library.task.item"); item.rebuild(_pt, _infos); } }, // 展示描述页 showDescPage: function showDescPage(_infos) { this.nodPhotos.active = false; this.nodTasks.active = false; this.nodDesc.active = true; this.nodPicture.active = true; // 内容 var node = nx.gui.find(this.nodDesc, "view/content"); var chds = node.children; nx.gui.gocChildren(node, "", _infos.content.length, chds[0]); for (var i = 0; i < _infos.content.length; ++i) { var item = chds[i]; var txt = nx.text.getKey(_infos.content[i]); var arr = txt.split("#"); nx.gui.setString(item, "head/txt", arr[0]); nx.gui.setString(item, "desc", arr[1]); nx.tween.fadeIn(item, "", 0.1); } var layout = nx.gui.getComponent(node, "", cc.Layout); if (layout) { layout.updateLayout(); } var scv = nx.gui.getComponent(this.nodDesc, "", cc.ScrollView); if (scv) { scv.scrollToTop(0); } // 图片 var path = cc.path.join("prefab/home/library/photos", _infos.photo); nx.gui.setSpriteFrame(this.nodPicture, "img", path); }, // 点击照片 onTouchPhoto: function onTouchPhoto(_node) { var partner = _node ? _node.parent.partner : null; if (!partner) { return; } var self = this; var fresh = function fresh() { var lst = nx.gui.find(self.nodTasks, "task/view/content"); for (var i = 0; i < lst.children.length; ++i) { var node = lst.children[i]; var cmp = nx.gui.getComponent(node, "", "cmp.library.task.item"); if (cmp && partner) { cmp.updateState(cmp.partner.statu); } } }; nx.bridge.createPanel("WndLibraryPartner", { bid: partner.id, auto: false, cbClose: function cbClose() { fresh(); } }); } }); cc._RF.pop();