GamePanel.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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(GameMain)
  21. GameMain: GameMain = null;
  22. protected onLoad(): void {
  23. setTimeout(() => {
  24. this.callAndroid('loading:over');
  25. }, 500);
  26. this.node.on(Global.EventType_ShowTips, (e) => {
  27. this.ShowTips(e.data);
  28. e.propagationStopped = false;
  29. });
  30. }
  31. start() {
  32. if (Global.IsDevelop) {
  33. this.fullRoot.active = true;
  34. }else{
  35. this.fullRoot.active = false;
  36. }
  37. }
  38. /** *
  39. * 刷新UI
  40. */
  41. RefreshTime(timer: number) {
  42. // const minutes = Math.floor(timer / 60);
  43. // const seconds = timer % 60;
  44. if (!Global.IsDevelop) {
  45. this.callAndroid('setTime:' + timer);
  46. }else{
  47. this.timeLabel2.string = timer.toString();
  48. }
  49. }
  50. RefreshScore(score: number) {
  51. if (!Global.IsDevelop) {
  52. this.callAndroid('setScore:' + score);
  53. }else{
  54. this.scoreLabel2.string = score.toString();
  55. }
  56. }
  57. RefreshLevel(level: number) {
  58. if (!Global.IsDevelop) {
  59. this.callAndroid('setLevel:' + level);
  60. }else{
  61. this.levelLabel2.string = '第' + level + '关';
  62. }
  63. }
  64. RefreshUI() {
  65. this.GameMain.startGame();
  66. // this.GameMain.getComponent(GameMain).initUI();
  67. }
  68. GameOver() {
  69. this.GameMain.gameOver();
  70. }
  71. ShowTips(tip: string) {
  72. // this.tipLabelEffect.setText(tip);
  73. console.log('tip:'+tip);
  74. //  AudioManage.instance.setBgVolume(0.5);
  75. if (!Global.IsDevelop) {
  76. this.callAndroid('voice:' + tip);
  77. }
  78. }
  79. callAndroid(data:string)
  80. {
  81. let ss: any = window;
  82. if (typeof ss.AndroidInterface !== 'undefined') {
  83. ss.AndroidInterface.performAndroidMethod(data);
  84. } else {
  85. console.log('安卓方法未定义');
  86. }
  87. }
  88. showGameEndTip(curLevel: number, curScore: number, totalScore: number, result: boolean, isTime: boolean) {
  89. AudioManage.instance.pauseMusic();
  90. this.scheduleOnce(function () {
  91. this.gameEndTip.active = true;
  92. AudioManage.instance.pauseMusic();
  93. const gameEndTipScr = this.gameEndTip.getComponent(GameEndTip);
  94. gameEndTipScr.showEndView(curLevel, curScore, totalScore, result,isTime);
  95. }, 1.5);
  96. }
  97. showPlayAendTip(curScore: number) {
  98. this.scheduleOnce(function () {
  99. this.playAEndTip.active = true;
  100. //AudioManage.instance.pauseMusic();
  101. const palyATipScr = this.playAEndTip.getComponent(PlayClassAend);
  102. palyATipScr.setResultScore(curScore);
  103. }, 1.5);
  104. }
  105. hideLevelUi() {
  106. // this.levelRoot.active = false;
  107. // console.log('leveRoot:');
  108. }
  109. }