GetPropUI.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * 游戏内获取道具弹窗
  3. */
  4. import { PROPTYPE } from "../data/Enum";
  5. import GamePlay from "../GamePlay";
  6. import DataMgr from "../mgr/DataMgr";
  7. import EffectMgr from "../mgr/EffectMgr";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class GetPropUI extends cc.Component {
  11. @property(cc.Node)
  12. public node_rectBg: cc.Node = null;
  13. @property(cc.Node)
  14. public node_closeBtn: cc.Node = null;
  15. @property(cc.Node)
  16. public node_getBtn: cc.Node = null;
  17. @property(cc.Node)
  18. node_prop: cc.Node = null;
  19. start() {
  20. this.adapt();
  21. this.initEvent();
  22. }
  23. onEnable() {
  24. this.init();
  25. }
  26. onDisable() {
  27. GamePlay.Inst.curPropType = PROPTYPE.Null;
  28. }
  29. /**适配 */
  30. adapt() {
  31. this.node_rectBg.setContentSize(cc.winSize.width, cc.winSize.height);
  32. }
  33. init() {
  34. for (var i = 0; i < this.node_prop.childrenCount; i++) {
  35. let prop = this.node_prop.children[i];
  36. let propCode = prop.children[0] ? prop.children[0].name : "";
  37. if (propCode == GamePlay.Inst.curPropType) {
  38. prop.active = true;
  39. }
  40. else {
  41. prop.active = false;
  42. }
  43. }
  44. }
  45. /**初始化事件 */
  46. initEvent() {
  47. this.node_getBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  48. this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  49. }
  50. onClick(event: cc.Event.EventTouch) {
  51. mk.audio.playEffect("button");
  52. switch (event.currentTarget) {
  53. case this.node_getBtn:
  54. this.onClickGet();
  55. break;
  56. case this.node_closeBtn:
  57. this.onClickClose();
  58. break;
  59. }
  60. }
  61. onClickClose() {
  62. mk.ui.closePanel("GetPropUI");
  63. }
  64. /**点击获取 */
  65. onClickGet() {
  66. GamePlay.Inst.cancelShowInter();
  67. mk.ad.watchAd((ifsuccess: boolean,request_id: string) => {
  68. this.watchCallBack(ifsuccess)
  69. });
  70. }
  71. /**观看回调 */
  72. watchCallBack(ifSuccess: boolean = false) {
  73. if (ifSuccess) {
  74. this.scheduleOnce(() => {
  75. mk.tip.pop("观看成功,获取奖励")
  76. }, 0)
  77. this.watchSuccess();
  78. }
  79. else {
  80. this.scheduleOnce(() => {
  81. mk.tip.pop("观看失败,无法领取奖励哦")
  82. }, 0)
  83. this.watchFailed();
  84. }
  85. }
  86. /**观看成功 */
  87. watchSuccess() {
  88. EffectMgr.Inst.addTip("观看视频成功,获得道具");
  89. DataMgr.Inst.updatePropNum(1, GamePlay.Inst.curPropType, 1);
  90. }
  91. /**观看失败 */
  92. watchFailed() {
  93. // EffectMgr.Inst.addTip("观看视频失败,请稍后再试");
  94. }
  95. }