From f4717073878a3598209f760b996c2f27ea19a94a Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Mon, 21 Nov 2022 21:30:27 +0530 Subject: [PATCH] statistics...and gold backgrounds --- src/MarbleWorld.hx | 2 +- src/gui/HelpCreditsGui.hx | 2 +- src/gui/LoadingGui.hx | 4 +- src/gui/MainMenuGui.hx | 2 +- src/gui/OptionsDlg.hx | 2 +- src/gui/PlayMissionGui.hx | 11 +- src/gui/StatisticsGui.hx | 211 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 227 insertions(+), 7 deletions(-) create mode 100644 src/gui/StatisticsGui.hx diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 2fda0597..aa0fc1d5 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -183,7 +183,7 @@ class MarbleWorld extends Scheduler { } public function initLoading() { - this.loadingGui = new LoadingGui(this.mission.title); + this.loadingGui = new LoadingGui(this.mission.title, this.mission.game); MarbleGame.canvas.setContent(this.loadingGui); function scanMission(simGroup:MissionElementSimGroup) { diff --git a/src/gui/HelpCreditsGui.hx b/src/gui/HelpCreditsGui.hx index c7d87412..24178a09 100644 --- a/src/gui/HelpCreditsGui.hx +++ b/src/gui/HelpCreditsGui.hx @@ -15,7 +15,7 @@ class HelpCreditsGui extends GuiImage { var manualPageList:GuiTextListCtrl; public function new() { - var img = ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg'); + var img = Math.random() >= 0.7 ? ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg') : ResourceLoader.getImage('data/ui/backgrounds/gold/${cast (Math.floor(Util.lerp(1, 12, Math.random())), Int)}.jpg'); super(img.resource.toTile()); this.position = new Vector(0, 0); this.extent = new Vector(640, 480); diff --git a/src/gui/LoadingGui.hx b/src/gui/LoadingGui.hx index 3b641168..4e3254aa 100644 --- a/src/gui/LoadingGui.hx +++ b/src/gui/LoadingGui.hx @@ -10,8 +10,8 @@ import src.Util; class LoadingGui extends GuiImage { public var setProgress:Float->Void; - public function new(missionName:String) { - var img = ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg'); + public function new(missionName:String, game:String) { + var img = game == "platinum" ? ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg') : ResourceLoader.getImage('data/ui/backgrounds/gold/${cast (Math.floor(Util.lerp(1, 12, Math.random())), Int)}.jpg'); super(img.resource.toTile()); this.horizSizing = Width; this.vertSizing = Height; diff --git a/src/gui/MainMenuGui.hx b/src/gui/MainMenuGui.hx index 3259d39c..7db15cf5 100644 --- a/src/gui/MainMenuGui.hx +++ b/src/gui/MainMenuGui.hx @@ -10,7 +10,7 @@ import src.Util; class MainMenuGui extends GuiImage { public function new() { - var img = ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg'); + var img = Math.random() >= 0.7 ? ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg') : ResourceLoader.getImage('data/ui/backgrounds/gold/${cast (Math.floor(Util.lerp(1, 12, Math.random())), Int)}.jpg'); super(img.resource.toTile()); var domcasual32fontdata = ResourceLoader.getFileEntry("data/font/DomCasualD.fnt"); var domcasual32b = new BitmapFont(domcasual32fontdata.entry); diff --git a/src/gui/OptionsDlg.hx b/src/gui/OptionsDlg.hx index 1b5016f2..d9136eb7 100644 --- a/src/gui/OptionsDlg.hx +++ b/src/gui/OptionsDlg.hx @@ -19,7 +19,7 @@ class OptionsDlg extends GuiImage { var musicSliderFunc:(dt:Float, mouseState:MouseState) -> Void; public function new() { - var img = ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg'); + var img = Math.random() >= 0.7 ? ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg') : ResourceLoader.getImage('data/ui/backgrounds/gold/${cast (Math.floor(Util.lerp(1, 12, Math.random())), Int)}.jpg'); super(img.resource.toTile()); this.horizSizing = Width; this.vertSizing = Height; diff --git a/src/gui/PlayMissionGui.hx b/src/gui/PlayMissionGui.hx index e9f66c60..009c2bff 100644 --- a/src/gui/PlayMissionGui.hx +++ b/src/gui/PlayMissionGui.hx @@ -27,6 +27,7 @@ import src.MarbleGame; class PlayMissionGui extends GuiImage { static var currentSelectionStatic:Int = -1; static var currentCategoryStatic:String = "beginner"; + static var currentGameStatic:String = "platinum"; var currentGame:String = "platinum"; var currentSelection:Int = 0; @@ -62,8 +63,9 @@ class PlayMissionGui extends GuiImage { currentSelection = PlayMissionGui.currentSelectionStatic; currentCategory = PlayMissionGui.currentCategoryStatic; + currentGame = PlayMissionGui.currentGameStatic; - var img = ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg'); + var img = currentGame == "platinum" ? ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg') : ResourceLoader.getImage('data/ui/backgrounds/gold/${cast (Math.floor(Util.lerp(1, 12, Math.random())), Int)}.jpg'); super(img.resource.toTile()); this.horizSizing = Width; @@ -723,6 +725,13 @@ class PlayMissionGui extends GuiImage { } currentCategoryStatic = currentCategory; + + if (currentGame != game) { + this.bmp.tile = (game == "platinum" ? ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg') : ResourceLoader.getImage('data/ui/backgrounds/gold/${cast (Math.floor(Util.lerp(1, 12, Math.random())), Int)}.jpg')) + .resource.toTile(); + } + + currentGameStatic = game; currentGame = game; setSelectedFunc(currentList.length - 1); if (doRender) diff --git a/src/gui/StatisticsGui.hx b/src/gui/StatisticsGui.hx new file mode 100644 index 00000000..3635c611 --- /dev/null +++ b/src/gui/StatisticsGui.hx @@ -0,0 +1,211 @@ +package gui; + +import hxd.res.BitmapFont; +import h3d.Vector; +import src.ResourceLoader; +import src.MarbleGame; +import src.Settings; +import src.Settings.PlayStatistics; +import src.Mission; +import src.Util; + +class StatisticsGui extends GuiImage { + public function new(game:String) { + var img = ResourceLoader.getImage("data/ui/achiev/window.png"); + super(img.resource.toTile()); + this.horizSizing = Center; + this.vertSizing = Center; + this.position = new Vector(73, -21); + this.extent = new Vector(493, 512); + + var stat = new GuiImage(ResourceLoader.getResource("data/ui/play/statistics_text.png", ResourceLoader.getImage, this.imageResources).toTile()); + stat.position = new Vector(176, 25); + stat.extent = new Vector(160, 39); + this.addChild(stat); + + 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 12 * Settings.uiScale, MultiChannel); + + var domcasual32fontdata = ResourceLoader.getFileEntry("data/font/DomCasualD.fnt"); + var domcasual32b = new BitmapFont(domcasual32fontdata.entry); + @:privateAccess domcasual32b.loader = ResourceLoader.loader; + var domcasual32 = domcasual32b.toSdfFont(cast 26 * Settings.uiScale, MultiChannel); + var domcasual64 = domcasual32b.toSdfFont(cast 58 * Settings.uiScale, MultiChannel); + var domcasual24 = domcasual32b.toSdfFont(cast 21 * Settings.uiScale, MultiChannel); + + function mlFontLoader(text:String) { + switch (text) { + case "DomCasual24": + return domcasual24; + case "Arial14": + return arial14; + default: + return null; + } + } + + 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(); + var disabled = ResourceLoader.getResource('${path}_i.png', ResourceLoader.getImage, this.imageResources).toTile(); + return [normal, hover, pressed, disabled]; + } + + var statLabel = new GuiMLText(domcasual24, mlFontLoader); + statLabel.position = new Vector(39, 51); + statLabel.extent = new Vector(341, 375); + statLabel.text.textColor = 0; + statLabel.text.lineSpacing = 4; + this.addChild(statLabel); + + var statText = new GuiMLText(domcasual24, mlFontLoader); + statText.position = new Vector(59, 54); + statText.extent = new Vector(389, 375); + statText.horizSizing = Left; + statText.text.textColor = 0; + statText.text.lineSpacing = 4; + + if (game == "platinum") { + statLabel.text.text = "Beginner:
" + "Intermediate:
" + "Advanced:
" + "Expert:
" + "Total:
" + "
" + + "Platinum times:
" + "Ultimate times:
" + "Easter Eggs:
" + "Out of Bounds:
" + "Respawns:
" + "Hardest Level:
" + + "
" + "Grand Total (hours:minutes:seconds):
" + "Total Wasted Time (hours:minutes:seconds):
"; + } + if (game == "gold") { + statLabel.text.text = "Beginner:
" + "Intermediate:
" + "Advanced:
" + "Total:
" + "
" + "Gold times:
" + + "Out of Bounds:
" + "Respawns:
" + "Hardest Level:
" + "
" + "Grand Total (hours:minutes:seconds):
" + + "Total Wasted Time (hours:minutes:seconds):"; + } + + this.addChild(statText); + + var closeButton = new GuiButton(loadButtonImages("data/ui/achiev/close")); + closeButton.position = new Vector(199, 431); + closeButton.extent = new Vector(95, 45); + closeButton.horizSizing = Center; + closeButton.pressedAction = (e) -> { + MarbleGame.canvas.popDialog(this); + } + this.addChild(closeButton); + + // Now do the actual achievement check logic + var completions:Map> = []; + + var totalPlatinums = 0; + var totalUltimates = 0; + var totalEggs = 0; + var totalBestTime = 0.0; + var hardestLevel:Mission = MissionList.missionList[game]["beginner"][0]; + var hardestStats:PlayStatistics = { + oobs: 0, + respawns: 0, + totalTime: 0 + }; + var hardestLevelScore = 0.0; + + for (difficulty => missions in MissionList.missionList[game]) { + completions.set(difficulty, missions.map(mis -> { + var misScores = Settings.getScores(mis.path); + if (misScores.length == 0) { + return { + mission: mis, + beatPar: false, + beatPlatinum: false, + beatUltimate: false, + beaten: false + } + } + var bestTime = misScores[0]; + totalBestTime += bestTime.time; + var beatPar = bestTime.time < mis.qualifyTime; + var beatPlatinum = bestTime.time < mis.goldTime; + var beatUltimate = bestTime.time < mis.ultimateTime; + var beaten = beatPar || beatPlatinum || beatUltimate; + + if (beatPlatinum) + totalPlatinums++; + if (beatUltimate) + totalUltimates++; + if (Settings.easterEggs.exists(mis.path)) + totalEggs++; + + if (Settings.levelStatistics.exists(mis.path)) { + var stats = Settings.levelStatistics.get(mis.path); + var metric = stats.oobs + stats.respawns + (stats.totalTime / 60); + if (metric > hardestLevelScore) { + hardestLevel = mis; + hardestLevelScore = metric; + hardestStats = stats; + } + } + + return { + mission: mis, + beatPar: beatPar, + beatPlatinum: beatPlatinum, + beatUltimate: beatUltimate, + beaten: beaten + }; + })); + } + + if (game == "platinum") { + var beginnerCompletion = completions["beginner"].filter(x -> x.beatPar).length / completions["beginner"].length; + var intermediateCompletion = completions["intermediate"].filter(x -> x.beatPar).length / completions["intermediate"].length; + var advancedCompletion = completions["advanced"].filter(x -> x.beatPar).length / completions["advanced"].length; + var expertCompletion = completions["expert"].filter(x -> x.beatPar).length / completions["expert"].length; + var totalCompletion:Float = completions["beginner"].filter(x -> x.beatPar).length + + completions["intermediate"].filter(x -> x.beatPar) + .length + completions["advanced"].filter(x -> x.beatPar).length + completions["expert"].filter(x -> x.beatPar).length; + totalCompletion /= completions["beginner"].length + + completions["intermediate"].length + completions["advanced"].length + completions["expert"].length; + + statText.text.text = '

${Math.floor(beginnerCompletion * 100)}%

' + + '

${Math.floor(intermediateCompletion * 100)}%

' + + '

${Math.floor(advancedCompletion * 100)}%

' + + '

${Math.floor(expertCompletion * 100)}%

' + + '

${Math.floor(totalCompletion * 100)}%

' + + '
' + + '

${totalPlatinums}/120 ${Math.floor(totalPlatinums / 120.0 * 100)}%

' + + '

${totalUltimates}/120 ${Math.floor(totalUltimates / 120.0 * 100)}%

' + + '

${totalEggs}/96 ${Math.floor(totalEggs / 96 * 100)}%

' + + '

${Settings.playStatistics.oobs}

' + + '

${Settings.playStatistics.respawns}

' + + '

${hardestLevel != null ? hardestLevel.title : ""}

' + + + '

${hardestLevel != null ? 'With ${hardestStats.oobs} OOBs, ${hardestStats.respawns} Respawns, and ${Util.formatTimeHours(hardestStats.totalTime)} Played': ""}

' + + '

${Util.formatTimeHours(totalBestTime)}

' + + '

${Util.formatTimeHours(Settings.playStatistics.totalTime)}

'; + } + if (game == "gold") { + var beginnerCompletion = completions["beginner"].filter(x -> x.beatPar).length / completions["beginner"].length; + var intermediateCompletion = completions["intermediate"].filter(x -> x.beatPar).length / completions["intermediate"].length; + var advancedCompletion = completions["advanced"].filter(x -> x.beatPar).length / completions["advanced"].length; + var totalCompletion:Float = completions["beginner"].filter(x -> x.beatPar).length + + completions["intermediate"].filter(x -> x.beatPar).length + completions["advanced"].filter(x -> x.beatPar).length; + totalCompletion /= completions["beginner"].length + completions["intermediate"].length + completions["advanced"].length; + + statText.text.text = '

${Math.floor(beginnerCompletion * 100)}%

' + + '

${Math.floor(intermediateCompletion * 100)}%

' + + '

${Math.floor(advancedCompletion * 100)}%

' + + '

${Math.floor(totalCompletion * 100)}%

' + + '
' + + '

${totalPlatinums}/100 ${Math.floor(totalPlatinums / 100.0 * 100)}%

' + + '

${Settings.playStatistics.oobs}

' + + '

${Settings.playStatistics.respawns}

' + + '

${hardestLevel != null ? hardestLevel.title : ""}

' + + + '

${hardestLevel != null ? 'With ${hardestStats.oobs} OOBs, ${hardestStats.respawns} Respawns, and ${Util.formatTimeHours(hardestStats.totalTime)} Played': ""}

' + + '

${Util.formatTimeHours(totalBestTime)}

' + + '

${Util.formatTimeHours(Settings.playStatistics.totalTime)}

'; + } + } +}