"use strict";
cc._RF.push(module, '0ad81sQHl9CU6uwSVzuqOoK', 'hero_skin_window');
// Scripts/mod/hero/view/hero_skin_window.js
"use strict";
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
// 英雄查看皮肤立绘界面
//
Create: 2019-09-11 20:22:43
// --------------------------------------------------------------------
var PathTool = require("pathtool");
var HeroController = require("hero_controller");
var CommonScrollViewSingleLayout = require("common_scrollview_single");
var BackPackConst = require("backpack_const");
var BackpackController = require("backpack_controller");
var CommonAlert = require("commonalert");
var ActionController = require("action_controller");
var MallConst = require("mall_const");
var MallController = require("mall_controller");
var BaseRole = require("baserole");
var HeroEvent = require("hero_event");
var MainUIController = require("mainui_controller");
var MainuiConst = require("mainui_const");
var Hero_skinWindow = cc.Class({
"extends": BaseView,
ctor: function ctor() {
this.prefabPath = PathTool.getPrefabPath("hero", "hero_skin_window");
this.viewTag = SCENE_TAG.dialogue; //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
this.win_type = WinType.Full; //是否是全屏窗体 WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
},
// 初始化一些配置数据,可以用于声明一些变量之类的
initConfig: function initConfig() {
//能否点击头像
this.can_click_btn = true;
this.ctrl = HeroController.getInstance();
this.model = this.ctrl.getModel();
this.color_1 = new cc.Color(0x64, 0x32, 0x23, 0xff);
},
// 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
openCallBack: function openCallBack() {
this.background = this.seekChild("background", cc.Sprite);
this.background.node.scale = FIT_SCALE;
this.loadRes(PathTool.getBigBg("hero_draw_bg", null, "hero"), function (sp) {
this.background.spriteFrame = sp;
}.bind(this));
this.main_container = this.seekChild("main_container"); //英雄名字
this.hero_name_lb = this.seekChild("hero_name", cc.Label);
this.hero_name_lb.string = "";
this.title_name_lb = this.seekChild("title_name", cc.Label);
this.title_name_lb.string = ""; //英雄立绘
this.hero_draw_icon_nd = this.seekChild(this.main_container, "hero_draw_icon");
this.hero_draw_icon_sp = this.seekChild(this.main_container, "hero_draw_icon", cc.Sprite);
this.hero_draw_icon_x = this.hero_draw_icon_nd.x;
this.hero_draw_icon_y = this.hero_draw_icon_nd.y; //底部面板
this.bottom_panel = this.seekChild(this.main_container, "bottom_panel"); //英雄信息面板
this.hero_panel = this.seekChild(this.bottom_panel, "hero_panel");
this.hero_panel_x = this.hero_panel.x;
this.hero_panel.x += cc.winSize.width * 2;
this.hero_panel.active = true;
this.mode_node = this.seekChild(this.hero_panel, "model_node");
this.hero_panel_bg_nd = this.seekChild(this.hero_panel, "bg");
this.line_nd = this.seekChild(this.hero_panel, "line");
this.name_lb = this.seekChild(this.hero_panel, "name", cc.Label); //属性面板
this.attr_panel = this.seekChild(this.bottom_panel, "attr_panel");
this.attr_panel_x = this.attr_panel.x;
this.attr_panel.x += cc.winSize.width * 2;
this.attr_panel.active = true;
var time_key = this.seekChild(this.attr_panel, "time_key", cc.Label);
time_key.string = Utils.TI18N("有效时间:");
var attr_key = this.seekChild(this.attr_panel, "attr_key", cc.Label);
attr_key.string = Utils.TI18N("属性加成:"); //时间
this.time_val_lb = this.seekChild(this.attr_panel, "time_val", cc.Label);
this.attr_item_list = {};
this.show_btn = this.seekChild(this.bottom_panel, "show_btn");
this.show_btn_icon_nd = this.seekChild(this.show_btn, "icon");
this.left_btn = this.seekChild(this.bottom_panel, "left_btn");
this.right_btn = this.seekChild(this.bottom_panel, "right_btn");
this.lay_scrollview = this.seekChild(this.bottom_panel, "lay_scrollview");
},
// 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
registerEvent: function registerEvent() {
Utils.onTouchEnd(this.left_btn, function () {
this.ctrl.openHeroSkinWindow(false);
}.bind(this), 2);
Utils.onTouchEnd(this.right_btn, function () {
//确定选择当前皮肤做作为显示皮肤
if (!this.hero_vo) return;
if (!this.skin_data_list) return;
var skin_data = this.skin_data_list[this.select_skin_index];
if (skin_data && skin_data.is_skin_data) {
//换成其他皮肤
if (this.hero_vo.use_skin != skin_data.skin_id) {
this.ctrl.sender11019(this.hero_vo.partner_id, skin_data.skin_id);
}
} else {
if (this.hero_vo.use_skin != 0) {
//换回原来皮肤
this.ctrl.sender11019(this.hero_vo.partner_id, 0);
}
}
}.bind(this), 1);
Utils.onTouchEnd(this.show_btn, function () {
//显示
if (!this.hero_vo) return;
if (!this.skin_data_list) return;
if (this.is_show_attr) {
this.is_show_attr = false;
this.attr_panel.x += cc.winSize.width * 2;
this.hero_panel.x = this.hero_panel_x;
this.updateHeroInfo(1);
if (this.show_btn_icon_nd) {
this.show_btn_icon_nd.setScale(-1);
}
} else {
this.is_show_attr = true;
var skin_data = this.skin_data_list[this.select_skin_index];
this.hero_panel.x += cc.winSize.width * 2;
if (skin_data && skin_data.is_skin_data) {
this.attr_panel.x = this.attr_panel_x;
this.updateAttrInfo();
} else {
this.attr_panel.x += cc.winSize.width * 2;
}
if (this.show_btn_icon_nd) {
this.show_btn_icon_nd.setScale(1);
}
}
}.bind(this), 2);
this.addGlobalEvent(HeroEvent.Hero_Skin_Info_Event, function () {
if (this.select_skin_index == null) return;
if (!this.skin_data_list) return;
for (var i in this.skin_data_list) {
var v = this.skin_data_list[i];
if (this.model.isUnlockHeroSkin(v.skin_id)) {
v.is_lock = false;
} else {
v.is_lock = true;
}
}
if (this.use_skin_index != null) {
this.updateSkinList(this.use_skin_index);
this.use_skin_index = null;
} else {
this.updateSkinList(this.select_skin_index);
}
}, this);
},
// 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
openRootWnd: function openRootWnd(hero_vo) {
if (!hero_vo) return;
this.hero_vo = hero_vo;
var bid_config = Config.partner_skin_data.data_partner_bid_info[this.hero_vo.bid];
if (!bid_config) return;
var partner_config = Config.partner_data.data_partner_base[this.hero_vo.bid];
if (partner_config) {
this.hero_name_lb.string = partner_config.name;
} //皮肤数据
this.skin_data_list = [];
for (var skin_id in bid_config) {
var v = bid_config[skin_id];
var data = {};
data.is_skin_data = true; //表示是皮肤数据
if (this.model.isUnlockHeroSkin(v.skin_id)) {
data.is_lock = false;
} else {
data.is_lock = true;
}
data.skin_id = skin_id;
data.config = Config.partner_skin_data.data_skin_info[v.skin_id];
this.skin_data_list.push(data);
}
this.skin_data_list.sort(Utils.tableLowerSorter(["skin_id"])); //第一个肯定是本体
this.skin_data_list.unshift(this.hero_vo);
var select_index = 0;
var use_skin = this.hero_vo.use_skin || 0;
if (use_skin != 0) {
for (var i in this.skin_data_list) {
var _v = this.skin_data_list[i];
if (_v.skin_id == use_skin) {
select_index = i;
}
}
}
this.is_show_attr = true;
this.updateSkinList(select_index);
},
updateSkinList: function updateSkinList(select_index) {
if (this.scroll_view == null) {
var scroll_view_size = this.lay_scrollview.getContentSize();
var list_setting = {
start_x: 0,
space_x: 0,
start_y: 0,
space_y: 0,
item_width: 120,
item_height: 120,
row: 1,
col: 1,
need_dynamic: true
};
this.scroll_view = new CommonScrollViewSingleLayout();
this.scroll_view.createScroll(this.lay_scrollview, cc.v2(0, 0), ScrollViewDir.horizontal, ScrollViewStartPos.top, scroll_view_size, list_setting, cc.v2(0.5, 0.5));
this.scroll_view.registerScriptHandlerSingle(this.createNewCell.bind(this), ScrollViewFuncType.CreateNewCell);
this.scroll_view.registerScriptHandlerSingle(this.numberOfCells.bind(this), ScrollViewFuncType.NumberOfCells);
this.scroll_view.registerScriptHandlerSingle(this.updateCellByIndex.bind(this), ScrollViewFuncType.UpdateCellByIndex);
this.scroll_view.registerScriptHandlerSingle(this.onCellTouched.bind(this), ScrollViewFuncType.OnCellTouched);
var max_count = Math.floor(scroll_view_size.width / list_setting.item_width);
if (this.skin_data_list.length <= max_count) {
this.scroll_view.setClickEnabled(false);
}
}
var select_index = select_index || 0;
this.scroll_view.reloadData(select_index);
},
// --创建cell
// --@width 是setting.item_width
// --@height 是setting.item_height
createNewCell: function createNewCell(width, height) {
var cell = ItemsPool.getInstance().getItem("backpack_item");
cell.initConfig(false, 1, false, true);
cell.show();
cell.setDefaultTip();
cell.setQualityBG(BackPackConst.quality.orange);
cell.addCallBack(function () {
this.onCellTouched(cell);
}.bind(this));
return cell;
},
//获取数据数量
numberOfCells: function numberOfCells() {
if (!this.skin_data_list) return 0;
return this.skin_data_list.length;
},
// --更新cell(拖动的时候.刷新数据时候会执行次方法)
// --cell :createNewCell的返回的对象
// --index :数据的索引
updateCellByIndex: function updateCellByIndex(cell, index) {
this.startUpdate(100, function () {
cell.index = index;
var skin_data = this.skin_data_list[index];
if (!skin_data) return;
var icon_res = null;
if (skin_data.is_skin_data) {
icon_res = PathTool.getHeadRes(skin_data.config.head_id);
cell.setItemIcon(icon_res);
if (skin_data.is_lock) {
cell.setItemIconUnEnabled(true);
} else {
cell.setItemIconUnEnabled(false);
}
} else {
var key = Utils.getNorKey(skin_data.bid, skin_data.star);
var star_config = gdata("partner_data", "data_partner_star", [key]);
if (star_config) {
icon_res = PathTool.getHeadRes(star_config.head_id);
cell.setItemIcon(icon_res);
}
cell.setItemIconUnEnabled(false);
}
if (this.select_skin_index != null && this.select_skin_index == index) {
cell.setSelected(true);
} else {
cell.setSelected(false);
}
}.bind(this), 1);
},
//点击cell .需要在 createNewCell 设置点击事件
onCellTouched: function onCellTouched(cell) {
if (!this.can_click_btn) return;
if (cell.index == null) return;
var index = cell.index;
var skin_data = this.skin_data_list[index];
if (!skin_data) return;
if (skin_data.is_skin_data) {
if (skin_data.is_lock) {
this.setLockInfo(skin_data, index);
return;
}
}
if (this.select_cell != null) {
this.select_cell.setSelected(false);
}
this.select_cell = cell;
this.select_cell.setSelected(true);
this.updateSelectSkinInfo(index);
},
//更新选中的皮肤信息
updateSelectSkinInfo: function updateSelectSkinInfo(index) {
if (!this.select_skin_index && this.select_skin_index == index) return;
this.select_skin_index = index;
var skin_data = this.skin_data_list[this.select_skin_index];
var name_str = "";
if (skin_data.config) {
name_str = skin_data.config.skin_name;
} else {
var config = gdata("partner_data", "data_partner_library", [skin_data.bid]);
if (config) {
name_str = config.title;
}
}
this.title_name_lb.string = name_str;
if (skin_data.is_skin_data) {
this.skin_config = skin_data.config;
if (this.is_show_attr) {
this.attr_panel.x = this.attr_panel_x;
this.updateAttrInfo();
} else {
this.attr_panel.x += cc.winSize.width * 2;
}
} else {
//英雄对象
this.skin_config = gdata("partner_data", "data_partner_library", [skin_data.bid]);
this.attr_panel.x += cc.winSize.width * 2;
}
this.updateDrawInfo();
if (!this.is_show_attr) {
this.updateHeroInfo(2);
}
},
setLockInfo: function setLockInfo(skin_data, index) {
var dic_item_id = {};
for (var i in skin_data.config.item_id_list) {
var id = skin_data.config.item_id_list[i];
dic_item_id[id] = true;
}
var have_item = null;
var have_list = [];
var list = BackpackController.getInstance().getModel().getBagItemList(BackPackConst.Bag_Code.BACKPACK) || {};
for (var _i in list) {
var item = list[_i];
if (item && item.config && dic_item_id[item.config.id]) {
//背包上有道具
var data = {};
if (item.config.client_effect[0] && item.config.client_effect[0][1]) {
data.time = item.config.client_effect[0][1];
} else {
data.time = 1;
}
if (data.time == 0) {
//表示有永久的皮肤
have_item = item;
break;
}
data.item_info = item;
have_list.push(data);
}
}
if (have_item) {
//表示有永久的皮肤
this.useSkinItemByID(have_item, index);
return;
}
if (have_list.length > 0) {
have_list.sort(Utils.tableUpperSorter(["time"]));
this.useSkinItemByID(have_list[0].item_info, index);
} else {
//说明该皮肤不能同商城获取
// if (skin_data.config.is_shop == 0) {
// message(Utils.TI18N("暂未获取此皮肤,请前往相关活动或玩法中获取!"));
// } else {
this.gotoSkinAction(skin_data.config); // }
}
},
//使用皮肤道具
useSkinItemByID: function useSkinItemByID(have_item, index) {
if (have_item.config) {
var color = BackPackConst.getWhiteQualityColorStr(have_item.config.quality);
var str = cc.js.formatStr(Utils.TI18N("已拥有解锁道具,是否消耗