GameOver.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { _decorator, director } from 'cc';
  2. import { UIBase } from '../../GameFrameWork/UIBase';
  3. import { resMgr } from '../../../Frames/ResourcesMgr';
  4. import { GameOverData } from './Data/GameOverData';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('GameOver')
  7. export class GameOver extends UIBase {
  8. // //是否胜利
  9. // win: boolean = null;
  10. // killCount: number = null;
  11. // killPercent: number = null;
  12. // //金币奖励
  13. // killAward: number = null;
  14. // lifeAward: number = null;
  15. // stageClearAward: number = null;
  16. // totalAward: number = null;
  17. // //经验奖励
  18. // xp: number = null;
  19. // //钻石奖励
  20. // lifeDia: number = null;
  21. // stageClearDia: number = null;
  22. // totalDia: number = null;
  23. gameOverDt: GameOverData = null;
  24. protected onStart() {
  25. this.gameOverDt = GameOverData.Instance;
  26. this.onBtnClick("_btnBack", this._onBtnBack);
  27. this.config();
  28. }
  29. // config() {
  30. // this.getSprite("_gameOverUITitle").spriteFrame = this.win ?
  31. // resMgr.getSpriteFrame("GameWin") :
  32. // resMgr.getSpriteFrame("GameOver");
  33. // this.getLabel("_labelRight").string = this.win ? "下一关" : "重新开始";
  34. // const labelDate = {
  35. // "_killCount":this.killCount,
  36. // "_lifePercent":`${this.killPercent} %`,
  37. // "_kill":this.killAward,
  38. // "_life":this.lifeAward,
  39. // "_stageClear":this.stageClearAward,
  40. // "_total":this.totalAward,
  41. // "_xp":this.xp,
  42. // "_lifeDia":this.lifeDia,
  43. // "_stageClearDia":this.stageClearDia,
  44. // "_totalDia":this.totalDia,
  45. // }
  46. // this._setLabels(labelDate);
  47. // // this.getLabel("_killCount").string = String(this.killCount);
  48. // // this.getLabel("_lifePercent").string = `${String(this.killPercent)} %`;
  49. // // this.getLabel("_kill").string = String(this.killAward);
  50. // // this.getLabel("_life").string = String(this.lifeAward);
  51. // // this.getLabel("_stageClear").string = String(this.stageClearAward);
  52. // // this.getLabel("_total").string = String(this.totalAward);
  53. // // this.getLabel("_xp").string = String(this.xp);
  54. // // this.getLabel("_lifeDia").string = String(this.lifeDia);
  55. // // this.getLabel("_stageClearDia").string = String(this.stageClearDia);
  56. // // this.getLabel("_totalDia").string = String(this.totalDia);
  57. // }
  58. // private _setLabels(labelDate){
  59. // for(const [labelName, value] of labelDate){
  60. // this.getLabel(labelName).string = String(value);
  61. // }
  62. // }
  63. config() {
  64. this.getSprite("_gameOverUITitle").spriteFrame = this.gameOverDt.Win ?
  65. resMgr.getSpriteFrame("GameWin") :
  66. resMgr.getSpriteFrame("GameOver");
  67. this.getLabel("_labelRight").string = this.gameOverDt.Win ? "下一关" : "重新开始";
  68. const labelData = new Map<string, number | string>();
  69. labelData.set("_killCount", this.gameOverDt.KillCount);
  70. labelData.set("_lifePercent", `${this.gameOverDt.LifePercent} %`);
  71. labelData.set("_kill", this.gameOverDt.KillAward);
  72. labelData.set("_life", this.gameOverDt.LifeAward);
  73. labelData.set("_stageClear", this.gameOverDt.StageClearAward);
  74. labelData.set("_total", this.gameOverDt.TotalAward);
  75. labelData.set("_xp", this.gameOverDt.Xp);
  76. labelData.set("_lifeDia", this.gameOverDt.LifeDia);
  77. labelData.set("_stageClearDia", this.gameOverDt.StageClearDia);
  78. labelData.set("_totalDia", this.gameOverDt.TotalDia);
  79. this._setLabels(labelData);
  80. }
  81. private _setLabels(labelData: Map<string, number | string>) {
  82. for (const [labelName, value] of labelData.entries()) {
  83. this.getLabel(labelName).string = String(value);
  84. }
  85. }
  86. private _onBtnBack(){
  87. //销毁
  88. this.gameOverDt.clearData();
  89. this.hide(true);
  90. director.loadScene("StartScene");
  91. }
  92. }