sign_receive_reward.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.btn_double.getComponent(Animation).play()
  32. this.onButtonListen(this.btn_double, ()=>{
  33. GameManager.showVideoAd(config.ADS_TYPE.GAME_SIGN_DOUBLE, (res)=>{
  34. this.requestUserSign(true)
  35. })
  36. })
  37. }
  38. initView(data:sign_reward_data, cb) {
  39. this.m_reward_data = data
  40. this.m_cb = cb
  41. this.img_title.getComponent(Sprite).spriteFrame = this.sf_dangrihuode
  42. this.node_btn.active = true
  43. tools.loadRemoteImg(data.icon, (d)=>{
  44. this.img_icon.getComponent(Sprite).spriteFrame = d.sf
  45. })
  46. this.lab_name.getComponent(Label).string = data.name
  47. this.setLabCount(data.quantity)
  48. }
  49. initReceiveSuccess(data:sign_total_reward_data) {
  50. this.img_title.getComponent(Sprite).spriteFrame = this.sf_gongxihuode
  51. this.node_btn.active = false
  52. tools.loadRemoteImg(data.icon, (d)=>{
  53. this.img_icon.getComponent(Sprite).spriteFrame = d.sf
  54. })
  55. this.lab_name.getComponent(Label).string = data.name
  56. this.setLabCount(data.quantity)
  57. }
  58. private setLabCount(count:number) {
  59. this.lab_count.getComponent(Label).string = `x${count}`
  60. }
  61. private showRewardDetails(is_double:boolean) {
  62. this.img_title.getComponent(Sprite).spriteFrame = this.sf_gongxihuode
  63. this.node_btn.active = false
  64. if(is_double) {
  65. let count = this.m_reward_data.quantity * 2
  66. this.setLabCount(count)
  67. }
  68. }
  69. private closeSelf() {
  70. this.btn_double.getComponent(Animation).stop()
  71. this.node.active = false
  72. }
  73. private requestUserSign(is_double:boolean) {
  74. let stype = 1
  75. if(is_double) {
  76. stype = 2
  77. }
  78. uiManager.Instance().showLoading()
  79. let opt = {'index':this.m_reward_data.index, 'stype': stype}
  80. http.post(config.API.user_sign, opt, (err,d)=>{
  81. uiManager.Instance().hideLoading()
  82. if(!err){
  83. let nd = JSON.parse(d)
  84. if(nd.code === config.status.SUCCESS){
  85. // console.log("user_sign", nd.content)
  86. this.showRewardDetails(is_double)
  87. this.m_cb && this.m_cb(this)
  88. }
  89. }
  90. })
  91. }
  92. }