477 lines
14 KiB
JavaScript
477 lines
14 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'fd09dRdxKdKqYQaO/30ble7', 'cmp.dispatch.selector.wnd');
|
|
// Scripts/mod/home/dispatch/cmps/cmp.dispatch.selector.wnd.js
|
|
|
|
"use strict";
|
|
|
|
/******************************************************************
|
|
*
|
|
* 派遣选择界面
|
|
*
|
|
******************************************************************/
|
|
|
|
var BridgeWindow = require("bridge.window");
|
|
var FxTogs = require("nx.fx.togs");
|
|
var FxSVC = require("nx.fx.sv.expand");
|
|
var HeroConst = require("hero_const");
|
|
var HeroControl = require("hero_controller");
|
|
var DispatchMod = require("dispatch.mod");
|
|
var HCT = HeroConst.CampType;
|
|
cc.Class({
|
|
"extends": BridgeWindow,
|
|
properties: {
|
|
nodHead: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodSource: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodTarget: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodOps: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
togCamp: {
|
|
"default": null,
|
|
type: FxTogs
|
|
},
|
|
svcList: {
|
|
"default": null,
|
|
type: FxSVC
|
|
}
|
|
},
|
|
// 重载:参数打开
|
|
onOpenConfigs: function onOpenConfigs(_params) {
|
|
var _this = this;
|
|
// 参数判定
|
|
if (nx.dt.objEmpty(_params) || nx.dt.objEmpty(_params.config)) {
|
|
nx.error("派遣选择界面参数为空!");
|
|
this.scheduleOnce(function () {
|
|
_this.close();
|
|
}, 0.01);
|
|
return;
|
|
}
|
|
this.order = _params;
|
|
this.config = _params.config;
|
|
this.selects = [];
|
|
|
|
// 基础刷新
|
|
this.freshBase();
|
|
|
|
// Tog监听
|
|
this.curCamp = -1;
|
|
this.togCamp.posTog = this.onTogCamp.bind(this);
|
|
this.togCamp.togTo(0);
|
|
this.onTogCamp(HCT.eNone);
|
|
},
|
|
// 重载:关闭前
|
|
onPreClosed: function onPreClosed() {
|
|
this.svcList.rebuild([]);
|
|
},
|
|
// 基础刷新
|
|
freshBase: function freshBase() {
|
|
// 订单名字
|
|
nx.gui.setString(this.nodHead, "title", nx.text.getKey(this.config.name));
|
|
|
|
// 要求
|
|
this.initConditions();
|
|
if (nx.dt.arrEmpty(this.conds)) {
|
|
nx.gui.setActive(this.nodTarget, "cond/infos/list", false);
|
|
nx.gui.setActive(this.nodTarget, "cond/infos/empty", true);
|
|
} else {
|
|
nx.gui.setActive(this.nodTarget, "cond/infos/empty", false);
|
|
var _node = nx.gui.setActive(this.nodTarget, "cond/infos/list", true);
|
|
nx.gui.gocChildren(_node, "", this.conds.length, _node.children[0]);
|
|
for (var i = 0; i < this.conds.length; ++i) {
|
|
var con = this.conds[i];
|
|
var tm = _node.children[i];
|
|
if (nx.dt.numPositive(con.star_num, false)) {
|
|
nx.gui.setSpriteFrame(tm, "ico", "coms/images/star");
|
|
nx.gui.setString(tm, "ico/txt", con.star_num);
|
|
nx.gui.setString(tm, "txt", "x" + con.need_num);
|
|
} else {
|
|
var path = cc.path.join("coms/images", "camps" + con.camp_type);
|
|
nx.gui.setSpriteFrame(tm, "ico", path);
|
|
nx.gui.setString(tm, "txt", "x" + con.need_num);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 用时
|
|
var node = nx.gui.find(this.nodTarget, "cond/time");
|
|
var txt = nx.bridge.time.toNeedSeconds(this.config.need_time);
|
|
nx.gui.setString(node, "", nx.text.format("DispatchTime", txt));
|
|
|
|
// 消耗
|
|
node = nx.gui.find(this.nodTarget, "cost");
|
|
var expend = this.config.expend[0];
|
|
var info = gitemdata(expend[0]);
|
|
nx.bridge.setIconS(node, "ico", info.icon);
|
|
nx.gui.setString(node, "txt", expend[[1]]);
|
|
|
|
// 需要数量
|
|
this.needCount = this.config.limit_num;
|
|
node = nx.gui.find(this.nodTarget, "list");
|
|
for (var _i = 0; _i < node.children.length; ++_i) {
|
|
var item = node.children[_i];
|
|
item.active = _i < this.needCount;
|
|
nx.gui.setActive(item, "partner", false);
|
|
nx.gui.setActive(item, "add", true);
|
|
}
|
|
},
|
|
// 整体刷新
|
|
freshList: function freshList() {
|
|
var HC = HeroControl.getInstance();
|
|
var mod = HC.getModel();
|
|
var DM = DispatchMod.getInstance().getModel();
|
|
this.partners = [];
|
|
var lst = mod.getHeroListByCamp(this.curCamp);
|
|
for (var i = 0; i < lst.length; ++i) {
|
|
var pt = lst[i];
|
|
if (!pt || DM.checkHeroIsInTaskById(pt.partner_id)) {
|
|
continue;
|
|
}
|
|
this.partners.push(pt);
|
|
}
|
|
nx.gui.setActive(this.svcList, "empty", nx.dt.arrEmpty(this.partners));
|
|
this.svcList.rebuild(this.partners);
|
|
|
|
// 聚焦刷新
|
|
this.freshSelections(true, false);
|
|
},
|
|
// 派遣条件归纳
|
|
initConditions: function initConditions() {
|
|
this.conds = [];
|
|
var DATA = game.configs.shipping_data.data_condition;
|
|
var temp = this.config.condition || [];
|
|
for (var i = 0; i < temp.length; ++i) {
|
|
var cid = temp[i];
|
|
var tmp = DATA[cid];
|
|
var con = tmp ? tmp.conition[0] : null;
|
|
if (nx.dt.arrEmpty(con)) {
|
|
continue;
|
|
}
|
|
var dt = {};
|
|
switch (con[0]) {
|
|
// 星数要求
|
|
case "partner_star":
|
|
{
|
|
dt = {
|
|
star_num: con[1],
|
|
need_num: con[2]
|
|
};
|
|
}
|
|
break;
|
|
// 阵营要求
|
|
case "partner_camp_type":
|
|
{
|
|
dt = {
|
|
camp_type: con[1],
|
|
need_num: con[2]
|
|
};
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
nx.error("派遣条件归纳,无效条件:", con[0]);
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
if (nx.dt.objNEmpty(dt)) {
|
|
this.conds.push(dt);
|
|
}
|
|
}
|
|
},
|
|
// 阵营切换
|
|
onTogCamp: function onTogCamp(_index) {
|
|
var idx = parseInt(_index) || 0;
|
|
if (this.curCamp == idx) {
|
|
return;
|
|
}
|
|
nx.debug("[Hero]\u9635\u8425\u5207\u6362:" + this.curCamp + " -> " + idx);
|
|
this.curCamp = idx;
|
|
|
|
// 整体刷新
|
|
this.freshList();
|
|
},
|
|
// 选中切换
|
|
onFocusChanged: function onFocusChanged(_item) {
|
|
// 空
|
|
if (nx.dt.objEmpty(_item) || nx.dt.objEmpty(_item.mdata)) {
|
|
return;
|
|
}
|
|
|
|
// 取消选择
|
|
var focus = this.svcList.isFocus(_item.index);
|
|
if (focus) {
|
|
this.svcList.removeFocus(_item.index);
|
|
nx.dt.arrDelete(this.selects, function (_t) {
|
|
return _t && _t.partner_id == _item.mdata.partner_id;
|
|
}, true);
|
|
} else {
|
|
// 已经足够
|
|
if (this.selects.length >= this.needCount) {
|
|
return;
|
|
}
|
|
this.svcList.addFocus(_item.index);
|
|
this.selects.push(_item.mdata);
|
|
}
|
|
|
|
// 刷新当前选中
|
|
this.freshSelections(false, true);
|
|
},
|
|
// 刷新当前选中
|
|
freshSelections: function freshSelections(_freshSource, _freshTarget) {
|
|
var _this2 = this;
|
|
// 刷新来源选中
|
|
if (_freshSource) {
|
|
this.svcList.cleanFocus();
|
|
var chds = this.svcList.bindSCV.content.children;
|
|
var _loop = function _loop() {
|
|
var node = chds[i];
|
|
if (node && node.svItem && node.svItem.mdata) {
|
|
if (nx.dt.arrMember(_this2.selects, null, function (_ptr) {
|
|
return _ptr && _ptr.partner_id == node.svItem.mdata.partner_id;
|
|
})) {
|
|
_this2.svcList.addFocus(node.svItem.index);
|
|
}
|
|
}
|
|
};
|
|
for (var i = 0; i < chds.length; ++i) {
|
|
_loop();
|
|
}
|
|
}
|
|
|
|
// 刷新派遣列表
|
|
if (_freshTarget) {
|
|
var list = nx.gui.find(this.nodTarget, "list");
|
|
for (var _i2 = 0; _i2 < this.needCount; ++_i2) {
|
|
var item = list.children[_i2];
|
|
var partner = this.selects[_i2];
|
|
if (nx.dt.objEmpty(partner)) {
|
|
nx.gui.setActive(item, "partner", false);
|
|
nx.gui.setActive(item, "add", true);
|
|
} else {
|
|
nx.gui.setActive(item, "partner", true);
|
|
nx.gui.setActive(item, "add", false);
|
|
var cmp = nx.gui.getComponent(item, "partner", "cmp.partner.inbag");
|
|
if (cmp) {
|
|
cmp.node.partner = partner;
|
|
cmp.setData(partner);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
// 指定取消
|
|
onTouchCancelPartner: function onTouchCancelPartner(_data) {
|
|
var partner = _data ? _data.target.partner : null;
|
|
if (!partner) {
|
|
return;
|
|
}
|
|
|
|
// 取消选中
|
|
nx.dt.arrDelete(this.selects, function (_t) {
|
|
return _t && _t.partner_id == partner.partner_id;
|
|
}, true);
|
|
|
|
// 聚焦刷新
|
|
this.freshSelections(true, true);
|
|
},
|
|
// 一键选择
|
|
onTouchOnce: function onTouchOnce() {
|
|
this.tmpSelects = [];
|
|
this.tryAutoSelect();
|
|
if (nx.dt.arrNEmpty(this.tmpSelects)) {
|
|
this.selects = this.tmpSelects;
|
|
this.freshSelections(true, true);
|
|
}
|
|
},
|
|
// 派遣
|
|
onTouchDispatch: function onTouchDispatch() {
|
|
var _this3 = this;
|
|
// 判空
|
|
if (nx.dt.arrEmpty(this.selects)) {
|
|
nx.tbox("DispatchMemeberEmpty");
|
|
return;
|
|
}
|
|
var ids = [];
|
|
for (var i in this.selects) {
|
|
var pt = this.selects[i];
|
|
if (pt) {
|
|
ids.push({
|
|
partner_id: pt.partner_id
|
|
});
|
|
}
|
|
}
|
|
var DC = DispatchMod.getInstance();
|
|
DC.requestReceiveOrder(this.order.order_id, ids, function (_ret, _data) {
|
|
if (!_ret) {
|
|
nx.tbox(_data);
|
|
return;
|
|
}
|
|
_this3.close();
|
|
});
|
|
},
|
|
// 自动选择
|
|
tryAutoSelect: function tryAutoSelect() {
|
|
var HM = HeroControl.getInstance().getModel();
|
|
var DM = DispatchMod.getInstance().getModel();
|
|
var star_num = 0,
|
|
star_need = 0,
|
|
need_camps = {};
|
|
for (var k in this.conds) {
|
|
var con_data = this.conds[k];
|
|
if (con_data.star_num) {
|
|
star_num = con_data.star_num;
|
|
star_need = con_data.need_num;
|
|
} else if (con_data.camp_type) {
|
|
need_camps[con_data.camp_type] = con_data.need_num;
|
|
}
|
|
}
|
|
var star_hero = [];
|
|
var both_hero = [];
|
|
var all_camp_hero = {};
|
|
var lst = HM.getHeroList();
|
|
for (var _k in lst) {
|
|
var hero_vo = lst[_k];
|
|
var star_is_meet = false;
|
|
if (hero_vo.star >= star_num && !DM.checkHeroIsInTaskById(hero_vo.partner_id)) {
|
|
star_is_meet = true;
|
|
star_hero.push(hero_vo);
|
|
}
|
|
for (var i in this.conds) {
|
|
var _con_data = this.conds[i];
|
|
if (_con_data.camp_type && _con_data.camp_type == hero_vo.camp_type && !DM.checkHeroIsInTaskById(hero_vo.partner_id)) {
|
|
if (!all_camp_hero[_con_data.camp_type]) {
|
|
all_camp_hero[_con_data.camp_type] = [];
|
|
}
|
|
all_camp_hero[_con_data.camp_type].push(hero_vo);
|
|
if (star_is_meet) {
|
|
both_hero.push(hero_vo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//按星级、等级、阵营从低到高排列
|
|
var sortFunc = Utils.tableLowerSorter(["star", "lev", "camp_type"]);
|
|
star_hero.sort(sortFunc);
|
|
both_hero.sort(sortFunc);
|
|
for (var _k2 in all_camp_hero) {
|
|
all_camp_hero[_k2].sort(sortFunc);
|
|
}
|
|
for (var _i3 in both_hero) {
|
|
var _hero_vo = both_hero[_i3];
|
|
if (this.tmpSelects.length < star_need) {
|
|
this.tmpSelects.push(_hero_vo);
|
|
} else if (this.checkIsMeetAllCondition()) {
|
|
for (var camp in need_camps) {
|
|
var need_num = need_camps[camp];
|
|
if (_hero_vo.camp_type == camp && this.checkChoseHeroNumByCamp(camp) < need_num) {
|
|
this.tmpSelects.push(_hero_vo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (this.checkIsMeetAllCondition()) {
|
|
return;
|
|
}
|
|
var star_dif_num = star_need - this.tmpSelects.length; //满足星级条件的英雄,还差的个数
|
|
if (star_dif_num > 0) {
|
|
var temp_num = 0;
|
|
for (var _i4 in star_hero) {
|
|
var vo = star_hero[_i4];
|
|
if (!this.checkIsChoseHeroById(vo.partner_id)) {
|
|
this.tmpSelects.push(vo);
|
|
temp_num = temp_num + 1;
|
|
}
|
|
if (temp_num >= star_dif_num) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//满足条件或者星级条件都无法满足,则无需选择其他英雄
|
|
if (this.checkIsMeetAllCondition()) {
|
|
return;
|
|
}
|
|
for (var camp_type in all_camp_hero) {
|
|
var hero_list = all_camp_hero[camp_type];
|
|
var _need_num = need_camps[camp_type];
|
|
var cur_num = this.checkChoseHeroNumByCamp(camp_type);
|
|
var diff_num = _need_num - cur_num;
|
|
if (diff_num > 0) {
|
|
var _temp_num = 0;
|
|
for (var _i5 in hero_list) {
|
|
var _vo = hero_list[_i5];
|
|
if (!this.checkIsChoseHeroById(_vo.partner_id)) {
|
|
this.tmpSelects.push(_vo);
|
|
_temp_num = _temp_num + 1;
|
|
}
|
|
if (_temp_num >= diff_num) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
// 判断所选英雄是否满足该条件 ttype:1星级 2阵营
|
|
checkIsMeetCondition: function checkIsMeetCondition(ttype, value, num) {
|
|
var have_num = 0;
|
|
for (var k in this.tmpSelects) {
|
|
var hero_vo = this.tmpSelects[k];
|
|
if (ttype == 1 && hero_vo.star >= value) {
|
|
have_num = have_num + 1;
|
|
} else if (ttype == 2 && hero_vo.camp_type == value) {
|
|
have_num = have_num + 1;
|
|
}
|
|
}
|
|
return have_num >= num;
|
|
},
|
|
// 判断当前所选的英雄是否满足所有条件
|
|
checkIsMeetAllCondition: function checkIsMeetAllCondition() {
|
|
var con_status = true;
|
|
for (var k in this.conds) {
|
|
var v = this.conds[k];
|
|
var is_meet = false;
|
|
if (v.star_num) {
|
|
is_meet = this.checkIsMeetCondition(1, v.star_num, v.need_num);
|
|
} else if (v.camp_type) {
|
|
is_meet = this.checkIsMeetCondition(2, v.star_num, v.need_num);
|
|
}
|
|
if (is_meet == false) {
|
|
con_status = false;
|
|
break;
|
|
}
|
|
}
|
|
return con_status;
|
|
},
|
|
checkChoseHeroNumByCamp: function checkChoseHeroNumByCamp(camp_type) {
|
|
var have_num = 0;
|
|
for (var k in this.tmpSelects) {
|
|
if (this.tmpSelects[k].camp_type == camp_type) {
|
|
have_num = have_num + 1;
|
|
}
|
|
}
|
|
return have_num;
|
|
},
|
|
checkIsChoseHeroById: function checkIsChoseHeroById(id) {
|
|
var is_have = false;
|
|
for (var k in this.tmpSelects) {
|
|
if (this.tmpSelects[k].partner_id == id) {
|
|
is_have = true;
|
|
break;
|
|
}
|
|
}
|
|
return is_have;
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |