SignIconItem.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { RewardState, RewardType } from "../../data/GameData";
  2. import { CSignType } from "../../data/module/SignData";
  3. const { ccclass, property } = cc._decorator;
  4. /**
  5. * 签到icon组件
  6. * @author 薛鸿潇
  7. * - 红包icon:用红包样式
  8. * - 现金、金猪现金:用提现样式
  9. */
  10. @ccclass
  11. export default class SignIconItem extends cc.Component {
  12. @property({ displayName: '提现样式', type: cc.Node })
  13. private node_cash: cc.Node = null!;
  14. @property({ displayName: '红包样式', type: cc.Node })
  15. private node_redbag: cc.Node = null!;
  16. @property({ displayName: '现金提示', type: cc.Node })
  17. private node_money: cc.Node = null!;
  18. @property({ displayName: '天数', type: cc.Label })
  19. private lbl_day: cc.Label = null!;
  20. @property({ displayName: '蒙版', type: cc.Node })
  21. private node_mask: cc.Node = null!;
  22. @property({ displayName: '勾', type: cc.Node })
  23. private node_gou: cc.Node = null!;
  24. /** 数据 */
  25. private icon_data: CSignType = {
  26. id: 0,
  27. rewardType: 0,
  28. rewardNum: 0,
  29. loginDay: 0,
  30. videoNum: 0
  31. }
  32. /**
  33. * 初始化数据
  34. */
  35. public async setItemData(icon_data) {
  36. await this.initIcon(icon_data);
  37. }
  38. /**
  39. * 初始化icon
  40. * @param icon_data 数据
  41. */
  42. private initIcon(icon_data) {
  43. this.icon_data = icon_data;
  44. if (!this.icon_data) {
  45. this.node.active = false;
  46. return
  47. }
  48. this.lbl_day.string = '第' + this.icon_data.id + '天';
  49. if (this.icon_data.rewardType == RewardType.rmb || this.icon_data.rewardType == RewardType.pigRmb) {
  50. this.node_cash.active = true;
  51. this.node_redbag.active = false;
  52. this.lbl_day.node.getComponent(cc.LabelOutline).color = cc.color(DayOutLineColor.cash);
  53. } else {
  54. this.node_cash.active = false;
  55. this.node_redbag.active = true;
  56. this.lbl_day.node.getComponent(cc.LabelOutline).color = cc.color(DayOutLineColor.red_bag);
  57. }
  58. // 状态样式
  59. let state = gData.sign.getStateByDay(this.icon_data.id);
  60. if (state == RewardState.none) {
  61. this.node_mask.active = true;
  62. this.node_gou.active = true;
  63. this.node_money.active = false;
  64. } else if (state == RewardState.unlock) {
  65. this.node_mask.active = false;
  66. this.node_gou.active = false;
  67. } else if (state == RewardState.lock) {
  68. this.node_mask.active = false;
  69. this.node_gou.active = false;
  70. }
  71. }
  72. }
  73. /** 天数描边 */
  74. enum DayOutLineColor {
  75. /** 红包 */
  76. red_bag = '#EB3A0E' as any,
  77. /** 提现 */
  78. cash = '#2AB718' as any,
  79. }