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

189 lines
5.5 KiB
JavaScript

const BridgeWindow = require("bridge.window");
const NxExpand = require("nx.fx.sv.expand");
const PlanesafkController = require("planesafk_controller");
const PlanesafkEvent = require("planesafk_event");
const BackpackController = require("backpack_controller");
const TipsController = require("tips_controller");
const HeroController = require("hero_controller");
const PathTool = require("pathtool");
cc.Class({
extends: BridgeWindow,
properties: {
list:{
default:null,
type:NxExpand
},
buy_cost:{
default:null,
type:cc.Node
},
tips:{
default:null,
type:cc.Node
}
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
this.ctrl = PlanesafkController.getInstance();
this.model = this.ctrl.getModel();
this.bindGEvent( PlanesafkEvent.Get_All_Hero_Event, this.getAllHeros.bind( this ) );
this.bindGEvent( PlanesafkEvent.Look_Other_Hero_Event, this.lookOtherHeros.bind( this ) );
this.bindGEvent( PlanesafkEvent.Get_Hero_Live_Event, this.getAllHeros.bind( this ) );
},
getAllHeros(){
let list = this.model.getAllPlanesHeroData();
list.sort( Utils.tableUpperSorter( [ "star", "lev", "flag" ] ) );
list.sort( Utils.tableLowerSorter( [ "hp_per" ] ) );
this.setData(list);
},
lookOtherHeros(data){
if (! data) return;
this.is_ther_send = false;
this.dic_other_hero[data.pos] = data;
},
start() {
},
onOpenConfigs(setting) {
let item_config = gitemdata(10034);
if( item_config) {
nx.gui.setString(this.buy_cost,"key",item_config.name)
}
let planes_spar_atk_radio = 1300
var config = gdata("planes_data","data_const","planes_spar_atk_radio")
if (config) {
planes_spar_atk_radio = config.val
}
var per = (planes_spar_atk_radio - 1000)/10
this.per = per;
let tip_str = cc.js.formatStr(nx.text.getKey("msg_planesafk_item_use_panel_tip1"),per);
nx.gui.setString(this.tips,"",tip_str);
var list = this.model.getAllPlanesHeroData()
if (list == null) {
this.ctrl.sender28613()
}
else
{
list.sort( Utils.tableUpperSorter( [ "star", "lev", "flag" ] ) );
list.sort( Utils.tableLowerSorter( [ "hp_per" ] ) );
this.setData(list)
}
},
onPreClosed() {
this.list.rebuild([]);
},
setData:function(list){
this.hero_list = list || []
this.list.rebuild(this.hero_list);
},
// 确定使用
onClickBtnRight:function(){
if (! this.hero_list) return;
let is_not_have = true;
for (var i in this.hero_list) {
var v = this.hero_list[i]
if (v.hp_per < 100) {
is_not_have = false
}
}
if (is_not_have) {
nx.tbox("msg_planesafk_item_use_panel_tip3");
return
}
var item_config = gitemdata(10034);
var count = BackpackController.getInstance().getModel().getItemNumByBid(10034);
if (count <= 0) {
nx.tbox( "SummonItemNotEnough" );
// BackpackController.getInstance().openTipsSource(true, item_config)
// this.onClickBtnClose()
return
}
let fun = function (){
var id = BackpackController.getInstance().getModel().getBackPackItemIDByBid(10034)
BackpackController.getInstance().sender10515(id, 1)
}
if (item_config) {
var res = PathTool.getItemRes(item_config.icon)
var per = this.per || 30
let str = cc.js.formatStr(nx.text.getKey("msg_planesafk_item_use_panel_tip4"),res, per)
nx.mbox(str,["cancel","confirm"],(_key,_box)=>{
_box.close();
if(_key == "confirm"){
fun();
}
});
}
},
// 选中切换
onFocusChanged: function( _item ) {
// 空
if( nx.dt.objEmpty( _item ) ||
nx.dt.objEmpty( _item.mdata ) ) {
return;
}
// 聚焦
this.list.cleanFocus();
this.list.addFocus( _item.index );
let hero_vo = _item.mdata;
if (hero_vo) {
if (hero_vo.flag == 0) {
var new_hero_vo = HeroController.getInstance().getModel().getHeroById(hero_vo.partner_id)
if (new_hero_vo) {
TipsController.getInstance().showPartnerTips(new_hero_vo);
}
else
{
nx.tbox("msg_planesafk_hero_from")
}
}
else
{
if (this.dic_other_hero[hero_vo.partner_id]) {
TipsController.getInstance().showPartnerTips(this.dic_other_hero[hero_vo.partner_id]);
}
else{
if (this.is_ther_send) return;
this.is_ther_send = true;
this.ctrl.sender28623(hero_vo.partner_id)
}
}
}
},
// 规则说明
onTouchTip: function(){
let TC = TipsController.getInstance();
if( TC ) {
let txt = gdata("planes_data","data_const","planes_forever_dock_desc");
TC.showTextPanel( "tip", txt.desc );
}
},
// update (dt) {},
});