OverView.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import BasicView from "../../../Engine/Basic/BasicView";
  2. import EventManager from "../../../Engine/Event/EventManager";
  3. import Tool from "../../../Engine/Tool/Tool";
  4. import GameManager from "../../Game/GameManager";
  5. import { ConstObject } from "../../Data/GameDataType";
  6. import GameEventName from "../../Event/GameEventName";
  7. import { SDK } from "../../SDK/sdk";
  8. import SDKManager from "../../SDK/SDKManager";
  9. import GameView from "../GameView/GameView";
  10. import HintView from "../HintView/HintView";
  11. import GameAudioResData from "../../Game/Data/GameMusicResData";
  12. import { _IPlaySound } from "../../../Engine/Audio/Data/AudioConfig";
  13. /**
  14. * 结算页
  15. */
  16. export default class OverView extends BasicView {
  17. public static resPath: string = "OverView";
  18. protected _initView(): void {
  19. let againButton: fgui.GComponent = this.fgui.getChild("againButton").asCom;
  20. Tool.Tool2D.Button.addEvent(againButton, {
  21. "touchend": () => {
  22. this.onAgain();
  23. }
  24. }, this.fgui.id);
  25. let quitButton: fgui.GComponent = this.fgui.getChild("quitButton").asCom;
  26. Tool.Tool2D.Button.addEvent(quitButton, {
  27. "touchend": () => {
  28. this.onQuit();
  29. }
  30. }, this.fgui.id);
  31. this.fgui.getChild("score").asTextField.text = ""+ConstObject.Score;
  32. this.fgui.getChild("record").asTextField.text = ""+ConstObject.Score;
  33. this.fgui.getChild("time").asTextField.text = Tool.converNumberToTimeText(ConstObject.Time);
  34. let rankList: fgui.GList = this.fgui.getChild("rankList").asList;
  35. SDK.onGameEnd(0, ConstObject.Score, 1, 0, 0, (data: any) => {
  36. let stepCount: fgui.GTextField = this.fgui.getChild("stepCount").asTextField;
  37. let consume: fgui.GTextField = this.fgui.getChild("consume").asTextField;
  38. stepCount.text = "相当于步行 " + data["equivalent"] + " 步";
  39. consume.text = "消耗了 " + data["consume"] + " 千卡";
  40. SDK.getRank(0, (data: any) => {
  41. console.log(data);
  42. let rankData: Array<any> = data[1]["list"];
  43. if (rankData == null || rankData.length == null || rankData.length == 0) {
  44. return;
  45. }
  46. let tag: number = 0;
  47. for (let index = 0; index < rankData.length; index++) {
  48. // 判断历史最高分
  49. if (ConstObject.User != null && ConstObject.User["id"] == rankData[index]["user"]["id"]) {
  50. if (ConstObject.Score < rankData[index]["score"]) {
  51. this.fgui.getChild("record").asTextField.text = ""+rankData[index]["score"];
  52. }
  53. tag = (index < 3)? 0:index;
  54. break;
  55. }
  56. }
  57. rankList.numItems = rankData.length;
  58. for (let index = 0; index < rankData.length; index++) {
  59. let item: fgui.GComponent = rankList.getChildAt(index).asCom;
  60. item.getChild("index").asTextField.text = rankData[index]["rank"]+"";
  61. item.getChild("score").asTextField.text = rankData[index]["score"]+"";
  62. item.getChild("name").asTextField.text = rankData[index]["user"]["nickname"];
  63. item.getChild("name").height = item.getChild("name").asTextField.fontSize;
  64. item.getChild("avatar").asLoader.url = rankData[index]["user"]["avatar"];
  65. // 判断历史最高分
  66. // if (ConstObject.User != null && ConstObject.User["id"] == rankData[index]["user"]["id"]) {
  67. // item.getChild("up").visible = (ConstObject.Score > rankData[index]["score"]);
  68. // item.getChild("score").asTextField.text = (item.getChild("up").visible)? ConstObject.Score:rankData[index]["score"];
  69. // }
  70. }
  71. rankList.scrollToView(tag, false);
  72. if (tag > 0) {
  73. rankList.scrollPane.setPosY(rankList.scrollPane.posY+rankList.lineGap);
  74. }
  75. });
  76. });
  77. EventManager.sendEvent(GameEventName.View.View_HideView, GameView);
  78. EventManager.sendEvent(GameEventName.View.View_ShowView, HintView);
  79. //GameManager.setGameView(GameEventName.View.View_HideView);
  80. SDKManager.addButton([
  81. {
  82. button: againButton,
  83. color: [
  84. cc.Color.WHITE,
  85. cc.Color.BLACK,
  86. ],
  87. callback: () => {
  88. this.onAgain();
  89. }
  90. },
  91. {
  92. button: quitButton,
  93. color: [
  94. cc.Color.WHITE,
  95. cc.Color.BLACK,
  96. ],
  97. callback: () => {
  98. this.onQuit();
  99. }
  100. }
  101. ]);
  102. }
  103. protected _refreshView(): void {
  104. }
  105. protected _clearView(): void {
  106. SDKManager.removeButton();
  107. EventManager.sendEvent(GameEventName.Audio.Audio_StopSound, GameAudioResData.GameEnd);
  108. }
  109. protected resize () {
  110. this.fgui.width = fgui.GRoot.inst.width;
  111. }
  112. private onAgain (): void {
  113. let playSound: _IPlaySound = {
  114. url: GameAudioResData.ClickButton,
  115. callback: null,
  116. }
  117. EventManager.sendEvent(GameEventName.Audio.Audio_PlaySound, playSound);
  118. EventManager.sendEvent(GameEventName.View.View_DestroyView, OverView);
  119. EventManager.sendEvent(GameEventName.View.View_DestroyView, HintView);
  120. EventManager.sendEvent(GameEventName.View.View_ShowView, GameView);
  121. GameManager.setGameView(GameEventName.View.View_ShowView);
  122. }
  123. private onQuit (): void {
  124. let playSound: _IPlaySound = {
  125. url: GameAudioResData.ClickButton,
  126. callback: null,
  127. }
  128. EventManager.sendEvent(GameEventName.Audio.Audio_PlaySound, playSound);
  129. EventManager.sendEvent(GameEventName.Game_QuitGame);
  130. }
  131. }