sign_reward_item.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { _decorator, Color, color, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { sign_reward_data } from '../../data';
  4. import { tools } from '../../tools';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('sign_reward_item')
  7. export class sign_reward_item extends base_ui {
  8. @property(Node) img_state:Node = null
  9. @property(Node) img_bg:Node = null
  10. @property(Node) lab_xingqi:Node = null
  11. @property(Node) lab_days:Node = null
  12. @property(Node) img_icon:Node = null
  13. @property(Node) lab_count:Node = null
  14. @property(Node) lab_name:Node = null
  15. @property(Node) img_mask:Node = null
  16. @property(SpriteFrame) sf_icon_lq:SpriteFrame = null
  17. @property(SpriteFrame) sf_icon_bq:SpriteFrame = null
  18. @property(SpriteFrame) sf_item_default:SpriteFrame = null
  19. @property(SpriteFrame) sf_item_current:SpriteFrame = null
  20. private color_default = new Color().fromHEX("#6a70e9") //蓝色
  21. private color_current = new Color().fromHEX("#ef941d") //橘黄色
  22. private m_data:sign_reward_data = null
  23. private m_cb = null
  24. start() {
  25. this.onButtonListen(this.node,()=>{
  26. this.m_cb && this.m_cb(this)
  27. })
  28. }
  29. initView(data:sign_reward_data, cb) {
  30. this.setData(data)
  31. this.m_cb = cb
  32. }
  33. public getData():sign_reward_data {
  34. return this.m_data
  35. }
  36. public setData(data:sign_reward_data) {
  37. this.m_data = data
  38. this.lab_days.getComponent(Label).string = `${data.index+1}`
  39. tools.loadRemoteImg(data.icon, (d)=>{
  40. this.img_icon.getComponent(Sprite).spriteFrame = d.sf
  41. })
  42. this.lab_count.getComponent(Label).string = `x${data.quantity}`
  43. this.lab_name.getComponent(Label).string = data.name
  44. this.img_state.active = false
  45. if(data.receive_status==1) {
  46. // 已领取
  47. this.img_mask.active = true
  48. this.setState(true)
  49. } else {
  50. // 未领取
  51. this.img_mask.active = false
  52. // 当前今天
  53. if(data.current_sign_status==1) {
  54. this.img_state.active = true
  55. this.img_state.getComponent(Sprite).spriteFrame = this.sf_icon_lq
  56. this.setState(false)
  57. } else {
  58. // 补签
  59. if(data.repair_sign_status==1) {
  60. this.img_state.active = true
  61. this.img_state.getComponent(Sprite).spriteFrame = this.sf_icon_bq
  62. }
  63. }
  64. }
  65. }
  66. private setState(is_default:boolean) {
  67. if(is_default) {
  68. this.img_bg.getComponent(Sprite).spriteFrame = this.sf_item_default
  69. this.lab_xingqi.getComponent(Label).color = this.color_default
  70. this.lab_days.getComponent(Label).color = this.color_default
  71. this.lab_name.getComponent(Label).color = this.color_default
  72. } else {
  73. this.img_bg.getComponent(Sprite).spriteFrame = this.sf_item_current
  74. this.lab_xingqi.getComponent(Label).color = this.color_current
  75. this.lab_days.getComponent(Label).color = this.color_current
  76. this.lab_name.getComponent(Label).color = this.color_current
  77. }
  78. }
  79. }