OverView.ts 5.8 KB

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