diff --git a/src/net/torvald/terrarum/App.java b/src/net/torvald/terrarum/App.java index 51c8dca69..7374273d9 100644 --- a/src/net/torvald/terrarum/App.java +++ b/src/net/torvald/terrarum/App.java @@ -14,6 +14,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer; import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.utils.GdxRuntimeException; import com.badlogic.gdx.utils.JsonValue; import com.github.strikerx3.jxinput.XInputDevice; import net.torvald.gdx.graphics.PixmapIO2; @@ -752,7 +753,7 @@ public class App implements ApplicationListener { try { it.dispose(); } - catch (NullPointerException | IllegalArgumentException e) { } + catch (NullPointerException | IllegalArgumentException | GdxRuntimeException e) { } }); ModMgr.INSTANCE.disposeMods(); diff --git a/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt b/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt index ad2e5c072..bb9ff7f35 100644 --- a/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt +++ b/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt @@ -33,13 +33,13 @@ class EntryPoint : ModuleEntryPoint() { // load common resources to the AssetsManager CommonResourcePool.addToLoadingList("$moduleName.items16") { - TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items.tga"), 16, 16, flipY = true) + TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items.tga"), 16, 16, flipY = false) } CommonResourcePool.addToLoadingList("$moduleName.items24") { - TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items24.tga"), 24, 24, flipY = true) + TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items24.tga"), 24, 24, flipY = false) } CommonResourcePool.addToLoadingList("$moduleName.items48") { - TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items48.tga"), 48, 48, flipY = true) + TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items48.tga"), 48, 48, flipY = false) } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt index ee46ce093..473576dc5 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt @@ -78,8 +78,6 @@ internal class UIStorageChest : UICanvas( override var height = App.scr.height override var openCloseTime: Second = 0.0f - private val shapeRenderer = ShapeRenderer() - private val negotiator = object : InventoryNegotiator() { override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Int) { player.remove(item, amount) @@ -201,7 +199,7 @@ internal class UIStorageChest : UICanvas( override fun renderUI(batch: SpriteBatch, camera: Camera) { // background fill - UIInventoryFull.drawBackground(batch, shapeRenderer) + UIInventoryFull.drawBackground(batch) // UI items batch.color = Color.WHITE @@ -271,6 +269,5 @@ internal class UIStorageChest : UICanvas( override fun dispose() { - try { shapeRenderer.dispose() } catch (e: IllegalArgumentException) {} } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryEscMenu.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryEscMenu.kt index 45cb862c8..22093da97 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryEscMenu.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryEscMenu.kt @@ -42,7 +42,6 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() { textAreaWidth = gameMenuListWidth, activeBackCol = Color(0), highlightBackCol = Color(0), - backgroundCol = Color(0), inactiveCol = Color.WHITE, defaultSelection = null ) @@ -55,7 +54,6 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() { textAreaWidth = gameMenuListWidth, activeBackCol = Color(0), highlightBackCol = Color(0), - backgroundCol = Color(0), inactiveCol = Color.WHITE, defaultSelection = null ) @@ -68,7 +66,6 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() { textAreaWidth = gameMenuListWidth, activeBackCol = Color(0), highlightBackCol = Color(0), - backgroundCol = Color(0), inactiveCol = Color.WHITE, defaultSelection = null ) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt index 5cf3e638f..bca23001b 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt @@ -34,6 +34,9 @@ class UIInventoryFull( override var openCloseTime: Second = 0.0f companion object { + private var shapeRenderer: ShapeRenderer? = null + + val CELL_COL = Toolkit.Theme.COL_CELL_FILL const val INVEN_DEBUG_MODE = false @@ -62,24 +65,28 @@ class UIInventoryFull( val controlHelpHeight = App.fontGame.lineHeight - fun drawBackground(batch: SpriteBatch, shapeRenderer: ShapeRenderer) { + fun drawBackground(batch: SpriteBatch) { batch.end() gdxSetBlendNormal() + if (shapeRenderer == null) { + shapeRenderer = ShapeRenderer() + App.disposables.add(shapeRenderer) + } + val gradTopStart = (App.scr.height - internalHeight).div(2).toFloat() val gradBottomEnd = App.scr.height - gradTopStart - shapeRenderer.inUse { + shapeRenderer!!.inUse { // shaperender starts at bottom-left! + it.rect(0f, gradTopStart, App.scr.wf, gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol) + it.rect(0f, gradBottomEnd, App.scr.wf, -gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol) - shapeRenderer.rect(0f, gradTopStart, App.scr.wf, gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol) - shapeRenderer.rect(0f, gradBottomEnd, App.scr.wf, -gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol) + it.rect(0f, gradTopStart + gradHeight, App.scr.wf, internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol) - shapeRenderer.rect(0f, gradTopStart + gradHeight, App.scr.wf, internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol) - - shapeRenderer.rect(0f, 0f, App.scr.wf, gradTopStart, gradStartCol, gradStartCol, gradStartCol, gradStartCol) - shapeRenderer.rect(0f, App.scr.hf, App.scr.wf, -(App.scr.hf - gradBottomEnd), gradStartCol, gradStartCol, gradStartCol, gradStartCol) + it.rect(0f, 0f, App.scr.wf, gradTopStart, gradStartCol, gradStartCol, gradStartCol, gradStartCol) + it.rect(0f, App.scr.hf, App.scr.wf, -(App.scr.hf - gradBottomEnd), gradStartCol, gradStartCol, gradStartCol, gradStartCol) } batch.begin() @@ -235,7 +242,6 @@ class UIInventoryFull( //private val gradStartCol = Color(0x404040_60) //private val gradEndCol = Color(0x000000_70) //private val gradHeight = 48f - private val shapeRenderer = ShapeRenderer() internal var xEnd = (width + internalWidth).div(2).toFloat() private set @@ -244,7 +250,7 @@ class UIInventoryFull( override fun renderUI(batch: SpriteBatch, camera: Camera) { - drawBackground(batch, shapeRenderer) + drawBackground(batch) // UI items catBar.render(batch, camera) @@ -274,7 +280,6 @@ class UIInventoryFull( override fun dispose() { catBar.dispose() transitionPanel.dispose() - } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt index d0a026ca3..7b0fc08f8 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt @@ -5,7 +5,9 @@ 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.random.HQRNG import net.torvald.terrarum.App +import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.ModMgr import net.torvald.terrarum.Second import net.torvald.terrarum.langpack.Lang @@ -50,23 +52,35 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() { { 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, - { RandomWordsName(4) }, InputLenCap(256, InputLenCap.CharLenUnit.CODEPOINTS)) + { 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 { tex.forEach { it.flip(false, true) } - sizeSelector.selectionChangeListener = {} + goButton.touchDownListener = { _, _, _, _ -> + printdbg(this, "generate!") + } + backButton.touchDownListener = { _, _, _, _ -> + printdbg(this, "back!") + } addUIitem(sizeSelector) addUIitem(nameInput) addUIitem(seedInput) + addUIitem(goButton) + addUIitem(backButton) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt index f38038587..d83114f64 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt @@ -245,7 +245,6 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode posX + width.minus(textW).div(2) + (paddingLeft - paddingRight).div(2) + Alignment.LEFT -> posX + paddingLeft + Alignment.RIGHT -> width - paddingRight - textW + } + val fontY = posY + (hitboxSize - font.lineHeight.toInt()) / 2 // draw background @@ -97,21 +102,29 @@ open class UIItemTextButton( blendNormal(batch) + if (hasBorder) { + batch.color = Toolkit.Theme.COL_CELL_FILL + Toolkit.fillArea(batch, posX, posY, width, height) + } + batch.color = if (highlighted) highlightCol else if (mouseUp) activeCol else inactiveCol - font.draw(batch, - label, -// "$label/H:${highlighted.toInt()}, M:${mouseUp.toInt()}", - when (alignment) { - Alignment.CENTRE -> posX.toFloat() + width.minus(textW).div(2) + (paddingLeft - paddingRight).div(2) - Alignment.LEFT -> posX.toFloat() + paddingLeft - Alignment.RIGHT -> width - paddingRight - textW.toFloat() - }, - posY.toFloat() + (hitboxSize - UIItemTextButton.height) / 2f - ) + + // draw border + if (hasBorder) { + val c = batch.color.cpy() + if (batch.color == inactiveCol) { + batch.color = Toolkit.Theme.COL_INACTIVE + } + Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2) + batch.color = c + } + + // draw text + font.draw(batch, label, fontX, fontY) } override fun dispose() { diff --git a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt index 67307ba34..7f8c619d7 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt @@ -1,11 +1,12 @@ package net.torvald.terrarum.ui -import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.terrarum.* -import net.torvald.terrarum.App.printdbg +import net.torvald.terrarum.BlendMode +import net.torvald.terrarum.Second +import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.toInt import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack /** @@ -43,11 +44,6 @@ class UIItemTextButtonList( val highlightBackBlendMode: String = BlendMode.NORMAL, /** Colour on normal status */ val inactiveCol: Color = Toolkit.Theme.COL_LIST_DEFAULT, - val backgroundCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL, - val backgroundBlendMode: String = BlendMode.NORMAL, - - - val kinematic: Boolean = false, val leftPadding: Int = 0, val rightPadding: Int = 0, @@ -83,7 +79,7 @@ class UIItemTextButtonList( val lh = itemHitboxSize val vertOff = lineHeight * i - if (!kinematic) { +// if (!kinematic) { UIItemTextButton( parentUI, s, initialX = posX, @@ -97,37 +93,34 @@ class UIItemTextButtonList( highlightBackCol = highlightBackCol, highlightBackBlendMode = highlightBackBlendMode, inactiveCol = inactiveCol, - backgroundCol = backgroundCol, - backgroundBlendMode = backgroundBlendMode, paddingLeft = pregap, paddingRight = postgap, alignment = alignment, hitboxSize = itemHitboxSize, tags = tagsCollection[i] ) - } - else { - UIItemTextButton( - parentUI, s, - initialX = posX, - initialY = posY + vertOff, - width = width, - readFromLang = readFromLang, - activeCol = activeCol, - activeBackCol = activeBackCol, - activeBackBlendMode = activeBackBlendMode, - highlightCol = highlightCol, - highlightBackCol = activeBackCol, // we are using custom highlighter - highlightBackBlendMode = activeBackBlendMode, // we are using custom highlighter - backgroundCol = Color(0), - inactiveCol = inactiveCol, - paddingLeft = pregap, - paddingRight = postgap, - alignment = alignment, - hitboxSize = itemHitboxSize, - tags = tagsCollection[i] - ) - } +// } +// else { +// UIItemTextButton( +// parentUI, s, +// initialX = posX, +// initialY = posY + vertOff, +// width = width, +// readFromLang = readFromLang, +// activeCol = activeCol, +// activeBackCol = activeBackCol, +// activeBackBlendMode = activeBackBlendMode, +// highlightCol = highlightCol, +// highlightBackCol = activeBackCol, // we are using custom highlighter +// highlightBackBlendMode = activeBackBlendMode, // we are using custom highlighter +// inactiveCol = inactiveCol, +// paddingLeft = pregap, +// paddingRight = postgap, +// alignment = alignment, +// hitboxSize = itemHitboxSize, +// tags = tagsCollection[i] +// ) +// } } @@ -203,16 +196,16 @@ class UIItemTextButtonList( if (!clickLatched && btn.mousePushed && index != selectedIndex) { val oldIndex = selectedIndex - if (kinematic) { - selectedIndex = index - highlighterYStart = buttons[selectedIndex!!].posY.toFloat() - highlighterMoving = true - highlighterYEnd = buttons[selectedIndex!!].posY.toFloat() - } - else { +// if (kinematic) { +// selectedIndex = index +// highlighterYStart = buttons[selectedIndex!!].posY.toFloat() +// highlighterMoving = true +// highlighterYEnd = buttons[selectedIndex!!].posY.toFloat() +// } +// else { selectedIndex = index highlightY = buttons[selectedIndex!!].posY.toFloat() - } +// } selectionChangeListener?.invoke(oldIndex, index) } @@ -229,7 +222,7 @@ class UIItemTextButtonList( override fun render(batch: SpriteBatch, camera: Camera) { - if (kinematic) { + /*if (kinematic) { batch.color = backgroundCol BlendMode.resolve(backgroundBlendMode, batch) Toolkit.fillArea(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat()) @@ -239,7 +232,7 @@ class UIItemTextButtonList( if (highlightY != null) { Toolkit.fillArea(batch, posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), itemHitboxSize.toFloat()) } - } + }*/ buttons.forEach { it.render(batch, camera) } @@ -253,7 +246,7 @@ class UIItemTextButtonList( } } - batch.color = backgroundCol +// batch.color = backgroundCol } fun select(index: Int) {