581 lines
18 KiB
JavaScript
581 lines
18 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'f9db01akrJPOIoNAYG8QPSe', 'act.dailytreasure.wnd');
|
|
// Scripts/mod/acts/dailytreasure/cmp/act.dailytreasure.wnd.js
|
|
|
|
"use strict";
|
|
|
|
var BridgeWindow = require("bridge.window");
|
|
var NxSpine = require("nx.fx.spine");
|
|
var Mod = require("act.dailytreasure.mod");
|
|
var ItemBase = require("cmp.item.base");
|
|
var themeMod = require("acts.mod");
|
|
var FxTogs = require("nx.fx.togs");
|
|
var BackPackController = require("backpack_controller");
|
|
var FID = require("bridge.function.ids");
|
|
var TipsController = require("tips_controller");
|
|
var ActPopup = require("act.popup.base");
|
|
var NormalLen = 56;
|
|
var TotalLen = 156;
|
|
cc.Class({
|
|
"extends": ActPopup,
|
|
properties: {
|
|
nodMenu: {
|
|
"default": null,
|
|
type: FxTogs
|
|
},
|
|
nodShow: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodTask: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
spRole: {
|
|
"default": null,
|
|
type: NxSpine
|
|
},
|
|
sppRole: {
|
|
"default": null,
|
|
type: NxSpine
|
|
},
|
|
nodRewards: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodRewardsR: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodRight: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodProg: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodTimes: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodEndTimes: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodJump: {
|
|
"default": null,
|
|
type: cc.Toggle
|
|
},
|
|
nodMat: {
|
|
"default": null,
|
|
type: cc.Node
|
|
}
|
|
// E90901
|
|
},
|
|
|
|
// 初始化
|
|
onOpenConfigs: function onOpenConfigs(_params) {
|
|
var _this = this;
|
|
this._super(_params);
|
|
this.mod = Mod.getInstance();
|
|
// 无效
|
|
if (!this.mod) {
|
|
this.delayClose();
|
|
return;
|
|
}
|
|
this.spRole.load("resDB/models/H30102/H30102", function (_e) {
|
|
if (!_e) {
|
|
_this.spRole.action("stand2", true);
|
|
} else {
|
|
_this.spRole.stop();
|
|
}
|
|
});
|
|
this.sppRole.load("resDB/models/H30019/show", function (_e) {
|
|
if (!_e) {
|
|
_this.sppRole.action("action1", true);
|
|
} else {
|
|
_this.sppRole.stop();
|
|
}
|
|
});
|
|
|
|
// this.periods_num = gdata( this.mod.data.config, "data_const" ).periods_num ;
|
|
// Tog监听
|
|
var period = this.mod.vget("dailySPrayTask");
|
|
var rewards = gdata(this.mod.data.config, "data_reach_reward")[period.period];
|
|
this.cfg = gdata(this.mod.data.config, "data_base_info")[period.period];
|
|
this.tasks = gdata(this.mod.data.config, "data_day_task_list")[period.period];
|
|
var mat = this.cfg.loss_item_once[0][0];
|
|
this.nodMenu.posTog = this.onTogMenu.bind(this);
|
|
this.nodMenu.togTo(1);
|
|
this.onTogMenu(1);
|
|
var mcmp = nx.gui.getComponent(this.nodMat, "", "bridge.binder.item.icon.count");
|
|
if (mcmp) {
|
|
mcmp.setID(mat);
|
|
}
|
|
var reachs = [];
|
|
for (var i in rewards) {
|
|
var reward = rewards[i];
|
|
reachs.push(reward);
|
|
}
|
|
this.reaches = reachs;
|
|
var time = new Date();
|
|
var showtime = this.mod.data.end_time - time / 1000;
|
|
nx.gui.setCdTxt(this.nodEndTimes, "time", showtime);
|
|
this.showRewards = reachs;
|
|
var chd = this.nodRewards.children;
|
|
for (var r = 0; r < reachs.length; r++) {
|
|
var reach = reachs[r];
|
|
var nod = chd[r];
|
|
if (nod) {
|
|
var cmp = nx.gui.getComponent(nod, "box", "cmp.common.itemlayout");
|
|
if (cmp) {
|
|
cmp.rebuild(reach.reward);
|
|
}
|
|
nx.gui.find(nod, "can/get").zIndex = reach.id;
|
|
nx.gui.setActive(nod, "can", false);
|
|
nx.gui.setString(nod, "point", reach.num);
|
|
nx.gui.setActive(nod, "boxopen", false);
|
|
}
|
|
}
|
|
this.onShowRewards();
|
|
// 活动监听
|
|
this.mod.vbind(this, [["dailyStarPrayData", this.freshInfo.bind(this)]]);
|
|
this.mod.reqBaseData();
|
|
// this.setTask();
|
|
},
|
|
|
|
onEnable: function onEnable() {},
|
|
// 销毁
|
|
onDestroy: function onDestroy() {
|
|
// 活动监听解除
|
|
if (this.mod) {
|
|
this.mod.vunbind(this);
|
|
}
|
|
delete this.mod;
|
|
this._super();
|
|
},
|
|
/** {"free_end_time":0,"draw_times":0,"gold_times":20,"luck_num":0,"ids":[],"log_info":[]}*/
|
|
freshInfo: function freshInfo(_data) {
|
|
if (_data) {
|
|
var luck_num = _data.luck_num;
|
|
var free_time = _data.free_end_time;
|
|
var left = this.diamond_times - _data.gold_times;
|
|
this.leftDia = left;
|
|
// this.records = _data.log_info;
|
|
// nx.gui.setString( this.nodTimes, "txt", _data.draw_times );
|
|
nx.gui.setString(this.nodEndTimes, "times/num", left);
|
|
nx.gui.setString(this.nodEndTimes, "times/all", this.diamond_times);
|
|
this.nodJump.isChecked = _data.is_skip == 1;
|
|
this.skip = _data.is_skip == 1;
|
|
this.setProg(luck_num);
|
|
var time = new Date();
|
|
var showtime = free_time - time / 1000;
|
|
var nodd = nx.gui.find(this.nodRight, "ops/once/time");
|
|
nx.gui.setCdTxt(nodd, "ttime", showtime);
|
|
this.dealOp();
|
|
this.dealReachRewards(_data.ids);
|
|
this.index = -1; //当前光环在哪个奖品上
|
|
// this.nodFocus.position = this.nodReward.children[this.index].position; //初始化光环位置
|
|
this.delayTime = 0.3; //开始的时候延迟调用的时间(最小时间间隔)
|
|
this.delayTime_max = 1.5; //最大时间间隔
|
|
// this.addOrSub = false; //增加还是减少的bool值
|
|
this.loopCount = 0; //循环次数
|
|
this.circleCount = 2; //前面循环的圈数(效果圈,只为效果,和奖品无关)
|
|
}
|
|
},
|
|
|
|
onShowRewards: function onShowRewards() {
|
|
var period = this.mod.vget("dailySPrayTask");
|
|
var rewards = gdata(this.mod.data.config, "data_reward_info")[period.period];
|
|
var chd = this.nodRewardsR.children;
|
|
for (var i in rewards) {
|
|
var reward = rewards[i];
|
|
var id = reward.point;
|
|
var nod = chd[id - 1];
|
|
// { bid, num }
|
|
var shows = {
|
|
bid: reward.item_id,
|
|
num: reward.num,
|
|
info: reward.id
|
|
};
|
|
var cmp = nx.gui.getComponent(nod, "item", ItemBase);
|
|
if (cmp) {
|
|
cmp.setData(shows);
|
|
}
|
|
var level = 0;
|
|
switch (reward.level_name) {
|
|
case "A":
|
|
{
|
|
level = 2;
|
|
}
|
|
;
|
|
break;
|
|
case "B":
|
|
{
|
|
level = 3;
|
|
}
|
|
;
|
|
break;
|
|
case "S":
|
|
{
|
|
level = 4;
|
|
}
|
|
;
|
|
break;
|
|
}
|
|
var ico = "prefab/acts/starskyprayer/ui/starskyprayer_0" + level;
|
|
nx.gui.setSpriteFrame(nod, "icor", ico);
|
|
nx.gui.setActive(nod, "focus", false);
|
|
}
|
|
},
|
|
setProg: function setProg(_num) {
|
|
// 右上角 幸運值 相關顯示
|
|
|
|
var lucknod = nx.gui.find(this.nodTimes, "times/num");
|
|
nx.gui.setString(lucknod, "", _num);
|
|
var showval = 0;
|
|
switch (_num) {
|
|
case 200:
|
|
showval = 300;
|
|
break;
|
|
}
|
|
var bar = nx.gui.getComponent(this.nodProg, "", cc.ProgressBar);
|
|
if (bar) {
|
|
bar.progress = _num / (bar.totalLength - 100);
|
|
}
|
|
},
|
|
dealReachRewards: function dealReachRewards(_reds) {
|
|
// ids":[{"id":7,"status":0},{"id":6,"status":0},{"id":5,"status":0},{"id":4,"status":0},{"id":3,"status":0},{"id":2,"status":0},{"id":1,"status":2}]
|
|
var ids = _reds;
|
|
if (_reds) {
|
|
var chd = this.nodRewards.children;
|
|
for (var i = 0; i < ids.length; i++) {
|
|
var dataa = ids[i];
|
|
var nod = chd[dataa.id - 1];
|
|
nx.gui.setActive(nod, "can", dataa.status == 1);
|
|
nx.gui.setActive(nod, "boxopen", dataa.status == 2);
|
|
// nx.gui.setActive( nod, "box", dataa.status == 1 || dataa.status == 0 );
|
|
nx.gui.setActive(nod, "box", true);
|
|
}
|
|
}
|
|
},
|
|
// 處理 操作以及材料顯示
|
|
dealOp: function dealOp() {
|
|
if (!this.cfg) {
|
|
return;
|
|
}
|
|
this.useItemF = false;
|
|
this.useItemT = false;
|
|
var mat = this.cfg.loss_item_once[0][0];
|
|
var needmatf = this.cfg.loss_item_once[0][1];
|
|
var needmatt = this.cfg.loss_item_ten[0][1];
|
|
var model = BackPackController.getInstance().getModel();
|
|
var have = model.getItemNumByBid(mat);
|
|
this.havemat = have;
|
|
this.needMatT = needmatt;
|
|
this.needMatF = needmatf;
|
|
this.name = gitemdata(mat);
|
|
var once = nx.gui.find(this.nodRight, "ops/once");
|
|
var ten = nx.gui.find(this.nodRight, "ops/ten");
|
|
nx.gui.setActive(once, "mat", true);
|
|
nx.gui.setActive(once, "time", false);
|
|
|
|
// 当拥有的材料数量不小于10个时
|
|
if (have >= needmatt) {
|
|
nx.bridge.setIconS(once, "mat/icon", mat);
|
|
nx.bridge.setIconS(ten, "mat/icon", mat);
|
|
nx.gui.setString(once, "mat/neednum", "X" + needmatf);
|
|
nx.gui.setString(ten, "mat/neednum", "X" + needmatt);
|
|
this.useItemF = true;
|
|
this.useItemT = true;
|
|
|
|
// dealUseDia();
|
|
} else {
|
|
// 当材料可以 1抽
|
|
if (have >= needmatf) {
|
|
nx.bridge.setIconS(once, "mat/icon", mat);
|
|
nx.bridge.setIconS(ten, "mat/icon", mat);
|
|
nx.gui.setString(once, "mat/neednum", "X" + needmatf);
|
|
nx.gui.setString(ten, "mat/neednum", "X" + needmatt);
|
|
this.useItemF = true;
|
|
this.useItemT = false;
|
|
} else {
|
|
nx.bridge.setIconS(once, "mat/icon", mat);
|
|
nx.bridge.setIconS(ten, "mat/icon", mat);
|
|
nx.gui.setString(once, "mat/neednum", "X" + needmatf);
|
|
nx.gui.setString(ten, "mat/neednum", "X" + needmatt);
|
|
this.useItemF = false;
|
|
this.useItemT = false;
|
|
}
|
|
}
|
|
},
|
|
// 打開 記錄
|
|
onTouchRecord: function onTouchRecord() {
|
|
this.mod.reqStarPrayRecord(function (_ret, _data) {
|
|
if (!_ret) {
|
|
return;
|
|
}
|
|
nx.bridge.createPanel("WndActStarSkyPrayRecords", _data);
|
|
});
|
|
},
|
|
//
|
|
onTouchShop: function onTouchShop() {
|
|
var shopInfo = gdata(this.mod.data.config, "data_shop_info");
|
|
nx.bridge.createPanel("WndActStarSkyPrayShop", shopInfo);
|
|
},
|
|
// 播放輪轉動畫
|
|
onDoAni: function onDoAni(_time, _result, _loop, _usetype) {
|
|
var _this2 = this;
|
|
var result = _result[0];
|
|
if (this.tween) {
|
|
this.tween.stop();
|
|
}
|
|
var period = this.mod.vget("dailySPrayTask");
|
|
var ggid = period.period;
|
|
this.loopCount = _loop >= 0 ? _loop : this.loopCount;
|
|
this.usetype = _usetype;
|
|
// this.nodFocus.opacity = 156;
|
|
var num = 0;
|
|
for (var i = 0; i < this.nodRewardsR.children.length; i++) {
|
|
var nod = this.nodRewardsR.children[i];
|
|
var cmp = nx.gui.getComponent(nod, "item", ItemBase);
|
|
if (cmp) {
|
|
if (cmp.mdata.info == result.id) {
|
|
// nx.gui.setActive( nod, "focus", true );
|
|
|
|
num = i;
|
|
}
|
|
}
|
|
}
|
|
var all = num + 3 * this.nodRewardsR.children.length;
|
|
this.unscheduleAllCallbacks();
|
|
var self = this;
|
|
this.scheduleOnce(function () {
|
|
_this2.index++;
|
|
|
|
//循环到最后一个值之后从0开始
|
|
if (_this2.index >= _this2.nodRewardsR.children.length) {
|
|
_this2.index = 0;
|
|
}
|
|
if (_this2.loopCount > 0) {
|
|
_this2.delayTime = 0.05;
|
|
_this2.onDoing = true;
|
|
}
|
|
//当前运行次数++
|
|
if (_this2.loopCount >= _this2.nodRewardsR.children.length * _this2.circleCount && _result > 0) {
|
|
//加速度,为最大时间间隔/空转之外需要运行的间隔(空转之外需要运行的间隔是一圈+抽奖的结果)
|
|
_this2.delayTime = 0.20;
|
|
}
|
|
_this2.loopCount++;
|
|
if (_this2.loopCount > all) {
|
|
_this2.loopCount = all;
|
|
}
|
|
//总的运行次数 = 空转三圈 + 一圈缓冲 + 抽奖结果
|
|
|
|
_this2.count = _this2.nodRewardsR.children.length * (_this2.circleCount + 1) + _time;
|
|
|
|
//判断是不是运行完了
|
|
if (_this2.loopCount >= all && result.id > 0) {
|
|
for (var _i = 0; _i < _this2.nodRewardsR.children.length; _i++) {
|
|
var _nod = _this2.nodRewardsR.children[_i];
|
|
var _cmp = nx.gui.getComponent(_nod, "item", ItemBase);
|
|
if (_cmp) {
|
|
if (_cmp.mdata.info == result.id) {
|
|
nx.gui.setActive(_nod, "focus", true);
|
|
nx.audio.playSFX("audios/effects/praycell");
|
|
_nod = _nod;
|
|
} else {
|
|
nx.gui.setActive(_nod, "focus", false);
|
|
}
|
|
}
|
|
// nx.gui.setActive( nod, "focus", false );
|
|
}
|
|
//隐藏遮罩
|
|
_this2.tween = cc.tween(_this2.node)
|
|
// .delay( 0.3 )
|
|
// .call( ()=>{
|
|
|
|
// } )
|
|
.delay(0.5).call(function () {
|
|
var nowresult = _result.shift();
|
|
if (!nowresult || nx.dt.arrEmpty(_result)) {
|
|
var dataa = {
|
|
group_id: ggid,
|
|
type: self.usetype,
|
|
id: 0
|
|
};
|
|
self.mod.reqGetStarPrayRewardData(dataa);
|
|
self.onDoing = false;
|
|
for (var _i2 = 0; _i2 < _this2.nodRewardsR.children.length; _i2++) {
|
|
var _nod2 = _this2.nodRewardsR.children[_i2];
|
|
var _cmp2 = nx.gui.getComponent(_nod2, "item", ItemBase);
|
|
if (_cmp2) {
|
|
nx.gui.setActive(_nod2, "focus", false);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
for (var _i3 = 0; _i3 < _this2.nodRewardsR.children.length; _i3++) {
|
|
var _nod3 = _this2.nodRewardsR.children[_i3];
|
|
var _cmp3 = nx.gui.getComponent(_nod3, "item", ItemBase);
|
|
if (_cmp3) {
|
|
nx.gui.setActive(_nod3, "focus", false);
|
|
}
|
|
}
|
|
_this2.onDoAni(_time, _result, 0, self.usetype);
|
|
_this2.onDoing = false;
|
|
}).start();
|
|
return;
|
|
} else {
|
|
//切换光环位置
|
|
for (var _i4 = 0; _i4 < _this2.nodRewardsR.children.length; _i4++) {
|
|
var _nod4 = _this2.nodRewardsR.children[_i4];
|
|
nx.gui.setActive(_nod4, "focus", false);
|
|
}
|
|
nx.gui.setActive(_this2.nodRewardsR.children[_this2.index], "focus", true);
|
|
//重新调用本方法(因为schedule不能动态修改运行间隔时间)
|
|
nx.audio.playSFX("audios/effects/praycell");
|
|
_this2.onDoAni(_time, _result, _this2.loopCount, self.usetype);
|
|
}
|
|
}, this.delayTime, 0); //执行次数为0,实际执行次数为1
|
|
},
|
|
|
|
onTouchPray: function onTouchPray(_idx) {
|
|
var _this3 = this;
|
|
var self = this;
|
|
var times = parseInt(_idx);
|
|
var period = this.mod.vget("dailySPrayTask");
|
|
var ggid = period.period;
|
|
// if( this.havemat > )
|
|
// if( this.useFree )
|
|
if (times == 1) {
|
|
if (this.havemat < this.needMatF) {
|
|
var name = this.name ? this.name.name : "";
|
|
var _str = nx.text.format("ActDailyTreasureBuyTip", name);
|
|
nx.mbox(_str, ['cancel', 'Goto'], function (_key, _box) {
|
|
_box.close();
|
|
if (_key == "Goto") {
|
|
self.nodMenu.togTo(0);
|
|
self.onTogMenu(0);
|
|
}
|
|
});
|
|
// nx.tbox( "PrayDiaTimesLimit" );
|
|
return;
|
|
} else {}
|
|
} else {
|
|
if (this.havemat < this.needMatT) {
|
|
var _name = this.name ? this.name.name : "";
|
|
var _str2 = nx.text.format("ActDailyTreasureBuyTip", _name);
|
|
nx.mbox(_str2, ['cancel', 'Goto'], function (_key, _box) {
|
|
_box.close();
|
|
if (_key == "Goto") {
|
|
self.nodMenu.togTo(0);
|
|
self.onTogMenu(0);
|
|
}
|
|
});
|
|
// nx.tbox( "PrayDiaTimesLimit" );
|
|
return;
|
|
}
|
|
}
|
|
var str = nx.text.format("elfin_hatch_unlock_6", nx.text.getKey("Dia"));
|
|
var usetype = 0;
|
|
|
|
// 正在播動畫
|
|
if (this.onDoing) {
|
|
nx.tbox("DailyDiaDoing");
|
|
return;
|
|
}
|
|
this.unscheduleAllCallbacks();
|
|
if (times == 1) {
|
|
if (this.useItemF) {
|
|
usetype = 4;
|
|
}
|
|
} else {
|
|
if (this.useItemT) {
|
|
usetype = 4;
|
|
}
|
|
}
|
|
var dataa = {
|
|
group_id: ggid,
|
|
times: times
|
|
};
|
|
this.mod.reqGetStarPray(dataa, function (_ret, _data) {
|
|
// console.log( "當前的返回相關" + JSON.stringify( _data ) );
|
|
if (!_ret) {
|
|
nx.tbox(_data);
|
|
return;
|
|
}
|
|
// {"flag":1,"msg":"","item_id":[{"id":102}]}
|
|
// 本地道具-1
|
|
// nx.gui.setString( this.nodMat, "count/txt", nx.dt.shortCount( this.have - 1 ) );
|
|
// 过程模拟
|
|
var num = -_this3.nodRewardsR.children.length;
|
|
|
|
// nx.tween.fadeIn( this.nodFocus,"", 0.1 );
|
|
var self = _this3;
|
|
_this3.finalResult = _data.item_id;
|
|
if (_this3.skip || times == 10) {
|
|
var _dataa = {
|
|
group_id: ggid,
|
|
type: usetype,
|
|
id: 0
|
|
};
|
|
self.onDoing = false;
|
|
self.mod.reqGetStarPrayRewardData(_dataa);
|
|
return;
|
|
}
|
|
// this.schedule( dealPlay, _data.item_id.length, cc.macro.REPEAT_FOREVER );
|
|
_this3.onDoAni(num / 3, _data.item_id, 0, usetype);
|
|
// dealPlay();
|
|
});
|
|
},
|
|
|
|
onTouchGetReach: function onTouchGetReach(_btn) {
|
|
this.mod.reqGetStarReachReward(_btn.zIndex);
|
|
},
|
|
onTouchJump: function onTouchJump() {
|
|
var jump = this.nodJump.isChecked;
|
|
// this.mod.reqGetStarReachReward( _btn.zIndex );
|
|
this.mod.reqSetStatus(jump);
|
|
},
|
|
onTouchHelp: function onTouchHelp() {
|
|
var explain = gdata(this.mod.data.config, "data_explain")[1];
|
|
var prob = gdata(this.mod.data.config, "data_prob_info");
|
|
var probs = [];
|
|
for (var i in prob) {
|
|
var pro = prob[i];
|
|
probs.push(pro);
|
|
}
|
|
var ruleinfo = {
|
|
desc: explain.desc,
|
|
prob: probs,
|
|
mod: this.mod
|
|
};
|
|
nx.bridge.createPanel("WndActStarSkyPrayRule", ruleinfo);
|
|
},
|
|
onTogMenu: function onTogMenu(_idx) {
|
|
var id = parseInt(_idx);
|
|
nx.gui.setActive(this.nodShow, "", id == 1);
|
|
nx.gui.setActive(this.nodTask, "", id == 0);
|
|
var mat = this.cfg.loss_item_once[0][0];
|
|
var model = BackPackController.getInstance().getModel();
|
|
this.havemat = model.getItemNumByBid(mat);
|
|
if (id == 1) {
|
|
this.mod.reqBaseInfo();
|
|
} else {
|
|
this.mod.reqBaseData();
|
|
var time = new Date();
|
|
var showtime = this.mod.data.end_time - time / 1000;
|
|
nx.gui.setCdTxt(this.nodEndTimes, "time", showtime);
|
|
}
|
|
},
|
|
setTask: function setTask() {
|
|
var cmp = nx.gui.getComponent(this.nodTask, "", "act.dailytreasure.task");
|
|
if (cmp) {
|
|
cmp.setCfg(this.tasks);
|
|
}
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |