new world ui wip

This commit is contained in:
minjaesong
2021-10-26 00:03:19 +09:00
parent b78e6ebe01
commit d8aed8a34c
12 changed files with 252 additions and 11 deletions

BIN
assets/mods/basegame/gui/huge.png LFS Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -10,5 +10,6 @@
"GAME_INVENTORY_FAVORITES": "Favorites",
"GAME_INVENTORY_REGISTER": "Register",
"CONTEXT_ITEM_MAP": "Map",
"MENU_LABEL_MENU": "Menu"
"MENU_LABEL_MENU": "Menu",
"CONTEXT_GENERATOR_SEED": "Seed"
}

View File

@@ -11,5 +11,6 @@
"GAME_INVENTORY_FAVORITES": "즐겨찾기",
"GAME_INVENTORY_REGISTER": "등록하기",
"MENU_LABEL_MENU": "메뉴",
"CONTEXT_ITEM_MAP": "지도"
"CONTEXT_ITEM_MAP": "지도",
"CONTEXT_GENERATOR_SEED": "시드"
}

View File

@@ -0,0 +1,123 @@
package net.torvald.terrarum.modulebasegame.ui
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.TextureRegion
import net.torvald.terrarum.App
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Second
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.savegame.VirtualDisk
import net.torvald.terrarum.ui.*
import net.torvald.terrarum.utils.RandomWordsName
/**
* Created by minjaesong on 2021-10-25.
*/
class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
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
override var openCloseTime: Second = 0f
private val drawX = (Toolkit.drawWidth - width) / 2
private val drawY = (App.scr.height - height) / 2
private val radioCellWidth = 100
private val inputWidth = 340
private val radioX = (width - (radioCellWidth * 4 + 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_SMALL"] },
{ Lang["MENU_SETTING_MEDIUM"] }, // ;p
{ Lang["CONTEXT_DESCRIPTION_BIG"] },
{ Lang["CONTEXT_DESCRIPTION_HUGE"] }
))
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,
{ RandomWordsName(4) }, InputLenCap(256, InputLenCap.CharLenUnit.CODEPOINTS))
init {
tex.forEach { it.flip(false, true) }
sizeSelector.selectionChangeListener = {}
addUIitem(sizeSelector)
addUIitem(nameInput)
addUIitem(seedInput)
}
override fun updateUI(delta: Float) {
uiItems.forEach { it.update(delta) }
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
batch.color = Color.WHITE
// ui title
val titlestr = Lang["CONTEXT_WORLD_NEW"]
// "Game Load"
App.fontGame.draw(batch, titlestr, drawX + (width - App.fontGame.getWidth(titlestr)).div(2).toFloat(), titleTextPosY.toFloat())
// draw size previews
val texture = tex[sizeSelector.selection]
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) }
}
override fun doOpening(delta: Float) {
}
override fun doClosing(delta: Float) {
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
}
override fun dispose() {
hugeTex.texture.dispose()
largeTex.texture.dispose()
normalTex.texture.dispose()
smallTex.texture.dispose()
}
}

View File

@@ -17,6 +17,7 @@ object UITitleRemoConYaml {
- MENU_LABEL_GRAPHICS : net.torvald.terrarum.modulebasegame.ui.GraphicsControlPanel
- MENU_OPTIONS_CONTROLS : net.torvald.terrarum.modulebasegame.ui.UIKeyboardControlPanel
- MENU_LABEL_LANGUAGE : net.torvald.terrarum.modulebasegame.ui.UITitleLanguage
- TEST : net.torvald.terrarum.modulebasegame.ui.UINewWorld
- MENU_MODULES : net.torvald.terrarum.ModOptionsHost
- MENU_LABEL_RETURN+WRITETOCONFIG
- MENU_LABEL_CREDITS
@@ -39,7 +40,7 @@ object UITitleRemoConYaml {
"""
val injectedMenuSingleWorldSel = """
- CONTEXT_WORLD_NEW
- CONTEXT_WORLD_NEW : net.torvald.terrarum.modulebasegame.ui.UINewWorld
- MENU_LABEL_RETURN
"""

View File

@@ -0,0 +1,103 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
/**
* Created by minjaesong on 2021-10-25.
*/
class UIItemInlineRadioButtons(
parentUI: UICanvas,
initialX: Int,
initialY: Int,
val cellWidth: Int,
val labelfuns: List<() -> String>,
initialSelection: Int = 0
) : UIItem(parentUI, initialX, initialY) {
companion object {
const val HEIGHT = 24
}
override val width = cellWidth * labelfuns.size + 3 * (labelfuns.size - 1)
override val height = HEIGHT
var selectionChangeListener: (Int) -> Unit = {}
var selection = initialSelection
var mouseOnSelection = -1
private fun getCellX(i: Int) = posX - 3 + cellWidth * i + 3 * (i + 1)
override fun update(delta: Float) {
val mx = relativeMouseX
val my = relativeMouseY
mouseOnSelection = -1
val oldSelection = selection
if (my in 0 until height) {
for (i in labelfuns.indices) {
val cx = getCellX(i) - posX
if (mx in cx until cx + cellWidth) {
mouseOnSelection = i
if (mousePushed) {
selection = i
if (i != oldSelection) selectionChangeListener(i)
}
break
}
}
}
super.update(delta)
}
override fun render(batch: SpriteBatch, camera: Camera) {
// backgrounds
batch.color = UIItemTextLineInput.TEXTINPUT_COL_BACKGROUND
for (i in labelfuns.indices) {
Toolkit.fillArea(batch, getCellX(i), posY, cellWidth, height)
}
// back border
batch.color = Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
for (i in labelfuns.indices) {
val xpos = getCellX(i)
Toolkit.drawBoxBorder(batch, xpos - 1, posY - 1, cellWidth + 2, height + 2)
}
// text
for (i in labelfuns.indices) {
if (i != mouseOnSelection && i != selection) {
val xpos = getCellX(i)
val text = labelfuns[i]()
val tw = App.fontGame.getWidth(text)
App.fontGame.draw(batch, text, xpos + (cellWidth - tw) / 2, posY + 2)
}
}
// mouseover borders and text
if (mouseOnSelection > -1 && mouseOnSelection != selection) {
val xpos = getCellX(mouseOnSelection)
batch.color = Toolkit.Theme.COL_ACTIVE
Toolkit.drawBoxBorder(batch, xpos - 1, posY - 1, cellWidth + 2, height + 2)
val text = labelfuns[mouseOnSelection]()
val tw = App.fontGame.getWidth(text)
App.fontGame.draw(batch, text, xpos + (cellWidth - tw) / 2, posY + 2)
}
// selection borders and text
val xpos = getCellX(selection)
batch.color = Toolkit.Theme.COL_HIGHLIGHT
Toolkit.drawBoxBorder(batch, xpos - 1, posY - 1, cellWidth + 2, height + 2)
val text = labelfuns[selection]()
val tw = App.fontGame.getWidth(text)
App.fontGame.draw(batch, text, xpos + (cellWidth - tw) / 2, posY + 2)
super.render(batch, camera)
}
override fun dispose() {
}
}

View File

@@ -49,11 +49,11 @@ class UIItemSpinner(
super.update(delta)
mouseOnButton =
if (relativeMouseX in 0..buttonW && relativeMouseY in 0..height)
if (relativeMouseX in 0 until buttonW && relativeMouseY in 0 until height)
1
else if (relativeMouseX in width - buttonW..width && relativeMouseY in 0..height)
else if (relativeMouseX in width - buttonW until width && relativeMouseY in 0 until height)
2
else if (relativeMouseX in buttonW + 3..width - buttonW - 3 && relativeMouseY in 0..height)
else if (relativeMouseX in buttonW + 3 until width - buttonW - 3 && relativeMouseY in 0 until height)
3
else
0

View File

@@ -53,9 +53,9 @@ class UIItemTextLineInput(
initialX: Int, initialY: Int,
override val width: Int,
var placeholder: () -> String = { "" },
val maxLen: InputLenCap = InputLenCap(1000, InputLenCap.CharLenUnit.CODEPOINTS),
val enablePasteButton: Boolean = true,
val enableIMEButton: Boolean = false,
val maxLen: InputLenCap = InputLenCap(1000, InputLenCap.CharLenUnit.CODEPOINTS)
val enableIMEButton: Boolean = true
) : UIItem(parentUI, initialX, initialY) {
init {

View File

@@ -50,11 +50,11 @@ class UIItemTextSelector(
super.update(delta)
mouseOnButton =
if (relativeMouseX in 0..buttonW && relativeMouseY in 0..height)
if (relativeMouseX in 0 until buttonW && relativeMouseY in 0 until height)
1
else if (relativeMouseX in width - buttonW..width && relativeMouseY in 0..height)
else if (relativeMouseX in width - buttonW until width && relativeMouseY in 0 until height)
2
else if (relativeMouseX in buttonW + 3..width - buttonW - 3 && relativeMouseY in 0..height)
else if (relativeMouseX in buttonW + 3 until width - buttonW - 3 && relativeMouseY in 0 until height)
3
else
0