GetPropUI.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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(4);
  30. // mk.ad.showInterAd(0);
  31. }
  32. // update (dt) {}
  33. onEnable() {
  34. GameMgr.Inst.sendEvent(UI_NAME.GetPropUI, `进入获取道具界面`);
  35. this.init();
  36. }
  37. onDisable() {
  38. GamePlay.Inst.curPropType = PROPTYPE.Null;
  39. }
  40. /**适配 */
  41. adapt() {
  42. this.node_rectBg.setContentSize(cc.winSize.width, cc.winSize.height);
  43. }
  44. init() {
  45. for (var i = 0; i < this.node_prop.childrenCount; i++) {
  46. let prop = this.node_prop.children[i];
  47. let propCode = prop.children[0] ? prop.children[0].name : "";
  48. if (propCode == GamePlay.Inst.curPropType) {
  49. prop.active = true;
  50. }
  51. else {
  52. prop.active = false;
  53. }
  54. }
  55. }
  56. /**初始化事件 */
  57. initEvent() {
  58. this.node_getBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  59. this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  60. }
  61. onClick(event: cc.Event.EventTouch) {
  62. //AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  63. mk.audio.playEffect("button");
  64. switch (event.currentTarget) {
  65. case this.node_getBtn:
  66. this.onClickGet();
  67. break;
  68. case this.node_closeBtn:
  69. this.onClickClose();
  70. break;
  71. }
  72. }
  73. onClickClose() {
  74. GameMgr.Inst.sendEvent(UI_NAME.GetPropUI, "点击关闭按钮");
  75. mk.ui.closePanel("GetPropUI");
  76. }
  77. /**点击获取 */
  78. onClickGet() {
  79. GameMgr.Inst.sendEvent(UI_NAME.GetPropUI, `点击${GamePlay.Inst.curPropType}按钮`);
  80. GamePlay.Inst.cancelShowInter();
  81. mk.ad.watchAd((ifsuccess: boolean) => {
  82. this.watchCallBack(ifsuccess)
  83. });
  84. }
  85. /**观看回调 */
  86. watchCallBack(ifSuccess: boolean = false) {
  87. if (ifSuccess) {
  88. this.scheduleOnce(() => {
  89. mk.tip.pop("观看成功,获取奖励")
  90. }, 0)
  91. this.watchSuccess();
  92. }
  93. else {
  94. this.scheduleOnce(() => {
  95. mk.tip.pop("观看失败,无法领取奖励哦")
  96. }, 0)
  97. this.watchFailed();
  98. }
  99. }
  100. /**观看成功 */
  101. watchSuccess() {
  102. GameMgr.Inst.sendEvent(UI_NAME.GetPropUI, `视频获取${GamePlay.Inst.curPropType}道具成功`);
  103. EffectMgr.Inst.addTip("观看视频成功,获得道具");
  104. DataMgr.Inst.updatePropNum(1, GamePlay.Inst.curPropType, 1);
  105. // mk.ui.closePanel("GetPropUI")
  106. }
  107. /**观看失败 */
  108. watchFailed() {
  109. GameMgr.Inst.sendEvent(UI_NAME.GetPropUI, `视频获取${GamePlay.Inst.curPropType}道具失败`);
  110. // EffectMgr.Inst.addTip("观看视频失败,请稍后再试");
  111. }
  112. }