disposable UI; loading screen mockup (i heard like loading screen -- sonic 06)

This commit is contained in:
minjaesong
2017-07-13 17:53:40 +09:00
parent fb899dae2d
commit 2a5cb3ee38
33 changed files with 253 additions and 33 deletions

View File

@@ -3,10 +3,13 @@ package net.torvald.terrarum
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Screen
import com.badlogic.gdx.ScreenAdapter
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.jme3.math.FastMath
import net.torvald.dataclass.CircularArray
import net.torvald.dataclass.HistoryArray
import net.torvald.terrarum.gameactors.floor
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -21,7 +24,7 @@ object LoadScreen : ScreenAdapter() {
private val messages = HistoryArray<String>(20)
fun setMessage(msg: String) {
fun addMessage(msg: String) {
messages.add(msg)
}
@@ -30,17 +33,21 @@ object LoadScreen : ScreenAdapter() {
private var arrowObjPos = 0f // 0 means at starting position, regardless of screen position
private var arrowObjGlideOffsetX = 0f
private var arrowObjGlideSize = 0f
private var arrowGlideSpeed = Terrarum.WIDTH * 1.2f // pixels per sec
private lateinit var arrowObjTex: TextureRegionPack
private val arrowGlideSpeed: Float; get() = Terrarum.WIDTH * 1.5f // pixels per sec
private lateinit var arrowObjTex: Texture
private var glideTimer = 0f
private var glideDispY = 0f
private var arrowColours = arrayOf(
Color(0xff847fff.toInt()),
Color(0xffc87fff.toInt()),
Color(0xbffff2ff.toInt()),
Color(0x7fcaffff)
Color(0xff4c4cff.toInt()),
Color(0xffd24cff.toInt()),
Color(0x4cb5ffff.toInt())
)
private lateinit var textOverlayTex: Texture
private lateinit var textFbo: FrameBuffer
private val ghostMaxZoom = 1.3f
private val ghostAlphaMax = 1f
var camera = OrthographicCamera(Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
@@ -63,20 +70,39 @@ object LoadScreen : ScreenAdapter() {
override fun show() {
initViewPort(Terrarum.WIDTH, Terrarum.HEIGHT)
arrowObjTex = TextureRegionPack(Gdx.files.internal("assets/graphics/test_loading_arrow_atlas.tga"), 22, 17)
arrowObjGlideOffsetX = -arrowObjTex.texture.width.toFloat()
arrowObjGlideSize = arrowObjTex.texture.width + 1.5f * Terrarum.WIDTH
glideDispY = Terrarum.HEIGHT - 140f
textFbo = FrameBuffer(
Pixmap.Format.RGBA4444,
Terrarum.fontGame.getWidth(Lang["MENU_IO_LOADING"]),
Terrarum.fontGame.lineHeight.toInt(),
true
)
arrowObjTex = Texture(Gdx.files.internal("assets/graphics/test_loading_arrow_atlas.tga"))
arrowObjGlideOffsetX = -arrowObjTex.width.toFloat()
textOverlayTex = Texture(Gdx.files.internal("assets/graphics/test_loading_text_tint.tga"))
addMessage("**** This is a test ****")
addMessage("Segmentation fault")
}
private val textColour = Color(0xeeeeeeff.toInt())
val textX: Float; get() = (Terrarum.WIDTH * 0.75f).floor()
override fun render(delta: Float) {
glideDispY = Terrarum.HEIGHT - 100f - Terrarum.fontGame.lineHeight
arrowObjGlideSize = arrowObjTex.width + 2f * Terrarum.WIDTH
Gdx.gl.glClearColor(.157f, .157f, .157f, 0f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
textFbo.inAction(null, null) {
Gdx.gl.glClearColor(0f, 0f, 0f, 0f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
}
glideTimer += delta
if (glideTimer >= arrowObjGlideSize / arrowGlideSpeed) {
@@ -85,25 +111,105 @@ object LoadScreen : ScreenAdapter() {
arrowObjPos = glideTimer * arrowGlideSpeed
// draw text to FBO
textFbo.inAction(camera, Terrarum.batch) {
Terrarum.batch.inUse {
blendNormal()
Terrarum.fontGame
it.color = Color.WHITE
Terrarum.fontGame.draw(it, Lang["MENU_IO_LOADING"], 0.5f, 0f) // x 0.5? I dunno but it breaks w/o it
blendMul()
// draw flipped
it.draw(textOverlayTex,
0f,
Terrarum.fontGame.lineHeight,
textOverlayTex.width.toFloat(),
-Terrarum.fontGame.lineHeight
)
}
}
Terrarum.batch.inUse {
initViewPort(Terrarum.WIDTH, Terrarum.HEIGHT) // dunno, no render without this
it.projectionMatrix = camera.combined
blendNormal()
// draw text FBO to screen
val textTex = textFbo.colorBufferTexture
textTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
// --> original text
it.color = Color.WHITE
it.draw(textTex, textX, glideDispY - 2f)
// --> ghost
it.color = getPulseEffCol()
val drawWidth = getPulseEffWidthMul() * textTex.width
it.draw(textTex,
textX - (drawWidth - textTex.width) / 2f,
glideDispY - 2f,
drawWidth,
textTex.height.toFloat()
)
it.color = textColour
val textWidth = Terrarum.fontGame.getWidth(Lang["MENU_IO_LOADING"])
Terrarum.fontGame.draw(it, Lang["MENU_IO_LOADING"], (Terrarum.WIDTH - 2.5f * textWidth).round(), glideDispY - 2f)
// draw coloured arrows
arrowColours.forEachIndexed { index, color ->
it.color = color
it.draw(arrowObjTex.get(index, 0), arrowObjPos + arrowObjGlideOffsetX + 22 * index, glideDispY)
it.draw(arrowObjTex, arrowObjPos + arrowObjGlideOffsetX + arrowObjTex.width * index, glideDispY)
}
// log messages
it.color = Color.LIGHT_GRAY
for (i in 0 until messages.elemCount) {
Terrarum.fontGame.draw(it,
messages[i] ?: "",
40f,
80f + (messages.size - i - 1) * Terrarum.fontGame.lineHeight
)
}
}
}
private fun getPulseEffCol(): Color {
if (arrowObjPos + arrowObjTex.width * 3f < textX)
return Color(1f, 1f, 1f, 0f)
else {
// ref point: top-left of arrow drawn to the screen, 0 being start of the RAIL
val scaleStart = textX - arrowObjTex.width * 3f
val scaleEnd = arrowObjGlideSize - arrowObjTex.width * 3f
val scale = (arrowObjPos - scaleStart) / (scaleEnd - scaleStart)
val alpha = FastMath.interpolateLinear(scale, ghostAlphaMax, 0f)
return Color(1f, 1f, 1f, alpha)
}
}
private fun getPulseEffWidthMul(): Float {
if (arrowObjPos + arrowObjTex.width * 3f < textX)
return 1f
else {
// ref point: top-left of arrow drawn to the screen, 0 being start of the RAIL
val scaleStart = textX - arrowObjTex.width * 3f
val scaleEnd = arrowObjGlideSize - arrowObjTex.width * 3f
val scale = (arrowObjPos - scaleStart) / (scaleEnd - scaleStart)
return FastMath.interpolateLinear(scale, 1f, ghostMaxZoom)
}
}
override fun dispose() {
arrowObjTex.dispose()
textFbo.dispose()
textOverlayTex.dispose()
}
override fun hide() {