NativeAdAwardNode.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /** 点击信息流奖励界面 */
  2. import { MONEY_TYPE } from "../datas/CommonData";
  3. import MoreGameData from "../datas/MoreGameData";
  4. import Main from "../Main";
  5. import AdM from "../manager/AdM";
  6. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  7. import NativeAdAwardData from "../manager/NativeAdAwardData";
  8. import UiM, { PANEL_NAME } from "../manager/UiM";
  9. import CarSpace from "../prefabs/CarSpace";
  10. import Sciencen_M from "../utils/Sciencen_M";
  11. import EffectNode from "./EffectNode";
  12. import Gift from "./Gift";
  13. const { ccclass, property } = cc._decorator;
  14. @ccclass
  15. export default class NativeADAwardNode extends cc.Component {
  16. @property(cc.Label)
  17. labAward: cc.Label = null;
  18. @property(cc.Label)
  19. labGetAward: cc.Label = null;
  20. @property(cc.Node)
  21. btnGetAward: cc.Node = null;
  22. @property(cc.Node)
  23. btnGetNo: cc.Node = null;
  24. @property(cc.Node)
  25. labDesNode: cc.Node = null;
  26. @property(cc.Node)
  27. hand: cc.Node = null;
  28. @property(cc.Label)
  29. labDes: cc.Label = null;
  30. @property(cc.Node)
  31. btnNo: cc.Node = null;
  32. @property(cc.Sprite)
  33. btnBanner: cc.Sprite = null;
  34. //1 工厂过热冷却 2 热气球奖励 3 车位上领取金币
  35. type = 1
  36. num = ''
  37. carSp = null
  38. //信息流位
  39. streamData = null
  40. start() {
  41. }
  42. onDisable() {
  43. NativeAdAwardData.Instance.openNativeState = false
  44. // AdM.destroyNative()
  45. }
  46. /** 初始化
  47. * @param type 1 工厂过热冷却 2 热气球奖励 3 车位上领取金币
  48. */
  49. init(type, num = '', carSp = null) {
  50. NativeAdAwardData.Instance.openNativeState = true
  51. // AdM.showNative(2)
  52. this.streamData = MoreGameData.Instance.getRandomSteam()
  53. if (this.streamData) {
  54. cc.loader.load(this.streamData.stream, (err, res) => {
  55. if (err) {
  56. console.log('err:', err);
  57. return;
  58. }
  59. if (this.btnBanner) {
  60. let tex: cc.Texture2D = res as cc.Texture2D;
  61. this.btnBanner.spriteFrame = new cc.SpriteFrame(tex);
  62. this.btnBanner.node.active = true
  63. }
  64. })
  65. }
  66. this.type = type
  67. this.num = num
  68. this.carSp = carSp
  69. let awardStr = ''
  70. let getAwardStr = ''
  71. switch (this.type) {
  72. case 1:
  73. awardStr = '冷却时间减半'
  74. getAwardStr = '领取奖励'
  75. break
  76. case 2:
  77. awardStr = '立即更换热气球奖励'
  78. getAwardStr = '换一个奖励'
  79. break
  80. case 3:
  81. awardStr = `${NativeAdAwardData.Instance.nativeAwardTimes}倍领取奖励`
  82. getAwardStr = `${NativeAdAwardData.Instance.nativeAwardTimes}倍领取`
  83. break
  84. }
  85. this.labAward.string = awardStr
  86. this.labGetAward.string = getAwardStr
  87. this.btnGetAward.active = false
  88. this.btnGetNo.active = true
  89. }
  90. cool = false
  91. /** 点击推荐banner */
  92. clickBanner() {
  93. GameM.audioM.playEffect(AUDIO_TYPE.button)
  94. if (this.cool) {
  95. return
  96. }
  97. this.cool = true
  98. this.scheduleOnce(() => {
  99. this.cool = false
  100. }, 3)
  101. MoreGameData.Instance.createNewTask(this.streamData)
  102. NativeAdAwardData.Instance.hasClickNative = true
  103. this.setCanGet()
  104. }
  105. /** 设置可领取 */
  106. setCanGet() {
  107. this.btnGetAward.active = true
  108. this.btnGetNo.active = false
  109. this.hand.scaleY = -1
  110. this.labDes.string = '请点击领取'
  111. this.btnNo.active = false
  112. }
  113. /** 点击领取奖励 */
  114. clickGetAward() {
  115. GameM.audioM.playEffect(AUDIO_TYPE.button)
  116. if (NativeAdAwardData.Instance.hasClickNative) {
  117. NativeAdAwardData.Instance.hasClickNative = false
  118. GameM.globalStorage.setStorage('nativeAdAwardGet' + this.type, 2)
  119. let successTip = ''
  120. switch (this.type) {
  121. // case 1:
  122. // if (GameM.commonData.roleData.shutDownCoolTime > 0) {
  123. // GameM.commonData.roleData.shutDownCoolTime = Math.floor(GameM.commonData.roleData.shutDownCoolTime * 0.5)
  124. // }
  125. // let gift = UiM.Instance.giftNode.getComponent(Gift)
  126. // gift.init(MONEY_TYPE.facCool, '0')
  127. // UiM.Instance.giftNode.active = true
  128. // successTip = '时间减半成功'
  129. // break
  130. case 2:
  131. UiM.Instance.hallNode.getComponent(Main).ranNewAirShip()
  132. successTip = '更换奖励成功'
  133. break
  134. case 3:
  135. let gold = Sciencen_M.instance.accMul(this.num, NativeAdAwardData.Instance.nativeAwardTimes.toString())
  136. GameM.commonData.updateGold(gold)
  137. GameM.audioM.playEffect(AUDIO_TYPE.getGold, false)
  138. EffectNode.instance.PlayCoinAnim(0, 20, cc.v2(0, -300));
  139. let s = this.carSp.getComponent(CarSpace)
  140. s.changeType(0)
  141. GameM.commonData.updateBagCarData(s.index.toString(), 0)
  142. this.scheduleOnce(() => {
  143. UiM.Instance.hallNode.getComponent(Main).checkGiftByQucece()
  144. }, 0.1)
  145. successTip = `${NativeAdAwardData.Instance.nativeAwardTimes}倍领取成功`
  146. break
  147. }
  148. // AdM.onSendEvent('NativeAdAwardGet' + this.type, `信息流变现领取${this.type}`, 'NativeAdAwardGet')
  149. UiM.Instance.offPanel(PANEL_NAME.NativeAdAwardNode)
  150. EffectNode.instance.PlayTip(successTip)
  151. }
  152. else {
  153. // EffectNode.instance.PlayTip('点击上方广告后可领取奖励')
  154. }
  155. }
  156. clickGetAwardNo() {
  157. GameM.audioM.playEffect(AUDIO_TYPE.button)
  158. cc.tween(this.labDesNode).to(0.15, { scale: 1.3 }).to(0.15, { scale: 1 }).start()
  159. }
  160. /** 点击关闭 */
  161. clickClose() {
  162. GameM.audioM.playEffect(AUDIO_TYPE.button)
  163. UiM.Instance.offPanel(PANEL_NAME.NativeAdAwardNode)
  164. switch (this.type) {
  165. case 1:
  166. break
  167. case 2:
  168. UiM.Instance.hallNode.getComponent(Main).resumeAirShip()
  169. break
  170. case 3:
  171. GameM.commonData.updateGold(this.num)
  172. GameM.audioM.playEffect(AUDIO_TYPE.getGold, false)
  173. EffectNode.instance.PlayCoinAnim(0, 20, cc.v2(0, -300));
  174. let s = this.carSp.getComponent(CarSpace)
  175. s.changeType(0)
  176. GameM.commonData.updateBagCarData(s.index.toString(), 0)
  177. this.scheduleOnce(() => {
  178. UiM.Instance.hallNode.getComponent(Main).checkGiftByQucece()
  179. }, 0.1)
  180. break
  181. }
  182. }
  183. }