Files
fc/dev/project/assets/Scripts/mod/pve/planesafk/cmp/cmp.planesafk.wnd.js
T
2026-05-23 22:10:14 +08:00

542 lines
16 KiB
JavaScript

const BridgeWindow = require("bridge.window");
const PlanesafkController = require("planesafk_controller");
const PlanesafkEvent = require("planesafk_event");
const TipsController = require("tips_controller");
const MallController = require("mall_controller")
const MallConst = require( "mall_const" );
const NXSpine = require("nx.fx.spine");
const PlaneRole = require("cmp.planesafk.role");
const RoleController = require("role_controller");
const { PlayerAction } = require( "define" );
cc.Class({
extends: BridgeWindow,
properties: {
map:{
default:null,
type:cc.Node
},
list:{
default:null,
type:cc.Node
},
fabLine:{
default:null,
type:cc.Node
},
fabMap:{
default:null,
type:cc.Node
},
//当前层数
floor_txt:{
default:null,
type:cc.Node
},
//剩余时间
time_val:{
default:null,
type:cc.Node
},
//難度等級
diff_txt:{
default:null,
type:cc.Node
},
ico_list:{
default:[],
type:[cc.Node]
},
reward_list:{
default:[],
type:[cc.RichText],
},
cmpRole:{
default:null,
type:PlaneRole
},
scroll:{
default:null,
type:cc.ScrollView
},
boxNd:{
default:null,
type:cc.Node
},
holeNd:{
default:null,
type:cc.Node
},
endNd:{
default:null,
type:cc.Node
}
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
this.ctrl = PlanesafkController.getInstance();
this.model = this.ctrl.getModel();
this.pushPath = [];
this.up_item_list = [];
//最大层数
this.max_floor = 3
let diff_config = gdata("planes_data", "data_const", "planes_difficult_limit_lev");
if (diff_config) {
this.difficult_limit_lev = diff_config.val || 30;
}
let diff_power = gdata("planes_data", "data_const", "planes_difficult_max_power");
if (diff_power) {
this.planes_difficult_max_power = diff_power.val || 300000;
}
this.is_init_over = false;
// 冒险角色
let role = RoleController.getInstance().getRoleVo();
let cfgs = game.configs.looks_data.data_data[role.look_id];
this.cmpRole.setModel( cfgs ? cfgs.model : "", this.roleMoveEvent.bind(this));
this.scroll.node.on("scrolling",this.roleMapMove.bind(this));
//基础信息
this.bindGEvent( PlanesafkEvent.Planesafk_Main_Base_Info_Event, this.baseInfoData.bind( this ) );
//地图信息
this.bindGEvent( PlanesafkEvent.Planesafk_Main_Map_Info_Event, this.initMapData.bind( this ) );
this.bindGEvent( PlanesafkEvent.Planesafk_Update_Map_Info_Event, this.initMapData.bind( this ) );
//buff进背包
this.bindGEvent( PlanesafkEvent.Chose_Buff_Event, this.showBuffItemMoveAni.bind( this ) );
//领取宝箱状态
this.bindGEvent( PlanesafkEvent.Planesafk_Pass_Reward_Info_Event, this.passRewardInfo.bind( this ) );
this.bindGEvent( PlanesafkEvent.Planesafk_Last_Reward_Info_Event, this.lastRewardInfo.bind( this ) );
//下一章地图
this.bindGEvent( PlanesafkEvent.Planesafk_Next_Map_Info_Event, ()=>{
this.scroll.scrollTo(0);
this.ctrl.sender28603()
} );
//本月以获取
this.bindGEvent( PlanesafkEvent.Planesafk_Update_Get_Reward_Event, this.updateRewardInfo.bind( this ) );
//创建角色
this.bindGEvent( PlanesafkEvent.Planesafk_Create_Role_Event, this.showRoleInfo.bind( this ) );
},
roleMapMove(){
this.map.x = this.scroll.content.x;
},
roleMoveEvent(_key){
if(_key == "end"){//检测是否要触发事件
let cur_pos = this.model.getRolePos();
let len = this.list.children.length;
let per = cur_pos[0]/len;
this.scroll.scrollTo(per);
this.map.x = this.scroll.content.x;
}else if(_key == "start"){//有可能要重置状态
}else if(_key == "move"){//移动中的事件
}
},
updateRewardInfo(data){
if(!data)return;
let self = this;
this.up_item_list = data.item_list;
// if (data.item_list) {
// var item_list = [];
// for (var i in data.item_list) {
// var v = data.item_list[i];
// item_list.push(v);
// }
// item_list.sort((a,b)=>{
// return b.base_id - a.base_id;
// });
// for (var i in item_list) {
// var v = item_list[i]
// var item_config = gitemdata(v.base_id);
// if (item_config && this.reward_list[i]) {
// let mst = self.reward_list[i];
// let str = cc.js.formatStr(":%s",Utils.getMoneyString(v.num))
// mst.string = str;
// let res = PathTool.querySmallIconPath(item_config.id);
// nx.gui.setSpriteFrame(this.ico_list[i],"",res);
// }
// }
// }
},
lastRewardInfo(data){
if (this.map_data) {
this.map_data.is_can_reward = data.is_can_reward
this.map_data.is_reward = data.is_reward
this.updateBoxInfo()
}
},
passRewardInfo(){
if (this.map_data) {
this.map_data.is_reward = 1
this.updateBoxInfo()
}
},
showBuffItemMoveAni(buff_id, world_pos){
},
baseInfoData(data){
//人物和 时间
if (!data)return;
this.base_data = data;
this.setData();
},
initMapData(data){
if (! data)return;
//層級
if(data.floor){
nx.gui.setString(this.floor_txt,"", "0" + data.floor);
}
//難易度
if(data.difficulty){
nx.gui.setString(this.diff_txt,"", data.difficulty == 1?nx.text.getKey("lab_guildwar_defend_look_item_tip3"):nx.text.getKey("lab_guildwar_defend_look_item_tip5") );
}
if(data.tile_list){
if((data.is_reward != null) && (data.is_can_reward != null)){
this.map_data = data;
if(this.map_data.is_reward == 0){
this.holeNd.active = false;
}else{
this.holeNd.active = true;
}
if(this.map_data.is_can_reward != 1){
this.boxNd.active = true;
}else{
this.boxNd.active = false;
}
}
let map_list = [];
if(!this.is_init_over){
let len = data.tile_list.length;
let pop = data.tile_list[len-1];
let bottom = data.tile_list[0];
let max_line = Math.max(pop.line,bottom.line);
for(let i=max_line;i>=1;i--){
this.createLineList(i);
}
map_list = this.formSortList(data.tile_list);
for(let i in map_list){
let tile_cfg = map_list[i];
this.createMapItem(tile_cfg,i);
}
this.is_init_over = true;
}else{
map_list = this.formSortList(data.tile_list);
for(let i in map_list){
let tile_cfg = map_list[i];
let par = null;
for(let i in this.list.children){
let line = this.list.children[i];
if(Number(line.name) == tile_cfg.line){
par = line;
}
}
if(par){
for(let j in par.children){
let map = par.children[j];
let cmp = nx.gui.getComponent(map,"","cmp.planesafk.item.map");
if(cmp.data && cmp.data.index == tile_cfg.index){
cmp.setData(tile_cfg);
}
}
}
}
}
}
this.updateRoleInfo();
this.scheduleOnce(()=>{
this.updateBoxInfo();
},0.5);
},
formSortList(tile_list){
if(!tile_list || tile_list.length == 0)return [];
let len = tile_list.length;
let pop = tile_list[len-1];
let bottom = tile_list[0];
let max_line = Math.max(pop.line,bottom.line);
let map_list = [];
for(let i=max_line;i>=1;i--){
let maps = [];
for( let l in tile_list){
if(tile_list[l].line == i){
maps.push(tile_list[l]);
}
}
maps.sort((a,b)=>{
return b.index - a.index;
});
map_list = map_list.concat(maps);
}
return map_list;
},
createLineList(index){
let line = cc.instantiate(this.fabLine);
line.parent = this.list;
line.name = String(index);
line.y = 0;
line.x = 0;
line.active = true;
},
createMapItem(cfg,index){
let par = null;
for(let i in this.list.children){
let line = this.list.children[i];
if(Number(line.name) == cfg.line){
par = line;
}
}
if(par){
let map = cc.instantiate(this.fabMap);
map.parent = par;
map.x = 0;
map.y = 0;
map.name = String(cfg.line-1)
map.active = true;
map.zIndex = index;
let cmp = nx.gui.getComponent(map,"","cmp.planesafk.item.map");
if(cmp){
cmp.setData(cfg);
}
}
},
//直接更换冒险形象
// 显示角色信息角色
showRoleInfo:function(line,index){
//先保存位置
this.pushPath.push([line,index]);
},
updateRoleInfo(){
//常规定点位置无效,使用line,index当坐标
let line_box = {w:300,h:624};
let line_padx = 80;
//line上的item从上到下排列,从0向上下延伸
//分为2,4 1,3,5两种模式
let par = this.list.children;
let line_group = {};
for(let i in par){
line_group[par[i].name] = par[i].children.length;
}
let pos_group = {
[1]:{[3]:0},
[2]:{[2]:-84,[4]:84},
[3]:{[1]:-168,[3]:0,[5]:168}
}
this.pathSort(this.pushPath);
let pts = [];
let start_pos = null;
for(let i=0;i<this.pushPath.length;i++){
let mpos = this.pushPath[i];
if(line_group[mpos[0]]){
let poses = pos_group[line_group[mpos[0]]];
let role_y = poses[mpos[1]] + 50;
let role_x = mpos[0]*line_box.w - (mpos[0] - 1)*line_padx -150;
let real_pos = new cc.v2(role_x,role_y);
if(i == 0){
start_pos = real_pos;
}
pts.push(real_pos);
}
}
if(start_pos!=null){
this.cmpRole.node.position = start_pos;
this.cmpRole.pushPaths( pts );
this.pushPath = [];
}else{
this.roleMapMove();
}
},
pathSort(arr){
arr.sort((a,b)=>{
if(a[0] != b[0]){
return a[0] - b[0];
}
});
},
setData(){
var time = this.base_data.update_time - client.socket.getTime();
//处理时间
nx.gui.setCdTxt(this.time_val,"",time);
},
getBoxStatus:function( ){
if (! this.map_data) return;
//显示宝箱状态 1 表示 未激活 2 表示可领取 3 表示已领取 0 表示不显示并且要显示门
var is_show_box_staus = 0
if (this.map_data.is_can_reward == 1) {
if (this.map_data.is_reward == 1) {
//已领取
if (this.max_floor > this.map_data.floor) {
// 不是最后一层 要显示门
is_show_box_staus = 0
}
else{
is_show_box_staus = 3
}
}
else{
//可领取
is_show_box_staus = 2
}
}else{
//未激活
is_show_box_staus = 1
}
return is_show_box_staus
},
//更新宝箱逻辑
updateBoxInfo:function(){
let self = this;
var is_show_box_staus = this.getBoxStatus()
this.is_show_box_staus = is_show_box_staus;
if(is_show_box_staus == 0){
this.boxNd.active = false;
this.holeNd.active = true;
}else if(is_show_box_staus == 3){
this.boxNd.active = false;
this.holeNd.active = false;
this.endNd.active = true;
}else{
this.boxNd.active = true;
this.holeNd.active = false;
// this.spBox.stop();
if(is_show_box_staus == 3){
this.onClickHardBtn();
}
// let res_path = PathTool.getSpinePath( "E27703", "action", false );
// self.spBox.load( res_path, ( _e ) => {
// if( !_e ) {
// if (is_show_box_staus == 1) {
// //未激活
// self.spBox.action( "action", true );
// }
// else if ( is_show_box_staus == 2) {
// //可领取
// self.spBox.action( "action1", true );
// }
// else if ( is_show_box_staus == 3) {
// //已领取
// self.spBox.action( "baoji", true );
// this.onClickHardBtn();
// }
// } else {
// self.spBox.stop();
// }
// } );
}
//判断弹窗逻辑
if (this.is_reward != null && this.is_reward != this.map_data.is_reward && is_show_box_staus == 3) {
this.model.setIsShowSearchFinish(true)
}
this.is_reward = this.map_data.is_reward
},
start() {
},
onOpenConfigs(param) {
this.ctrl.sender28602() // 基本信息
this.ctrl.sender28603() //地图信息
this.ctrl.sender28625();
},
onPreClosed() {
nx.bridge.NodeChidrenDestroy(this.list);
},
// 打开振魂结晶
onClickBagBtn:function( ){
this.ctrl.openPlanesafkItemUsePanel(true)
},
// 打开英雄列表
onClickHeroBtn:function( ){
this.ctrl.openPlanesafkHeroListPanel(true)
},
// 打开buff列表
onClickBuffBtn:function( ){
this.ctrl.openPlanesafkBuffListPanel(true)
},
// 打开商店
onClickShopBtn:function( ){
MallController.getInstance().openMallPanel(true, [ MallConst.MallType.ScoreShop,MallConst.MallType.FriendShop])
},
//点击难度
onClickHardBtn:function(index){
if (! this.map_data) { return }
var role_vo = RoleController.getInstance().getRoleVo()
if (this.map_data.floor && this.map_data.floor > 1 && role_vo && role_vo.power >= this.planes_difficult_max_power && role_vo.lev >= this.difficult_limit_lev) {
this.ctrl.sender28604(this.map_data.floor + 1, 2)
}
else
{
this.ctrl.sender28604(this.map_data.floor + 1, 1)
}
},
//点击了宝箱
onClickBoxBtn(){
if (! this.map_data) { return }
if (this.map_data.is_can_reward == 1){
this.ctrl.sender28605(this.map_data.floor)
}
},
onOpenTip(){
let TC = TipsController.getInstance();
if( TC ) {
let config = gdata("planes_data","data_const","planes_rule");
TC.showTextPanel(null,config.desc );
}
},
onClickShowGet(){
nx.bridge.createPanel("WndPlanesafkGet",{
item_list:this.up_item_list
});
}
// update (dt) {},
});