world search ui integrated to world portal ui

This commit is contained in:
minjaesong
2023-06-18 21:29:18 +09:00
parent 93c427473d
commit a33f0e7ab4
10 changed files with 259 additions and 21 deletions

View File

@@ -252,8 +252,8 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
} } } } } }
) )
// make grid mode buttons work together // make grid mode buttons work together
// itemListPlayer.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) } // itemListPlayer.gridModeButtons[0].clickOnceListener = { _,_ -> setCompact(false) }
// itemListPlayer.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) } // itemListPlayer.gridModeButtons[1].clickOnceListener = { _,_ -> setCompact(true) }
@@ -317,7 +317,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
} }
buttonCraft.touchDownListener = { _,_,_,_ -> buttonCraft.clickOnceListener = { _,_ ->
getPlayerInventory().let { player -> recipeClicked?.let { recipe -> getPlayerInventory().let { player -> recipeClicked?.let { recipe ->
// check if player has enough amount of ingredients // check if player has enough amount of ingredients
val itemCraftable = itemListIngredients.getInventory().itemList.all { (itm, qty) -> val itemCraftable = itemListIngredients.getInventory().itemList.all { (itm, qty) ->
@@ -340,8 +340,8 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
refreshCraftButtonStatus() refreshCraftButtonStatus()
} }
// make grid mode buttons work together // make grid mode buttons work together
// itemListCraftable.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) } // itemListCraftable.gridModeButtons[0].clickOnceListener = { _,_ -> setCompact(false) }
// itemListCraftable.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) } // itemListCraftable.gridModeButtons[1].clickOnceListener = { _,_ -> setCompact(true) }
handler.allowESCtoClose = true handler.allowESCtoClose = true

View File

@@ -151,6 +151,8 @@ class UIItemListNavBarVertical(
extraDrawOpOnBottom(this, batch) extraDrawOpOnBottom(this, batch)
super.render(batch, camera) super.render(batch, camera)
oldPosX = posX
} }
override fun update(delta: Float) { override fun update(delta: Float) {

View File

@@ -47,7 +47,7 @@ class UINewCharacter(val remoCon: UIRemoCon) : UICanvas() {
private var uiLocked = false private var uiLocked = false
init { init {
goButton.touchDownListener = { _, _, _, _ -> goButton.clickOnceListener = { _,_ ->
uiLocked = true uiLocked = true
@@ -83,7 +83,7 @@ class UINewCharacter(val remoCon: UIRemoCon) : UICanvas() {
}, "TerrarumBasegameNewCharcterSaveThread") }, "TerrarumBasegameNewCharcterSaveThread")
savingThread.start() savingThread.start()
} }
backButton.touchDownListener = { _, _, _, _ -> backButton.clickOnceListener = { _,_ ->
remoCon.openUI(UILoadDemoSavefiles(remoCon, 0)) remoCon.openUI(UILoadDemoSavefiles(remoCon, 0))
} }

View File

@@ -86,7 +86,7 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
private val goButton = UIItemTextButton(this, "MENU_LABEL_CONFIRM_BUTTON", drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) private val goButton = UIItemTextButton(this, "MENU_LABEL_CONFIRM_BUTTON", drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
init { init {
goButton.touchDownListener = { _, _, _, _ -> goButton.clickOnceListener = { _, _ ->
// printdbg(this, "generate! Size=${sizeSelector.selection}, Name=${nameInput.getTextOrPlaceholder()}, Seed=${seedInput.getTextOrPlaceholder()}") // printdbg(this, "generate! Size=${sizeSelector.selection}, Name=${nameInput.getTextOrPlaceholder()}, Seed=${seedInput.getTextOrPlaceholder()}")
val ingame = TerrarumIngame(App.batch) val ingame = TerrarumIngame(App.batch)
@@ -111,7 +111,7 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
App.setLoadScreen(loadScreen) App.setLoadScreen(loadScreen)
} }
backButton.touchDownListener = { _, _, _, _ -> backButton.clickOnceListener = { _, _ ->
remoCon.openUI(UILoadDemoSavefiles(remoCon, 1)) remoCon.openUI(UILoadDemoSavefiles(remoCon, 1))
} }

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.YPOS_CORRECTION import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.YPOS_CORRECTION
@@ -135,6 +136,57 @@ class UIWorldPortal : UICanvas(
INGAME.setTooltipMessage(null) // required! 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( class UIItemWorldPortalTopBar(

View File

@@ -1,25 +1,190 @@
package net.torvald.terrarum.modulebasegame.ui package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.random.HQRNG
import net.torvald.random.XXHash64
import net.torvald.terrarum.App import net.torvald.terrarum.App
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.WorldgenLoadScreen
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
import net.torvald.terrarum.modulebasegame.serialise.ReadActor
import net.torvald.terrarum.savegame.ByteArray64Reader
import net.torvald.terrarum.savegame.VDFileID
import net.torvald.terrarum.savegame.VirtualDisk
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.ui.*
import net.torvald.terrarum.utils.RandomWordsName
/** /**
* Created by minjaesong on 2023-05-19. * Created by minjaesong on 2023-05-19.
*/ */
class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() { class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() {
override var width: Int = Toolkit.drawWidth // override var width: Int = Toolkit.drawWidth
override var height: Int = App.scr.height // override var height: Int = App.scr.height
private val hugeTex = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "gui/huge.png")))
private val largeTex = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "gui/large.png")))
private val normalTex = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "gui/normal.png")))
private val smallTex = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "gui/small.png")))
private val tex = arrayOf(smallTex, normalTex, largeTex, hugeTex)
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 radioCellWidth = 116
private val inputWidth = 340
private val radioX = (width - (radioCellWidth * tex.size + 9)) / 2
private val inputX = width - inputWidth
private val sizeSelY = 186 + 40
internal val titleTextPosY: Int = App.scr.tvSafeGraphicsHeight + 10
private val sizeSelector = UIItemInlineRadioButtons(this,
drawX + radioX, drawY + sizeSelY, radioCellWidth,
listOf(
{ Lang["CONTEXT_DESCRIPTION_TINY"] },
{ Lang["CONTEXT_DESCRIPTION_SMALL"] },
{ Lang["CONTEXT_DESCRIPTION_BIG"] },
{ Lang["CONTEXT_DESCRIPTION_HUGE"] }
)
)
private val rng = HQRNG()
private val nameInput = UIItemTextLineInput(this,
drawX + width - inputWidth, drawY + sizeSelY + 80, inputWidth,
{ RandomWordsName(4) }, InputLenCap(VirtualDisk.NAME_LENGTH, InputLenCap.CharLenUnit.UTF8_BYTES)
)
private val seedInput = UIItemTextLineInput(this,
drawX + width - inputWidth, drawY + sizeSelY + 120, inputWidth,
{ rng.nextLong().toString() }, InputLenCap(256, InputLenCap.CharLenUnit.CODEPOINTS)
)
private val goButtonWidth = 180
private val backButton = UIItemTextButton(this, "MENU_LABEL_BACK", drawX + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
private val goButton = UIItemTextButton(this, "MENU_LABEL_CONFIRM_BUTTON", drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
init {
goButton.clickOnceListener = { _, _ ->
// printdbg(this, "generate! Size=${sizeSelector.selection}, Name=${nameInput.getTextOrPlaceholder()}, Seed=${seedInput.getTextOrPlaceholder()}")
/*val ingame = TerrarumIngame(App.batch)
val player = ReadActor.invoke(UILoadGovernor.playerDisk!!, ByteArray64Reader(UILoadGovernor.playerDisk!!.getFile(
VDFileID.SAVEGAMEINFO
)!!.bytes, Common.CHARSET)
) as IngamePlayer
val seed = try {
seedInput.getTextOrPlaceholder().toLong()
}
catch (e: NumberFormatException) {
XXHash64.hash(seedInput.getTextOrPlaceholder().toByteArray(Charsets.UTF_8), 10000)
}
val (wx, wy) = TerrarumIngame.NEW_WORLD_SIZE[sizeSelector.selection]
val worldParam = TerrarumIngame.NewGameParams(
player, TerrarumIngame.NewWorldParameters(
wx, wy, seed, nameInput.getTextOrPlaceholder()
)
)
ingame.gameLoadInfoPayload = worldParam
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW
Terrarum.setCurrentIngameInstance(ingame)
val loadScreen = WorldgenLoadScreen(ingame, wx, wy)
App.setLoadScreen(loadScreen)*/
}
backButton.clickOnceListener = { _, _ ->
full.requestTransition(0)
}
addUIitem(sizeSelector)
addUIitem(seedInput) // order is important
addUIitem(nameInput) // because of the IME candidates overlay
addUIitem(goButton)
addUIitem(backButton)
}
override fun show() {
uiItems.forEach { it.show() }
seedInput.clearText()
seedInput.refreshPlaceholder()
nameInput.clearText()
nameInput.refreshPlaceholder()
}
private var oldPosX = full.posX
override fun updateUI(delta: Float) { override fun updateUI(delta: Float) {
uiItems.forEach { it.update(delta) }
} }
override fun renderUI(batch: SpriteBatch, camera: Camera) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
val posXDelta = posX - oldPosX
// ugh why won't you just scroll along??
seedInput.posX += posXDelta
nameInput.posX += posXDelta
goButton.posX += posXDelta
backButton.posX += posXDelta
batch.color = Color.WHITE
// ui title
// val titlestr = Lang["CONTEXT_WORLD_NEW"]
// App.fontUITitle.draw(batch, titlestr, drawX + (width - App.fontGame.getWidth(titlestr)).div(2).toFloat(), titleTextPosY.toFloat())
// draw size previews
val texture = tex[sizeSelector.selection.coerceAtMost(tex.lastIndex)]
val tx = drawX + (width - texture.regionWidth) / 2
val ty = drawY + (160 - texture.regionHeight) / 2
batch.draw(texture, tx.toFloat(), ty.toFloat())
// border
batch.color = Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(batch, tx - 1, ty - 1, texture.regionWidth + 2, texture.regionHeight + 2)
batch.color = Color.WHITE
// size selector title
val sizestr = Lang["MENU_OPTIONS_SIZE"]
App.fontGame.draw(batch, sizestr, drawX + (width - App.fontGame.getWidth(sizestr)).div(2).toFloat(), drawY + sizeSelY - 40f)
// name/seed input labels
App.fontGame.draw(batch, Lang["MENU_NAME"], drawX, drawY + sizeSelY + 80)
App.fontGame.draw(batch, Lang["CONTEXT_GENERATOR_SEED"], drawX, drawY + sizeSelY + 120)
uiItems.forEach { it.render(batch, camera) }
oldPosX = posX
}
override fun hide() {
uiItems.forEach { it.hide() }
} }
override fun dispose() { override fun dispose() {
hugeTex.texture.dispose()
largeTex.texture.dispose()
normalTex.texture.dispose()
smallTex.texture.dispose()
} }
} }

View File

@@ -128,9 +128,15 @@ abstract class UICanvas(
/** A function that is run ONCE when the UI is requested to be opened; will work identical to [endOpening] if [openCloseTime] is zero */ /** A function that is run ONCE when the UI is requested to be opened; will work identical to [endOpening] if [openCloseTime] is zero */
open fun show() {} open fun show() {
uiItems.forEach { it.show() }
handler.subUIs.forEach { it.show() }
}
/** A function that is run ONCE when the UI is requested to be closed; will work identical to [endClosing] if [openCloseTime] is zero */ /** A function that is run ONCE when the UI is requested to be closed; will work identical to [endClosing] if [openCloseTime] is zero */
open fun hide() {} open fun hide() {
uiItems.forEach { it.hide() }
handler.subUIs.forEach { it.hide() }
}
/** **DO NOT CALL THIS FUNCTION FOR THE ACTUAL UPDATING OF THE UI — USE update() INSTEAD** /** **DO NOT CALL THIS FUNCTION FOR THE ACTUAL UPDATING OF THE UI — USE update() INSTEAD**

View File

@@ -110,6 +110,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
open var keyTypedListener: ((Char) -> Unit)? = null open var keyTypedListener: ((Char) -> Unit)? = null
open var touchDraggedListener: ((Int, Int, Int) -> Unit)? = null open var touchDraggedListener: ((Int, Int, Int) -> Unit)? = null
/** Parameters: screenX, screenY, pointer, button */ /** Parameters: screenX, screenY, pointer, button */
@Deprecated("Not really deprecated but you MOST DEFINITELY want to use clickOnceListener(mouseX, mouseY) instead.")
open var touchDownListener: ((Int, Int, Int, Int) -> Unit)? = null open var touchDownListener: ((Int, Int, Int, Int) -> Unit)? = null
open var touchUpListener: ((Int, Int, Int, Int) -> Unit)? = null open var touchUpListener: ((Int, Int, Int, Int) -> Unit)? = null
/** Parameters: amountX, amountY */ /** Parameters: amountX, amountY */
@@ -146,14 +147,14 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
mouseOverCall?.update(delta) mouseOverCall?.update(delta)
if (mouseUp) { if (mouseUp) {
if (mouseOverCall?.isVisible ?: false) { if (mouseOverCall?.isVisible == true) {
mouseOverCall?.setAsOpen() mouseOverCall?.setAsOpen()
} }
mouseOverCall?.updateUI(delta) mouseOverCall?.updateUI(delta)
} }
else { else {
if (mouseOverCall?.isVisible ?: false) { if (mouseOverCall?.isVisible == true) {
mouseOverCall?.setAsClose() mouseOverCall?.setAsClose()
} }
} }

View File

@@ -18,7 +18,7 @@ class UIItemHorizontalFadeSlide(
//transitionLength: Float, //transitionLength: Float,
currentPosition: Float, currentPosition: Float,
vararg uis: UICanvas vararg uis: UICanvas
) : UIItemTransitionContainer(parent, initialX, initialY, width, height, 0.10f, currentPosition, uis) { ) : UIItemTransitionContainer(parent, initialX, initialY, width, height, 0.12f, currentPosition, uis) {
fun getOffX(index: Int) = ((currentPosition - index) * width / 2f).roundToInt() fun getOffX(index: Int) = ((currentPosition - index) * width / 2f).roundToInt()
fun getOpacity(index: Int) = 1f - (currentPosition - index).absoluteValue.coerceIn(0f, 1f) fun getOpacity(index: Int) = 1f - (currentPosition - index).absoluteValue.coerceIn(0f, 1f)

View File

@@ -121,9 +121,9 @@ class UIItemTextLineInput(
private var currentPlaceholderText = ArrayList<Int>(placeholder().toCodePoints()) // the placeholder text may change every time you call it private var currentPlaceholderText = ArrayList<Int>(placeholder().toCodePoints()) // the placeholder text may change every time you call it
private val btn1PosX = posX private val btn1PosX; get() = posX
private val btn2PosX = posX + width - WIDTH_ONEBUTTON private val btn2PosX; get() = posX + width - WIDTH_ONEBUTTON
private val inputPosX = posX + WIDTH_ONEBUTTON + 3 private val inputPosX; get() = posX + WIDTH_ONEBUTTON + 3
var mouseoverUpdateLatch = true // keep it true by default! var mouseoverUpdateLatch = true // keep it true by default!
set(value) { set(value) {
@@ -242,6 +242,13 @@ class UIItemTextLineInput(
} }
} }
/**
* Only makes sense when the placeholder returns randomised texts
*/
fun refreshPlaceholder() {
currentPlaceholderText = ArrayList<Int>(placeholder().toCodePoints())
}
override fun inputStrobed(e: TerrarumKeyboardEvent) { override fun inputStrobed(e: TerrarumKeyboardEvent) {
val oldActive = isActive val oldActive = isActive
@@ -496,6 +503,8 @@ class UIItemTextLineInput(
private var textDrawOffset = 0 private var textDrawOffset = 0
override fun render(batch: SpriteBatch, camera: Camera) { override fun render(batch: SpriteBatch, camera: Camera) {
val posXDelta = posX - oldPosX
val ime = getIME(true) val ime = getIME(true)
@@ -646,6 +655,9 @@ class UIItemTextLineInput(
batch.color = Color.WHITE batch.color = Color.WHITE
super.render(batch, camera) super.render(batch, camera)
oldPosX = posX
} }
fun getText() = textbufToString() fun getText() = textbufToString()