From fa915d63d247002c11353e89c10dc7b9db6cb85f Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 27 Dec 2023 23:48:56 +0900 Subject: [PATCH] ctrl btn for musicplayer --- .../terrarum/musicplayer/gui/MusicPlayer.kt | 33 +++++++++++++++++++ .../mods/musicplayer/gui/control_buttons.tga | 3 ++ 2 files changed, 36 insertions(+) create mode 100644 assets/mods/musicplayer/gui/control_buttons.tga diff --git a/MusicPlayer/src/net/torvald/terrarum/musicplayer/gui/MusicPlayer.kt b/MusicPlayer/src/net/torvald/terrarum/musicplayer/gui/MusicPlayer.kt index 1d1ac7993..12d1d1c09 100644 --- a/MusicPlayer/src/net/torvald/terrarum/musicplayer/gui/MusicPlayer.kt +++ b/MusicPlayer/src/net/torvald/terrarum/musicplayer/gui/MusicPlayer.kt @@ -36,6 +36,7 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() { private var capsuleHeight = 28 private var capsuleMosaicSize = capsuleHeight / 2 + 1 + private val BUTTON_SIZE = 40 private val nameStrMaxLen = 180 private val nameFBO = FrameBuffer(Pixmap.Format.RGBA8888, 1024, capsuleHeight, false) @@ -46,6 +47,9 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() { private val textmask = ModMgr.getGdxFile("musicplayer", "gui/textmask.tga").let { TextureRegionPack(it, maskOffWidth, capsuleHeight) } + private val controlButtons = ModMgr.getGdxFile("musicplayer", "gui/control_buttons.tga").let { + TextureRegionPack(it, BUTTON_SIZE, BUTTON_SIZE) + } private val MODE_IDLE = 0 private val MODE_PLAYING = 1 @@ -68,6 +72,8 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() { private val colourMeter = Color(0xddddddff.toInt()) private val colourMeter2 = Color(0xdddddd80.toInt()) + private val colourControlButton = Color(0xddddddff.toInt()) + init { setAsAlwaysVisible() @@ -227,6 +233,8 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() { } } + private val transitionPercentage = 0f + private val transitionDB = HashMap, (Float) -> Unit>().also { it[MODE_IDLE to MODE_IDLE] = { akku -> } it[MODE_IDLE to MODE_PLAYING] = { akku -> @@ -295,6 +303,7 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() { drawBaloon(batch, _posX, _posY, width.toFloat(), (height - capsuleHeight.toFloat()).coerceAtLeast(0f)) drawText(batch, posXforMusicLine, _posY) drawFreqMeter(batch, posXforMusicLine + widthForFreqMeter - 18f, _posY + height - (capsuleHeight / 2) + 1f) + drawControls(batch, _posX, _posY) batch.color = Color.WHITE } @@ -327,6 +336,28 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() { } } + private fun drawControls(batch: SpriteBatch, posX: Float, posY: Float) { + val (alpha, reverse) = if (mode < MODE_MOUSE_UP && modeNext == MODE_MOUSE_UP) + (transitionAkku / TRANSITION_LENGTH).let { if (it.isNaN()) 0f else it } to false + else if (mode == MODE_MOUSE_UP && modeNext < MODE_MOUSE_UP) + (transitionAkku / TRANSITION_LENGTH).let { if (it.isNaN()) 0f else it } to true + else if (mode == MODE_MOUSE_UP) + 1f to false + else + 0f to false + + if (alpha > 0f) { + val alpha0 = alpha.coerceIn(0f, 1f).organicOvershoot().coerceAtMost(1f) + batch.color = colourControlButton mul Color(1f, 1f, 1f, (if (reverse) 1f - alpha0 else alpha0).pow(2f)) + val posX = Toolkit.hdrawWidthf - 100f + val posY = posY + 10f + for (i in 0..4) { + val iconY = if (!AudioMixer.musicTrack.isPlaying && i == 2) 1 else 0 + batch.draw(controlButtons.get(i, iconY), posX + i * BUTTON_SIZE, posY) + } + } + } + private fun drawText(batch: SpriteBatch, posX: Float, posY: Float) { batch.color = colourText batch.draw(nameFBO.colorBufferTexture, posX - maskOffWidth, posY + height - capsuleHeight + 1) @@ -447,4 +478,6 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() { fun organicOvershoot(x: Double): Double { return splineFunction.value(x) } + + private fun Float.organicOvershoot() = splineFunction.value(this.toDouble()).toFloat() } \ No newline at end of file diff --git a/assets/mods/musicplayer/gui/control_buttons.tga b/assets/mods/musicplayer/gui/control_buttons.tga new file mode 100644 index 000000000..e77f3cf61 --- /dev/null +++ b/assets/mods/musicplayer/gui/control_buttons.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f7054fd4efe43f62653f18729ee55cf53bde9f1e908e9534b0f7ac2e5c78951c +size 64018