SignIconItem.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { RewardState } from "../../../data/GameData";
  2. const { ccclass, property } = cc._decorator;
  3. /**
  4. * 签到icon组件
  5. * @author 薛鸿潇
  6. * - 红包icon:用红包样式
  7. * - 现金、金猪现金:用提现样式
  8. */
  9. @ccclass
  10. export default class SignIconItem extends cc.Component {
  11. @property({ displayName: '提现样式', type: cc.Node })
  12. private node_cash: cc.Node = null!;
  13. @property({ displayName: '红包样式', type: cc.Node })
  14. private node_redbag: cc.Node = null!;
  15. @property({ displayName: '现金提示', type: cc.Node })
  16. private node_money: cc.Node = null!;
  17. @property({ displayName: '天数', type: cc.Label })
  18. private lbl_day: cc.Label = null!;
  19. @property({ type: cc.Node, displayName: '蒙版' })
  20. private node_mask: cc.Node = null!;
  21. @property({ type: cc.Node, displayName: '勾' })
  22. private node_gou: cc.Node = null!;
  23. /** 数据 */
  24. private icon_data = {
  25. id: 0,
  26. reward_type: 0,
  27. count: 0,
  28. login_day: 0,
  29. video_limit: 0,
  30. state: RewardState.none,
  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. if (!icon_data) {
  44. this.node.active = false;
  45. return
  46. }
  47. this.lbl_day.string = '第' + icon_data.login_day + '天';
  48. if (icon_data.reward_type) {
  49. this.node_cash.active = true;
  50. this.node_redbag.active = false;
  51. this.lbl_day.node.getComponent(cc.LabelOutline).color = cc.color(DayOutLineColor.cash);
  52. } else {
  53. this.node_cash.active = false;
  54. this.node_redbag.active = true;
  55. this.lbl_day.node.getComponent(cc.LabelOutline).color = cc.color(DayOutLineColor.red_bag);
  56. }
  57. this.icon_data = icon_data;
  58. // 状态样式
  59. let state = gData.sign.getStateByDay(icon_data.login_day);
  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. }