mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
better music player behaviour
This commit is contained in:
@@ -176,7 +176,10 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
private var mouseOnButton: Int? = null
|
private var mouseOnButton: Int? = null
|
||||||
private var mouseOnList: Int? = null
|
private var mouseOnList: Int? = null
|
||||||
|
|
||||||
|
private var transactionLocked = MusicService.transactionLocked
|
||||||
|
|
||||||
override fun updateImpl(delta: Float) {
|
override fun updateImpl(delta: Float) {
|
||||||
|
transactionLocked = MusicService.transactionLocked // the value need to be "latched"
|
||||||
val currentPlaylist = getCurrentPlaylist()
|
val currentPlaylist = getCurrentPlaylist()
|
||||||
|
|
||||||
// process transition request
|
// process transition request
|
||||||
@@ -296,9 +299,13 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
else {
|
else {
|
||||||
mouseOnButton = null
|
mouseOnButton = null
|
||||||
}
|
}
|
||||||
|
//// manually nullify the buttons that does nothing when locked
|
||||||
|
if (transactionLocked && mode < MODE_SHOW_LIST && (mouseOnButton == 1 || mouseOnButton == 3)) {
|
||||||
|
mouseOnButton = null
|
||||||
|
}
|
||||||
|
|
||||||
// mouse is over which list
|
// mouse is over which list
|
||||||
mouseOnList = if (mode >= MODE_SHOW_LIST &&
|
mouseOnList = if (!transactionLocked && mode >= MODE_SHOW_LIST &&
|
||||||
relativeMouseY.toFloat() in _posY + 9.._posY + 9 + PLAYLIST_LINES*PLAYLIST_LINE_HEIGHT &&
|
relativeMouseY.toFloat() in _posY + 9.._posY + 9 + PLAYLIST_LINES*PLAYLIST_LINE_HEIGHT &&
|
||||||
relativeMouseX.toFloat() in _posX.._posX + width) {
|
relativeMouseX.toFloat() in _posX.._posX + width) {
|
||||||
|
|
||||||
@@ -335,9 +342,11 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
1 -> { // prev
|
1 -> { // prev
|
||||||
// prev song
|
// prev song
|
||||||
if (mode < MODE_SHOW_LIST) {
|
if (mode < MODE_SHOW_LIST) {
|
||||||
MusicService.playPrevSongInPlaylist {
|
if (!transactionLocked) {
|
||||||
iHitTheStopButton = false
|
MusicService.playPrevSongInPlaylist(true) {
|
||||||
stopRequested = false
|
iHitTheStopButton = false
|
||||||
|
stopRequested = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// prev page in the playlist
|
// prev page in the playlist
|
||||||
@@ -365,7 +374,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
if (thisMusic is MusicContainer) thisMusic.let { ingame.backgroundMusicPlayer.queueMusicToPlayNext(it) }
|
if (thisMusic is MusicContainer) thisMusic.let { ingame.backgroundMusicPlayer.queueMusicToPlayNext(it) }
|
||||||
iHitTheStopButton = true*/
|
iHitTheStopButton = true*/
|
||||||
|
|
||||||
MusicService.stopPlaylistPlayback {
|
MusicService.stopPlaylistPlayback(true) {
|
||||||
iHitTheStopButton = true
|
iHitTheStopButton = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,9 +400,11 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
3 -> { // next
|
3 -> { // next
|
||||||
// next song
|
// next song
|
||||||
if (mode < MODE_SHOW_LIST) {
|
if (mode < MODE_SHOW_LIST) {
|
||||||
MusicService.playNextSongInPlaylist {
|
if (!transactionLocked) {
|
||||||
iHitTheStopButton = false
|
MusicService.playNextSongInPlaylist(true) {
|
||||||
stopRequested = false
|
iHitTheStopButton = false
|
||||||
|
stopRequested = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// next page in the playlist
|
// next page in the playlist
|
||||||
@@ -435,9 +446,11 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
if (index < currentPlaylist.musicList.size) {
|
if (index < currentPlaylist.musicList.size) {
|
||||||
// if selected song != currently playing
|
// if selected song != currently playing
|
||||||
if (App.audioMixer.musicTrack.currentTrack == null || currentPlaylist.musicList[index] != App.audioMixer.musicTrack.currentTrack) {
|
if (App.audioMixer.musicTrack.currentTrack == null || currentPlaylist.musicList[index] != App.audioMixer.musicTrack.currentTrack) {
|
||||||
MusicService.playNthSongInPlaylist(index) {
|
if (!transactionLocked) {
|
||||||
iHitTheStopButton = false
|
MusicService.playNthSongInPlaylist(index, true) {
|
||||||
stopRequested = false
|
iHitTheStopButton = false
|
||||||
|
stopRequested = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -452,9 +465,11 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
// if selected album is not the same album currently playing, queue that album immediately
|
// if selected album is not the same album currently playing, queue that album immediately
|
||||||
// (navigating into the selected album involves too much complication :p)
|
// (navigating into the selected album involves too much complication :p)
|
||||||
if (MusicService.currentPlaylist?.source != albumsList[index].canonicalPath) {
|
if (MusicService.currentPlaylist?.source != albumsList[index].canonicalPath) {
|
||||||
val playlist = loadNewAlbum(albumsList[index])
|
if (!transactionLocked) {
|
||||||
MusicService.putNewPlaylistAndResumePlayback(playlist) {
|
val playlist = loadNewAlbum(albumsList[index])
|
||||||
resetPlaylistScroll(App.audioMixer.musicTrack.nextTrack as? MusicContainer)
|
MusicService.putNewPlaylistAndResumePlayback(playlist, true) {
|
||||||
|
resetPlaylistScroll(App.audioMixer.musicTrack.nextTrack as? MusicContainer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -680,7 +695,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
|
|
||||||
// debug codes
|
// debug codes
|
||||||
//// transaction state
|
//// transaction state
|
||||||
/*if (MusicService.transactionLocked) {
|
/*if (transactionLocked) {
|
||||||
batch.color = Color.RED
|
batch.color = Color.RED
|
||||||
Toolkit.drawTextCentered(batch, App.fontSmallNumbers, "LOCKED", Toolkit.drawWidth, 0, _posY.toInt() + height + 5)
|
Toolkit.drawTextCentered(batch, App.fontSmallNumbers, "LOCKED", Toolkit.drawWidth, 0, _posY.toInt() + height + 5)
|
||||||
}
|
}
|
||||||
@@ -1020,7 +1035,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val playControlAnimAkku = FloatArray(5) // how many control buttons?
|
private val playControlAnimAkku = FloatArray(5) // how many control buttons?
|
||||||
private val playControlAnimLength = 0.2f
|
private val playControlAnimLength = 0.16f
|
||||||
|
|
||||||
private val colInactive = Color(0xaaaaaaff.toInt())
|
private val colInactive = Color(0xaaaaaaff.toInt())
|
||||||
|
|
||||||
@@ -1043,7 +1058,7 @@ class MusicPlayerControl(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
else
|
else
|
||||||
0f
|
0f
|
||||||
|
|
||||||
val baseCol = if (MusicService.transactionLocked) colInactive else Color.WHITE
|
val baseCol = if (transactionLocked) colInactive else Color.WHITE
|
||||||
|
|
||||||
if (alpha > 0f) {
|
if (alpha > 0f) {
|
||||||
val alpha0 = alpha.coerceIn(0f, 1f).organicOvershoot().coerceAtMost(1f)
|
val alpha0 = alpha.coerceIn(0f, 1f).organicOvershoot().coerceAtMost(1f)
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ object MusicService : TransactionListener() {
|
|||||||
* @param playlist An instance of a [TerrarumMusicPlaylist] to be changed into
|
* @param playlist An instance of a [TerrarumMusicPlaylist] to be changed into
|
||||||
* @param onSuccess What to do after the transaction
|
* @param onSuccess What to do after the transaction
|
||||||
*/
|
*/
|
||||||
private fun createTransactionPlaylistChangeAndPlayImmediately(playlist: TerrarumMusicPlaylist, onSuccess: () -> Unit): Transaction {
|
private fun createTransactionPlaylistChangeAndPlayImmediately(playlist: TerrarumMusicPlaylist, fadeLen: Double, onSuccess: () -> Unit): Transaction {
|
||||||
return object : Transaction {
|
return object : Transaction {
|
||||||
var oldPlaylist: TerrarumMusicPlaylist? = null
|
var oldPlaylist: TerrarumMusicPlaylist? = null
|
||||||
var oldState = currentPlaybackState.get()
|
var oldState = currentPlaybackState.get()
|
||||||
@@ -273,7 +273,7 @@ object MusicService : TransactionListener() {
|
|||||||
if (App.audioMixer.musicTrack.isPlaying) {
|
if (App.audioMixer.musicTrack.isPlaying) {
|
||||||
var fadedOut = false
|
var fadedOut = false
|
||||||
|
|
||||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack) {
|
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, fadeLen) {
|
||||||
// put new playlist
|
// put new playlist
|
||||||
state["currentPlaylist"] = playlist
|
state["currentPlaylist"] = playlist
|
||||||
|
|
||||||
@@ -329,7 +329,7 @@ object MusicService : TransactionListener() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createTransactionForNextMusicInPlaylist(onSuccess: () -> Unit): Transaction {
|
private fun createTransactionForNextMusicInPlaylist(fadeLen: Double, onSuccess: () -> Unit): Transaction {
|
||||||
return object : Transaction {
|
return object : Transaction {
|
||||||
var oldState = currentPlaybackState.get()
|
var oldState = currentPlaybackState.get()
|
||||||
var oldAkku = waitAkku
|
var oldAkku = waitAkku
|
||||||
@@ -339,7 +339,7 @@ object MusicService : TransactionListener() {
|
|||||||
var fadedOut = false
|
var fadedOut = false
|
||||||
var err: Throwable? = null
|
var err: Throwable? = null
|
||||||
// request fadeout
|
// request fadeout
|
||||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack) {
|
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, fadeLen) {
|
||||||
try {
|
try {
|
||||||
// do nothing, really
|
// do nothing, really
|
||||||
|
|
||||||
@@ -374,7 +374,7 @@ object MusicService : TransactionListener() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createTransactionForPrevMusicInPlaylist(onSuccess: () -> Unit): Transaction {
|
private fun createTransactionForPrevMusicInPlaylist(fadeLen: Double, onSuccess: () -> Unit): Transaction {
|
||||||
return object : Transaction {
|
return object : Transaction {
|
||||||
var oldState = currentPlaybackState.get()
|
var oldState = currentPlaybackState.get()
|
||||||
var oldAkku = waitAkku
|
var oldAkku = waitAkku
|
||||||
@@ -384,7 +384,7 @@ object MusicService : TransactionListener() {
|
|||||||
var fadedOut = false
|
var fadedOut = false
|
||||||
var err: Throwable? = null
|
var err: Throwable? = null
|
||||||
// request fadeout
|
// request fadeout
|
||||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack) {
|
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, fadeLen) {
|
||||||
try {
|
try {
|
||||||
// unshift the playlist
|
// unshift the playlist
|
||||||
// FIREPLAY always pulls next track, that's why we need two prev()
|
// FIREPLAY always pulls next track, that's why we need two prev()
|
||||||
@@ -425,7 +425,7 @@ object MusicService : TransactionListener() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createTransactionForNthMusicInPlaylist(index: Int, onSuccess: () -> Unit): Transaction {
|
private fun createTransactionForNthMusicInPlaylist(index: Int, fadeLen: Double, onSuccess: () -> Unit): Transaction {
|
||||||
return object : Transaction {
|
return object : Transaction {
|
||||||
var oldState = currentPlaybackState.get()
|
var oldState = currentPlaybackState.get()
|
||||||
var oldAkku = waitAkku
|
var oldAkku = waitAkku
|
||||||
@@ -435,7 +435,7 @@ object MusicService : TransactionListener() {
|
|||||||
var fadedOut = false
|
var fadedOut = false
|
||||||
var err: Throwable? = null
|
var err: Throwable? = null
|
||||||
// request fadeout
|
// request fadeout
|
||||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack) {
|
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, fadeLen) {
|
||||||
try {
|
try {
|
||||||
// callback: play prev song in the playlist
|
// callback: play prev song in the playlist
|
||||||
// queue the nth song on the playlist, the actual playback will be done by the state machine update
|
// queue the nth song on the playlist, the actual playback will be done by the state machine update
|
||||||
@@ -584,11 +584,11 @@ object MusicService : TransactionListener() {
|
|||||||
else
|
else
|
||||||
runTransaction(createTransactionPlaylistChange(playlist, {}))
|
runTransaction(createTransactionPlaylistChange(playlist, {}))
|
||||||
}
|
}
|
||||||
fun putNewPlaylistAndResumePlayback(playlist: TerrarumMusicPlaylist, onSuccess: (() -> Unit)? = null) {
|
fun putNewPlaylistAndResumePlayback(playlist: TerrarumMusicPlaylist, shortFade: Boolean = false, onSuccess: (() -> Unit)? = null) {
|
||||||
if (onSuccess != null)
|
if (onSuccess != null)
|
||||||
runTransaction(createTransactionPlaylistChangeAndPlayImmediately(playlist, onSuccess))
|
runTransaction(createTransactionPlaylistChangeAndPlayImmediately(playlist, DEFAULT_FADEOUT_LEN / shortFade.toInt().plus(1), onSuccess))
|
||||||
else
|
else
|
||||||
runTransaction(createTransactionPlaylistChangeAndPlayImmediately(playlist, {}))
|
runTransaction(createTransactionPlaylistChangeAndPlayImmediately(playlist, DEFAULT_FADEOUT_LEN / shortFade.toInt().plus(1), {}))
|
||||||
}
|
}
|
||||||
fun putNewPlaylist(playlist: TerrarumMusicPlaylist, onSuccess: () -> Unit, onFinally: () -> Unit) {
|
fun putNewPlaylist(playlist: TerrarumMusicPlaylist, onSuccess: () -> Unit, onFinally: () -> Unit) {
|
||||||
runTransaction(createTransactionPlaylistChange(playlist, onSuccess), onFinally)
|
runTransaction(createTransactionPlaylistChange(playlist, onSuccess), onFinally)
|
||||||
@@ -603,25 +603,25 @@ object MusicService : TransactionListener() {
|
|||||||
runTransaction(createTransactionPausePlaylistForMusicalFixture(action, musicFinished, onSuccess, onFailure), onFinally)
|
runTransaction(createTransactionPausePlaylistForMusicalFixture(action, musicFinished, onSuccess, onFailure), onFinally)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun playNextSongInPlaylist(onSuccess: () -> Unit) {
|
fun playNextSongInPlaylist(shortFade: Boolean = false, onSuccess: () -> Unit) {
|
||||||
runTransaction(createTransactionForNextMusicInPlaylist(onSuccess))
|
runTransaction(createTransactionForNextMusicInPlaylist(DEFAULT_FADEOUT_LEN / shortFade.toInt().plus(1), onSuccess))
|
||||||
}
|
}
|
||||||
fun playNextSongInPlaylist(onSuccess: () -> Unit, onFinally: () -> Unit) {
|
fun playNextSongInPlaylist(shortFade: Boolean = false, onSuccess: () -> Unit, onFinally: () -> Unit) {
|
||||||
runTransaction(createTransactionForNextMusicInPlaylist(onSuccess), onFinally)
|
runTransaction(createTransactionForNextMusicInPlaylist(DEFAULT_FADEOUT_LEN / shortFade.toInt().plus(1), onSuccess), onFinally)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun playPrevSongInPlaylist(onSuccess: () -> Unit) {
|
fun playPrevSongInPlaylist(shortFade: Boolean = false, onSuccess: () -> Unit) {
|
||||||
runTransaction(createTransactionForPrevMusicInPlaylist(onSuccess))
|
runTransaction(createTransactionForPrevMusicInPlaylist(DEFAULT_FADEOUT_LEN / shortFade.toInt().plus(1), onSuccess))
|
||||||
}
|
}
|
||||||
fun playPrevSongInPlaylist(onSuccess: () -> Unit, onFinally: () -> Unit) {
|
fun playPrevSongInPlaylist(shortFade: Boolean = false, onSuccess: () -> Unit, onFinally: () -> Unit) {
|
||||||
runTransaction(createTransactionForPrevMusicInPlaylist(onSuccess), onFinally)
|
runTransaction(createTransactionForPrevMusicInPlaylist(DEFAULT_FADEOUT_LEN / shortFade.toInt().plus(1), onSuccess), onFinally)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun playNthSongInPlaylist(index: Int, onSuccess: () -> Unit) {
|
fun playNthSongInPlaylist(index: Int, shortFade: Boolean = false, onSuccess: () -> Unit) {
|
||||||
runTransaction(createTransactionForNthMusicInPlaylist(index, onSuccess))
|
runTransaction(createTransactionForNthMusicInPlaylist(index, DEFAULT_FADEOUT_LEN / shortFade.toInt().plus(1), onSuccess))
|
||||||
}
|
}
|
||||||
fun playNthSongInPlaylist(index: Int, onSuccess: () -> Unit, onFinally: () -> Unit) {
|
fun playNthSongInPlaylist(index: Int, shortFade: Boolean = false, onSuccess: () -> Unit, onFinally: () -> Unit) {
|
||||||
runTransaction(createTransactionForNthMusicInPlaylist(index, onSuccess), onFinally)
|
runTransaction(createTransactionForNthMusicInPlaylist(index, DEFAULT_FADEOUT_LEN / shortFade.toInt().plus(1), onSuccess), onFinally)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopPlaylistPlayback(onSuccess: () -> Unit) {
|
fun stopPlaylistPlayback(onSuccess: () -> Unit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user