mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 03:54:06 +09:00
save manage scr
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user