From d8aed8a34c35dfb69281cf8b8bbcd31353bf5904 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 26 Oct 2021 00:03:19 +0900 Subject: [PATCH] new world ui wip --- assets/mods/basegame/gui/huge.png | 3 + assets/mods/basegame/gui/large.png | 3 + assets/mods/basegame/gui/normal.png | 3 + assets/mods/basegame/gui/small.png | 3 + assets/mods/basegame/locales/en/game.json | 3 +- assets/mods/basegame/locales/koKR/game.json | 3 +- .../terrarum/modulebasegame/ui/UINewWorld.kt | 123 ++++++++++++++++++ .../modulebasegame/ui/UITitleRemoConYaml.kt | 3 +- .../terrarum/ui/UIItemInlineRadioButtons.kt | 103 +++++++++++++++ src/net/torvald/terrarum/ui/UIItemSpinner.kt | 6 +- .../terrarum/ui/UIItemTextLineInput.kt | 4 +- .../torvald/terrarum/ui/UIItemTextSelector.kt | 6 +- 12 files changed, 252 insertions(+), 11 deletions(-) create mode 100644 assets/mods/basegame/gui/huge.png create mode 100644 assets/mods/basegame/gui/large.png create mode 100644 assets/mods/basegame/gui/normal.png create mode 100644 assets/mods/basegame/gui/small.png create mode 100644 src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt create mode 100644 src/net/torvald/terrarum/ui/UIItemInlineRadioButtons.kt diff --git a/assets/mods/basegame/gui/huge.png b/assets/mods/basegame/gui/huge.png new file mode 100644 index 000000000..eca4386fc --- /dev/null +++ b/assets/mods/basegame/gui/huge.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cf4121a675f4af81db47a049c5dbbe683657b1fd61ffca008e2dad58d4ca0e11 +size 7536 diff --git a/assets/mods/basegame/gui/large.png b/assets/mods/basegame/gui/large.png new file mode 100644 index 000000000..4563e6bde --- /dev/null +++ b/assets/mods/basegame/gui/large.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:172d1098fcdf749fbaa6e0d91bb5cf047fcd080364b4b462f8e367fc7b30503d +size 2639 diff --git a/assets/mods/basegame/gui/normal.png b/assets/mods/basegame/gui/normal.png new file mode 100644 index 000000000..4f1c06dd2 --- /dev/null +++ b/assets/mods/basegame/gui/normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67ca75d254bbf680b9a11edcb00352f7f54cd8a130b4abf61c2864573d42edf3 +size 1242 diff --git a/assets/mods/basegame/gui/small.png b/assets/mods/basegame/gui/small.png new file mode 100644 index 000000000..85da6c012 --- /dev/null +++ b/assets/mods/basegame/gui/small.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:877d79cd28c45ce7f3291e8dc8b31dc437e3129c5a9cf5079041ddf86389a759 +size 890 diff --git a/assets/mods/basegame/locales/en/game.json b/assets/mods/basegame/locales/en/game.json index afc8ca4c3..6fd915426 100644 --- a/assets/mods/basegame/locales/en/game.json +++ b/assets/mods/basegame/locales/en/game.json @@ -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" } \ No newline at end of file diff --git a/assets/mods/basegame/locales/koKR/game.json b/assets/mods/basegame/locales/koKR/game.json index 0a3747981..6c7d9f160 100644 --- a/assets/mods/basegame/locales/koKR/game.json +++ b/assets/mods/basegame/locales/koKR/game.json @@ -11,5 +11,6 @@ "GAME_INVENTORY_FAVORITES": "즐겨찾기", "GAME_INVENTORY_REGISTER": "등록하기", "MENU_LABEL_MENU": "메뉴", - "CONTEXT_ITEM_MAP": "지도" + "CONTEXT_ITEM_MAP": "지도", + "CONTEXT_GENERATOR_SEED": "시드" } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt new file mode 100644 index 000000000..d0a026ca3 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt @@ -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() + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConYaml.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConYaml.kt index 30791e243..bca18b277 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConYaml.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConYaml.kt @@ -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 """ diff --git a/src/net/torvald/terrarum/ui/UIItemInlineRadioButtons.kt b/src/net/torvald/terrarum/ui/UIItemInlineRadioButtons.kt new file mode 100644 index 000000000..5fc03567b --- /dev/null +++ b/src/net/torvald/terrarum/ui/UIItemInlineRadioButtons.kt @@ -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() { + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/UIItemSpinner.kt b/src/net/torvald/terrarum/ui/UIItemSpinner.kt index ebfb31202..7f399d698 100644 --- a/src/net/torvald/terrarum/ui/UIItemSpinner.kt +++ b/src/net/torvald/terrarum/ui/UIItemSpinner.kt @@ -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 diff --git a/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt b/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt index 1768b2c8f..9dd03109c 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextLineInput.kt @@ -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 { diff --git a/src/net/torvald/terrarum/ui/UIItemTextSelector.kt b/src/net/torvald/terrarum/ui/UIItemTextSelector.kt index 34d37d852..6b5761951 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextSelector.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextSelector.kt @@ -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