mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 19:44:05 +09:00
musicplayer: mouseup wip
This commit is contained in:
@@ -38,7 +38,7 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
|
|
||||||
|
|
||||||
private val nameStrMaxLen = 180
|
private val nameStrMaxLen = 180
|
||||||
private val nameFBO = FrameBuffer(Pixmap.Format.RGBA8888, nameStrMaxLen + 2*maskOffWidth, capsuleHeight, false)
|
private val nameFBO = FrameBuffer(Pixmap.Format.RGBA8888, 1024, capsuleHeight, false)
|
||||||
|
|
||||||
private val baloonTexture = ModMgr.getGdxFile("musicplayer", "gui/blob.tga").let {
|
private val baloonTexture = ModMgr.getGdxFile("musicplayer", "gui/blob.tga").let {
|
||||||
TextureRegionPack(it, capsuleMosaicSize, capsuleMosaicSize)
|
TextureRegionPack(it, capsuleMosaicSize, capsuleMosaicSize)
|
||||||
@@ -56,7 +56,8 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
private var modeNext = MODE_IDLE
|
private var modeNext = MODE_IDLE
|
||||||
private var transitionAkku = 0f
|
private var transitionAkku = 0f
|
||||||
private var transitionRequest: Int? = null
|
private var transitionRequest: Int? = null
|
||||||
private var transitionOngoing = false
|
private val transitionOngoing
|
||||||
|
get() = transitionAkku < TRANSITION_LENGTH
|
||||||
|
|
||||||
private val TRANSITION_LENGTH = 0.6f
|
private val TRANSITION_LENGTH = 0.6f
|
||||||
|
|
||||||
@@ -182,6 +183,18 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateMeter()
|
updateMeter()
|
||||||
|
|
||||||
|
|
||||||
|
if (!transitionOngoing) {
|
||||||
|
if (mouseUp) {
|
||||||
|
transitionRequest = MODE_MOUSE_UP
|
||||||
|
}
|
||||||
|
else if (mode == MODE_MOUSE_UP) {
|
||||||
|
transitionRequest = if (currentMusicName.isEmpty()) MODE_IDLE else MODE_PLAYING
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// printdbg(this, "mode = $mode; req = $transitionRequest")
|
||||||
}
|
}
|
||||||
|
|
||||||
// private fun smoothstep(x: Float) = (x*x*(3f-2f*x)).coerceIn(0f, 1f)
|
// private fun smoothstep(x: Float) = (x*x*(3f-2f*x)).coerceIn(0f, 1f)
|
||||||
@@ -198,6 +211,12 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
width = FastMath.interpolateLinearNoClamp(step, zeroWidth, maxWidth).roundToInt()
|
width = FastMath.interpolateLinearNoClamp(step, zeroWidth, maxWidth).roundToInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setUIheight(heightOld: Int, heightNew: Int, percentage: Float) {
|
||||||
|
val percentage = if (percentage.isNaN()) 0f else percentage
|
||||||
|
val step = organicOvershoot(percentage.coerceIn(0f, 1f).toDouble()).toFloat()
|
||||||
|
height = FastMath.interpolateLinearNoClamp(step, heightOld.toFloat(), heightNew.toFloat()).roundToInt().coerceAtLeast(capsuleHeight)
|
||||||
|
}
|
||||||
|
|
||||||
// changes ui width
|
// changes ui width
|
||||||
private fun makeTransition() {
|
private fun makeTransition() {
|
||||||
transitionDB[mode to modeNext].let {
|
transitionDB[mode to modeNext].let {
|
||||||
@@ -217,24 +236,49 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
it[MODE_PLAYING to MODE_IDLE] = { akku ->
|
it[MODE_PLAYING to MODE_IDLE] = { akku ->
|
||||||
setUIwidthFromTextWidth(nameLengthOld, nameLength, akku / TRANSITION_LENGTH)
|
setUIwidthFromTextWidth(nameLengthOld, nameLength, akku / TRANSITION_LENGTH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it[MODE_IDLE to MODE_MOUSE_UP] = { akku ->
|
||||||
|
setUIwidthFromTextWidth(nameLengthOld, (nameStrMaxLen + METERS_WIDTH + maskOffWidth).toInt(), akku / TRANSITION_LENGTH)
|
||||||
|
setUIheight(28, 80, akku / TRANSITION_LENGTH)
|
||||||
|
}
|
||||||
|
it[MODE_PLAYING to MODE_MOUSE_UP] = { akku ->
|
||||||
|
setUIwidthFromTextWidth(nameLengthOld, (nameStrMaxLen + METERS_WIDTH + maskOffWidth).toInt(), akku / TRANSITION_LENGTH)
|
||||||
|
setUIheight(28, 80, akku / TRANSITION_LENGTH)
|
||||||
|
}
|
||||||
|
it[MODE_MOUSE_UP to MODE_PLAYING] = { akku ->
|
||||||
|
setUIwidthFromTextWidth((nameStrMaxLen + METERS_WIDTH + maskOffWidth).toInt(), nameLength, akku / TRANSITION_LENGTH)
|
||||||
|
setUIheight(80, 28, akku / TRANSITION_LENGTH)
|
||||||
|
}
|
||||||
|
it[MODE_MOUSE_UP to MODE_IDLE] = { akku ->
|
||||||
|
setUIwidthFromTextWidth((nameStrMaxLen + METERS_WIDTH + maskOffWidth).toInt(), 0, akku / TRANSITION_LENGTH)
|
||||||
|
setUIheight(80, 28, akku / TRANSITION_LENGTH)
|
||||||
|
}
|
||||||
|
|
||||||
|
it[MODE_MOUSE_UP to MODE_MOUSE_UP] = { akku -> }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var _posX = 0f // not using provided `posX` as there is one frame delay between update and it actually used to drawing
|
||||||
|
private var _posY = 0f
|
||||||
|
|
||||||
override val mouseUp: Boolean
|
override val mouseUp: Boolean
|
||||||
get() = (relativeMouseX) in -capsuleMosaicSize until width+capsuleMosaicSize && relativeMouseY in 0 until height
|
get() = relativeMouseX.toFloat() in _posX-capsuleMosaicSize .. _posX+width+capsuleMosaicSize &&
|
||||||
|
relativeMouseY.toFloat() in _posY .. _posY+height
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) {
|
override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) {
|
||||||
batch.end()
|
batch.end()
|
||||||
renderNameToFBO(batch, camera, currentMusicName, 0f..width.toFloat() - METERS_WIDTH.toInt() - maskOffWidth)
|
renderNameToFBO(batch, camera, currentMusicName)
|
||||||
batch.begin()
|
batch.begin()
|
||||||
|
|
||||||
|
|
||||||
posX = ((Toolkit.drawWidth - width) / 2)
|
_posX = ((Toolkit.drawWidth - width) / 2).toFloat()
|
||||||
posY = (App.scr.height - App.scr.tvSafeGraphicsHeight - height)
|
_posY = (App.scr.height - App.scr.tvSafeGraphicsHeight - height).toFloat()
|
||||||
|
|
||||||
blendNormalStraightAlpha(batch)
|
blendNormalStraightAlpha(batch)
|
||||||
drawBaloon(batch, 0f, 0f, width.toFloat(), height - capsuleHeight.toFloat())
|
drawBaloon(batch, _posX, _posY, width.toFloat(), (height - capsuleHeight.toFloat()).coerceAtLeast(0f))
|
||||||
drawText(batch, 0f, 0f)
|
drawText(batch, _posX, _posY)
|
||||||
drawFreqMeter(batch, width - 18f, height - (capsuleHeight / 2) + 1f)
|
drawFreqMeter(batch, _posX + width - 18f, _posY + height - (capsuleHeight / 2) + 1f)
|
||||||
|
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
}
|
}
|
||||||
@@ -245,49 +289,51 @@ class MusicPlayer(private val ingame: TerrarumIngame) : UICanvas() {
|
|||||||
batch.color = if (k == 0) colourEdge else colourBack// (if (mouseUp) Color.MAROON else colourBack)
|
batch.color = if (k == 0) colourEdge else colourBack// (if (mouseUp) Color.MAROON else colourBack)
|
||||||
|
|
||||||
// top left
|
// top left
|
||||||
batch.draw(baloonTexture.get(k, 0), x, y)
|
batch.draw(baloonTexture.get(k+0, 0), x, y, capsuleMosaicSize.toFloat(), capsuleMosaicSize.toFloat())
|
||||||
// top
|
// top
|
||||||
batch.draw(baloonTexture.get(k+1, 0), x + capsuleMosaicSize, y, width, capsuleMosaicSize.toFloat())
|
batch.draw(baloonTexture.get(k+1, 0), x + capsuleMosaicSize, y, width, capsuleMosaicSize.toFloat())
|
||||||
// top right
|
// top right
|
||||||
batch.draw(baloonTexture.get(k+2, 0), x + capsuleMosaicSize + width, y)
|
batch.draw(baloonTexture.get(k+2, 0), x + capsuleMosaicSize + width, y, capsuleMosaicSize.toFloat(), capsuleMosaicSize.toFloat())
|
||||||
if (height > 0) {
|
|
||||||
// left
|
// left
|
||||||
batch.draw(baloonTexture.get(k, 1), x, y + capsuleMosaicSize)
|
batch.draw(baloonTexture.get(k+0, 1), x, y + capsuleMosaicSize, capsuleMosaicSize.toFloat(), height)
|
||||||
// centre
|
// centre
|
||||||
batch.draw(baloonTexture.get(k+1, 1), x + capsuleMosaicSize, y + capsuleMosaicSize, width, height)
|
batch.draw(baloonTexture.get(k+1, 1), x + capsuleMosaicSize, y + capsuleMosaicSize, width, height)
|
||||||
// right
|
// right
|
||||||
batch.draw(baloonTexture.get(k+2, 1), x + capsuleMosaicSize + width, y + capsuleMosaicSize)
|
batch.draw(baloonTexture.get(k+2, 1), x + capsuleMosaicSize + width, y + capsuleMosaicSize, capsuleMosaicSize.toFloat(), height)
|
||||||
}
|
|
||||||
// bottom left
|
// bottom left
|
||||||
batch.draw(baloonTexture.get(k, 2), x, y + capsuleMosaicSize + height)
|
batch.draw(baloonTexture.get(k+0, 2), x, y + capsuleMosaicSize + height, capsuleMosaicSize.toFloat(), capsuleMosaicSize.toFloat())
|
||||||
// bottom
|
// bottom
|
||||||
batch.draw(baloonTexture.get(k+1, 2), x + capsuleMosaicSize, y + capsuleMosaicSize + height, width, capsuleMosaicSize.toFloat())
|
batch.draw(baloonTexture.get(k+1, 2), x + capsuleMosaicSize, y + capsuleMosaicSize + height, width, capsuleMosaicSize.toFloat())
|
||||||
// bottom right
|
// bottom right
|
||||||
batch.draw(baloonTexture.get(k+2, 2), x + capsuleMosaicSize + width, y + capsuleMosaicSize + height)
|
batch.draw(baloonTexture.get(k+2, 2), x + capsuleMosaicSize + width, y + capsuleMosaicSize + height, capsuleMosaicSize.toFloat(), capsuleMosaicSize.toFloat())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun drawText(batch: SpriteBatch, posX: Float, posY: Float) {
|
private fun drawText(batch: SpriteBatch, posX: Float, posY: Float) {
|
||||||
batch.color = colourText
|
batch.color = colourText
|
||||||
batch.draw(nameFBO.colorBufferTexture, posX - maskOffWidth, posY - 1)
|
batch.draw(nameFBO.colorBufferTexture, posX - maskOffWidth, posY + height - capsuleHeight + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderNameToFBO(batch: SpriteBatch, camera: OrthographicCamera, str: String, window: ClosedFloatingPointRange<Float>) {
|
private fun renderNameToFBO(batch: SpriteBatch, camera: OrthographicCamera, str: String) {
|
||||||
|
val windowEnd = width.toFloat() - METERS_WIDTH - maskOffWidth
|
||||||
|
|
||||||
nameFBO.inAction(camera, batch) {
|
nameFBO.inAction(camera, batch) {
|
||||||
batch.inUse {
|
batch.inUse {
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
// draw text
|
// draw text
|
||||||
gdxClearAndEnableBlend(0f, 0f, 0f, 0f)
|
gdxClearAndEnableBlend(0f, 0f, 0f, 0f)
|
||||||
blendNormalStraightAlpha(batch)
|
blendNormalStraightAlpha(batch)
|
||||||
App.fontGameFBO.draw(batch, str, maskOffWidth.toFloat() - nameScroll, 0f)
|
App.fontGameFBO.draw(batch, str, maskOffWidth.toFloat() - nameScroll, 2f)
|
||||||
|
|
||||||
// mask off the area
|
// mask off the area
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
blendAlphaMask(batch)
|
blendAlphaMask(batch)
|
||||||
batch.draw(textmask.get(0, 0), window.start, 0f)
|
batch.draw(textmask.get(0, 0), 0f, 0f)
|
||||||
batch.draw(textmask.get(1, 0), window.start + maskOffWidth, 0f, window.endInclusive - window.start, capsuleHeight.toFloat())
|
batch.draw(textmask.get(1, 0), maskOffWidth.toFloat(), 0f, windowEnd, capsuleHeight.toFloat())
|
||||||
batch.draw(textmask.get(2, 0), window.start + window.endInclusive + maskOffWidth, 0f)
|
batch.draw(textmask.get(2, 0), windowEnd + maskOffWidth, 0f)
|
||||||
batch.draw(textmask.get(3, 0), window.start + window.endInclusive + 2 * maskOffWidth, 0f, 1000f, capsuleHeight.toFloat())
|
batch.draw(textmask.get(3, 0), windowEnd + 2 * maskOffWidth, 0f, 1000f, capsuleHeight.toFloat())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user