import BasicView from "../../../Engine/Basic/BasicView"; import EventManager from "../../../Engine/Event/EventManager"; import Tool from "../../../Engine/Tool/Tool"; import { ConstObject, _EGameBehavior } from "../../Data/GameDataType"; 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"; import GameAudioResData from "../../Game/Data/GameMusicResData"; import { _IPlaySound } from "../../../Engine/Audio/Data/AudioConfig"; /** * 结算页 */ 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 = 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.Audio.Audio_StopSound, GameAudioResData.GameEnd); } protected resize () { this.fgui.width = fgui.GRoot.inst.width; } private onAgain (): void { let playSound: _IPlaySound = { url: GameAudioResData.ClickButton, callback: null, } EventManager.sendEvent(GameEventName.Audio.Audio_PlaySound, playSound); EventManager.sendEventByTargetID(GameEventName.Behavior.Behavior_ForceEnterBehavior, ConstObject.GameFlowTreeID, _EGameBehavior.Gameing); EventManager.sendEvent(GameEventName.Game_AgainStartGame); } private onQuit (): void { let playSound: _IPlaySound = { url: GameAudioResData.ClickButton, callback: null, } EventManager.sendEvent(GameEventName.Audio.Audio_PlaySound, playSound); EventManager.sendEvent(GameEventName.Game_QuitGame); } }