sign_receive_reward.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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(Node) public_close_text:Node = null
  21. @property(SpriteFrame) sf_dangrihuode = null
  22. @property(SpriteFrame) sf_gongxihuode = null
  23. private m_reward_data:sign_reward_data = null
  24. private m_is_buqian:boolean = false
  25. private m_cb = null
  26. start() {
  27. this.onButtonListen(this.public_bg, ()=>{
  28. if(this.m_is_buqian==true) { return }
  29. this.closeSelf()
  30. })
  31. this.onButtonListen(this.btn_receive, ()=>{
  32. this.requestUserSign(false)
  33. })
  34. this.onButtonListen(this.btn_double, ()=>{
  35. GameManager.showVideoAd(config.ADS_TYPE.GAME_SIGN_DOUBLE, (res)=>{
  36. this.requestUserSign(true)
  37. })
  38. })
  39. }
  40. initView(data:sign_reward_data, is_buqian:boolean, cb) {
  41. this.m_reward_data = data
  42. this.m_cb = cb
  43. this.m_is_buqian = is_buqian
  44. if(this.m_is_buqian==true) {
  45. this.public_close_text.active = false
  46. }
  47. this.img_title.getComponent(Sprite).spriteFrame = this.sf_dangrihuode
  48. this.showNodeBtn(true)
  49. tools.loadRemoteImg(data.icon, (d)=>{
  50. this.img_icon.getComponent(Sprite).spriteFrame = d.sf
  51. })
  52. this.lab_name.getComponent(Label).string = data.name
  53. this.setLabCount(data.quantity)
  54. }
  55. initReceiveSuccess(data:sign_total_reward_data) {
  56. this.img_title.getComponent(Sprite).spriteFrame = this.sf_gongxihuode
  57. this.showNodeBtn(false)
  58. tools.loadRemoteImg(data.icon, (d)=>{
  59. this.img_icon.getComponent(Sprite).spriteFrame = d.sf
  60. })
  61. this.lab_name.getComponent(Label).string = data.name
  62. this.setLabCount(data.quantity)
  63. }
  64. private setLabCount(count:number) {
  65. this.lab_count.getComponent(Label).string = `x${count}`
  66. }
  67. private showRewardDetails(is_double:boolean) {
  68. this.img_title.getComponent(Sprite).spriteFrame = this.sf_gongxihuode
  69. this.showNodeBtn(false)
  70. if(is_double) {
  71. let count = this.m_reward_data.quantity * 2
  72. this.setLabCount(count)
  73. }
  74. if(this.m_is_buqian==true) {
  75. this.public_close_text.active = true
  76. this.m_is_buqian = false
  77. }
  78. }
  79. private showNodeBtn(is_show:boolean) {
  80. if(is_show) {
  81. this.node_btn.active = true
  82. this.btn_double.getComponent(Animation).play()
  83. } else {
  84. this.node_btn.active = false
  85. this.btn_double.getComponent(Animation).stop()
  86. }
  87. }
  88. private closeSelf() {
  89. this.showNodeBtn(false)
  90. this.node.active = false
  91. }
  92. private requestUserSign(is_double:boolean) {
  93. let stype = 1
  94. if(is_double) {
  95. stype = 2
  96. }
  97. uiManager.Instance().showLoading()
  98. let opt = {'index':this.m_reward_data.index, 'stype': stype}
  99. http.post(config.API.user_sign, opt, (err,d)=>{
  100. uiManager.Instance().hideLoading()
  101. if(!err){
  102. let nd = JSON.parse(d)
  103. if(nd.code === config.status.SUCCESS){
  104. // console.log("user_sign", nd.content)
  105. this.showRewardDetails(is_double)
  106. this.m_cb && this.m_cb(this)
  107. }
  108. }
  109. })
  110. }
  111. }