mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
working loading spinner; closing menu while loading will gracefully kill the loading thread
This commit is contained in:
@@ -59,7 +59,12 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
|
|||||||
private val mode1Node = Yaml(UITitleRemoConYaml.injectedMenuSingleCharSel).parse()
|
private val mode1Node = Yaml(UITitleRemoConYaml.injectedMenuSingleCharSel).parse()
|
||||||
|
|
||||||
private var showSpinner = false
|
private var showSpinner = false
|
||||||
|
private val spinner = CommonResourcePool.getAsTextureRegionPack("inline_loading_spinner")
|
||||||
|
private var spinnerTimer = 0f
|
||||||
|
private var spinnerFrame = 0
|
||||||
|
private val spinnerInterval = 1f / 60
|
||||||
|
|
||||||
|
private lateinit var cellLoadThread: Thread
|
||||||
|
|
||||||
fun advanceMode() {
|
fun advanceMode() {
|
||||||
App.printdbg(this, "Load playerUUID: ${UILoadGovernor.playerUUID}, worldUUID: ${UILoadGovernor.worldUUID}")
|
App.printdbg(this, "Load playerUUID: ${UILoadGovernor.playerUUID}, worldUUID: ${UILoadGovernor.worldUUID}")
|
||||||
@@ -107,17 +112,16 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
|
|||||||
playerCells.clear()
|
playerCells.clear()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
full.remoCon.handler.lockToggle()
|
// full.remoCon.handler.lockToggle() // lock not needed -- hide() will interrupt the thread
|
||||||
showSpinner = true
|
showSpinner = true
|
||||||
|
|
||||||
Thread {
|
cellLoadThread = Thread {
|
||||||
// read savegames
|
// read savegames
|
||||||
var savegamesCount = 0
|
var savegamesCount = 0
|
||||||
printdbg(this, "============== ${this.hashCode()} ============== ")
|
printdbg(this, "============== ${this.hashCode()} ============== ")
|
||||||
App.sortedPlayers.forEach { uuid ->
|
App.sortedPlayers.forEach { uuid ->
|
||||||
printdbg(this, "Reading player $uuid")
|
printdbg(this, "Reading player $uuid")
|
||||||
|
|
||||||
|
|
||||||
val x = full.uiX
|
val x = full.uiX
|
||||||
val y = titleTopGradEnd + cellInterval * savegamesCount
|
val y = titleTopGradEnd + cellInterval * savegamesCount
|
||||||
try {
|
try {
|
||||||
@@ -129,12 +133,13 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
|
|||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printdbg(this, "============== ${this.hashCode()} ============== ")
|
printdbg(this, "============== ${this.hashCode()} ============== ")
|
||||||
|
|
||||||
|
|
||||||
full.remoCon.handler.unlockToggle()
|
// full.remoCon.handler.unlockToggle()
|
||||||
showSpinner = false
|
showSpinner = false
|
||||||
}.start()
|
}.also { it.start() }
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (e: UninitializedPropertyAccessException) {
|
catch (e: UninitializedPropertyAccessException) {
|
||||||
@@ -167,6 +172,14 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
|
|||||||
it.update(delta)
|
it.update(delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showSpinner) {
|
||||||
|
spinnerTimer += delta
|
||||||
|
while (spinnerTimer > spinnerInterval) {
|
||||||
|
spinnerFrame = (spinnerFrame + 1) % 32
|
||||||
|
spinnerTimer -= spinnerInterval
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
@@ -238,6 +251,14 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
|
|||||||
savePixmap.dispose()
|
savePixmap.dispose()
|
||||||
|
|
||||||
batch.begin()
|
batch.begin()
|
||||||
|
|
||||||
|
batch.color = Color.WHITE
|
||||||
|
if (showSpinner) {
|
||||||
|
val spin = spinner.get(spinnerFrame % 8, spinnerFrame / 8)
|
||||||
|
val offX = UIRemoCon.menubarOffX - UIRemoCon.UIRemoConElement.paddingLeft + 72 + 1
|
||||||
|
val offY = UIRemoCon.menubarOffY - UIRemoCon.UIRemoConElement.lineHeight * 3 + 16
|
||||||
|
batch.draw(spin, offX.toFloat(), offY.toFloat())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
@@ -293,6 +314,7 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
|
|||||||
playerCells.forEach { it.dispose() }
|
playerCells.forEach { it.dispose() }
|
||||||
playerCells.clear()
|
playerCells.clear()
|
||||||
showCalled = false
|
showCalled = false
|
||||||
|
cellLoadThread.interrupt()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resize(width: Int, height: Int) {
|
override fun resize(width: Int, height: Int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user