GetPropUI.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import { PROPTYPE, SURPRISETASKTYPE, VIDEOADSTATE, VIDEOTYPE } from "../data/Enum";
  8. import GamePlay from "../GamePlay";
  9. import DataMgr from "../mgr/DataMgr";
  10. import EffectMgr from "../mgr/EffectMgr";
  11. import GameMgr, { UI_NAME } from "../mgr/GameMgr";
  12. const { ccclass, property } = cc._decorator;
  13. @ccclass
  14. export default class GetPropUI extends cc.Component {
  15. @property(cc.Node)
  16. public node_rectBg: cc.Node = null;
  17. @property(cc.Node)
  18. public node_closeBtn: cc.Node = null;
  19. @property(cc.Node)
  20. public node_getBtn: cc.Node = null;
  21. @property(cc.Node)
  22. node_prop: cc.Node = null;
  23. // LIFE-CYCLE CALLBACKS:
  24. // onLoad () {}
  25. start() {
  26. this.adapt();
  27. this.initEvent();
  28. // mk.ad.showBannerAd();
  29. //mk.ad.showNativeAd();
  30. mk.ad.showInterAd(0);
  31. }
  32. // update (dt) {}
  33. onEnable() {
  34. GameMgr.Inst.sendEvent(UI_NAME.GetPropUI, `进入获取道具界面`);
  35. // //显示广告
  36. // AdMgr.Inst.showNativeAd(4, true);
  37. this.init();
  38. }
  39. onDisable() {
  40. GamePlay.Inst.curPropType = PROPTYPE.Null;
  41. // AdMgr.Inst.destroyNativeAd();
  42. }
  43. /**适配 */
  44. adapt() {
  45. this.node_rectBg.setContentSize(cc.winSize.width, cc.winSize.height);
  46. }
  47. init() {
  48. for (var i = 0; i < this.node_prop.childrenCount; i++) {
  49. let prop = this.node_prop.children[i];
  50. let propCode = prop.children[0] ? prop.children[0].name : "";
  51. if (propCode == GamePlay.Inst.curPropType) {
  52. prop.active = true;
  53. }
  54. else {
  55. prop.active = false;
  56. }
  57. }
  58. }
  59. /**初始化事件 */
  60. initEvent() {
  61. this.node_getBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  62. this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  63. }
  64. onClick(event: cc.Event.EventTouch) {
  65. //AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  66. mk.audio.playEffect("button");
  67. switch (event.currentTarget) {
  68. case this.node_getBtn:
  69. this.onClickGet();
  70. break;
  71. case this.node_closeBtn:
  72. this.onClickClose();
  73. break;
  74. }
  75. }
  76. onClickClose() {
  77. GameMgr.Inst.sendEvent(UI_NAME.GetPropUI, "点击关闭按钮");
  78. mk.ui.closePanel("GetPropUI");
  79. }
  80. /**点击获取 */
  81. onClickGet() {
  82. GameMgr.Inst.sendEvent(UI_NAME.GetPropUI, `点击${GamePlay.Inst.curPropType}按钮`);
  83. mk.ad.watchAd((ifsuccess: boolean) => {
  84. this.watchCallBack(ifsuccess)
  85. });
  86. }
  87. /**观看回调 */
  88. watchCallBack(ifSuccess: boolean = false) {
  89. mk.tip.pop("观看失败,无法领取奖励哦")
  90. if (ifSuccess) {
  91. this.watchSuccess();
  92. mk.tip.pop("观看成功,获取奖励")
  93. }
  94. else {
  95. this.watchFailed();
  96. mk.tip.pop("观看失败,无法领取奖励哦")
  97. }
  98. }
  99. /**观看成功 */
  100. watchSuccess() {
  101. GameMgr.Inst.sendEvent(UI_NAME.GetPropUI, `视频获取${GamePlay.Inst.curPropType}道具成功`);
  102. EffectMgr.Inst.addTip("观看视频成功,获得道具");
  103. DataMgr.Inst.updatePropNum(1, GamePlay.Inst.curPropType, 1);
  104. // mk.ui.closePanel("GetPropUI")
  105. }
  106. /**观看失败 */
  107. watchFailed() {
  108. GameMgr.Inst.sendEvent(UI_NAME.GetPropUI, `视频获取${GamePlay.Inst.curPropType}道具失败`);
  109. // EffectMgr.Inst.addTip("观看视频失败,请稍后再试");
  110. }
  111. }