DailyUpItem.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import DailyData from "../datas/DailyData";
  8. import GameM from "../manager/GameM";
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class DailyUpItem extends cc.Component {
  12. @property(cc.Node)
  13. bgNormal: cc.Node = null;
  14. @property(cc.Node)
  15. bgSel: cc.Node = null;
  16. @property(cc.Sprite)
  17. icon: cc.Sprite = null;
  18. @property(cc.Label)
  19. labState: cc.Label = null;
  20. @property(cc.Node)
  21. iconGet: cc.Node = null;
  22. @property(cc.Node)
  23. red: cc.Node = null;
  24. private selState = false
  25. /** 数据
  26. * index 下标 从0开始
  27. getDay 第x天可领取
  28. rewardType 奖励类型 1:红包币 2:汽车
  29. rewardNum 奖励数量/汽车等级
  30. conditionType 获得条件类型 1:累计登陆x天 2:汽车等级达到x级 3:玩家等级达到x级
  31. conditionLv 获得条件累计登陆天数/汽车等级/玩家等级
  32. */
  33. data = null
  34. start() {
  35. }
  36. init(data, hasGet) {
  37. this.data = data
  38. //console.log("Data:",data);
  39. let iconName = ''
  40. if (this.data.rewardType == 1) {
  41. iconName = 'hongbao'
  42. this.icon.node.scale = 0.15
  43. }
  44. else {
  45. this.icon.node.scale = 0.22
  46. iconName = 'che_' + this.data.rewardNum.toString()
  47. }
  48. cc.loader.loadRes('daily/' + iconName, cc.SpriteFrame, (err, assets) => {
  49. if (err) {
  50. cc.error(err);
  51. return;
  52. }
  53. this.icon.getComponent(cc.Sprite).spriteFrame = assets;
  54. })
  55. if (hasGet) {
  56. this.iconGet.parent.active = true
  57. this.iconGet.active = true
  58. this.labState.string = '已领取'
  59. this.red.active = false
  60. }
  61. else {
  62. this.iconGet.parent.active = false
  63. this.iconGet.active = false
  64. this.labState.string = `登录${this.data.getDay}天`
  65. }
  66. this.setSel(false)
  67. this.showRed()
  68. }
  69. showRed() {
  70. let red = false
  71. let data = null
  72. data = DailyData.Instance.dailyCfg[this.node.name]
  73. if (DailyData.Instance.dailyGetArr[this.node.name] == '0') {
  74. if (GameM.commonData.loginDays >= data.getDay) {
  75. if (data.conditionType == 1) {
  76. red = true
  77. }
  78. if (data.conditionType == 2) {
  79. if (GameM.commonData.maxCarLevel >= data.conditionLv) {
  80. red = true
  81. }
  82. }
  83. else if (data.conditionType == 3) {
  84. if (GameM.commonData.roleData.lv >= data.conditionLv) {
  85. red = true
  86. }
  87. }
  88. }
  89. }
  90. this.red.active = red
  91. }
  92. setSel(sel) {
  93. this.selState = sel
  94. if (this.selState) {
  95. this.bgSel.active = true
  96. // this.bgNormal.active = false
  97. }
  98. else {
  99. this.bgSel.active = false
  100. // this.bgNormal.active = true
  101. }
  102. }
  103. // update (dt) {}
  104. }