play_list_item.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { _decorator, Animation, Component, Label, log, Node, Sprite, SpriteFrame, Vec3 } from 'cc';
  2. import { server_play_list_data_item } from '../data/server_play_list_data';
  3. import { gameManager } from '../gameManager';
  4. import { tools } from '../tools';
  5. import { config } from '../config';
  6. import { Lack } from '../dialog/Lack';
  7. import { ClientEvent } from '../framework/clientEvent';
  8. import { Util } from '../framework/util';
  9. import { SdkUtil } from '../framework/sdkUtil';
  10. import { StatisticsManager } from '../framework/statisticsManager';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('play_list_item')
  13. export class play_list_item extends Component {
  14. @property(Node) item_bg;
  15. @property(Node) lab_cur_level;
  16. @property(Node) mask_layer;
  17. @property(Node) btn_lock_coin;
  18. @property(Node) lab_coin_number;
  19. @property(Node) btn_lock_video:Node;
  20. @property(Node) lab_video_number:Node;
  21. @property(Node) btn_sub_coin:Node;
  22. @property(Node) lab_consume_coin:Node;
  23. private m_data:server_play_list_data_item = null;
  24. private m_call_back = null;
  25. public initView(data:server_play_list_data_item,sf:SpriteFrame,call_back){
  26. this.m_call_back = call_back;
  27. this.node.getComponent(Sprite).spriteFrame = sf;
  28. this.node.on(Node.EventType.TOUCH_END,()=>{
  29. if(this.m_call_back!=null){
  30. if(this.m_data.id===config.PLAY_TYPE.JI_YI_LI||this.m_data.id===config.PLAY_TYPE.DOU_DI_ZHU){
  31. this.btn_sub_coin.active = true;
  32. if(gameManager.get_user_coin()>=this.m_data.consume_coin){
  33. gameManager.sub_coin(this.m_data.consume_coin)
  34. this.m_call_back(this.m_data);
  35. }else{
  36. this.showViewLack()
  37. }
  38. }else{
  39. this.m_call_back(this.m_data);
  40. }
  41. }
  42. },this);
  43. this.btn_sub_coin.on(Node.EventType.TOUCH_END,()=>{
  44. if(this.m_call_back!=null){
  45. if(this.m_data.id===config.PLAY_TYPE.JI_YI_LI||this.m_data.id===config.PLAY_TYPE.DOU_DI_ZHU){
  46. this.btn_sub_coin.active = true;
  47. if(gameManager.get_user_coin()>=this.m_data.consume_coin){
  48. gameManager.sub_coin(this.m_data.consume_coin)
  49. this.m_call_back(this.m_data);
  50. }else{
  51. this.showViewLack()
  52. }
  53. }else{
  54. this.m_call_back(this.m_data);
  55. }
  56. }
  57. })
  58. this.btn_sub_coin.active = false;
  59. this.btn_lock_coin.on(Node.EventType.TOUCH_START,()=>{
  60. gameManager.playBtnSound()
  61. if(gameManager.get_user_coin()>=this.m_data.coin_number){
  62. tools.showDialog(`使用${this.m_data.coin_number}金币解锁${this.m_data.name}`,()=>{
  63. gameManager.sub_coin(this.m_data.coin_number);
  64. let data = gameManager.get_cur_level_by_categoryid(this.m_data.id);
  65. data.is_lock_game_play = 1;
  66. gameManager.set_unlock_levels_data(data);
  67. gameManager.sync_data((is_sync)=>{},config.sync_data_type.LEVELS)
  68. ClientEvent.dispatchEvent(config.EVENT_MSG.ON_UPDATE_HOME_VIEW)
  69. })
  70. }else{
  71. this.showViewLack()
  72. }
  73. },this);
  74. this.btn_lock_video.on(Node.EventType.TOUCH_END,()=>{
  75. SdkUtil.showVideoAd(config.rewardVideoAdUnitId.Earn_coins_AdUnitId,(res)=>{
  76. if(res.isEnded){
  77. let data = gameManager.get_cur_level_by_categoryid(this.m_data.id);
  78. data.look_video_number+=1;
  79. if(data.look_video_number>=this.m_data.unlock_ads_number){
  80. data.is_lock_game_play = 1;
  81. }
  82. gameManager.set_unlock_levels_data(data);
  83. gameManager.sync_data((is_sync)=>{},config.sync_data_type.LEVELS)
  84. if(data.is_lock_game_play===1){
  85. ClientEvent.dispatchEvent(config.EVENT_MSG.ON_UPDATE_HOME_VIEW)
  86. }else{
  87. this.updateView()
  88. }
  89. }
  90. // 统计-激励视频广告
  91. let collect_data = StatisticsManager.get_collect_data(this.m_data.id, 0, 0, res, config.STATISTICS_ACTION_TYPE.JIE_SUO)
  92. StatisticsManager.request_collect_rewardVideoData(collect_data)
  93. })
  94. })
  95. this.m_data = data;
  96. this.updateView();
  97. this.hide();
  98. }
  99. public showViewLack(){
  100. gameManager.addTopView(config.PREFAB_PATH.Lack,(node:Node)=>{
  101. node.getComponent(Lack).initView(null,(lack:Lack)=>{
  102. SdkUtil.showVideoAd(config.rewardVideoAdUnitId.Earn_coins_AdUnitId,(res)=>{
  103. if(res.isEnded){
  104. lack.close()
  105. ClientEvent.dispatchEvent(config.EVENT_MSG.ON_SHOW_REWARD_VIEW)
  106. }
  107. // 统计-激励视频广告
  108. let collect_data = StatisticsManager.get_collect_data(0, 0, 0, res, config.STATISTICS_ACTION_TYPE.ZHUAN_JIN_BI)
  109. StatisticsManager.request_collect_rewardVideoData(collect_data)
  110. })
  111. });
  112. })
  113. }
  114. public updateView(){
  115. let data = gameManager.get_cur_level_by_categoryid(this.m_data.id);
  116. if(data!=null){
  117. if(data.is_lock_game_play===1){
  118. this.mask_layer.active = false;
  119. }else{
  120. this.mask_layer.active = true;
  121. }
  122. if(gameManager.get_user_coin()>=this.m_data.coin_number){
  123. this.btn_lock_coin.getComponent(Sprite).grayscale = false;
  124. }else{
  125. this.btn_lock_coin.getComponent(Sprite).grayscale = true;
  126. }
  127. if(this.m_data.unlock_ads_number>0){
  128. this.btn_lock_video.active = true;
  129. this.lab_video_number.getComponent(Label).string = `${data.look_video_number}/${this.m_data.unlock_ads_number}`
  130. }else{
  131. this.btn_lock_video.active = false;
  132. }
  133. this.lab_coin_number.getComponent(Label).string = this.m_data.coin_number+"";
  134. this.lab_cur_level.getComponent(Label).string = `${data.level}/${this.m_data.barrier_number}`
  135. if(this.m_data.id===config.PLAY_TYPE.JI_YI_LI||this.m_data.id===config.PLAY_TYPE.DOU_DI_ZHU){
  136. this.btn_sub_coin.active = true;
  137. this.item_bg.active = false;
  138. this.lab_consume_coin.getComponent(Label).string = `-${this.m_data.consume_coin}`
  139. if(gameManager.get_user_coin()>=this.m_data.consume_coin){
  140. this.btn_sub_coin.getComponent(Sprite).grayscale = false;
  141. }else{
  142. this.btn_sub_coin.getComponent(Sprite).grayscale = true;
  143. }
  144. }
  145. }
  146. }
  147. public hide(){
  148. this.unscheduleAllCallbacks()
  149. this.node.position = new Vec3(-500,this.node.position.y,this.node.position.z)
  150. this.node.getComponent(Animation).stop()
  151. }
  152. public play(time:number,_index:number){
  153. let clip = this.node.getComponent(Animation).clips[_index]
  154. let list = clip.tracks[0].channels()[1].curve._values;
  155. let pos_y = this.node.position.y;
  156. for (let index = 0; index < list.length; index++) {
  157. clip.tracks[0].channels()[1].curve._values[index].value = pos_y
  158. }
  159. this.scheduleOnce(()=>{
  160. this.node.getComponent(Animation).play(`show_play_item_animation${_index}`)
  161. },time)
  162. }
  163. }