sign_receive_reward.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { _decorator, Component, Label, Node, Sprite, Animation, SpriteFrame } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { sign_reward_data, sign_total_reward_data } from '../../data';
  4. import { tools } from '../../tools';
  5. import { http } from '../../http';
  6. import { config } from '../../config';
  7. import { GameManager } from '../../GameManager';
  8. import { uiManager } from '../../manager/uiManager';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('sign_receive_reward')
  11. export class sign_receive_reward extends base_ui {
  12. @property(Node) public_bg:Node = null
  13. @property(Node) img_title:Node = null
  14. @property(Node) img_icon:Node = null
  15. @property(Node) lab_name:Node = null
  16. @property(Node) lab_count:Node = null
  17. @property(Node) node_btn:Node = null
  18. @property(Node) btn_receive:Node = null
  19. @property(Node) btn_double:Node = null
  20. @property(SpriteFrame) sf_dangrihuode = null
  21. @property(SpriteFrame) sf_gongxihuode = null
  22. private m_reward_data:sign_reward_data = null
  23. private m_cb = null
  24. start() {
  25. this.onButtonListen(this.public_bg, ()=>{
  26. this.closeSelf()
  27. })
  28. this.onButtonListen(this.btn_receive, ()=>{
  29. this.requestUserSign(false)
  30. })
  31. this.onButtonListen(this.btn_double, ()=>{
  32. GameManager.showVideoAd(config.ADS_TYPE.GAME_SIGN_DOUBLE, (res)=>{
  33. this.requestUserSign(true)
  34. })
  35. })
  36. }
  37. initView(data:sign_reward_data, cb) {
  38. this.m_reward_data = data
  39. this.m_cb = cb
  40. this.img_title.getComponent(Sprite).spriteFrame = this.sf_dangrihuode
  41. this.showNodeBtn(true)
  42. tools.loadRemoteImg(data.icon, (d)=>{
  43. this.img_icon.getComponent(Sprite).spriteFrame = d.sf
  44. })
  45. this.lab_name.getComponent(Label).string = data.name
  46. this.setLabCount(data.quantity)
  47. }
  48. initReceiveSuccess(data:sign_total_reward_data) {
  49. this.img_title.getComponent(Sprite).spriteFrame = this.sf_gongxihuode
  50. this.showNodeBtn(false)
  51. tools.loadRemoteImg(data.icon, (d)=>{
  52. this.img_icon.getComponent(Sprite).spriteFrame = d.sf
  53. })
  54. this.lab_name.getComponent(Label).string = data.name
  55. this.setLabCount(data.quantity)
  56. }
  57. private setLabCount(count:number) {
  58. this.lab_count.getComponent(Label).string = `x${count}`
  59. }
  60. private showRewardDetails(is_double:boolean) {
  61. this.img_title.getComponent(Sprite).spriteFrame = this.sf_gongxihuode
  62. this.showNodeBtn(false)
  63. if(is_double) {
  64. let count = this.m_reward_data.quantity * 2
  65. this.setLabCount(count)
  66. }
  67. }
  68. private showNodeBtn(is_show:boolean) {
  69. if(is_show) {
  70. this.node_btn.active = true
  71. this.btn_double.getComponent(Animation).play()
  72. } else {
  73. this.node_btn.active = false
  74. this.btn_double.getComponent(Animation).stop()
  75. }
  76. }
  77. private closeSelf() {
  78. this.showNodeBtn(false)
  79. this.node.active = false
  80. }
  81. private requestUserSign(is_double:boolean) {
  82. let stype = 1
  83. if(is_double) {
  84. stype = 2
  85. }
  86. uiManager.Instance().showLoading()
  87. let opt = {'index':this.m_reward_data.index, 'stype': stype}
  88. http.post(config.API.user_sign, opt, (err,d)=>{
  89. uiManager.Instance().hideLoading()
  90. if(!err){
  91. let nd = JSON.parse(d)
  92. if(nd.code === config.status.SUCCESS){
  93. // console.log("user_sign", nd.content)
  94. this.showRewardDetails(is_double)
  95. this.m_cb && this.m_cb(this)
  96. }
  97. }
  98. })
  99. }
  100. }