diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonSounds.kt b/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonSounds.kt index bdbccc6222..7faf143251 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonSounds.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonSounds.kt @@ -103,6 +103,11 @@ object CobblemonSounds : PlatformRegistry, ResourceKey> = listOf( - ChatScreen::class.java, - BattleGUI::class.java - ) + private val screenExemptions: List> = listOf( + ChatScreen::class.java, + BattleGUI::class.java + ) + + fun canRender(): Boolean { + val minecraft = Minecraft.getInstance() + // Hiding if a Screen is open and not exempt + if (minecraft.screen != null) { + if (!screenExemptions.contains(minecraft.screen?.javaClass as Class)) + return false + } + if (minecraft.options.hideGui || minecraft.debugOverlay.showDebugScreen()) { + return false + } + // Hiding if toggled via Keybind + if (HidePartyBinding.shouldHide) { + return false + } + return true + } + } val starterToast = CobblemonToast( Mth.createInsecureUUID(), @@ -94,23 +111,11 @@ class PartyOverlay : Gui(Minecraft.getInstance()) { } override fun render(context: GuiGraphics, tickCounter: DeltaTracker) { + if (!canRender()) return + val partialDeltaTicks = tickCounter.realtimeDeltaTicks - val minecraft = Minecraft.getInstance() - // Hiding if a Screen is open and not exempt - if (minecraft.screen != null) { - if (!screenExemptions.contains(minecraft.screen?.javaClass as Class)) - return - } - if (minecraft.options.hideGui || minecraft.debugOverlay.showDebugScreen()) { - return - } - // Hiding if toggled via Keybind - if (HidePartyBinding.shouldHide) { - return - } - val panelX = 0 val party = CobblemonClient.storage.party val matrices = context.pose() diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/PartyOverlayDataControl.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/PartyOverlayDataControl.kt index 936fe4b048..735e97dee7 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/PartyOverlayDataControl.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/PartyOverlayDataControl.kt @@ -8,6 +8,11 @@ package com.cobblemon.mod.common.client.gui +import com.cobblemon.mod.common.CobblemonSounds +import net.minecraft.client.Minecraft +import net.minecraft.client.resources.sounds.SimpleSoundInstance +import net.minecraft.client.resources.sounds.SoundInstance +import net.minecraft.sounds.SoundEvent import java.util.* object PartyOverlayDataControl { @@ -28,6 +33,9 @@ object PartyOverlayDataControl { private val overlayData = mutableMapOf() + private var barFillupSound: SoundInstance? = null + private var levelUpJingleSound: SoundInstance? = null + fun pokemonGainedExp(pokemonUuid : UUID, oldLevel: Int?, expGained: Int, countOfMovesLearned: Int, countOfEvosUnlocked: Int = 0) { var time = BAR_UPDATE_NO_LEVEL_TIME if (countOfMovesLearned > 0 || countOfEvosUnlocked > 0) { @@ -55,6 +63,9 @@ object PartyOverlayDataControl { } } overlayData[pokemonUuid] = OverlayData(expGainedData = newData) + + stopSound(barFillupSound) + barFillupSound = playSound(CobblemonSounds.LEVELUP_START) } fun pokemonGainedEvo(pokemonUuid : UUID, evoCount: Int) { @@ -130,6 +141,10 @@ object PartyOverlayDataControl { if (data.expGainedData != null) { // We update this in order and render these in order, and as such we don't tick others val expGainedData = data.expGainedData!! expGainedData.ticks += 1 + if (expGainedData.ticks == BAR_UPDATE_BEFORE_TIME && expGainedData.oldLevel != null) { + stopSound(levelUpJingleSound) + levelUpJingleSound = playSound(CobblemonSounds.LEVELUP) + } if (expGainedData.ticks >= expGainedData.ticksMax) { data.expGainedData = null } @@ -158,6 +173,8 @@ object PartyOverlayDataControl { fun clear() { overlayData.clear() + stopSound(barFillupSound) + stopSound(levelUpJingleSound) } open class TickCounter( @@ -195,4 +212,16 @@ object PartyOverlayDataControl { return fadeIn + hold + fadeOut } } + + //SOUNDS + private fun playSound(soundEvent: SoundEvent): SoundInstance? { + if (!PartyOverlay.canRender()) return null + val soundInstance = SimpleSoundInstance.forUI(soundEvent, 1F) + Minecraft.getInstance().soundManager.play(soundInstance) + return soundInstance + } + + private fun stopSound(soundInstance: SoundInstance?) { + if (soundInstance != null) Minecraft.getInstance().soundManager.stop(soundInstance) + } } \ No newline at end of file