mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
load list: thumbnail on management scr
This commit is contained in:
@@ -265,6 +265,6 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
|
||||
|
||||
override fun dispose() {
|
||||
minimapFBO.dispose()
|
||||
renderTextures.forEach { try { it.dispose() } catch (e: GdxRuntimeException) {} }
|
||||
renderTextures.forEach { it.tryDispose() }
|
||||
}
|
||||
}
|
||||
@@ -138,8 +138,6 @@ class UILoadAutosave(val full: UILoadSavegame) : UICanvas() {
|
||||
|
||||
private fun DiskPair.getThumbnail(): TextureRegion {
|
||||
return this.player.requestFile(VDFileID.PLAYER_SCREENSHOT).let { file ->
|
||||
CommonResourcePool.getAsTextureRegion("terrarum-defaultsavegamethumb")
|
||||
|
||||
if (file != null) {
|
||||
val zippedTga = (file.contents as EntryFile).bytes
|
||||
val gzin = GZIPInputStream(ByteArray64InputStream(zippedTga))
|
||||
|
||||
@@ -6,9 +6,7 @@ import com.badlogic.gdx.graphics.*
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||
import com.badlogic.gdx.utils.JsonReader
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.unicode.EMDASH
|
||||
import net.torvald.unicode.getKeycapConsole
|
||||
@@ -458,8 +456,8 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : Advanceable() {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
try { shapeRenderer.dispose() } catch (e: IllegalArgumentException) {}
|
||||
try { sliderFBO.dispose() } catch (e: IllegalArgumentException) {}
|
||||
shapeRenderer.tryDispose()
|
||||
sliderFBO.tryDispose()
|
||||
}
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
@@ -560,12 +558,12 @@ class UIItemPlayerCells(
|
||||
private var highlightCol: Color = defaultCol
|
||||
private var highlightTextCol: Color = defaultCol
|
||||
|
||||
var forceMouseDown = false
|
||||
var forceUnhighlight = false
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
highlightCol = if (mouseUp && !forceMouseDown) litCol else defaultCol
|
||||
highlightTextCol = if (mouseUp && !forceMouseDown) litCol else Toolkit.Theme.COL_LIST_DEFAULT
|
||||
highlightCol = if (mouseUp && !forceUnhighlight) litCol else defaultCol
|
||||
highlightTextCol = if (mouseUp && !forceUnhighlight) litCol else Toolkit.Theme.COL_LIST_DEFAULT
|
||||
}
|
||||
|
||||
fun render(batch: SpriteBatch, camera: Camera, offX: Int, offY: Int) {
|
||||
|
||||
@@ -3,10 +3,13 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.gdxClearAndEnableBlend
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.serialise.LoadSavegame
|
||||
import net.torvald.terrarum.savegame.VDFileID.PLAYER_SCREENSHOT
|
||||
import net.torvald.terrarum.tryDispose
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItemTextButton
|
||||
@@ -119,12 +122,25 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
|
||||
|
||||
}
|
||||
|
||||
private var screencap: TextureRegion? = null
|
||||
private val screencapW = SAVE_CELL_WIDTH
|
||||
private val screencapH = SAVE_CELL_HEIGHT * 2
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
full.playerButtonSelected?.forceMouseDown = true
|
||||
full.playerButtonSelected?.forceUnhighlight = true
|
||||
full.playerButtonSelected?.let { button ->
|
||||
screencap?.texture?.tryDispose()
|
||||
screencap = App.savegamePlayers[button.playerUUID]!!.getPlayerThumbnail(screencapW, screencapH, 2.0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
full.playerButtonSelected?.forceMouseDown = false
|
||||
full.playerButtonSelected?.forceUnhighlight = false
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
super.show()
|
||||
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
@@ -141,12 +157,25 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
|
||||
private var loadFiredFrameCounter = 0
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
val buttonYdelta = (full.titleTopGradEnd + full.cellInterval) - full.playerButtonSelected!!.posY
|
||||
val buttonYdelta = (full.titleTopGradEnd) - full.playerButtonSelected!!.posY
|
||||
full.playerButtonSelected!!.render(batch, camera, 0, buttonYdelta)
|
||||
|
||||
when (mode) {
|
||||
MODE_INIT -> {
|
||||
mainButtons.forEach { it.render(batch, camera) }
|
||||
|
||||
// draw thumbnails of the most recent game
|
||||
val tex = screencap ?: CommonResourcePool.getAsTextureRegion("terrarum-defaultsavegamethumb")
|
||||
val tx = (Toolkit.drawWidth - screencapW) / 2
|
||||
val ty = full.titleTopGradEnd + SAVE_CELL_HEIGHT + buttonGap
|
||||
|
||||
batch.color = Toolkit.Theme.COL_INACTIVE
|
||||
Toolkit.drawBoxBorder(batch, tx - 1, ty - 1, screencapW + 2, screencapH + 2)
|
||||
batch.color = UIInventoryFull.CELL_COL
|
||||
Toolkit.fillArea(batch, tx, ty, screencapW, screencapH)
|
||||
batch.color = Color.WHITE
|
||||
batch.draw(tex, tx.toFloat(), ty.toFloat(), screencapW.toFloat(), screencapH.toFloat())
|
||||
|
||||
}
|
||||
MODE_DELETE -> {
|
||||
Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_SAVE_WILL_BE_DELETED"], Toolkit.drawWidth, 0, full.titleTopGradEnd + full.cellInterval - 46)
|
||||
|
||||
@@ -60,20 +60,8 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
|
||||
internal val titleBottomGradStart: Int = height - App.scr.tvSafeGraphicsHeight - gradAreaHeight
|
||||
internal val titleBottomGradEnd: Int = titleBottomGradStart + gradAreaHeight
|
||||
|
||||
|
||||
private var scrollAreaHeight = height - 2 * App.scr.tvSafeGraphicsHeight - 64
|
||||
private var listScroll = 0 // only update when animation is finished
|
||||
private var savesVisible = (scrollAreaHeight + cellGap) / cellInterval
|
||||
private var uiScroll = 0f
|
||||
private var scrollFrom = 0
|
||||
private var scrollTarget = 0
|
||||
private var scrollAnimCounter = 0f
|
||||
private val scrollAnimLen = 0.1f
|
||||
private var sliderFBO = FrameBuffer(Pixmap.Format.RGBA8888, uiWidth + 10, height, false)
|
||||
|
||||
internal var playerButtonSelected: UIItemPlayerCells? = null
|
||||
|
||||
|
||||
internal lateinit var loadables: SavegameCollectionPair // will be used and modified by subUIs
|
||||
|
||||
internal lateinit var loadManageSelectedGame: DiskPair
|
||||
@@ -88,7 +76,6 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
|
||||
private val transitionalAutosave = UILoadAutosave(this)
|
||||
private val transitionalManage = UILoadManage(this)
|
||||
private val transitionalNewCharacter = UINewCharacter(remoCon)
|
||||
// private val transitionalSaveDamaged = UILoadSaveDamaged(this)
|
||||
private val transitionPanel = UIItemHorizontalFadeSlide(
|
||||
this,
|
||||
(width - internalWidth) / 2,
|
||||
@@ -103,7 +90,6 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
|
||||
|
||||
internal fun queueUpManageScr() { transitionPanel.setCentreUIto(0) }
|
||||
internal fun queueUpNewCharScr() { transitionPanel.setCentreUIto(1) }
|
||||
// internal fun queueUpDamagedSaveScr() { transitionPanel.setCentreUIto(2) }
|
||||
|
||||
internal fun bringAutosaveSelectorUp() { transitionPanel.setRightUIto(1) }
|
||||
internal fun takeAutosaveSelectorDown() { transitionPanel.setRightUIto(0) }
|
||||
@@ -125,178 +111,19 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
|
||||
override fun show() {
|
||||
takeAutosaveSelectorDown()
|
||||
transitionPanel.show()
|
||||
// hasNewerAutosave = false
|
||||
/*try {
|
||||
remoCon.handler.lockToggle()
|
||||
showSpinner = true
|
||||
|
||||
Thread {
|
||||
// read savegames
|
||||
var savegamesCount = 0
|
||||
App.sortedPlayers.forEach { uuid ->
|
||||
val skimmer = App.savegamePlayers[uuid]!!.loadable()
|
||||
val x = uiX
|
||||
val y = titleTopGradEnd + cellInterval * savegamesCount
|
||||
try {
|
||||
playerCells.add(UIItemPlayerCells(this, x, y, skimmer))
|
||||
savegamesCount += 1
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
System.err.println("[UILoadSavegame] Error while loading Player '${skimmer.diskFile.absolutePath}'")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
remoCon.handler.unlockToggle()
|
||||
showSpinner = false
|
||||
}.start()
|
||||
|
||||
}
|
||||
catch (e: UninitializedPropertyAccessException) {}*/
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
transitionPanel.hide()
|
||||
// playerCells.forEach { it.dispose() }
|
||||
// playerCells.clear()
|
||||
}
|
||||
|
||||
private var touchLatched = false
|
||||
|
||||
// private fun getCells() = playerCells
|
||||
private var loadFired = 0
|
||||
private var oldMode = -1
|
||||
|
||||
// private val mode1Node = Yaml(UITitleRemoConYaml.injectedMenuSingleCharSel).parse()
|
||||
// private val mode2Node = Yaml(UITitleRemoConYaml.injectedMenuSingleWorldSel).parse()
|
||||
|
||||
// private val menus = listOf(mode1Node, mode2Node)
|
||||
|
||||
/*private val deleteCharacterButton = UIItemTextButton(
|
||||
this, "CONTEXT_CHARACTER_DELETE",
|
||||
UIRemoCon.menubarOffX - UIRemoCon.UIRemoConElement.paddingLeft + 72,
|
||||
UIRemoCon.menubarOffY - UIRemoCon.UIRemoConElement.lineHeight * 3 + 16,
|
||||
remoCon.width + UIRemoCon.UIRemoConElement.paddingLeft,
|
||||
true,
|
||||
inactiveCol = Toolkit.Theme.COL_RED,
|
||||
activeCol = Toolkit.Theme.COL_REDD,
|
||||
hitboxSize = UIRemoCon.UIRemoConElement.lineHeight - 2,
|
||||
alignment = UIItemTextButton.Companion.Alignment.LEFT
|
||||
).also {
|
||||
it.clickOnceListener = { _,_ ->
|
||||
mode = MODE_SAVE_DELETE
|
||||
it.highlighted = true
|
||||
}
|
||||
}*/
|
||||
|
||||
init {
|
||||
// this UI will NOT persist; the parent of the mode1Node must be set using an absolute value (e.g. treeRoot, not remoCon.currentRemoConContents)
|
||||
|
||||
//printdbg(this, "UILoadSavegame called, from:")
|
||||
//printStackTrace(this)
|
||||
|
||||
// mode1Node.parent = remoCon.treeRoot
|
||||
// mode2Node.parent = mode1Node
|
||||
|
||||
// mode1Node.data = "MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadSavegame"
|
||||
// mode2Node.data = "MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadSavegame"
|
||||
|
||||
// printdbg(this, "mode1Node parent: ${mode1Node.parent?.data}") // will be 'null' because the parent is the root node
|
||||
// printdbg(this, "mode1Node data: ${mode1Node.data}")
|
||||
// printdbg(this, "mode2Node data: ${mode2Node.data}")
|
||||
|
||||
}
|
||||
|
||||
private fun modeChangedHandler(mode: Int) {
|
||||
printdbg(this, "Change mode: $oldMode -> $mode")
|
||||
// remoCon.setNewRemoConContents(menus[mode])
|
||||
// remoCon.setNewRemoConContents(mode1Node)
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
transitionPanel.update(delta)
|
||||
/*if (mode == MODE_SELECT || mode == MODE_SAVE_DELETE) {
|
||||
|
||||
if (oldMode != mode) {
|
||||
modeChangedHandler(mode)
|
||||
oldMode = mode
|
||||
}
|
||||
|
||||
if (scrollTarget != listScroll) {
|
||||
if (scrollAnimCounter < scrollAnimLen) {
|
||||
scrollAnimCounter += delta
|
||||
uiScroll = Movement.fastPullOut(
|
||||
scrollAnimCounter / scrollAnimLen,
|
||||
listScroll * cellInterval.toFloat(),
|
||||
scrollTarget * cellInterval.toFloat()
|
||||
)
|
||||
}
|
||||
else {
|
||||
scrollAnimCounter = 0f
|
||||
listScroll = scrollTarget
|
||||
uiScroll = cellInterval.toFloat() * scrollTarget
|
||||
}
|
||||
}
|
||||
|
||||
val cells = getCells()
|
||||
|
||||
for (index in 0 until cells.size) {
|
||||
|
||||
|
||||
val it = cells[index]
|
||||
if (index in listScroll - 2 until listScroll + savesVisible + 2) {
|
||||
// re-position
|
||||
it.posY = (it.initialY - uiScroll).roundToInt()
|
||||
it.update(delta)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/*if (mode == MODE_SAVE_DELETE_CONFIRM && deleteCellAnimCounter <= scrollAnimLen) {
|
||||
// do transitional moving stuff
|
||||
buttonSelectedForDeletion?.posY = Movement.fastPullOut(deleteCellAnimCounter / scrollAnimLen, deleteCellPosYstart, (titleTopGradEnd + cellInterval).toFloat()).roundToInt()
|
||||
|
||||
deleteCellAnimCounter += delta
|
||||
if (deleteCellAnimCounter > scrollAnimLen) deleteCellAnimCounter = scrollAnimLen
|
||||
}*/
|
||||
}
|
||||
|
||||
private var deleteCellAnimCounter = 0f
|
||||
private var deleteCellPosYstart = 0f
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
transitionPanel.render(batch, camera)
|
||||
|
||||
/*if (mode == MODE_LOAD_DA_SHIT_ALREADY) {
|
||||
loadFired += 1
|
||||
// to hide the "flipped skybox" artefact
|
||||
batch.end()
|
||||
|
||||
gdxClearAndEnableBlend(.094f, .094f, .094f, 0f)
|
||||
|
||||
batch.begin()
|
||||
|
||||
batch.color = Color.WHITE
|
||||
val txt = Lang["MENU_IO_LOADING"]
|
||||
App.fontGame.draw(batch, txt, (App.scr.width - App.fontGame.getWidth(txt)) / 2f, (App.scr.height - App.fontGame.lineHeight) / 2f)
|
||||
|
||||
if (loadFired == 2) {
|
||||
LoadSavegame(UILoadGovernor.playerDisk!!, UILoadGovernor.worldDisk)
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == MODE_SAVE_DELETE_CONFIRM) {
|
||||
buttonSelectedForDeletion?.render(batch, camera)
|
||||
confirmCancelButton.render(batch, camera)
|
||||
confirmDeleteButton.render(batch, camera)
|
||||
|
||||
batch.color = Color.WHITE
|
||||
Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_SAVE_WILL_BE_DELETED"], Toolkit.drawWidth, 0, titleTopGradEnd + cellInterval - 46)
|
||||
Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_ARE_YOU_SURE"], Toolkit.drawWidth, 0, titleTopGradEnd + cellInterval + SAVE_CELL_HEIGHT + 36)
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
@@ -315,48 +142,18 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
|
||||
}
|
||||
|
||||
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||
/*if (this.isVisible && mode == MODE_SELECT || mode == MODE_SAVE_DELETE) {
|
||||
val cells = getCells()
|
||||
|
||||
if (amountY <= -1f && scrollTarget > 0) {
|
||||
scrollFrom = listScroll
|
||||
scrollTarget -= 1
|
||||
scrollAnimCounter = 0f
|
||||
}
|
||||
else if (amountY >= 1f && scrollTarget < cells.size - savesVisible) {
|
||||
scrollFrom = listScroll
|
||||
scrollTarget += 1
|
||||
scrollAnimCounter = 0f
|
||||
}
|
||||
}*/
|
||||
transitionPanel.scrolled(amountX, amountY)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
super.endClosing(delta)
|
||||
listScroll = 0
|
||||
scrollTarget = 0
|
||||
uiScroll = 0f
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
try { shapeRenderer.dispose() } catch (e: IllegalArgumentException) {}
|
||||
try { sliderFBO.dispose() } catch (e: IllegalArgumentException) {}
|
||||
try { transitionPanel.dispose() } catch (e: IllegalArgumentException) {}
|
||||
shapeRenderer.tryDispose()
|
||||
transitionPanel.tryDispose()
|
||||
}
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
transitionPanel.uis.forEach { it.resize(width, height) }
|
||||
super.resize(width, height)
|
||||
scrollAreaHeight = height - 2 * App.scr.tvSafeGraphicsHeight - 64
|
||||
savesVisible = (scrollAreaHeight + cellInterval) / (cellInterval + SAVE_CELL_HEIGHT)
|
||||
|
||||
listScroll = 0
|
||||
scrollTarget = 0
|
||||
uiScroll = 0f
|
||||
|
||||
sliderFBO.dispose()
|
||||
sliderFBO = FrameBuffer(Pixmap.Format.RGBA8888, uiWidth + 10, height, false)
|
||||
}
|
||||
|
||||
internal fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
|
||||
|
||||
@@ -244,7 +244,7 @@ class UITitleModules(val remoCon: UIRemoCon) : UICanvas() {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
try { sliderFBO.dispose() } catch (e: IllegalArgumentException) {}
|
||||
sliderFBO.tryDispose()
|
||||
}
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
@@ -138,8 +139,8 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
val lastPlayedString: String,
|
||||
val totalPlayedString: String,
|
||||
val screenshot: TextureRegion?,
|
||||
) {
|
||||
fun dispose() {
|
||||
): Disposable {
|
||||
override fun dispose() {
|
||||
screenshot?.texture?.dispose()
|
||||
}
|
||||
}
|
||||
@@ -419,14 +420,14 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
uiItems.forEach { it.hide() }
|
||||
if (::worldCells.isInitialized) worldCells.forEach { it.hide() }
|
||||
|
||||
if (::worldCells.isInitialized) worldCells.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} }
|
||||
worldList.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} }
|
||||
if (::worldCells.isInitialized) worldCells.forEach { it.tryDispose() }
|
||||
worldList.forEach { it.tryDispose() }
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
uiItems.forEach { it.dispose() }
|
||||
if (::worldCells.isInitialized) worldCells.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} }
|
||||
worldList.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} }
|
||||
if (::worldCells.isInitialized) worldCells.forEach { it.tryDispose() }
|
||||
worldList.forEach { it.tryDispose() }
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user