From 211f936bd3df5a431272c5abdc6cac18fe090a3d Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 8 Jul 2023 16:12:15 +0900 Subject: [PATCH] save manage scr --- .../modulebasegame/ui/UILoadDemoSavefiles.kt | 26 ++-- .../terrarum/modulebasegame/ui/UILoadList.kt | 5 +- .../modulebasegame/ui/UILoadManage.kt | 115 ++++++++++++++---- .../modulebasegame/ui/UILoadSaveDamaged.kt | 11 +- .../modulebasegame/ui/UILoadSavegame.kt | 9 +- .../terrarum/ui/UIItemTransitionContainer.kt | 2 +- 6 files changed, 114 insertions(+), 54 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt index 731df0bad..736dd97ba 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt @@ -564,7 +564,7 @@ class UIItemPlayerCells( highlightTextCol = if (mouseUp && !forceMouseDown) litCol else Toolkit.Theme.COL_LIST_DEFAULT } - override fun render(batch: SpriteBatch, camera: Camera) { + fun render(batch: SpriteBatch, camera: Camera, offX: Int, offY: Int) { // try to generate a texture if (!hasTexture) { val skimmer = App.savegamePlayers[playerUUID]!!.loadable() @@ -636,20 +636,20 @@ class UIItemPlayerCells( hasTexture = true } - val x = posX.toFloat() - val y = posY.toFloat() + val x = posX + offX + val y = posY + offY // draw box backgrounds batch.color = cellCol - Toolkit.fillArea(batch, posX, posY, 106, height) - Toolkit.fillArea(batch, posX + 116, posY + 34, width - 116, 86) + Toolkit.fillArea(batch, x, y, 106, height) + Toolkit.fillArea(batch, x + 116, y + 34, width - 116, 86) // draw borders batch.color = highlightCol // avatar border - Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, 106 + 2, height + 2) + Toolkit.drawBoxBorder(batch, x - 1, y - 1, 106 + 2, height + 2) // infocell border - Toolkit.drawBoxBorder(batch, posX + 115, posY + 33, width - 114, 88) + Toolkit.drawBoxBorder(batch, x + 115, y + 33, width - 114, 88) // texts batch.color = highlightTextCol @@ -666,19 +666,23 @@ class UIItemPlayerCells( // infocell divider batch.color = if (mouseUp) hruleColLit else hruleCol - Toolkit.fillArea(batch, posX + 118, posY + 62, width - 120, 1) - Toolkit.fillArea(batch, posX + 118, posY + 91, width - 120, 1) + Toolkit.fillArea(batch, x + 118, y + 62, width - 120, 1) + Toolkit.fillArea(batch, x + 118, y + 91, width - 120, 1) // player avatar batch.color = Color.WHITE this.sprite?.let { batch.draw(it, - x + FastMath.ceil((106f - it.regionWidth) / 2f) + EXTRA_HEADROOM_X / 2, - y + FastMath.ceil((height - it.regionHeight) / 2f) - EXTRA_HEADROOM_Y / 2 + x.toFloat() + FastMath.ceil((106f - it.regionWidth) / 2f) + EXTRA_HEADROOM_X / 2, + y.toFloat() + FastMath.ceil((height - it.regionHeight) / 2f) - EXTRA_HEADROOM_Y / 2 ) } } + override fun render(batch: SpriteBatch, camera: Camera) { + render(batch, camera, 0, 0) + } + override fun dispose() { sprite?.texture?.dispose() } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadList.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadList.kt index c75fafb4a..f62abf6ad 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadList.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadList.kt @@ -109,6 +109,7 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() { mode1Node.parent = full.remoCon.treeRoot mode1Node.data = "MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadSavegame" full.remoCon.setNewRemoConContents(mode1Node) + playerCells.forEach { it.dispose() } playerCells.clear() try { @@ -264,6 +265,8 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() { } override fun dispose() { + playerCells.forEach { it.dispose() } + playerCells.clear() } override fun keyDown(keycode: Int): Boolean { @@ -313,8 +316,6 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() { } override fun hide() { - playerCells.forEach { it.dispose() } - playerCells.clear() showCalled = false cellLoadThread.interrupt() } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt index 5061168b0..32d3d1068 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt @@ -1,13 +1,15 @@ 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 net.torvald.terrarum.App import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.round +import net.torvald.terrarum.ui.Movement import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UIItemTextButton +import kotlin.math.roundToInt /** * Created by minjaesong on 2023-07-05. @@ -17,24 +19,45 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { override var width: Int = Toolkit.drawWidth override var height: Int = App.scr.height - private val goButtonWidth = 180 + private val buttonHeight = 24 + private val buttonGap = 10 + private val buttonWidth = 180 private val drawX = (Toolkit.drawWidth - 480) / 2 private val drawY = (App.scr.height - 480) / 2 - private val buttonRowY = drawY + 480 - 24 - private val confirmCancelButton = UIItemTextButton(this, "MENU_LABEL_CANCEL", drawX + (240 - goButtonWidth) / 2, buttonRowY, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) - private val confirmDeleteButton = UIItemTextButton(this, "MENU_LABEL_DELETE", drawX + 240 + (240 - goButtonWidth) / 2, buttonRowY, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true, inactiveCol = Toolkit.Theme.COL_RED, activeCol = Toolkit.Theme.COL_REDD) + private val hx = Toolkit.hdrawWidth - private var mode = 0 + private val buttonX1third = hx - (buttonWidth * 1.5).toInt() - buttonGap + private val buttonXcentre = hx - (buttonWidth / 2) + private val buttonX3third = hx + (buttonWidth / 2) + buttonGap - private val MODE_INIT = 0 - private val MODE_DELETE = 16 // are you sure? - private val MODE_RENAME = 32 // show rename dialogue + private val buttonXleft = drawX + (240 - buttonWidth) / 2 + private val buttonXright = drawX + 240 + (240 - buttonWidth) / 2 - init { - confirmCancelButton.clickOnceListener = { _,_ -> full.remoCon.openUI(UILoadSavegame(full.remoCon)) } - confirmDeleteButton.clickOnceListener = { _,_ -> - val pu = full.buttonSelectedForDeletion!!.playerUUID - val wu = full.buttonSelectedForDeletion!!.worldUUID + private val buttonRowY = drawY + 480 - buttonHeight + private val buttonRowY2 = buttonRowY - buttonHeight - buttonGap + + private val mainGoButton = UIItemTextButton(this, "MENU_IO_LOAD_GAME", buttonX1third, buttonRowY2, buttonWidth * 3 + buttonGap * 2, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + + } + private val mainReturnButton = UIItemTextButton(this, "MENU_LABEL_RETURN", buttonX1third, buttonRowY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + it.clickOnceListener = { _,_ -> + full.changePanelTo(0) + } + } + private val mainRenameButton = UIItemTextButton(this, "MENU_LABEL_RENAME", buttonXcentre, buttonRowY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + + } + private val mainDeleteButton = UIItemTextButton(this, "CONTEXT_CHARACTER_DELETE", buttonX3third, buttonRowY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true, inactiveCol = Toolkit.Theme.COL_RED, activeCol = Toolkit.Theme.COL_REDD).also { + + } + + private val confirmCancelButton = UIItemTextButton(this, "MENU_LABEL_CANCEL", buttonXleft, buttonRowY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + it.clickOnceListener = { _,_ -> full.remoCon.openUI(UILoadSavegame(full.remoCon)) } + } + private val confirmDeleteButton = UIItemTextButton(this, "MENU_LABEL_DELETE", buttonXright, buttonRowY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true, inactiveCol = Toolkit.Theme.COL_RED, activeCol = Toolkit.Theme.COL_REDD).also { + it.clickOnceListener = { _,_ -> + val pu = full.playerButtonSelected!!.playerUUID + val wu = full.playerButtonSelected!!.worldUUID App.savegamePlayers[pu]?.moveToRecycle(App.recycledPlayersDir)?.let { App.sortedPlayers.remove(pu) App.savegamePlayers.remove(pu) @@ -43,26 +66,52 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { // don't delete the world please full.remoCon.openUI(UILoadSavegame(full.remoCon)) } - - addUIitem(confirmCancelButton) - addUIitem(confirmDeleteButton) } + private var mode = 0 + + private var mainButtons = listOf(mainGoButton, mainReturnButton, mainRenameButton, mainDeleteButton) + private var delButtons = listOf(confirmCancelButton, confirmDeleteButton) + + private val MODE_INIT = 0 + private val MODE_DELETE = 16 // are you sure? + private val MODE_RENAME = 32 // show rename dialogue + + init { + + } + + override fun doOpening(delta: Float) { + full.playerButtonSelected?.forceMouseDown = true + } + + override fun doClosing(delta: Float) { + full.playerButtonSelected?.forceMouseDown = false + } override fun updateUI(delta: Float) { - confirmCancelButton.update(delta) - confirmDeleteButton.update(delta) + when (mode) { + MODE_INIT -> { + mainButtons.forEach { it.update(delta) } + } + MODE_DELETE -> { + delButtons.forEach { it.update(delta) } + } + } } override fun renderUI(batch: SpriteBatch, camera: Camera) { + val buttonYdelta = (full.titleTopGradEnd + full.cellInterval) - full.playerButtonSelected!!.posY + full.playerButtonSelected!!.render(batch, camera, 0, buttonYdelta) + if (mode == MODE_DELETE) { Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_SAVE_WILL_BE_DELETED"], Toolkit.drawWidth, 0, full.titleTopGradEnd + full.cellInterval - 46) Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_ARE_YOU_SURE"], Toolkit.drawWidth, 0, full.titleTopGradEnd + full.cellInterval + SAVE_CELL_HEIGHT + 36) - full.buttonSelectedForDeletion!!.render(batch, camera) - - confirmCancelButton.render(batch, camera) - confirmDeleteButton.render(batch, camera) + delButtons.forEach { it.render(batch, camera) } + } + else if (mode == MODE_INIT) { + mainButtons.forEach { it.render(batch, camera) } } } @@ -70,15 +119,27 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { } override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { - confirmCancelButton.touchDown(screenX, screenY, pointer, button) - confirmDeleteButton.touchDown(screenX, screenY, pointer, button) + when (mode) { + MODE_INIT -> { + mainButtons.forEach { it.touchDown(screenX, screenY, pointer, button) } + } + MODE_DELETE -> { + delButtons.forEach { it.touchDown(screenX, screenY, pointer, button) } + } + } return true } override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { - confirmCancelButton.touchUp(screenX, screenY, pointer, button) - confirmDeleteButton.touchUp(screenX, screenY, pointer, button) + when (mode) { + MODE_INIT -> { + mainButtons.forEach { it.touchDown(screenX, screenY, pointer, button) } + } + MODE_DELETE -> { + delButtons.forEach { it.touchDown(screenX, screenY, pointer, button) } + } + } return true } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSaveDamaged.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSaveDamaged.kt index b8a469c23..74392e48c 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSaveDamaged.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSaveDamaged.kt @@ -21,14 +21,13 @@ class UILoadSaveDamaged(val full: UILoadSavegame) : UICanvas() { private val drawX = (Toolkit.drawWidth - 480) / 2 private val drawY = (App.scr.height - 480) / 2 private val buttonRowY = drawY + 480 - 24 - private val corruptedBackButton = UIItemTextButton(this, "MENU_LABEL_BACK", (Toolkit.drawWidth - goButtonWidth) / 2, buttonRowY, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + private val corruptedBackButton = UIItemTextButton(this, "MENU_LABEL_BACK", (Toolkit.drawWidth - goButtonWidth) / 2, buttonRowY, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + it.clickOnceListener = { _,_ -> + full.changePanelTo(0) + } + } init { - corruptedBackButton.clickOnceListener = { _,_ -> - full.changePanelTo(0) - println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa") - } - addUIitem(corruptedBackButton) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt index 002a96462..ec6fb0bfa 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt @@ -5,19 +5,13 @@ 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.utils.GdxRuntimeException -import net.torvald.unicode.getKeycapConsole -import net.torvald.unicode.getKeycapPC import net.torvald.terrarum.* import net.torvald.terrarum.App.printdbg -import net.torvald.terrarum.langpack.Lang -import net.torvald.terrarum.modulebasegame.serialise.LoadSavegame import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.internalWidth import net.torvald.terrarum.ui.* import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import java.util.* -import kotlin.math.roundToInt /** @@ -77,7 +71,7 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { private val scrollAnimLen = 0.1f private var sliderFBO = FrameBuffer(Pixmap.Format.RGBA8888, uiWidth + 10, height, false) - internal var buttonSelectedForDeletion: UIItemPlayerCells? = null + internal var playerButtonSelected: UIItemPlayerCells? = null private val goButtonWidth = 180 private val drawX = (Toolkit.drawWidth - 480) / 2 @@ -130,6 +124,7 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { if (button.javaClass.simpleName == "UIItemPlayerCells") { transitionalListing.advanceMode() + playerButtonSelected = button as UIItemPlayerCells } } diff --git a/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt index dce855574..0b15e4b80 100644 --- a/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt +++ b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt @@ -28,7 +28,7 @@ open class UIItemTransitionContainer( private val epsilon = 0.001f - private fun timeToUpdate(index: Int) = true//(currentPosition > index - 1 + epsilon && currentPosition < index + 1 - epsilon) + private fun timeToUpdate(index: Int) = (currentPosition > index - 1 + epsilon && currentPosition < index + 1 - epsilon) fun requestTransition(target: Int) { if (!transitionOngoing) {