SignIconBigItem.ts 2.4 KB

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