SamsaraGame/assets/Script/game/ChargeRewardUI.js
2025-04-24 17:03:28 +08:00

55 lines
1.5 KiB
JavaScript

import GameModel from "../ts/core/GameModel";
cc.Class({
extends: cc.Component,
properties: {
content: cc.Node,
reward_item: cc.Prefab,
},
start () {
this.initScroll(GameModel.player.chargesum, GameModel.player.rewardrecord);
},
initScroll (charge_sum, reward_record) {
let reward_list = GameModel.conf_charge_reward;
let list = [];
for (let i = 1; reward_list[i]; ++i) {
let item = reward_list[i];
list.push(item);
}
list.sort((a, b) => {
return a.money - b.money;
});
for(let item of list){
let node = cc.instantiate(this.reward_item);
node.parent = this.content;
let has_gain = ((reward_record&(1<<(item.id-1))) > 0);
let logic = node.getComponent('ChargeRewardItem');
let reward = [];
if (item.gid1 && item.gid1>0 && item.count1 && item.count1>0){
reward.push({gid: item.gid1, count: item.count1});
}
if (item.gid2 && item.gid2>0 && item.count2 && item.count2>0){
reward.push({gid: item.gid2, count: item.count2});
}
if (item.gid3 && item.gid3>0 && item.count3 && item.count3>0){
reward.push({gid: item.gid3, count: item.count3});
}
if (item.gid4 && item.gid4>0 && item.count4 && item.count4>0){
reward.push({gid: item.gid4, count: item.count4});
}
if (item.gid5 && item.gid5>0 && item.count5 && item.count5>0){
reward.push({gid: item.gid5, count: item.count5});
}
logic.init(item.money, charge_sum, has_gain, reward, item.id);
}
},
onButtonClick (event, param) {
if (param == 'close')
this.node.destroy();
},
});