From 7d60ec59f784eccedc2a9b3e00374d0b37e9117e Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 2 Jul 2024 01:55:26 +0530 Subject: [PATCH] fix various ui bugs --- src/MarbleWorld.hx | 68 ++++++++++++++++++++++++++++++++++------- src/Mission.hx | 11 +++++++ src/Radar.hx | 9 +++++- src/gui/MPPreGameDlg.hx | 6 ++++ 4 files changed, 82 insertions(+), 12 deletions(-) diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 3292047a..d7c559e9 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -590,6 +590,14 @@ class MarbleWorld extends Scheduler { MarbleGame.canvas.pushDialog(new MPPreGameDlg()); this.setCursorLock(false); this.marble.camera.startOverview(); + + // Hide all gems + for (gem in this.gems) { + gem.setHide(true); + gem.pickedUp = true; + gem.setHide(true); + this.collisionWorld.removeEntity(gem.boundingCollider); // remove from octree to make it easy + } } public function addJoiningClient(cc:GameConnection, onAdded:() -> Void) { @@ -661,6 +669,8 @@ class MarbleWorld extends Scheduler { this.rewindManager.clear(); + setCursorLock(true); + this.timeState.currentAttemptTime = 0; this.timeState.gameplayClock = this.gameMode.getStartTime(); this.timeState.ticks = 0; @@ -2014,7 +2024,7 @@ class MarbleWorld extends Scheduler { } if (_instancesNeedsUpdate) { if (this.radar != null) - this.radar.render(); + this.radar.render(this.serverStartTicks != 0); _instancesNeedsUpdate = false; this.instanceManager.render(); } @@ -2057,22 +2067,37 @@ class MarbleWorld extends Scheduler { function determineClockColor(timeToDisplay:Float) { if (this.finishTime != null) return 1; - if (this.timeState.currentAttemptTime < 3.5 || this.bonusTime > 0) - return 1; - if (timeToDisplay >= this.mission.qualifyTime) - return 2; + if (this.isMultiplayer) { + if (!this.multiplayerStarted) + return 1; - if (this.timeState.currentAttemptTime >= 3.5 && !Net.isMP) { // Create the flashing effect var alarmStart = this.mission.computeAlarmStartTime(); var elapsed = timeToDisplay - alarmStart; - if (elapsed < 0) + if (alarmStart < timeToDisplay) return 0; if (Math.floor(elapsed) % 2 == 0) return 2; - } - return 0; // Default yellow + return 0; + } else { + if (this.timeState.currentAttemptTime < 3.5 || this.bonusTime > 0) + return 1; + if (timeToDisplay >= this.mission.qualifyTime) + return 2; + + if (this.timeState.currentAttemptTime >= 3.5 && !Net.isMP) { + // Create the flashing effect + var alarmStart = this.mission.computeAlarmStartTime(); + var elapsed = timeToDisplay - alarmStart; + if (elapsed < 0) + return 0; + if (Math.floor(elapsed) % 2 == 0) + return 2; + } + + return 0; // Default yellow + } } public function updateTimer(dt:Float) { @@ -2121,14 +2146,17 @@ class MarbleWorld extends Scheduler { var clockTicks = Math.floor((ourStartTime - this.timeState.gameplayClock) / 0.032); var clockTickTime = ourStartTime - clockTicks * 0.032; var delta = clockTickTime - this.timeState.gameplayClock; - this.timeState.gameplayClock = gameplayHigh - delta; + this.timeState.gameplayClock = Math.max(0, gameplayHigh - delta); } } this.timeState.gameplayClock += dt * timeMultiplier; + this.timeState.gameplayClock = Math.max(0, this.timeState.gameplayClock); } - if (this.timeState.gameplayClock < 0 && !Net.isClient) + if (this.timeState.gameplayClock <= 0 && !Net.isClient) { this.gameMode.onTimeExpire(); + this.timeState.gameplayClock = 0; + } } this.timeState.currentAttemptTime += dt; } else { @@ -2170,6 +2198,24 @@ class MarbleWorld extends Scheduler { AudioManager.playSound(ResourceLoader.getResource("data/sound/alarm_timeout.wav", ResourceLoader.getAudio, this.soundResources)); } } + } else { + if (this.multiplayerStarted) { + var alarmStart = this.mission.computeAlarmStartTime(); + + if (prevGameplayClock > alarmStart && this.timeState.gameplayClock <= alarmStart) { + // Start the alarm + this.alarmSound = AudioManager.playSound(ResourceLoader.getResource("data/sound/alarm.wav", ResourceLoader.getAudio, this.soundResources), + null, true); // AudioManager.createAudioSource('alarm.wav'); + this.displayHelp('You have ${alarmStart} seconds remaining.'); + } + if (prevGameplayClock > 0 && this.timeState.gameplayClock <= 0) { + // Stop the alarm + if (this.alarmSound != null) { + this.alarmSound.stop(); + this.alarmSound = null; + } + } + } } if (finishTime != null) this.timeState.gameplayClock = finishTime.gameplayClock; diff --git a/src/Mission.hx b/src/Mission.hx index 2656c1e2..df3adf70 100644 --- a/src/Mission.hx +++ b/src/Mission.hx @@ -113,6 +113,9 @@ class Mission { mission.type = missionInfo.type.toLowerCase(); mission.missionInfo = missionInfo; mission.gameMode = missionInfo.gamemode; + if (mission.gameMode != null) { + mission.gameMode = StringTools.trim(mission.gameMode).toLowerCase(); + } return mission; } @@ -239,11 +242,19 @@ class Mission { /** Computes the clock time in MBP when the user should be warned that they're about to exceed the par time. */ public function computeAlarmStartTime() { var alarmStart = this.qualifyTime; + if (this.gameMode != null && this.gameMode == 'hunt') { + alarmStart = 15; + if (this.missionInfo.alarmstarttime != null) + alarmStart = MisParser.parseNumber(this.missionInfo.alarmstarttime); + return alarmStart; + } + alarmStart = 0; if (this.missionInfo.alarmstarttime != null) alarmStart -= MisParser.parseNumber(this.missionInfo.alarmstarttime); else { alarmStart -= 15; } + alarmStart = Math.max(0, alarmStart); return alarmStart; diff --git a/src/Radar.hx b/src/Radar.hx index 163efe62..44c8979b 100644 --- a/src/Radar.hx +++ b/src/Radar.hx @@ -64,10 +64,17 @@ class Radar { _dirty = true; } - public function render() { + public function render(doRender) { if (!_dirty) return; g.clear(); + if (!doRender) { + for (marble => marbleName in marbleNameTexts) { + if (marbleName != null) + marbleName.alpha = 0; + } + return; + } var gemCount = 0; for (gem in level.gems) { if (!gem.pickedUp) { diff --git a/src/gui/MPPreGameDlg.hx b/src/gui/MPPreGameDlg.hx index faebbeeb..14653886 100644 --- a/src/gui/MPPreGameDlg.hx +++ b/src/gui/MPPreGameDlg.hx @@ -266,6 +266,12 @@ class MPPreGameDlg extends GuiControl { playBtn.disabled = !allReady; + if (playerListArr.length > 1) { + spectateBtn.anim.visible = true; + } else { + spectateBtn.anim.visible = false; + } + var playerListCompiled = playerListArr.map(player -> player.spectate ? '[S] ${player.name}' : player.name); var playerListStateCompiled = playerListArr.map(player -> player.ready ? "[Ready]" : "[Waiting]"); playerListLeft.setTexts(playerListCompiled);