"use strict"; cc._RF.push(module, '1533c7/MopOpqQGfjv/Ukj+', 'strong_main_window'); // Scripts/mod/stronger/view/strong_main_window.js "use strict"; // -------------------------------------------------------------------- // @author: xxx@syg.com(必填, 创建模块的人员) // @description: // 这里是描述这个窗体的作用的 //
Create: 2019-03-29 11:44:54 // -------------------------------------------------------------------- var StrongerController = require("stronger_controller"); var PathTool = require("pathtool"); var HeroController = require("hero_controller"); var Strong_main_window = cc.Class({ "extends": BaseView, ctor: function ctor() { this.prefabPath = PathTool.getPrefabPath("stronger", "stronger_main_window"); // this.viewTag = SCENE_TAG.ui; //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意 this.win_type = WinType.Full; //是否是全屏窗体 WinType.Full, WinType.Big, WinType.Mini, WinType.Tips this.ctrl = StrongerController.getInstance(); this.partner_id = arguments[0]; }, // 初始化一些配置数据,可以用于声明一些变量之类的 initConfig: function initConfig() { this.view_list = {}; this.getZiyuanIndex = null; this.zhenrongIndex = null; this.wentiIndex = null; }, // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件 openCallBack: function openCallBack() { this.bianqiangScrollView = this.seekChild("bianqiangScrollView", cc.ScrollView); this.container = this.seekChild("container"); this.communal_nd = this.seekChild("communal"); this.background_nd = this.seekChild("background"); this.background_nd.scale = FIT_SCALE; this.tab_container_nd = this.seekChild("tab_container"); this.ziyuan_sv = this.seekChild("ziyuan_ScrollView", cc.ScrollView); this.zhenrong_sv = this.seekChild("zhenrong_ScrollView", cc.ScrollView); this.wenti_sv = this.seekChild("wenti_ScrollView", cc.ScrollView); this.back_nd = this.seekChild("close_btn"); }, // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent registerEvent: function registerEvent() { var _this = this; var _loop = function _loop(i) { _this.tab_container_nd.getChildByName("tab_btn_" + i).on("touchend", function () { Utils.playButtonSound(1); this.createSubPanel(i); }, _this); }; for (var i = 1; i <= 4; ++i) { _loop(i); } this.back_nd.on("touchend", function () { this.ctrl.openMainWin(false); Utils.playButtonSound(2); }, this); }, // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了 openRootWnd: function openRootWnd(index) { index = index || 1; this.ctrl.setIsFirst(false); this.createSubPanel(index); }, createSubPanel: function createSubPanel(index) { var panel = this.view_list[index]; if (!panel) { switch (index) { case 1: var StrongerPanel = require("stronger_panel"); panel = new StrongerPanel(this.partner_id); panel.setPosition(0, 15); panel.setParent(this.container); this.view_list[index] = panel; break; case 2: this.view_list[index] = this.ziyuan_sv.content; this.resourcePanel(); break; case 3: this.view_list[index] = this.zhenrong_sv.content; this.recommandPanel(); break; case 4: this.view_list[index] = this.wenti_sv.content; this.problemPanel(); break; } } if (index == 1) { panel.show(); this.communal_nd.active = false; } else { this.view_list[1].hide(); this.communal_nd.active = true; this.ziyuan_sv.node.active = false; this.zhenrong_sv.node.active = false; this.wenti_sv.node.active = false; if (index == 2) { this.ziyuan_sv.node.active = true; } else if (index == 3) { this.zhenrong_sv.node.active = true; } else if (index == 4) { this.wenti_sv.node.active = true; } } }, //获取资源 resourcePanel: function resourcePanel() { var path = PathTool.getPrefabPath("stronger", "stronger_item"); var self = this; var list = []; for (var i in Config.stronger_data.data_resource_one) { list.push(Config.stronger_data.data_resource_one[i]); } this.startUpdate(list.length, function (index) { var i = index; // for(let i in list){ var node = new cc.Node(); node.setAnchorPoint(0.5, 1); // Utils.delayRun(this.ziyuan_sv.content,Number(i)/30,function(){ this.ziyuan_sv.content.addChild(node); var a = node; this.loadRes(path, function (prefabPath) { var _this2 = this; var data = list[i]; var prefab = prefabPath; a.addChild(prefab); a.setContentSize(prefab.getContentSize()); var node = prefab.getChildByName("top").getChildByName("main_container"); node.getChildByName("name").getComponent(cc.Label).string = list[i].name; node.getChildByName("title").getComponent(cc.Label).string = list[i].desc; var res = PathTool.getIconPath("item", data.icon); var path1 = PathTool.getUIIconPath("common", "common_1078"); this.loadRes(res, function (SpriteFrame) { node.getChildByName("goods_icon").getComponent(cc.Sprite).spriteFrame = SpriteFrame; }.bind(this)); this.ziyuan_sv.content.getComponent(cc.Layout).updateLayout(); //创建展开列表 var arr = []; var path2 = PathTool.getPrefabPath("stronger", "stronger_sec_item"); var _loop2 = function _loop2(j) { var b = new cc.Node(); prefab.getChildByName("bottom").addChild(b); _this2.loadRes(path2, function (item) { var pre = item; b.addChild(pre); b.setContentSize(pre.getContentSize()); var list1 = Config.stronger_data.data_resource_two[data.sub_list[j]]; pre.getChildByName("main_container").getChildByName("title").getComponent(cc.Label).string = list1.desc; pre.getChildByName("main_container").getChildByName("name").getComponent(cc.Label).string = list1.name; pre.getChildByName("main_container").getChildByName("btn").on('click', function () { Utils.playButtonSound(1); this.ctrl.clickCallBack(list1.evt_type); }.bind(this)); // arr.push(pre) this.loadRes(path1, function (res) { pre.getChildByName("main_container").getChildByName("background").getComponent(cc.Sprite).spriteFrame = res; }.bind(this)); this.loadRes(res, function (SpriteFrame) { pre.getChildByName("main_container").getChildByName("goods_icon").getComponent(cc.Sprite).spriteFrame = SpriteFrame; }.bind(this)); }.bind(_this2)); }; for (var j = 0; j < data.sub_list.length; ++j) { _loop2(j); } node.getChildByName("btn").on('toggle', function (event) { var res; if (event.isChecked) { node.getChildByName("btn").getChildByName("btn_name").getComponent(cc.Label).string = "收起"; res = PathTool.getUIIconPath("common", "common_1020"); } else { node.getChildByName("btn").getChildByName("btn_name").getComponent(cc.Label).string = "展开"; res = PathTool.getUIIconPath("common", "common_1029"); } this.loadRes(res, function (SpriteFrame) { node.getChildByName("bg").getComponent(cc.Sprite).spriteFrame = SpriteFrame; }.bind(this)); if (this.getZiyuanIndex == i) { this.getZiyuanIndex = null; } else { if (this.getZiyuanIndex && this.getZiyuanIndex != i) { var toggle = this.view_list[2].children[this.getZiyuanIndex - 1].children[0].getChildByName("top").getChildByName("main_container").getChildByName("btn").getComponent(cc.Toggle); toggle.isChecked = false; } this.getZiyuanIndex = i; } Utils.playButtonSound(1); if (self.getZiyuanIndex) { // this.ziyuan_sv.content.getComponent(cc.Layout).updateLayout() // ScrollView里content高度没同步 所以延迟0.1秒滚动 this.ziyuan_sv.content.getComponent(cc.Layout).scheduleOnce(function () { self.ziyuan_sv.scrollToOffset(cc.v2(0, Math.abs(self.view_list[2].children[self.getZiyuanIndex - 1].y))); }, 0.1); } prefab.getChildByName("bottom").getComponent(cc.Layout).updateLayout(); prefab.getComponent(cc.Layout).updateLayout(); a.setContentSize(prefab.getContentSize()); }.bind(this)); // }.bind(this)) // }.bind(this)) }.bind(this)); }.bind(this)); }, recommandPanel: function recommandPanel() { var path2 = PathTool.getPrefabPath("stronger", "recommand_item"); var list = []; //Utils.deepCopy(Config.stronger_data.data_recommand) for (var i in Config.stronger_data.data_recommand) { list.push(Config.stronger_data.data_recommand[i]); } this.startUpdate(list.length, function (index) { // for(let i in list){ var i = index; var node = new cc.Node(); node.setAnchorPoint(0.5, 1); // Utils.delayRun(this.zhenrong_sv.content,Number(i)/30,function(){ this.zhenrong_sv.content.addChild(node); var a = node; this.loadRes(path2, function (prefabPath) { var _this3 = this; var prefab = prefabPath; a.addChild(prefab); a.setContentSize(prefab.getContentSize()); var main = prefab.getChildByName("main_container"); main.getChildByName("title").getComponent(cc.Label).string = list[i].name; var desc = StringUtil.parse(list[i].desc); prefab.getChildByName("messagePanel").getChildByName("desc").getComponent(cc.RichText).string = desc; main.getChildByName("btn").on('toggle', function (event) { var res; if (event.isChecked) { res = PathTool.getUIIconPath("common", "common_1020"); } else { res = PathTool.getUIIconPath("common", "common_1029"); } this.loadRes(res, function (SpriteFrame) { main.getChildByName("bg").getComponent(cc.Sprite).spriteFrame = SpriteFrame; }.bind(this)); if (i == this.zhenrongIndex) { this.zhenrongIndex = null; } else { if (this.zhenrongIndex && i != this.zhenrongIndex) { this.view_list[3].children[this.zhenrongIndex - 1].children[0].getChildByName("main_container").getChildByName("btn").getComponent(cc.Toggle).isChecked = false; } this.zhenrongIndex = i; } Utils.playButtonSound(1); prefab.getComponent(cc.Layout).updateLayout(); a.setContentSize(prefab.getContentSize()); }, this); prefab.getChildByName("messagePanel").on("touchend", function () { main.getChildByName("btn").getComponent(cc.Toggle).isChecked = false; }, this); var _loop3 = function _loop3(j) { var id = list[i].hero_list[0][j]; var config = Utils.deepCopy(Config.partner_data.data_partner_base[id]); if (config) { var hero_item = ItemsPool.getInstance().getItem("hero_exhibition_item"); hero_item.setData(config); hero_item.setParent(prefab.getChildByName("main_container").getChildByName("scroll_con")); hero_item.show(); hero_item.setScale(0.73); hero_item.setPosition(60 + j * 95, 0); hero_item.addCallBack(function () { if (config.bid) { HeroController.getInstance().openHeroTipsPanelByBid(config.bid); } }.bind(_this3)); } }; for (var j = 0; j < list[i].hero_list[0].length; ++j) { _loop3(j); } }.bind(this)); // }.bind(this)) // } }.bind(this)); }, problemPanel: function problemPanel() { var list = []; //Utils.deepCopy(Config.stronger_data.data_problem) for (var i in Config.stronger_data.data_problem) { list.push(Config.stronger_data.data_problem[i]); } this.startUpdate(list.length, function (index) { var i = index; // for(let i in list){ // Utils.delayRun(this.wenti_sv.content,Number(i)/30,function(){ var path = PathTool.getPrefabPath("stronger", "problem_item"); this.loadRes(path, function (prefabPath) { var prefab = prefabPath; this.wenti_sv.content.addChild(prefab); var main = prefab.getChildByName("main_container"); main.getChildByName("name").getComponent(cc.Label).string = list[i].name; prefab.getChildByName("msgBottom").getChildByName("desc").getComponent(cc.RichText).string = StringUtil.parse(list[i].desc); var height = prefab.getChildByName("msgBottom").getChildByName("desc").height; prefab.getChildByName("msgBottom").height = height + 25; main.getChildByName("btn").on('toggle', function (event) { var res, name; if (event.isChecked) { res = PathTool.getUIIconPath("common", "common_1020"); name = "收起"; } else { res = PathTool.getUIIconPath("common", "common_1029"); name = "查看"; } main.getChildByName("btn").getChildByName("Label").getComponent(cc.Label).string = name; this.loadRes(res, function (SpriteFrame) { main.getChildByName("bg").getComponent(cc.Sprite).spriteFrame = SpriteFrame; }.bind(this)); if (i == this.wentiIndex) { this.wentiIndex = null; } else { if (this.wentiIndex && this.wentiIndex != i) { this.view_list[4].children[this.wentiIndex - 1].getChildByName("main_container").getChildByName("btn").getComponent(cc.Toggle).isChecked = false; } this.wentiIndex = i; } Utils.playButtonSound(1); }, this); }.bind(this)); // }.bind(this)) // } }.bind(this)); }, // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象 closeCallBack: function closeCallBack() { if (this.view_list[1]) { this.view_list[1].deleteMe(); } this.ctrl.openMainWin(false); } }); module.exports = Strong_main_window; cc._RF.pop();