GamePanel.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { _decorator, Component, Label, Node } from 'cc';
  2. import { Global } from '../Common/Global';
  3. import { GameEndTip } from './GameEndTip';
  4. import { AudioManage } from '../Manager/AudioManage';
  5. import { PlayClassAend } from './PlayClassAend';
  6. import { GameMain } from '../Game/GameMain';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('GamePanel')
  9. export class GamePanel extends Component {
  10. @property(Node)
  11. fullRoot: Node = null;
  12. @property(Label)
  13. scoreLabel2: Label = null;
  14. @property(Label)
  15. timeLabel2: Label = null;
  16. @property(Label)
  17. levelLabel2: Label = null;
  18. @property(Node)
  19. gameEndTip: Node = null;
  20. @property(Node)
  21. playAEndTip: Node = null;
  22. @property(Node)
  23. GameMain: Node = null;
  24. protected onLoad(): void {
  25. setTimeout(() => {
  26. this.callAndroid('loading:over');
  27. }, 500);
  28. this.node.on(Global.EventType_ShowTips, (e) => {
  29. this.ShowTips(e.data);
  30. e.propagationStopped = false;
  31. });
  32. }
  33. start() {
  34. if (Global.IsDevelop) {
  35. this.fullRoot.active = true;
  36. } else {
  37. this.fullRoot.active = false;
  38. }
  39. // this.GameMain.getComponent(GameMain).initUI();
  40. }
  41. /** *
  42. * 刷新UI
  43. */
  44. RefreshUI() {
  45. // this.GameMain.initUI();
  46. this.GameMain.getComponent(GameMain).initUI();
  47. }
  48. RefreshTime(timer: number) {
  49. // const minutes = Math.floor(timer / 60);
  50. // const seconds = timer % 60;
  51. if (!Global.IsDevelop) {
  52. this.callAndroid('setTime:' + timer);
  53. } else {
  54. this.timeLabel2.string = timer.toString();
  55. }
  56. }
  57. RefreshScore(score: number) {
  58. if (!Global.IsDevelop) {
  59. this.callAndroid('setScore:' + score);
  60. } else {
  61. this.scoreLabel2.string = score.toString();
  62. }
  63. }
  64. RefreshLevel(level: number) {
  65. if (!Global.IsDevelop) {
  66. this.callAndroid('setLevel:' + level);
  67. } else {
  68. this.levelLabel2.string = '第' + level + '关';
  69. }
  70. }
  71. GameOver() {
  72. this.GameMain.getComponent(GameMain).gameOver();
  73. }
  74. ShowTips(tip: string) {
  75. // this.tipLabelEffect.setText(tip);
  76. console.log('tip:' + tip);
  77. AudioManage.instance.setBgVolume(0.5);
  78. if (!Global.IsDevelop) {
  79. this.callAndroid('voice:' + tip);
  80. }
  81. }
  82. callAndroid(data: string) {
  83. let ss: any = window;
  84. if (typeof ss.AndroidInterface !== 'undefined') {
  85. ss.AndroidInterface.performAndroidMethod(data);
  86. } else {
  87. console.log('安卓方法未定义');
  88. }
  89. }
  90. showGameEndTip(curLevel: number, curScore: number, totalScore: number, result: boolean, isTime: boolean) {
  91. AudioManage.instance.pauseMusic();
  92. if (result) {
  93. //播放成功音效
  94. AudioManage.instance.playSound(Global.Audio_nextLev);
  95. } else {
  96. //播放失败音效
  97. AudioManage.instance.playSound(Global.Audio_achieve);
  98. }
  99. this.scheduleOnce(function () {
  100. this.gameEndTip.active = true;
  101. AudioManage.instance.pauseMusic();
  102. const gameEndTipScr = this.gameEndTip.getComponent(GameEndTip);
  103. gameEndTipScr.showEndView(curLevel, curScore, totalScore, result, isTime);
  104. }, 1.5);
  105. }
  106. showPlayAendTip(curScore: number) {
  107. this.scheduleOnce(function () {
  108. this.playAEndTip.active = true;
  109. //AudioManage.instance.pauseMusic();
  110. const palyATipScr = this.playAEndTip.getComponent(PlayClassAend);
  111. palyATipScr.setResultScore(curScore);
  112. }, 1.5);
  113. }
  114. hideLevelUi() {
  115. // this.levelRoot.active = false;
  116. // console.log('leveRoot:');
  117. }
  118. }