mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
musicplayer: buttons are now well-behaving
This commit is contained in:
@@ -346,8 +346,15 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
// prev song
|
// prev song
|
||||||
if (mode < MODE_SHOW_LIST) {
|
if (mode < MODE_SHOW_LIST) {
|
||||||
getPrevSongFromPlaylist()?.let { ingame.musicGovernor.unshiftPlaylist(it) }
|
getPrevSongFromPlaylist()?.let { ingame.musicGovernor.unshiftPlaylist(it) }
|
||||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) {
|
if (!shouldPlayerBeDisabled) {
|
||||||
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
App.audioMixer.requestFadeOut(
|
||||||
|
App.audioMixer.musicTrack,
|
||||||
|
AudioMixer.DEFAULT_FADEOUT_LEN / 3f
|
||||||
|
) {
|
||||||
|
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
||||||
|
iHitTheStopButton = false
|
||||||
|
stopRequested = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// prev page in the playlist
|
// prev page in the playlist
|
||||||
@@ -371,9 +378,12 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
App.audioMixer.musicTrack.nextTrack = null
|
App.audioMixer.musicTrack.nextTrack = null
|
||||||
ingame.musicGovernor.stopMusic()
|
ingame.musicGovernor.stopMusic()
|
||||||
thisMusic?.let { ingame.musicGovernor.queueMusicToPlayNext(it) }
|
thisMusic?.let { ingame.musicGovernor.queueMusicToPlayNext(it) }
|
||||||
|
iHitTheStopButton = true
|
||||||
}
|
}
|
||||||
else if (!shouldPlayerBeDisabled) {
|
else if (!shouldPlayerBeDisabled) {
|
||||||
ingame.musicGovernor.startMusic()
|
ingame.musicGovernor.startMusic()
|
||||||
|
iHitTheStopButton = false
|
||||||
|
stopRequested = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -381,8 +391,15 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
3 -> { // next
|
3 -> { // next
|
||||||
// next song
|
// next song
|
||||||
if (mode < MODE_SHOW_LIST) {
|
if (mode < MODE_SHOW_LIST) {
|
||||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) {
|
if (!shouldPlayerBeDisabled) {
|
||||||
ingame.musicGovernor.startMusic() // required for "intermittent" mode, does seemingly nothing on "continuous" mode
|
App.audioMixer.requestFadeOut(
|
||||||
|
App.audioMixer.musicTrack,
|
||||||
|
AudioMixer.DEFAULT_FADEOUT_LEN / 3f
|
||||||
|
) {
|
||||||
|
ingame.musicGovernor.startMusic() // required for "intermittent" mode, does seemingly nothing on "continuous" mode
|
||||||
|
iHitTheStopButton = false
|
||||||
|
stopRequested = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// next page in the playlist
|
// next page in the playlist
|
||||||
@@ -432,6 +449,8 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) {
|
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, AudioMixer.DEFAULT_FADEOUT_LEN / 3f) {
|
||||||
if (!shouldPlayerBeDisabled) {
|
if (!shouldPlayerBeDisabled) {
|
||||||
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
||||||
|
iHitTheStopButton = false
|
||||||
|
stopRequested = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -451,6 +470,8 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
loadNewAlbum(albumsList[index])
|
loadNewAlbum(albumsList[index])
|
||||||
if (!shouldPlayerBeDisabled) {
|
if (!shouldPlayerBeDisabled) {
|
||||||
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
ingame.musicGovernor.startMusic() // required for "intermittent" mode
|
||||||
|
iHitTheStopButton = false
|
||||||
|
stopRequested = false
|
||||||
}
|
}
|
||||||
resetPlaylistScroll(App.audioMixer.musicTrack.nextTrack)
|
resetPlaylistScroll(App.audioMixer.musicTrack.nextTrack)
|
||||||
}
|
}
|
||||||
@@ -466,12 +487,15 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
|
|
||||||
// printdbg(this, "mode = $mode; req = $transitionRequest")
|
// printdbg(this, "mode = $mode; req = $transitionRequest")
|
||||||
|
|
||||||
if (shouldPlayerBeDisabled) {
|
if (shouldPlayerBeDisabled || iHitTheStopButton) {
|
||||||
ingame.musicGovernor.stopMusic()
|
if (!stopRequested) {
|
||||||
|
stopRequested = true
|
||||||
|
ingame.musicGovernor.stopMusic()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!jukeboxStopMonitorAlert && !App.audioMixer.musicTrack.isPlaying) {
|
else if (!jukeboxStopMonitorAlert && !App.audioMixer.musicTrack.isPlaying) {
|
||||||
jukeboxStopMonitorAlert = true
|
jukeboxStopMonitorAlert = true
|
||||||
ingame.musicGovernor.stopMusic(false, Math.random().toFloat() * 30f + 30f)
|
ingame.musicGovernor.stopMusic(false, ingame.musicGovernor.getRandomMusicInterval())
|
||||||
}
|
}
|
||||||
else if (App.audioMixer.musicTrack.isPlaying) {
|
else if (App.audioMixer.musicTrack.isPlaying) {
|
||||||
jukeboxStopMonitorAlert = false
|
jukeboxStopMonitorAlert = false
|
||||||
@@ -479,6 +503,8 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var jukeboxStopMonitorAlert = true
|
private var jukeboxStopMonitorAlert = true
|
||||||
|
private var iHitTheStopButton = false
|
||||||
|
private var stopRequested = false
|
||||||
|
|
||||||
private fun resetAlbumlistScroll() {
|
private fun resetAlbumlistScroll() {
|
||||||
val currentlyPlaying = albumsList.indexOfFirst { it.canonicalPath.replace('\\', '/') == ingame.musicGovernor.playlistSource }
|
val currentlyPlaying = albumsList.indexOfFirst { it.canonicalPath.replace('\\', '/') == ingame.musicGovernor.playlistSource }
|
||||||
|
|||||||
@@ -324,11 +324,13 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
|||||||
protected var ambState = 0
|
protected var ambState = 0
|
||||||
protected var ambFired = false
|
protected var ambFired = false
|
||||||
|
|
||||||
|
fun getRandomMusicInterval() = 25f + Math.random().toFloat() * 10f
|
||||||
|
|
||||||
private fun stopMusic(song: MusicContainer?, callStopMusicHook: Boolean = true, customPauseLen: Float? = null) {
|
private fun stopMusic(song: MusicContainer?, callStopMusicHook: Boolean = true, customPauseLen: Float? = null) {
|
||||||
musicState = STATE_INTERMISSION
|
musicState = STATE_INTERMISSION
|
||||||
intermissionAkku = 0f
|
intermissionAkku = 0f
|
||||||
intermissionLength = customPauseLen ?:
|
intermissionLength = customPauseLen ?:
|
||||||
if (diskJockeyingMode == "intermittent") 30f + 30f * Math.random().toFloat() else Float.POSITIVE_INFINITY // 30s-60s
|
if (diskJockeyingMode == "intermittent") getRandomMusicInterval() else Float.POSITIVE_INFINITY // 30s-60s
|
||||||
musicFired = false
|
musicFired = false
|
||||||
if (callStopMusicHook && musicStopHooks.isNotEmpty()) musicStopHooks.forEach {
|
if (callStopMusicHook && musicStopHooks.isNotEmpty()) musicStopHooks.forEach {
|
||||||
if (song != null) {
|
if (song != null) {
|
||||||
@@ -340,7 +342,8 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
|||||||
|
|
||||||
fun stopMusic(callStopMusicHook: Boolean = true, pauseLen: Float = Float.POSITIVE_INFINITY) {
|
fun stopMusic(callStopMusicHook: Boolean = true, pauseLen: Float = Float.POSITIVE_INFINITY) {
|
||||||
stopMusic(App.audioMixer.musicTrack.currentTrack, callStopMusicHook, pauseLen)
|
stopMusic(App.audioMixer.musicTrack.currentTrack, callStopMusicHook, pauseLen)
|
||||||
// printdbg(this, "StopMusic Intermission2: $intermissionLength seconds")
|
// printdbg(this, "StopMusic Intermission2: $pauseLen seconds, called by:")
|
||||||
|
// printStackTrace(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startMusic() {
|
fun startMusic() {
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class FixtureJukebox : Electric, PlaysMusic {
|
|||||||
|
|
||||||
printdbg(this, "Stop music $title - $artist")
|
printdbg(this, "Stop music $title - $artist")
|
||||||
|
|
||||||
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(pauseLen = Math.random().toFloat() * 30f + 30f)
|
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(pauseLen = (INGAME.musicGovernor as TerrarumMusicGovernor).getRandomMusicInterval())
|
||||||
}
|
}
|
||||||
|
|
||||||
discCurrentlyPlaying = index
|
discCurrentlyPlaying = index
|
||||||
@@ -136,7 +136,7 @@ class FixtureJukebox : Electric, PlaysMusic {
|
|||||||
*/
|
*/
|
||||||
fun stopGracefully() {
|
fun stopGracefully() {
|
||||||
stopDiscPlayback()
|
stopDiscPlayback()
|
||||||
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(pauseLen = Math.random().toFloat() * 30f + 30f)
|
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(pauseLen = (INGAME.musicGovernor as TerrarumMusicGovernor).getRandomMusicInterval())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
|
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
|
||||||
|
|||||||
Reference in New Issue
Block a user