SignIconItem.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_money: cc.Label = null;
  20. @property({ displayName: '天数', type: cc.Label })
  21. private lbl_day: cc.Label = null;
  22. @property({ displayName: '蒙版', type: cc.Node })
  23. private node_mask: cc.Node = null;
  24. @property({ displayName: '勾', type: cc.Node })
  25. private node_gou: cc.Node = null;
  26. /** 数据 */
  27. private icon_data: CSignType = {
  28. id: 0,
  29. rewardType: 0,
  30. rewardNum: 0,
  31. loginDay: 0,
  32. showType: 0
  33. }
  34. /**
  35. * 初始化数据
  36. */
  37. public async setItemData(icon_data) {
  38. await this.initIcon(icon_data);
  39. }
  40. /**
  41. * 初始化icon
  42. * @param icon_data 数据
  43. */
  44. private initIcon(icon_data) {
  45. this.icon_data = icon_data;
  46. if (!this.icon_data) {
  47. this.node.active = false;
  48. return
  49. }
  50. this.lbl_day.string = '第' + this.icon_data.id + '天';
  51. if (this.icon_data.showType == 2) {
  52. this.node_cash.active = true;
  53. this.node_redbag.active = false;
  54. this.lbl_money.string = (this.icon_data.rewardNum * 0.0001) + '元';
  55. this.lbl_day.node.getComponent(cc.LabelOutline).color = cc.color(DayOutLineColor.cash);
  56. } else {
  57. this.node_cash.active = false;
  58. this.node_redbag.active = true;
  59. this.lbl_day.node.getComponent(cc.LabelOutline).color = cc.color(DayOutLineColor.red_bag);
  60. }
  61. // 状态样式
  62. let state = gData.sign.getStateByDay(this.icon_data.id);
  63. if (state == RewardState.none) {
  64. this.node_mask.active = true;
  65. this.node_gou.active = true;
  66. this.node_money.active = false;
  67. } else if (state == RewardState.unlock) {
  68. this.node_mask.active = false;
  69. this.node_gou.active = false;
  70. } else if (state == RewardState.lock) {
  71. this.node_mask.active = false;
  72. this.node_gou.active = false;
  73. }
  74. }
  75. }
  76. /** 天数描边 */
  77. enum DayOutLineColor {
  78. /** 红包 */
  79. red_bag = '#EB3A0E' as any,
  80. /** 提现 */
  81. cash = '#2AB718' as any,
  82. }