GamePanel.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. RefreshTime(timer: number) {
  45. // const minutes = Math.floor(timer / 60);
  46. // const seconds = timer % 60;
  47. if (!Global.IsDevelop) {
  48. this.callAndroid('setTime:' + timer);
  49. }else{
  50. this.timeLabel2.string = timer.toString();
  51. }
  52. }
  53. RefreshScore(score: number) {
  54. if (!Global.IsDevelop) {
  55. this.callAndroid('setScore:' + score);
  56. }else{
  57. this.scoreLabel2.string = score.toString();
  58. }
  59. }
  60. RefreshLevel(level: number) {
  61. if (!Global.IsDevelop) {
  62. this.callAndroid('setLevel:' + level);
  63. }else{
  64. this.levelLabel2.string = '第' + level + '关';
  65. }
  66. }
  67. GameOver() {
  68. this.GameMain.getComponent(GameMain).gameOver();
  69. }
  70. ShowTips(tip: string) {
  71. // this.tipLabelEffect.setText(tip);
  72. console.log('tip:'+tip);
  73.  AudioManage.instance.setBgVolume(0.5);
  74. if (!Global.IsDevelop) {
  75. this.callAndroid('voice:' + tip);
  76. }
  77. }
  78. callAndroid(data:string)
  79. {
  80. let ss: any = window;
  81. if (typeof ss.AndroidInterface !== 'undefined') {
  82. ss.AndroidInterface.performAndroidMethod(data);
  83. } else {
  84. console.log('安卓方法未定义');
  85. }
  86. }
  87. showGameEndTip(curLevel: number, curScore: number, totalScore: number, result: boolean, isTime: boolean) {
  88. AudioManage.instance.pauseMusic();
  89. if( result ){
  90. //播放成功音效
  91. AudioManage.instance.playSound(Global.Audio_nextLev);
  92. }else{
  93. //播放失败音效
  94. AudioManage.instance.playSound(Global.Audio_achieve);
  95. }
  96. this.scheduleOnce(function () {
  97. this.gameEndTip.active = true;
  98. AudioManage.instance.pauseMusic();
  99. const gameEndTipScr = this.gameEndTip.getComponent(GameEndTip);
  100. gameEndTipScr.showEndView(curLevel, curScore, totalScore, result,isTime);
  101. }, 1.5);
  102. }
  103. showPlayAendTip(curScore: number) {
  104. this.scheduleOnce(function () {
  105. this.playAEndTip.active = true;
  106. //AudioManage.instance.pauseMusic();
  107. const palyATipScr = this.playAEndTip.getComponent(PlayClassAend);
  108. palyATipScr.setResultScore(curScore);
  109. }, 1.5);
  110. }
  111. hideLevelUi() {
  112. // this.levelRoot.active = false;
  113. // console.log('leveRoot:');
  114. }
  115. }