more interesting splash screen wip

This commit is contained in:
minjaesong
2026-04-06 02:05:05 +09:00
parent 281146dd92
commit f3fb8a96f0
5 changed files with 79 additions and 2 deletions

View File

@@ -946,6 +946,9 @@ public class App implements ApplicationListener {
logoBatch.end();
// draw loading bar and subtitle
SplashScreen.render(logoBatch, camera);
// draw health messages
if (getConfigBoolean("showhealthmessageonstartup")) {
logoBatch.setShader(null);

View File

@@ -31,6 +31,16 @@ object CommonResourcePool {
private val slowLoadingQueue = ConcurrentLinkedQueue<ResourceLoadingDescriptor>()
private val slowLoadingRemaining = AtomicInteger(0)
private val slowLoadingTotal = AtomicInteger(0)
/** 0.0 = not started yet, 1.0 = all done. Only meaningful during / after [loadAllSlowly]. */
val loadingProgress: Float
get() {
val total = slowLoadingTotal.get()
if (total == 0) return 0f
val remaining = slowLoadingRemaining.get()
return (total - remaining).toFloat() / total.toFloat()
}
fun setGLThread(thread: Thread) {
glThread = thread
@@ -152,6 +162,7 @@ object CommonResourcePool {
val desc = loadingList.removeFirst()
slowLoadingQueue.add(desc)
slowLoadingRemaining.incrementAndGet()
slowLoadingTotal.incrementAndGet()
}
// Block until the GL thread has processed all slow items
while (slowLoadingRemaining.get() > 0) {

View File

@@ -0,0 +1,63 @@
package net.torvald.terrarum
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemHorzSlider
/**
* Draws the loading bar and subtitle on the cold-boot splash screen.
* Called from App.drawSplash() (Java static context) on the GL thread.
*
* Created by minjaesong on 2026-04-06.
*/
object SplashScreen {
private val stubParent = object : UICanvas() {
override var width = 0
override var height = 0
override fun updateImpl(delta: Float) {}
override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {}
override fun dispose() {}
}
private var loadingBar: UIItemHorzSlider? = null
private var lastBarWidth = 0
private val subtitleCol = Color(0.75f, 0.75f, 0.75f, 1f)
@JvmStatic
fun render(batch: SpriteBatch, camera: OrthographicCamera) {
val progress = CommonResourcePool.loadingProgress
val barWidth = (Toolkit.drawWidth * 0.4f).toInt().coerceAtLeast(200)
val barX = (Toolkit.drawWidth - barWidth) / 2
val barY = App.scr.height - 48
if (loadingBar == null || lastBarWidth != barWidth) {
lastBarWidth = barWidth
loadingBar = UIItemHorzSlider(stubParent, barX, barY, 0.0, 0.0, 1.0, barWidth).also {
it.suppressHaptic = true
it.isEnabled = false
}
}
val bar = loadingBar ?: return
bar.posX = barX
bar.posY = barY
bar.handleWidth = (progress * barWidth).toInt().coerceIn(12, barWidth)
val subtitle = "${App.GAME_NAME} ${App.getVERSION_STRING()}"
val subtitleW = App.fontGame.getWidth(subtitle)
val subtitleX = (Toolkit.drawWidth - subtitleW) / 2f
val subtitleY = (barY - 20).toFloat() // leave gap above the bar
batch.begin()
batch.color = subtitleCol
App.fontGame.draw(batch, subtitle, subtitleX, subtitleY)
batch.color = Color.WHITE
bar.render(0f, batch, camera)
batch.end()
}
}

View File

@@ -63,7 +63,7 @@ class UIItemHorzSlider(
override fun update(delta: Float) {
super.update(delta)
mouseOnHandle = itemRelativeMouseX in handlePos.roundToInt() until handlePos.roundToInt() + handleWidth && itemRelativeMouseY in 0 until height
mouseOnHandle = if (!isEnabled) false else itemRelativeMouseX in handlePos.roundToInt() until handlePos.roundToInt() + handleWidth && itemRelativeMouseY in 0 until height
// update handle position and value
if (mouseUp && Terrarum.mouseDown || mouseLatched) {

View File

@@ -60,7 +60,7 @@ class UIItemVertSlider(
override fun update(delta: Float) {
super.update(delta)
mouseOnHandle = itemRelativeMouseY in handlePos.roundToInt() until handlePos.roundToInt() + handleHeight && itemRelativeMouseX in 0 until width
mouseOnHandle = if (!isEnabled) false else itemRelativeMouseY in handlePos.roundToInt() until handlePos.roundToInt() + handleHeight && itemRelativeMouseX in 0 until width
// update handle position and value
if (mouseUp && Terrarum.mouseDown || mouseLatched) {