StartPanel.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { _decorator, Component, Label, Node,Animation, VideoPlayer, RichText, WebView } from 'cc';
  2. import { GameManager } from '../Manager/GameManager';
  3. import { HttpManager } from '../Manager/HttpManager';
  4. import { Global } from '../Common/Global';
  5. import { ResponseData } from '../Data/ResponseData';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('StartPanel')
  8. export class StartPanel extends Component {
  9. @property(WebView)
  10. videoPlayer:WebView=null;
  11. @property(Label)
  12. gameNameLabel:Label=null;
  13. @property(Label)
  14. gameDesnLabel:Label=null;
  15. @property(Label)
  16. startBtnLabel:Label=null;
  17. @property(Label)
  18. bestRecord:Label=null;
  19. @property(Label)
  20. sortLabel:Label=null;
  21. @property(Node)
  22. countDownPanel:Node=null;
  23. @property(Node)
  24. exitPanel:Node=null;
  25. @property(Animation)
  26. countDownAni:Animation=null;
  27. start() {
  28. if(!Global.IsDevelop)
  29. {
  30. this.initGameData();
  31. }
  32. }
  33. //初始化游戏内容数据
  34. initGameData()
  35. {
  36. let playClass = this.getParameterByName('playClass');
  37. const requestData = { gameCode:Global.GameCode,playClass};
  38. const jsonRequestData = JSON.stringify(requestData);
  39. HttpManager.Instanct().httpPost(Global.Net_DetailUrl, jsonRequestData)
  40. .then(data => {
  41. console.log('responseData0:'+JSON.stringify(data));
  42. const jsonData=data as ResponseData;
  43. if(jsonData.success===true)
  44. {
  45. this.gameNameLabel.string=jsonData.data.gameName;
  46. this.gameDesnLabel.string=jsonData.data.desn
  47. this.videoPlayer.url=jsonData.data.gameVideoUrl;
  48. this.sortLabel.string=jsonData.data.gameType;
  49. this.bestRecord.string='最佳记录:'+jsonData.data.gameMaxScore;
  50. GameManager.getInstance().gameTotalTime= jsonData.data.gameTotalTime;
  51. GameManager.getInstance().gameTotalScore= parseInt(jsonData.data.gameTotalScore);
  52. //this.scheduleOnce(this.playDesnVideo,1);
  53. }else{
  54. console.log('请求失败');
  55. }
  56. })
  57. .catch(error => {
  58. console.error(error);
  59. });
  60. }
  61. //得到url参数值
  62. getParameterByName(name) {
  63. let url = window.location.href;
  64. name = name.replace(/[\[\]]/g, '\\$&');
  65. let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
  66. results = regex.exec(url);
  67. if (!results) return null;
  68. if (!results[2]) return '';
  69. return decodeURIComponent(results[2].replace(/\+/g, ' '));
  70. }
  71. playDesnVideo()
  72. {
  73. // this.videoPlayer.play();
  74. }
  75. quitBtn()
  76. {
  77. GameManager.getInstance().saveDataToServer(0);
  78. let ss:any=window;
  79. if (typeof ss.AndroidInterface !== 'undefined') {
  80. ss.AndroidInterface.performAndroidMethod('finishActivity');
  81. } else {
  82. console.log('安卓方法未定义');
  83. }
  84. }
  85. setBestRecord(num:number)
  86. {
  87. this.bestRecord.string='最佳记录:'+num;
  88. }
  89. cancelBtn()
  90. {
  91. this.exitPanel.active=false;
  92. this.videoPlayer.node.active=true;
  93. }
  94. showExitPanel()
  95. {
  96. this.exitPanel.active=true;
  97. this.videoPlayer.node.active=false;
  98. }
  99. startGameBtn()
  100. {
  101. this.node.active=false;
  102. if(!Global.IsFirstGame)
  103. {
  104. this.countDownPanel.active=true;
  105. this.countDownAni.play('counDownAni');
  106. this.scheduleOnce(this.showGamePanel,3);
  107. this.startBtnLabel.string='继续游戏';
  108. }else{
  109. GameManager.getInstance().ContinueGame();
  110. }
  111. }
  112. showGamePanel()
  113. {
  114. this.countDownPanel.active=false;
  115. Global.IsFirstGame=true;
  116. GameManager.getInstance().EnterGameScene();
  117. }
  118. }