123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import BasicView from "../../../Engine/Basic/BasicView";
- import EventManager from "../../../Engine/Event/EventManager";
- import Tool from "../../../Engine/Tool/Tool";
- import GameManager from "../../Game/GameManager";
- import { ConstObject } from "../../Data/GameDataType";
- import GameMusicResData from "../../Game/Data/GameMusicResData";
- import GameEventName from "../../Event/GameEventName";
- import { SDK } from "../../SDK/sdk";
- import SDKManager from "../../SDK/SDKManager";
- import GameView from "../GameView/GameView";
- import HintView from "../HintView/HintView";
- /**
- * 结算页
- */
- export default class OverView extends BasicView {
- public static resPath: string = "OverView";
- protected _initView(): void {
- let againButton: fgui.GComponent = this.fgui.getChild("againButton").asCom;
- Tool.Tool2D.Button.addEvent(againButton, {
- "touchend": () => {
- this.onAgain();
- }
- }, this.fgui.id);
- let quitButton: fgui.GComponent = this.fgui.getChild("quitButton").asCom;
- Tool.Tool2D.Button.addEvent(quitButton, {
- "touchend": () => {
- this.onQuit();
- }
- }, this.fgui.id);
- this.fgui.getChild("score").asTextField.text = ""+ConstObject.Score;
- this.fgui.getChild("record").asTextField.text = ""+ConstObject.Score;
- this.fgui.getChild("time").asTextField.text = Tool.converNumberToTimeText(ConstObject.Time);
- let rankList: fgui.GList = this.fgui.getChild("rankList").asList;
-
- SDK.onGameEnd(0, ConstObject.Score, 1, 0, 0, (data: any) => {
- let stepCount: fgui.GTextField = this.fgui.getChild("stepCount").asTextField;
- let consume: fgui.GTextField = this.fgui.getChild("consume").asTextField;
- stepCount.text = "相当于步行 " + data["equivalent"] + " 步";
- consume.text = "消耗了 " + data["consume"] + " 千卡";
- SDK.getRank(0, (data: any) => {
- console.log(data);
- let rankData: Array<any> = data[1]["list"];
- if (rankData == null || rankData.length == null || rankData.length == 0) {
- return;
- }
-
- let tag: number = 0;
- for (let index = 0; index < rankData.length; index++) {
- // 判断历史最高分
- if (ConstObject.User != null && ConstObject.User["id"] == rankData[index]["user"]["id"]) {
- if (ConstObject.Score < rankData[index]["score"]) {
- this.fgui.getChild("record").asTextField.text = ""+rankData[index]["score"];
- }
- tag = (index < 3)? 0:index;
- break;
- }
- }
-
- rankList.numItems = rankData.length;
- for (let index = 0; index < rankData.length; index++) {
- let item: fgui.GComponent = rankList.getChildAt(index).asCom;
- item.getChild("index").asTextField.text = rankData[index]["rank"]+"";
- item.getChild("score").asTextField.text = rankData[index]["score"]+"";
- item.getChild("name").asTextField.text = rankData[index]["user"]["nickname"];
- item.getChild("name").height = item.getChild("name").asTextField.fontSize;
- item.getChild("avatar").asLoader.url = rankData[index]["user"]["avatar"];
-
- // 判断历史最高分
- if (ConstObject.User != null && ConstObject.User["id"] == rankData[index]["user"]["id"]) {
- item.getChild("up").visible = (ConstObject.Score > rankData[index]["score"]);
- item.getChild("score").asTextField.text = (item.getChild("up").visible)? ConstObject.Score:rankData[index]["score"];
- }
- }
- rankList.scrollToView(tag, false);
- if (tag > 0) {
- rankList.scrollPane.setPosY(rankList.scrollPane.posY+rankList.lineGap);
- }
- });
- });
- EventManager.sendEvent(GameEventName.View.View_HideView, GameView);
- EventManager.sendEvent(GameEventName.View.View_ShowView, HintView);
- GameManager.setGameView(GameEventName.View.View_HideView);
- SDKManager.addButton([
- {
- button: againButton,
- color: [
- cc.Color.WHITE,
- cc.Color.BLACK,
- ],
- callback: () => {
- this.onAgain();
- }
- },
- {
- button: quitButton,
- color: [
- cc.Color.WHITE,
- cc.Color.BLACK,
- ],
- callback: () => {
- this.onQuit();
- }
- }
- ]);
- }
- protected _refreshView(): void {
-
- }
- protected _clearView(): void {
- SDKManager.removeButton();
- EventManager.sendEvent(GameEventName.Music.Music_StopSound, GameMusicResData.GameEnd);
- }
- protected resize () {
- this.fgui.width = fgui.GRoot.inst.width;
- }
- private onAgain (): void {
- EventManager.sendEvent(GameEventName.Music.Music_PlaySound, GameMusicResData.ClickButton);
- EventManager.sendEvent(GameEventName.View.View_DestroyView, OverView);
- EventManager.sendEvent(GameEventName.View.View_DestroyView, HintView);
- EventManager.sendEvent(GameEventName.View.View_ShowView, GameView);
- GameManager.setGameView(GameEventName.View.View_ShowView);
- }
- private onQuit (): void {
- EventManager.sendEvent(GameEventName.Music.Music_PlaySound, GameMusicResData.ClickButton);
-
- EventManager.sendEvent(GameEventName.Game_QuitGame);
- }
- }
|