"use strict";
|
cc._RF.push(module, '9d519STSvhOj6I6XYU/K6r2', 'action_acc_level_up_gift_panel');
|
// Scripts/mod/action/view/action_acc_level_up_gift_panel.js
|
|
"use strict";
|
|
// --------------------------------------------------------------------
|
// @author: xxx@syg.com(必填, 创建模块的人员)
|
// @description:
|
// 这里是描述这个窗体的作用的
|
// <br/>Create: 2019-04-18 17:58:10
|
// --------------------------------------------------------------------
|
var PathTool = require("pathtool");
|
|
var TimeTool = require("timetool");
|
|
var ActionController = require("action_controller");
|
|
var ActionEvent = require("action_event");
|
|
var RoleController = require("role_controller");
|
|
var ActionAccLevelUpGiftPanel = cc.Class({
|
"extends": BasePanel,
|
ctor: function ctor() {
|
this.prefabPath = PathTool.getPrefabPath("action", "action_acc_level_up_gift_panel");
|
this.ctrl = ActionController.getInstance();
|
this.holiday_bid = arguments[0];
|
},
|
// 可以初始化声明一些变量的
|
initConfig: function initConfig() {
|
// --列表数据
|
this.cell_data_list = []; // --预制
|
|
this.cell_list = {};
|
this.rewardList = [];
|
},
|
// 初始化一些配置数据,可以用于声明一些变量之类的
|
initPanel: function initPanel() {
|
var self = this;
|
self.main_container = self.root_wnd.getChildByName("main_container");
|
self.title_con = self.main_container.getChildByName("title_con");
|
self.title_img = self.title_con.getChildByName("title_img");
|
var tab_vo = self.ctrl.getActionSubTabVo(self.holiday_bid);
|
|
if (tab_vo) {
|
if (tab_vo.aim_title == null || tab_vo.aim_title == "") {
|
tab_vo.aim_title = "txt_cn_action_acc_level_up_gift";
|
}
|
|
var path = PathTool.getUIIconPath("bigbg/action", tab_vo.aim_title);
|
this.loadRes(path, function (res) {
|
self.title_img.getComponent(cc.Sprite).spriteFrame = res;
|
}.bind(this));
|
}
|
|
self.charge_con_sv = this.seekChild("charge_con", cc.ScrollView);
|
var dec = self.title_con.getChildByName("dec");
|
dec.getComponent(cc.Label).string = "活动期间,玩家可领取已达档次奖励\n奖励限时限量,先到先得";
|
this.time_rt = self.title_con.getChildByName("time_node").getChildByName("time_lab").getComponent(cc.RichText);
|
self.setLessTime(tab_vo.remain_sec);
|
},
|
// 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
|
registerEvent: function registerEvent() {
|
this.addGlobalEvent(ActionEvent.UPDATE_LEVEL_UP_GIFT, function (data) {
|
if (data) {
|
this.setData(data);
|
}
|
}.bind(this));
|
this.ctrl.send21200();
|
},
|
// 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
|
onShow: function onShow(params) {},
|
// 面板设置不可见的回调,这里做一些不可见的屏蔽处理
|
onHide: function onHide() {},
|
setData: function setData(data) {
|
this.cell_data_list = [];
|
var self = this;
|
var is_redpoint = false;
|
|
for (var i = 0; i < data.gifts.length; ++i) {
|
var v = data.gifts[i];
|
var config = gdata("lev_gift_data", "data_level_welfare", v.id);
|
|
if (config) {
|
var _data = {};
|
_data.id = v.id;
|
_data.config = config;
|
self.cell_data_list.push(_data);
|
} //--status 0:不能领取, 1:可领取, 2:已领取
|
|
|
if (self.cell_data_list[i]) {
|
if (v.status == 1 && v.num >= self.cell_data_list[i].config.num) {
|
// --已领数量已经满了 也算不能领取
|
v.status = 4;
|
}
|
|
if (v.status == 0) {
|
//--不可领取
|
self.cell_data_list[i].order = 2;
|
} else if (v.status == 4) {
|
//--可领取但是已经没有得领取了
|
self.cell_data_list[i].order = 3;
|
v.status = 0;
|
} else if (v.status == 2) {
|
// --已领取
|
self.cell_data_list[i].order = 4;
|
} else {
|
// --可领取
|
self.cell_data_list[i].order = 1;
|
}
|
|
self.cell_data_list[i].status = v.status; //--状态
|
// --判定是否有红点
|
|
if (!is_redpoint && v.status == 1) {
|
is_redpoint = true;
|
}
|
|
self.cell_data_list[i].num = v.num; //--全服数量
|
}
|
}
|
|
self.cell_data_list.sort(Utils.tableLowerSorter(["order"], ["id"]));
|
this.ctrl.setHolidayStatus(self.holiday_bid, is_redpoint);
|
self.updateScrollviewList();
|
},
|
updateScrollviewList: function updateScrollviewList() {
|
var _this = this;
|
|
this.charge_con_sv.content.height = this.cell_data_list.length * 150;
|
|
var _loop = function _loop(i) {
|
var k = _this.cell_data_list[i];
|
|
if (_this.cell_list[k.id] == null) {
|
Utils.delayRun(_this.charge_con_sv.content, i / 30, function () {
|
this.loadRes(PathTool.getPrefabPath("action", "action_acc_level_up_gift_item"), function (Prefab) {
|
var node = Prefab;
|
this.charge_con_sv.content.addChild(node);
|
var cellView = node.getChildByName("main_container").getChildByName("item_scrollview").getComponent(cc.ScrollView);
|
var offsetX = 10;
|
var scale = 0.8;
|
var width = 120;
|
cellView.content.widht = width * scale * k.config.reward.length + (k.config.reward.length - 1 * offsetX);
|
var item_count = k.config.reward.length;
|
|
if (item_count <= 4) {
|
cellView.enabled = false;
|
} else {
|
cellView.enabled = true;
|
}
|
|
node.getChildByName("main_container").getChildByName("btn_go").on("click", function () {
|
Utils.playButtonSound(1);
|
this.setCellTouched(k.id);
|
}, this);
|
var arr = [];
|
|
for (var j = 0; j < k.config.reward.length; ++j) {
|
var v = k.config.reward[j];
|
var item_node = ItemsPool.getInstance().getItem("backpack_item");
|
item_node.setDefaultTip();
|
item_node.setPosition(width / 2 + j * (width + offsetX) * scale, 0);
|
item_node.setParent(cellView.content);
|
item_node.initConfig(false, scale, false, true);
|
item_node.show();
|
item_node.setData({
|
bid: v[0],
|
num: v[1]
|
});
|
arr.push(item_node);
|
}
|
|
this.cell_list[k.id] = node;
|
this.setCellByIndex(node, k);
|
this.updateCellByIndex(node, i);
|
this.rewardList.push(arr);
|
}.bind(this));
|
}.bind(_this));
|
} else {
|
_this.updateCellByIndex(_this.cell_list[k.id], i);
|
}
|
};
|
|
for (var i = 0; i < this.cell_data_list.length; ++i) {
|
_loop(i);
|
}
|
},
|
setCellTouched: function setCellTouched(id) {
|
for (var i = 0; i < this.cell_data_list.length; ++i) {
|
var v = this.cell_data_list[i];
|
|
if (v.id == id) {
|
if (v.status == 1) {
|
this.ctrl.send21201(id);
|
}
|
|
break;
|
}
|
}
|
},
|
setCellByIndex: function setCellByIndex(cell, data) {
|
var cell_data = data;
|
if (!cell_data) return;
|
var config = cell_data.config; // --角色等级
|
|
var role_vo = RoleController.getInstance().getRoleVo();
|
var lev = role_vo && role_vo.lev || 0;
|
var levStr;
|
var main_container = cell.getChildByName("main_container");
|
var title = main_container.getChildByName("title");
|
|
if (lev >= config.lev) {
|
title.color = new cc.Color(44, 125, 8);
|
levStr = "达到" + config.lev + "级 (" + config.lev + "/" + config.lev + ")";
|
} else {
|
title.color = new cc.Color(90, 58, 51);
|
levStr = "达到" + config.lev + "级 (" + lev + "/" + config.lev + ")";
|
}
|
|
title.getComponent(cc.Label).string = levStr;
|
},
|
updateCellByIndex: function updateCellByIndex(cell, index) {
|
cell.y = -cell.height / 2 - index * cell.height;
|
var cell_data = this.cell_data_list[index];
|
var btn_go = cell.getChildByName("main_container").getChildByName("btn_go");
|
var pic_has = cell.getChildByName("main_container").getChildByName("pic_has");
|
var config = cell_data.config; // --按钮
|
|
if (cell_data.status == 0) {
|
// --不可领取
|
btn_go.active = true;
|
pic_has.active = false;
|
Utils.setGreyButton(btn_go.getComponent(cc.Button), true);
|
btn_go.getChildByName("Label").color = new cc.Color(255, 255, 255);
|
} else if (cell_data.status == 1) {
|
// --可以领取
|
btn_go.active = true;
|
pic_has.active = false;
|
Utils.setGreyButton(btn_go.getComponent(cc.Button), false);
|
btn_go.getChildByName("Label").color = new cc.Color(37, 85, 6);
|
} else {
|
// --已领取
|
btn_go.active = false;
|
pic_has.active = true;
|
}
|
|
var portion_count = cell.getChildByName("main_container").getChildByName("portion_count"); // --领取数量
|
|
var count = config.num - cell_data.num;
|
|
if (count < 0) {
|
count = 0;
|
}
|
|
portion_count.getComponent(cc.Label).string = "还剩" + count + "份";
|
},
|
setVisibleStatus: function setVisibleStatus(bool) {
|
bool = bool || false;
|
this.setVisible(bool);
|
},
|
setLessTime: function setLessTime(less_time) {
|
if (!this.time_rt) {
|
return;
|
}
|
|
less_time = less_time || 0;
|
|
if (less_time > 0) {
|
this.setTimeFormatString(less_time);
|
|
if (this.time_tichet == null) {
|
this.time_tichet = gcore.Timer.set(function () {
|
less_time--;
|
this.setTimeFormatString(less_time);
|
|
if (less_time <= 0) {
|
gcore.Timer.del(this.time_tichet);
|
this.time_tichet = null;
|
}
|
}.bind(this), 1000, -1);
|
}
|
} else {
|
this.setTimeFormatString(less_time);
|
}
|
},
|
setTimeFormatString: function setTimeFormatString(time) {
|
var self = this;
|
|
if (time > 0) {
|
var str = "剩余时间:<color=#14ff32>" + TimeTool.getTimeFormatDayIIIIII(time) + "</color>";
|
self.time_rt.string = str;
|
} else {
|
self.time_rt.string = "";
|
}
|
},
|
// 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
|
onDelete: function onDelete() {
|
if (this.time_tichet) {
|
gcore.Timer.del(this.time_tichet);
|
this.time_tichet = null;
|
}
|
|
if (this.cell_list) {
|
for (var i = 0; i < this.rewardList.length; ++i) {
|
for (var j = 0; j < this.rewardList[i].length; ++j) {
|
if (this.rewardList[i][j].deleteMe) {
|
this.rewardList[i][j].deleteMe();
|
}
|
}
|
}
|
}
|
}
|
});
|
|
cc._RF.pop();
|