package gui; import modes.GameMode.ScoreType; import mis.MisParser; import hxd.BitmapData; import h2d.Tile; import src.MarbleGame; import src.Settings.Score; import src.Settings.Settings; import src.Mission; import h2d.filter.DropShadow; import hxd.res.BitmapFont; import h3d.Vector; import src.ResourceLoader; import src.TimeState; import src.Util; class EndGameGui extends GuiImage { var mission:Mission; var innerCtrl:GuiControl; var endGameWnd:GuiImage; var scoreSubmitted:Bool = false; public function new(continueFunc:GuiControl->Void, restartFunc:GuiControl->Void, nextLevelFunc:GuiControl->Void, mission:Mission, score:Float, scoreType:ScoreType) { var res = ResourceLoader.getImage("data/ui/xbox/BG_fadeOutSoftEdge.png").resource.toTile(); super(res); this.horizSizing = Width; this.vertSizing = Height; this.position = new Vector(0, 0); this.extent = new Vector(640, 480); this.mission = mission; function loadButtonImages(path:String) { var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile(); var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile(); var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile(); return [normal, hover, pressed]; } var scene2d = MarbleGame.canvas.scene2d; var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; var subX = 640 - (scene2d.width - offsetX) * 640 / scene2d.width; var subY = 480 - (scene2d.height - offsetY) * 480 / scene2d.height; innerCtrl = new GuiControl(); innerCtrl.position = new Vector(offsetX, offsetY); innerCtrl.extent = new Vector(640 - subX, 480 - subY); innerCtrl.horizSizing = Width; innerCtrl.vertSizing = Height; this.addChild(innerCtrl); var coliseumfontdata = ResourceLoader.getFileEntry("data/font/ColiseumRR.fnt"); var coliseumb = new BitmapFont(coliseumfontdata.entry); @:privateAccess coliseumb.loader = ResourceLoader.loader; var coliseum = coliseumb.toSdfFont(cast 44 * Settings.uiScale, MultiChannel); var rootTitle = new GuiText(coliseum); rootTitle.position = new Vector(100, 30); rootTitle.extent = new Vector(1120, 80); rootTitle.text.textColor = 0xFFFFFF; rootTitle.text.text = "LEVEL COMPLETE!"; rootTitle.text.alpha = 0.5; innerCtrl.addChild(rootTitle); endGameWnd = new GuiImage(ResourceLoader.getResource("data/ui/xbox/endGameWindow.png", ResourceLoader.getImage, this.imageResources).toTile()); endGameWnd.horizSizing = Left; endGameWnd.vertSizing = Top; endGameWnd.position = new Vector(80 - offsetX, 150 - offsetY); endGameWnd.extent = new Vector(336, 150); innerCtrl.addChild(endGameWnd); var arial14fontdata = ResourceLoader.getFileEntry("data/font/Arial Bold.fnt"); var arial14b = new BitmapFont(arial14fontdata.entry); @:privateAccess arial14b.loader = ResourceLoader.loader; var arial14 = arial14b.toSdfFont(cast 22 * Settings.uiScale, h2d.Font.SDFChannel.MultiChannel); var statIcon = new GuiImage(ResourceLoader.getResource("data/ui/xbox/statIcon.png", ResourceLoader.getImage, this.imageResources).toTile()); statIcon.position = new Vector(38, 27); statIcon.extent = new Vector(20, 20); endGameWnd.addChild(statIcon); function mlFontLoader(text:String) { return arial14; } var beatPar = score < mission.qualifyTime; var egResultLeft = new GuiMLText(arial14, mlFontLoader); egResultLeft.position = new Vector(28, 26); egResultLeft.extent = new Vector(180, 100); if (scoreType == Time) egResultLeft.text.text = '

Time:
Par Time:
Rating:
My Best Time:

'; if (scoreType == Score) egResultLeft.text.text = '

Score:
My Best Score:

'; endGameWnd.addChild(egResultLeft); var c0 = 0xEBEBEB; var c1 = 0x8DFF8D; var c2 = 0x88BCEE; var c3 = 0xFF7575; function calcRating(time:Float, parTime:Float, goldTime:Float, difficulty:Int):Int { var t = time - (time % 10); if (t == 0) return 0; var completionBonus = 1000; var timeBonus = 0; if (t < parTime) timeBonus = Math.floor(parTime / t) * 1000; else timeBonus = Math.floor(parTime / t) * 500; return (completionBonus + timeBonus) * difficulty; } var rating = calcRating(score * 1000, mission.qualifyTime * 1000, mission.goldTime * 1000, Std.parseInt(mission.missionInfo.difficulty)); var myScore = {name: "Player", time: score}; Settings.saveScore(mission.path, myScore, scoreType); var scoreData:Array = Settings.getScores(mission.path); while (scoreData.length < 1) { if (scoreType == Score) scoreData.push({name: "Nardo Polo", time: 0}); if (scoreType == Time) scoreData.push({name: "Nardo Polo", time: 5999.999}); } var bestScore = scoreData[0]; var egResultRight = new GuiMLText(arial14, mlFontLoader); egResultRight.position = new Vector(214, 26); egResultRight.extent = new Vector(180, 100); if (scoreType == Score) egResultRight.text.text = '${Util.formatScore(score)}
${Util.formatScore(bestScore.time)}'; if (scoreType == Time) egResultRight.text.text = '${Util.formatTime(score)}
${Util.formatTime(mission.qualifyTime)}
${rating}
${Util.formatTime(bestScore.time)}'; endGameWnd.addChild(egResultRight); var bottomBar = new GuiControl(); bottomBar.position = new Vector(0, 590); bottomBar.extent = new Vector(640, 200); bottomBar.horizSizing = Width; bottomBar.vertSizing = Bottom; innerCtrl.addChild(bottomBar); var retryButton = new GuiXboxButton("Retry", 160); retryButton.position = new Vector(400, 0); retryButton.vertSizing = Bottom; retryButton.horizSizing = Right; retryButton.gamepadAccelerator = ["B"]; retryButton.accelerators = [hxd.Key.ESCAPE, hxd.Key.BACKSPACE]; retryButton.pressedAction = (e) -> restartFunc(retryButton); bottomBar.addChild(retryButton); var lbButton = new GuiXboxButton("Leaderboard", 220); lbButton.position = new Vector(750, 0); lbButton.vertSizing = Bottom; lbButton.horizSizing = Right; bottomBar.addChild(lbButton); var nextButton = new GuiXboxButton("Next", 160); nextButton.position = new Vector(960, 0); nextButton.vertSizing = Bottom; nextButton.horizSizing = Right; nextButton.gamepadAccelerator = ["A"]; nextButton.accelerators = [hxd.Key.ENTER]; nextButton.pressedAction = (e) -> continueFunc(nextButton); bottomBar.addChild(nextButton); } override function onResize(width:Int, height:Int) { var offsetX = (width - 1280) / 2; var offsetY = (height - 720) / 2; var subX = 640 - (width - offsetX) * 640 / width; var subY = 480 - (height - offsetY) * 480 / height; innerCtrl.position = new Vector(offsetX, offsetY); innerCtrl.extent = new Vector(640 - subX, 480 - subY); endGameWnd.position = new Vector(80 - offsetX, 170 - offsetY); super.onResize(width, height); } }