GamePanel.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { _decorator, assetManager, Component, ImageAsset, Label, Node, SpriteFrame, Texture2D, Sprite } 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. //import { GameMain } from '../Game/GameMain';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('GamePanel')
  10. export class GamePanel extends Component {
  11. @property(Node)
  12. fullRoot: Node = null;
  13. @property(Label)
  14. scoreLabel2: Label = null;
  15. @property(Label)
  16. timeLabel2: Label = null;
  17. @property(Label)
  18. levelLabel2: Label = null;
  19. @property(Node)
  20. gameEndTip: Node = null;
  21. @property(Node)
  22. GameMain: Node = null;
  23. protected onLoad(): void {
  24. setTimeout(() => {
  25. this.callAndroid('loading:over');
  26. }, 500);
  27. this.node.on(Global.EventType_ShowTips, (e) => {
  28. this.ShowTips(e.data);
  29. e.propagationStopped = false;
  30. });
  31. }
  32. start() {
  33. if (Global.IsDevelop) {
  34. this.fullRoot.active = true;
  35. } else {
  36. this.fullRoot.active = false;
  37. }
  38. }
  39. /** *
  40. * 刷新UI
  41. */
  42. RefreshTime(timer: number) {
  43. // const minutes = Math.floor(timer / 60);
  44. // const seconds = timer % 60;
  45. if (!Global.IsDevelop) {
  46. this.callAndroid('setTime:' + timer);
  47. } else {
  48. this.timeLabel2.string = timer.toString();
  49. }
  50. }
  51. RefreshScore(score: number) {
  52. if (!Global.IsDevelop) {
  53. this.callAndroid('setScore:' + score);
  54. } else {
  55. this.scoreLabel2.string = score.toString();
  56. }
  57. }
  58. RefreshLevel(level: number) {
  59. if (!Global.IsDevelop) {
  60. this.callAndroid('setLevel:' + level);
  61. } else {
  62. this.levelLabel2.string = '第' + level + '关';
  63. }
  64. }
  65. RefreshUI() {
  66. this.GameMain.getComponent(GameMain).startGame();
  67. // this.GameMain.getComponent(GameMain).initUI();
  68. }
  69. GameOver() {
  70. // this.GameMain.gameOver();
  71. }
  72. ShowTips(tip: string) {
  73. // this.tipLabelEffect.setText(tip);
  74. console.log('tip:' + tip);
  75. AudioManage.instance.setBgVolume(0.5);
  76. if (!Global.IsDevelop) {
  77. this.callAndroid('voice:' + tip);
  78. }
  79. }
  80. callAndroid(data: string) {
  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. }