"use strict"; cc._RF.push(module, '6b6a2Ngwu5CLaSrT9lrtvei', 'vedio_collect_window'); // Scripts/mod/vedio/view/vedio_collect_window.js "use strict"; // -------------------------------------------------------------------- // @author: xxx@syg.com(必填, 创建模块的人员) // @description: // 录像收藏界面 //
Create: 2019-05-22 14:22:43 // -------------------------------------------------------------------- var PathTool = require("pathtool"); var CommonScrollView = require("common_scrollview"); var VedioController = require("vedio_controller"); var VedioConst = require("vedio_const"); var VedioMainItem = require("vedio_item_panel"); var VedioEvent = require("vedio_event"); var RoleController = require("role_controller"); var ChatConst = require("chat_const"); var VedioCollectWindow = cc.Class({ "extends": BaseView, ctor: function ctor() { this.prefabPath = PathTool.getPrefabPath("vedio", "vedio_collect_window"); this.viewTag = SCENE_TAG.dialogue; //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意 this.win_type = WinType.big; //是否是全屏窗体 WinType.Full, WinType.Big, WinType.Mini, WinType.Tips this.ctrl = VedioController.getInstance(); this._model = this.ctrl.getModel(); }, // 初始化一些配置数据,可以用于声明一些变量之类的 initConfig: function initConfig() {}, // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件 openCallBack: function openCallBack() { var self = this; self.background = self.root_wnd.getChildByName("background"); var main_container = self.root_wnd.getChildByName("main_container"); self.main_container = main_container; self.share_panel = self.root_wnd.getChildByName("share_panel"); self.share_panel.active = false; self.share_bg = self.share_panel.getChildByName("share_bg"); self.btn_guild = self.share_bg.getChildByName("btn_guild"); self.btn_world = self.share_bg.getChildByName("btn_world"); self.btn_cross = self.share_bg.getChildByName("btn_cross"); self.share_bg.getChildByName("guild_label").getComponent(cc.Label).string = Utils.TI18N("分享到公会频道"); self.share_bg.getChildByName("world_label").getComponent(cc.Label).string = Utils.TI18N("分享到世界频道"); // self.share_bg.getChildByName("cross_label"):setString(TI18N("分享到跨服频道")) var win_title = main_container.getChildByName("win_title"); win_title.getComponent(cc.Label).string = Utils.TI18N("个人收藏"); self.num_txt = main_container.getChildByName("num_txt").getComponent(cc.Label); self.no_vedio_image = main_container.getChildByName("no_vedio_image"); self.no_vedio_image.getChildByName("label").getComponent(cc.Label).string = Utils.TI18N("暂无录像收藏"); var vedio_list = main_container.getChildByName("vedio_list"); var scroll_view_size = vedio_list.getContentSize(); var setting = { item_class: VedioMainItem, //-- 单元类 start_x: 0, //-- 第一个单元的X起点 space_x: 0, //-- x方向的间隔 start_y: 0, //-- 第一个单元的Y起点 space_y: 5, //-- y方向的间隔 item_width: 620, //-- 单元的尺寸width item_height: 374, //-- 单元的尺寸height row: 0, //-- 行数,作用于水平滚动类型 col: 1, //-- 列数,作用于垂直滚动类型 need_dynamic: true }; this.vedio_scrollview = new CommonScrollView(); this.vedio_scrollview.createScroll(vedio_list, cc.v2(0, 0), ScrollViewDir.vertical, ScrollViewStartPos.top, scroll_view_size, setting); }, // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent registerEvent: function registerEvent() { this.btn_guild.on('click', function () { Utils.playButtonSound(1); if (RoleController.getInstance().getRoleVo().isHasGuild() == false) { message(Utils.TI18N("您暂未加入公会")); return; } if (this.replay_id) { this.ctrl.requestShareVedio(this.replay_id, ChatConst.Channel.Gang, this.srv_id, this.combat_type); this._model.updateVedioData(null, this.replay_id, "share", this.share_num); var new_data = this.updateVedioDataById(this.replay_id, "share", this.share_num); gcore.GlobalEvent.fire(VedioEvent.UpdateVedioDataEvent, new_data); } this.replay_id = null; this.srv_id = null; this.combat_type = null; this.share_panel.active = false; }, this); this.btn_world.on("click", function () { Utils.playButtonSound(1); if (this.replay_id) { this.ctrl.requestShareVedio(this.replay_id, ChatConst.Channel.World, this.srv_id, this.combat_type); this._model.updateVedioData(null, this.replay_id, "share", this.share_num); var new_data = this.updateVedioDataById(this.replay_id, "share", this.share_num); gcore.GlobalEvent.fire(VedioEvent.UpdateVedioDataEvent, new_data); } this.replay_id = null; this.srv_id = null; this.combat_type = null; this.share_panel.active = false; }, this); this.share_panel.on("touchend", function () { this.share_panel.active = false; }, this); this.background.on("touchend", function () { Utils.playButtonSound(2); this.ctrl.openVedioCollectWindow(false); }, this); this.addGlobalEvent(VedioEvent.UpdateCollectVedioEvent, function (data) { this.setData(data); }.bind(this)); this.addGlobalEvent(VedioEvent.CancelCollectVedioEvent, function (id) { for (var i = 0; i < this.data.length; ++i) { var v = this.data[i]; if (v.id == id) { this.data.splice(i, 1); break; } } if (Utils.next(this.data) == null) { this.no_vedio_image.active = true; this.vedio_scrollview.setData(this.data); } else { this.vedio_scrollview.resetAddPosition(this.data, this._onClickShareBtn.bind(this), { is_collect: true }); this.no_vedio_image.active = false; } this.refreshCollectNum(); }.bind(this)); }, // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了 openRootWnd: function openRootWnd(params) { this.ctrl.requestMyVedioByType(VedioConst.MyVedio_Type.Collect); this.refreshCollectNum(); gcore.GlobalEvent.fire(VedioEvent.OpenCollectViewEvent, true); }, setData: function setData(data) { var self = this; if (!data || Utils.next(data) == null) { self.no_vedio_image.active = true; } else { self.no_vedio_image.active = false; self.data = data; self.vedio_scrollview.setData(self.data, this._onClickShareBtn.bind(this), { is_collect: true }); // self.vedio_scrollview:reloadData() // --self.vedio_scrollview:setData(data, handler(self, self._onClickShareBtn), nil, {is_collect = true}) self.refreshCollectNum(); } }, refreshCollectNum: function refreshCollectNum() { var cur_num = 0; if (this.data) { cur_num = this.data.length; } var max_num = 0; var collect_cfg = Config.video_data.data_const["self_collection_limit"]; if (collect_cfg) { max_num = collect_cfg.val; } this.num_txt.string = cc.js.formatStr(Utils.TI18N("收藏数:%d/%d"), cur_num, max_num); }, _onClickShareBtn: function _onClickShareBtn(world_pos, replay_id, share_num, srv_id, combat_type) { var self = this; self.replay_id = replay_id; self.share_num = share_num; self.srv_id = srv_id; self.combat_type = combat_type; var node_pos = self.share_panel.convertToNodeSpaceAR(world_pos); if (node_pos) { self.share_bg.setPosition(cc.v2(node_pos.x - 60, node_pos.y + 45)); self.share_panel.active = true; } }, updateVedioDataById: function updateVedioDataById(id, key, val) { if (!this.data) return; var vedio_data = {}; for (var k = 0; k < this.data.length; ++k) { var v = this.data[k]; if (v.id == id) { v[key] = val; vedio_data = v; break; } } return vedio_data; }, // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象 closeCallBack: function closeCallBack() { if (this.vedio_scrollview) { this.vedio_scrollview.DeleteMe(); this.vedio_scrollview = null; } gcore.GlobalEvent.fire(VedioEvent.OpenCollectViewEvent, false); this.ctrl.openVedioCollectWindow(false); } }); cc._RF.pop();