GameOverUI.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 GameConst from "../data/GameConst";
  8. import GamePlay from "../GamePlay";
  9. import PlayerConst from "../data/PlayerConst";
  10. import GameMgr, { UI_NAME } from "../mgr/GameMgr";
  11. import EffectMgr from "../mgr/EffectMgr";
  12. import Util from "../util/Util";
  13. import { EVENT_TYPE } from "../../game/data/GameData";
  14. const { ccclass, property } = cc._decorator;
  15. @ccclass
  16. export default class GameOverUI extends cc.Component {
  17. @property(cc.Node)
  18. node_bg: cc.Node = null;
  19. @property(cc.Node)
  20. node_score: cc.Node = null;
  21. @property(cc.Label)
  22. label_score: cc.Label = null;
  23. @property(cc.Node)
  24. node_cashNum: cc.Node = null;
  25. @property(cc.Label)
  26. label_cashNum: cc.Label = null;
  27. @property(cc.Node)
  28. node_shopScoreNum: cc.Node = null;
  29. @property(cc.Label)
  30. label_shopScoreNum: cc.Label = null;
  31. @property(cc.Node)
  32. node_homeBtn: cc.Node = null;
  33. @property(cc.Node)
  34. node_continueBtn: cc.Node = null;
  35. @property(sp.Skeleton)
  36. skAni_title: sp.Skeleton = null;
  37. // LIFE-CYCLE CALLBACKS:
  38. // onLoad () {}
  39. start() {
  40. this.node_bg.setContentSize(cc.winSize.width, cc.winSize.height);
  41. this.initEvent();
  42. }
  43. onEnable() {
  44. //正常埋点
  45. GameMgr.Inst.sendEvent(UI_NAME.GameOverUI, `进入关卡结算界面`);
  46. //关卡分析
  47. GameMgr.Inst.sendEvent("PassLevel", `第${PlayerConst.levelNum}关`);
  48. this.skAni_title.setAnimation(0, "chushi", false);
  49. // DataMgr.Inst.updateJuliangApi();
  50. this.node_continueBtn.active = true;
  51. this.node_homeBtn.active = true;
  52. this.initScore();
  53. this.initCashNum();
  54. }
  55. onDisable() {
  56. this.node_score.active = false;
  57. this.node_cashNum.active = false;
  58. this.node_shopScoreNum.active = false;
  59. this.node_continueBtn.active = false;
  60. this.node_homeBtn.active = false;
  61. }
  62. // update (dt) {}
  63. init() {
  64. //this.initSwitchState();
  65. }
  66. initScore() {
  67. this.label_score.string = GamePlay.Inst.finalGetScore.toString();
  68. // this.label_score.string = Game.Inst.curGetScore.toString();
  69. //为避免视频之后 资源显示问题(观看视频之后,文本有可能显示异常)
  70. this.node_score.active = true;
  71. }
  72. initCashNum() {
  73. // let num = Math.round((PlayerConst.cashNum * 100)) / 100;
  74. let num = Util.numberFixed(PlayerConst.cashNum, 2);
  75. this.label_cashNum.string = `${num}`;
  76. // //为避免视频之后 资源显示问题(观看视频之后,文本有可能显示异常)
  77. this.node_cashNum.active = true;
  78. }
  79. initEvent() {
  80. this.node_continueBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  81. this.node_homeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  82. this.skAni_title.setCompleteListener(() => {
  83. //LogUtil.log("skAni,.,.,.,.,.............")
  84. this.skAni_title.setAnimation(0, "xunhuan", true);
  85. });
  86. //如果未授权则添加监听
  87. if (!GameConst.isAuth) {
  88. mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  89. }
  90. }
  91. onClickBtn(event: cc.Event.EventTouch) {
  92. //AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  93. mk.audio.playEffect("ef_button_click");
  94. switch (event.currentTarget) {
  95. case this.node_homeBtn:
  96. this.onClickHomeBtn();
  97. break;
  98. case this.node_continueBtn:
  99. this.onClickContinueBtn();
  100. break;
  101. }
  102. }
  103. onClickHomeBtn() {
  104. if (!GamePlay.Inst.ifGetPass) {
  105. EffectMgr.Inst.addTip("结算中,等1秒再试哈");
  106. return;
  107. }
  108. GameMgr.Inst.sendEvent(UI_NAME.GameOverUI, "点击返回按钮");
  109. // this.node.active = false;
  110. mk.ui.closePanel("GameOverUI");
  111. GamePlay.Inst.nextLevel(false);
  112. }
  113. onClickContinueBtn() {
  114. if (!GamePlay.Inst.ifGetPass) {
  115. EffectMgr.Inst.addTip("结算中,等1秒再试哈");
  116. return;
  117. }
  118. GameMgr.Inst.sendEvent(UI_NAME.GameOverUI, "点击继续按钮");
  119. if (PlayerConst.energyNum <= 0) {
  120. EffectMgr.Inst.addTip("体力不足,请补充体力");
  121. // this.node.active = false;
  122. mk.ui.closePanel("GameOverUI")
  123. mk.ui.openPanel("prefab/game/uiPanel/GetEnergyUI")
  124. return;
  125. }
  126. GamePlay.Inst.nextLevel();
  127. mk.ui.closePanel("GameOverUI")
  128. }
  129. //自定义事件---------------------------------------------------------------------
  130. /**微信授权返回 */
  131. onWxAuthBack() {
  132. mk.ui.closePanel("GameOverUI")
  133. mk.event.remove(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  134. }
  135. }