diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt index 047d10e0e..db7715ecc 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt @@ -96,13 +96,16 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() { private val goButtonWidth = 180 private val backButton = UIItemTextButton(this, - { Lang["MENU_LABEL_BACK"] }, drawX + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + { Lang["MENU_LABEL_BACK"] }, drawX + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + + it.clickOnceListener = { _, _ -> + remoCon.openUI(UILoadSavegame(remoCon)) + } + } private val goButton = UIItemTextButton(this, - { Lang["MENU_LABEL_CONFIRM_BUTTON"] }, drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + { Lang["MENU_LABEL_CONFIRM_BUTTON"] }, drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { - - init { - goButton.clickOnceListener = { _, _ -> + it.clickOnceListener = { _, _ -> // after the save is complete, proceed to new world generation if (existingPlayer == null) { @@ -136,10 +139,11 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() { App.setLoadScreen(loadScreen) } - backButton.clickOnceListener = { _, _ -> - remoCon.openUI(UILoadSavegame(remoCon)) - } + } + + + init { addUIitem(sizeSelector) addUIitem(seedInput) // order is important addUIitem(nameInput) // because of the IME candidates overlay diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt index fabb149a8..47f4f3eeb 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt @@ -56,9 +56,7 @@ class UIWorldPortal : UICanvas( get() = if (App.environment == RunningEnvironment.PC) "${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}" else - "${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" + - "$SP${App.gamepadLabelLT} ${Lang["GAME_WORLD_SEARCH"]}" + - "$SP${App.gamepadLabelRT} ${Lang["GAME_INVENTORY"]}" + "${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" @@ -70,6 +68,7 @@ class UIWorldPortal : UICanvas( val transitionalDelete = UIWorldPortalDelete(this) val transitionalRename = UIWorldPortalRename(this) val transitionalShare = UIWorldPortalShare(this) + val transitionalUseInvitation = UIWorldPortalUseInvitation(this) // val transitionalCargo = UIWorldPortalCargo(this) private val transitionPanel = UIItemHorizontalFadeSlide( this, @@ -78,9 +77,9 @@ class UIWorldPortal : UICanvas( width, App.scr.height, 0f, - listOf(transitionalListing), + listOf(transitionalListing), listOf(transitionalSearch, transitionalDelete, transitionalRename, transitionalShare), - listOf() + listOf(transitionalUseInvitation) ) internal var selectedButton: UIItemWorldCellsSimple? = null @@ -89,6 +88,7 @@ class UIWorldPortal : UICanvas( internal fun queueUpDeleteScr() { transitionPanel.setCentreUIto(1) } internal fun queueUpRenameScr() { transitionPanel.setCentreUIto(2) } internal fun queueUpShareScr() { transitionPanel.setCentreUIto(3) } + internal fun queueUpUseInvitationScr() { transitionPanel.setRightUIto(0) } internal fun changePanelTo(index: Int) { transitionPanel.requestTransition(index) @@ -200,58 +200,6 @@ class UIWorldPortal : UICanvas( UIItemInventoryItemGrid.tooltipShowing.clear() INGAME.setTooltipMessage(null) // required! } - - override fun inputStrobed(e: TerrarumKeyboardEvent) { - super.inputStrobed(e) - transitionPanel.uis.forEach { it.inputStrobed(e) } - } - - override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { - super.touchDragged(screenX, screenY, pointer) - transitionPanel.uis.forEach { it.touchDragged(screenX, screenY, pointer) } - return true - } - - override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { - super.touchDown(screenX, screenY, pointer, button) - transitionPanel.uis.forEach { it.touchDown(screenX, screenY, pointer, button) } - return true - } - - override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { - super.touchUp(screenX, screenY, pointer, button) - transitionPanel.uis.forEach { it.touchUp(screenX, screenY, pointer, button) } - return true - } - - override fun scrolled(amountX: Float, amountY: Float): Boolean { - super.scrolled(amountX, amountY) - transitionPanel.uis.forEach { it.scrolled(amountX, amountY) } - return true - } - - override fun keyDown(keycode: Int): Boolean { - super.keyDown(keycode) - transitionPanel.uis.forEach { it.keyDown(keycode) } - return true - } - - override fun keyUp(keycode: Int): Boolean { - super.keyUp(keycode) - transitionPanel.uis.forEach { it.keyUp(keycode) } - return true - } - - override fun keyTyped(character: Char): Boolean { - super.keyTyped(character) - transitionPanel.uis.forEach { it.keyTyped(character) } - return true - } - - override fun resize(width: Int, height: Int) { - super.resize(width, height) - transitionPanel.uis.forEach { it.resize(width, height) } - } } class UIItemWorldPortalTopBar( diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt index f2910d302..80166cf57 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt @@ -88,6 +88,10 @@ class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() { private val useInvitationButton = UIItemTextButton(this, { Lang["MENU_LABEL_USE_CODE"] }, buttonBaseX + goButtonWidth + gridGap, buttonY, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + it.clickOnceListener = { _, _ -> + full.queueUpUseInvitationScr() + full.requestTransition(2) + } } private val goButton: UIItemTextButton = UIItemTextButton(this, { Lang["MENU_LABEL_CONFIRM_BUTTON"] }, buttonBaseX + (goButtonWidth + gridGap) * 2, buttonY, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { @@ -225,17 +229,13 @@ class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() { // control hints batch.color = Color.WHITE - App.fontGame.draw(batch, full.portalListingControlHelp, 16 + (Toolkit.drawWidth - width)/2 + 2, (full.yEnd - 20).toInt()) + App.fontGame.draw(batch, full.portalListingControlHelp, 2 + (Toolkit.drawWidth - 560)/2 + 2, (full.yEnd - 20).toInt()) uiItems.forEach { it.render(batch, camera) } oldPosX = posX } - override fun hide() { - uiItems.forEach { it.hide() } - } - override fun dispose() { hugeTex.texture.dispose() largeTex.texture.dispose() diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalShare.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalShare.kt index ff975c880..c095cd543 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalShare.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalShare.kt @@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.App import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.INGAME +import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent import net.torvald.terrarum.imagefont.BigAlphNum import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.serialise.toBig64 @@ -16,7 +17,7 @@ import net.torvald.terrarum.utils.PasswordBase32 class UIWorldPortalShare(private val full: UIWorldPortal) : UICanvas() { - override var width = 426 + override var width = 434 override var height = 400 private val drawX = (Toolkit.drawWidth - width) / 2 @@ -63,7 +64,7 @@ class UIWorldPortalShare(private val full: UIWorldPortal) : UICanvas() { override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) { batch.color = Color.WHITE - val textY = drawY + (height/2) - App.fontGame.lineHeight.toInt() * 4 + val textY = drawY + (height/2) - App.fontGame.lineHeight.toInt() * 4 - 2 val codeY = textY + App.fontGame.lineHeight.toInt() * 5 // share code background @@ -107,4 +108,5 @@ class UIWorldPortalShare(private val full: UIWorldPortal) : UICanvas() { override fun doClosing(delta: Float) { full.selectedButton?.forceMouseDown = false } + } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalUseInvitation.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalUseInvitation.kt new file mode 100644 index 000000000..e101dd725 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalUseInvitation.kt @@ -0,0 +1,98 @@ +package net.torvald.terrarum.modulebasegame.ui + +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.OrthographicCamera +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.App +import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent +import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.printStackTrace +import net.torvald.terrarum.savegame.VirtualDisk +import net.torvald.terrarum.ui.* +import net.torvald.terrarum.utils.RandomWordsName + +/** + * Created by minjaesong on 2023-09-03. + */ +class UIWorldPortalUseInvitation(val full: UIWorldPortal) : UICanvas() { + + override var width = 480 + override var height = 480 + + private val drawX = (Toolkit.drawWidth - width) / 2 + private val drawY = (App.scr.height - height) / 2 + + private val inputWidth = 350 + private val inputLineY1 = 90 + private val inputLineY2 = 130 + + private val sizeSelY = 186 + 40 + private val goButtonWidth = 180 + private val gridGap = 10 + private val buttonBaseX = (Toolkit.drawWidth - 3 * goButtonWidth - 2 * gridGap) / 2 + private val buttonY = drawY + height - 24 + + + private val codeInput = UIItemTextLineInput(this, + drawX + width - inputWidth + 5, drawY + sizeSelY + inputLineY1, inputWidth, + { "AAAA BB CCCCC DDDDD EEEEE FFFFF" }, InputLenCap(VirtualDisk.NAME_LENGTH, InputLenCap.CharLenUnit.UTF8_BYTES) + ) + + + + private val backButton = UIItemTextButton(this, + { Lang["MENU_LABEL_BACK"] }, buttonBaseX, buttonY, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + + it.clickOnceListener = { _, _ -> + full.requestTransition(0) + } + } + private val searchWorldButton = UIItemTextButton(this, + { Lang["CONTEXT_WORLD_NEW"] }, buttonBaseX + goButtonWidth + gridGap, buttonY, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + + it.clickOnceListener = { _, _ -> + full.queueUpSearchScr() + full.requestTransition(1) + } + } + private val goButton: UIItemTextButton = UIItemTextButton(this, + { Lang["MENU_LABEL_CONFIRM_BUTTON"] }, buttonBaseX + (goButtonWidth + gridGap) * 2, buttonY, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + + it.clickOnceListener = { _, _ -> + + } + } + + init { + addUIitem(backButton) + addUIitem(searchWorldButton) + addUIitem(goButton) + addUIitem(codeInput) + } + + override fun updateUI(delta: Float) { + uiItems.forEach { it.update(delta) } + } + + override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) { + + // input labels + batch.color = Color.WHITE + App.fontGame.draw(batch, Lang["CREDITS_CODE"], drawX - 4, drawY + sizeSelY + inputLineY1) + + // control hints + App.fontGame.draw(batch, full.portalListingControlHelp, 2 + (Toolkit.drawWidth - 560)/2 + 2, (full.yEnd - 20).toInt()) + + + uiItems.forEach { it.render(batch, camera) } + } + + override fun dispose() { + } + + + override fun inputStrobed(e: TerrarumKeyboardEvent) { + super.inputStrobed(e) + } + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index a9f616367..86fbd7ac6 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.utils.Disposable import net.torvald.terrarum.App +import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.Second import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent diff --git a/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt index eee11a3f0..06ca3ad25 100644 --- a/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt +++ b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt @@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.App import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent +import kotlin.math.roundToInt open class UIItemTransitionContainer( private val parent: UICanvas, @@ -55,6 +56,9 @@ open class UIItemTransitionContainer( open fun onTransition(currentPosition: Float, uis: List) {} + open val currentUI: UICanvas + get() = uis[currentPosition.roundToInt()] + override fun render(batch: SpriteBatch, camera: OrthographicCamera) { super.render(batch, camera) @@ -98,17 +102,17 @@ open class UIItemTransitionContainer( } override fun keyDown(keycode: Int): Boolean { - uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.keyDown(keycode) } + currentUI.keyDown(keycode) return true } override fun keyUp(keycode: Int): Boolean { - uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.keyUp(keycode) } + currentUI.keyUp(keycode) return true } override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { - uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.touchDragged(screenX, screenY, pointer) } + currentUI.touchDragged(screenX, screenY, pointer) return true } @@ -128,7 +132,7 @@ open class UIItemTransitionContainer( } override fun inputStrobed(e: TerrarumKeyboardEvent) { - uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.inputStrobed(e) } + currentUI.inputStrobed(e) } override fun show() {