mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
some more new world ui thingies/fixed a bug where drawing an inventory background would cause a segfault
This commit is contained in:
@@ -14,6 +14,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
|||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
import com.badlogic.gdx.utils.Disposable;
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
|
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||||
import com.badlogic.gdx.utils.JsonValue;
|
import com.badlogic.gdx.utils.JsonValue;
|
||||||
import com.github.strikerx3.jxinput.XInputDevice;
|
import com.github.strikerx3.jxinput.XInputDevice;
|
||||||
import net.torvald.gdx.graphics.PixmapIO2;
|
import net.torvald.gdx.graphics.PixmapIO2;
|
||||||
@@ -752,7 +753,7 @@ public class App implements ApplicationListener {
|
|||||||
try {
|
try {
|
||||||
it.dispose();
|
it.dispose();
|
||||||
}
|
}
|
||||||
catch (NullPointerException | IllegalArgumentException e) { }
|
catch (NullPointerException | IllegalArgumentException | GdxRuntimeException e) { }
|
||||||
});
|
});
|
||||||
|
|
||||||
ModMgr.INSTANCE.disposeMods();
|
ModMgr.INSTANCE.disposeMods();
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ class EntryPoint : ModuleEntryPoint() {
|
|||||||
|
|
||||||
// load common resources to the AssetsManager
|
// load common resources to the AssetsManager
|
||||||
CommonResourcePool.addToLoadingList("$moduleName.items16") {
|
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") {
|
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") {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -78,8 +78,6 @@ internal class UIStorageChest : UICanvas(
|
|||||||
override var height = App.scr.height
|
override var height = App.scr.height
|
||||||
override var openCloseTime: Second = 0.0f
|
override var openCloseTime: Second = 0.0f
|
||||||
|
|
||||||
private val shapeRenderer = ShapeRenderer()
|
|
||||||
|
|
||||||
private val negotiator = object : InventoryNegotiator() {
|
private val negotiator = object : InventoryNegotiator() {
|
||||||
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Int) {
|
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Int) {
|
||||||
player.remove(item, amount)
|
player.remove(item, amount)
|
||||||
@@ -201,7 +199,7 @@ internal class UIStorageChest : UICanvas(
|
|||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
// background fill
|
// background fill
|
||||||
UIInventoryFull.drawBackground(batch, shapeRenderer)
|
UIInventoryFull.drawBackground(batch)
|
||||||
|
|
||||||
// UI items
|
// UI items
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
@@ -271,6 +269,5 @@ internal class UIStorageChest : UICanvas(
|
|||||||
|
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
try { shapeRenderer.dispose() } catch (e: IllegalArgumentException) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,6 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
|||||||
textAreaWidth = gameMenuListWidth,
|
textAreaWidth = gameMenuListWidth,
|
||||||
activeBackCol = Color(0),
|
activeBackCol = Color(0),
|
||||||
highlightBackCol = Color(0),
|
highlightBackCol = Color(0),
|
||||||
backgroundCol = Color(0),
|
|
||||||
inactiveCol = Color.WHITE,
|
inactiveCol = Color.WHITE,
|
||||||
defaultSelection = null
|
defaultSelection = null
|
||||||
)
|
)
|
||||||
@@ -55,7 +54,6 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
|||||||
textAreaWidth = gameMenuListWidth,
|
textAreaWidth = gameMenuListWidth,
|
||||||
activeBackCol = Color(0),
|
activeBackCol = Color(0),
|
||||||
highlightBackCol = Color(0),
|
highlightBackCol = Color(0),
|
||||||
backgroundCol = Color(0),
|
|
||||||
inactiveCol = Color.WHITE,
|
inactiveCol = Color.WHITE,
|
||||||
defaultSelection = null
|
defaultSelection = null
|
||||||
)
|
)
|
||||||
@@ -68,7 +66,6 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
|||||||
textAreaWidth = gameMenuListWidth,
|
textAreaWidth = gameMenuListWidth,
|
||||||
activeBackCol = Color(0),
|
activeBackCol = Color(0),
|
||||||
highlightBackCol = Color(0),
|
highlightBackCol = Color(0),
|
||||||
backgroundCol = Color(0),
|
|
||||||
inactiveCol = Color.WHITE,
|
inactiveCol = Color.WHITE,
|
||||||
defaultSelection = null
|
defaultSelection = null
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ class UIInventoryFull(
|
|||||||
override var openCloseTime: Second = 0.0f
|
override var openCloseTime: Second = 0.0f
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private var shapeRenderer: ShapeRenderer? = null
|
||||||
|
|
||||||
|
|
||||||
val CELL_COL = Toolkit.Theme.COL_CELL_FILL
|
val CELL_COL = Toolkit.Theme.COL_CELL_FILL
|
||||||
|
|
||||||
const val INVEN_DEBUG_MODE = false
|
const val INVEN_DEBUG_MODE = false
|
||||||
@@ -62,24 +65,28 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
val controlHelpHeight = App.fontGame.lineHeight
|
val controlHelpHeight = App.fontGame.lineHeight
|
||||||
|
|
||||||
fun drawBackground(batch: SpriteBatch, shapeRenderer: ShapeRenderer) {
|
fun drawBackground(batch: SpriteBatch) {
|
||||||
batch.end()
|
batch.end()
|
||||||
gdxSetBlendNormal()
|
gdxSetBlendNormal()
|
||||||
|
|
||||||
|
if (shapeRenderer == null) {
|
||||||
|
shapeRenderer = ShapeRenderer()
|
||||||
|
App.disposables.add(shapeRenderer)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
val gradTopStart = (App.scr.height - internalHeight).div(2).toFloat()
|
val gradTopStart = (App.scr.height - internalHeight).div(2).toFloat()
|
||||||
val gradBottomEnd = App.scr.height - gradTopStart
|
val gradBottomEnd = App.scr.height - gradTopStart
|
||||||
|
|
||||||
shapeRenderer.inUse {
|
shapeRenderer!!.inUse {
|
||||||
// shaperender starts at bottom-left!
|
// 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)
|
it.rect(0f, gradTopStart + gradHeight, App.scr.wf, internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol)
|
||||||
shapeRenderer.rect(0f, gradBottomEnd, App.scr.wf, -gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
|
|
||||||
|
|
||||||
shapeRenderer.rect(0f, gradTopStart + gradHeight, App.scr.wf, internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol)
|
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)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.begin()
|
batch.begin()
|
||||||
@@ -235,7 +242,6 @@ class UIInventoryFull(
|
|||||||
//private val gradStartCol = Color(0x404040_60)
|
//private val gradStartCol = Color(0x404040_60)
|
||||||
//private val gradEndCol = Color(0x000000_70)
|
//private val gradEndCol = Color(0x000000_70)
|
||||||
//private val gradHeight = 48f
|
//private val gradHeight = 48f
|
||||||
private val shapeRenderer = ShapeRenderer()
|
|
||||||
|
|
||||||
internal var xEnd = (width + internalWidth).div(2).toFloat()
|
internal var xEnd = (width + internalWidth).div(2).toFloat()
|
||||||
private set
|
private set
|
||||||
@@ -244,7 +250,7 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
|
|
||||||
drawBackground(batch, shapeRenderer)
|
drawBackground(batch)
|
||||||
|
|
||||||
// UI items
|
// UI items
|
||||||
catBar.render(batch, camera)
|
catBar.render(batch, camera)
|
||||||
@@ -274,7 +280,6 @@ class UIInventoryFull(
|
|||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
catBar.dispose()
|
catBar.dispose()
|
||||||
transitionPanel.dispose()
|
transitionPanel.dispose()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.Texture
|
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 com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
|
import net.torvald.terrarum.App.printdbg
|
||||||
import net.torvald.terrarum.ModMgr
|
import net.torvald.terrarum.ModMgr
|
||||||
import net.torvald.terrarum.Second
|
import net.torvald.terrarum.Second
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
@@ -50,23 +52,35 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() {
|
|||||||
{ Lang["CONTEXT_DESCRIPTION_HUGE"] }
|
{ Lang["CONTEXT_DESCRIPTION_HUGE"] }
|
||||||
))
|
))
|
||||||
|
|
||||||
|
private val rng = HQRNG()
|
||||||
|
|
||||||
private val nameInput = UIItemTextLineInput(this,
|
private val nameInput = UIItemTextLineInput(this,
|
||||||
drawX + width - inputWidth, drawY + sizeSelY + 80, inputWidth,
|
drawX + width - inputWidth, drawY + sizeSelY + 80, inputWidth,
|
||||||
{ RandomWordsName(4) }, InputLenCap(VirtualDisk.NAME_LENGTH, InputLenCap.CharLenUnit.UTF8_BYTES))
|
{ RandomWordsName(4) }, InputLenCap(VirtualDisk.NAME_LENGTH, InputLenCap.CharLenUnit.UTF8_BYTES))
|
||||||
|
|
||||||
private val seedInput = UIItemTextLineInput(this,
|
private val seedInput = UIItemTextLineInput(this,
|
||||||
drawX + width - inputWidth, drawY + sizeSelY + 120, inputWidth,
|
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 {
|
init {
|
||||||
tex.forEach { it.flip(false, true) }
|
tex.forEach { it.flip(false, true) }
|
||||||
|
|
||||||
sizeSelector.selectionChangeListener = {}
|
goButton.touchDownListener = { _, _, _, _ ->
|
||||||
|
printdbg(this, "generate!")
|
||||||
|
}
|
||||||
|
backButton.touchDownListener = { _, _, _, _ ->
|
||||||
|
printdbg(this, "back!")
|
||||||
|
}
|
||||||
|
|
||||||
addUIitem(sizeSelector)
|
addUIitem(sizeSelector)
|
||||||
addUIitem(nameInput)
|
addUIitem(nameInput)
|
||||||
addUIitem(seedInput)
|
addUIitem(seedInput)
|
||||||
|
addUIitem(goButton)
|
||||||
|
addUIitem(backButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -245,7 +245,6 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
|
|||||||
readFromLang = true,
|
readFromLang = true,
|
||||||
activeBackCol = Color(0),//Color(1f,0f,.75f,1f),
|
activeBackCol = Color(0),//Color(1f,0f,.75f,1f),
|
||||||
highlightBackCol = Color(0),
|
highlightBackCol = Color(0),
|
||||||
backgroundCol = Color(0),
|
|
||||||
inactiveCol = Color.WHITE,
|
inactiveCol = Color.WHITE,
|
||||||
defaultSelection = null,
|
defaultSelection = null,
|
||||||
itemHitboxSize = lineHeight - 2,
|
itemHitboxSize = lineHeight - 2,
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ class UITitleLanguage(val remoCon: UIRemoCon) : UICanvas() {
|
|||||||
readFromLang = false,
|
readFromLang = false,
|
||||||
activeBackCol = Color(0),
|
activeBackCol = Color(0),
|
||||||
highlightBackCol = Color(0),
|
highlightBackCol = Color(0),
|
||||||
backgroundCol = Color(0),
|
|
||||||
inactiveCol = Color.WHITE,
|
inactiveCol = Color.WHITE,
|
||||||
defaultSelection = null
|
defaultSelection = null
|
||||||
)
|
)
|
||||||
@@ -52,7 +51,6 @@ class UITitleLanguage(val remoCon: UIRemoCon) : UICanvas() {
|
|||||||
readFromLang = false,
|
readFromLang = false,
|
||||||
activeBackCol = Color(0),
|
activeBackCol = Color(0),
|
||||||
highlightBackCol = Color(0),
|
highlightBackCol = Color(0),
|
||||||
backgroundCol = Color(0),
|
|
||||||
inactiveCol = Color.WHITE,
|
inactiveCol = Color.WHITE,
|
||||||
defaultSelection = null
|
defaultSelection = null
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package net.torvald.terrarum.ui
|
package net.torvald.terrarum.ui
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
|
||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import net.torvald.terrarum.App
|
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
|
|
||||||
|
|
||||||
@@ -209,7 +207,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
var actionDone = false
|
var actionDone = false
|
||||||
|
|
||||||
if (parentUI.isVisible) {
|
if (parentUI.isVisible) {
|
||||||
if (touchDownListener != null) {
|
if (touchDownListener != null && mouseUp) {
|
||||||
touchDownListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
touchDownListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
||||||
actionDone = true
|
actionDone = true
|
||||||
}
|
}
|
||||||
@@ -225,7 +223,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
open fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
open fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
clickOnceListenerFired = false
|
clickOnceListenerFired = false
|
||||||
|
|
||||||
if (parentUI.isVisible && touchUpListener != null) {
|
if (parentUI.isVisible && touchUpListener != null && mouseUp) {
|
||||||
touchUpListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
touchUpListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -233,7 +231,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
open fun scrolled(amountX: Float, amountY: Float): Boolean {
|
open fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||||
if (parentUI.isVisible && scrolledListener != null) {
|
if (parentUI.isVisible && scrolledListener != null && mouseUp) {
|
||||||
scrolledListener!!.invoke(amountX, amountY)
|
scrolledListener!!.invoke(amountX, amountY)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,8 @@ open class UIItemTextButton(
|
|||||||
val highlightBackBlendMode: String = BlendMode.NORMAL,
|
val highlightBackBlendMode: String = BlendMode.NORMAL,
|
||||||
/** Colour on normal status */
|
/** Colour on normal status */
|
||||||
val inactiveCol: Color = Toolkit.Theme.COL_LIST_DEFAULT,
|
val inactiveCol: Color = Toolkit.Theme.COL_LIST_DEFAULT,
|
||||||
val backgroundCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL,
|
|
||||||
val backgroundBlendMode: String = BlendMode.NORMAL,
|
|
||||||
|
|
||||||
|
val hasBorder: Boolean = false,
|
||||||
|
|
||||||
val paddingLeft: Int = 0,
|
val paddingLeft: Int = 0,
|
||||||
val paddingRight: Int = 0,
|
val paddingRight: Int = 0,
|
||||||
@@ -51,7 +50,7 @@ open class UIItemTextButton(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val font = App.fontGame
|
val font = App.fontGame
|
||||||
val height = font.lineHeight.toInt()
|
val height = 24
|
||||||
|
|
||||||
enum class Alignment {
|
enum class Alignment {
|
||||||
CENTRE, LEFT, RIGHT
|
CENTRE, LEFT, RIGHT
|
||||||
@@ -75,6 +74,12 @@ open class UIItemTextButton(
|
|||||||
|
|
||||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||||
val textW = font.getWidth(label)
|
val textW = font.getWidth(label)
|
||||||
|
val fontX = when (alignment) {
|
||||||
|
Alignment.CENTRE -> 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
|
// draw background
|
||||||
@@ -97,21 +102,29 @@ open class UIItemTextButton(
|
|||||||
|
|
||||||
blendNormal(batch)
|
blendNormal(batch)
|
||||||
|
|
||||||
|
if (hasBorder) {
|
||||||
|
batch.color = Toolkit.Theme.COL_CELL_FILL
|
||||||
|
Toolkit.fillArea(batch, posX, posY, width, height)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
batch.color = if (highlighted) highlightCol
|
batch.color = if (highlighted) highlightCol
|
||||||
else if (mouseUp) activeCol
|
else if (mouseUp) activeCol
|
||||||
else inactiveCol
|
else inactiveCol
|
||||||
|
|
||||||
font.draw(batch,
|
|
||||||
label,
|
// draw border
|
||||||
// "$label/H:${highlighted.toInt()}, M:${mouseUp.toInt()}",
|
if (hasBorder) {
|
||||||
when (alignment) {
|
val c = batch.color.cpy()
|
||||||
Alignment.CENTRE -> posX.toFloat() + width.minus(textW).div(2) + (paddingLeft - paddingRight).div(2)
|
if (batch.color == inactiveCol) {
|
||||||
Alignment.LEFT -> posX.toFloat() + paddingLeft
|
batch.color = Toolkit.Theme.COL_INACTIVE
|
||||||
Alignment.RIGHT -> width - paddingRight - textW.toFloat()
|
}
|
||||||
},
|
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
|
||||||
posY.toFloat() + (hitboxSize - UIItemTextButton.height) / 2f
|
batch.color = c
|
||||||
)
|
}
|
||||||
|
|
||||||
|
// draw text
|
||||||
|
font.draw(batch, label, fontX, fontY)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package net.torvald.terrarum.ui
|
package net.torvald.terrarum.ui
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
|
||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.BlendMode
|
||||||
import net.torvald.terrarum.App.printdbg
|
import net.torvald.terrarum.Second
|
||||||
|
import net.torvald.terrarum.Terrarum
|
||||||
|
import net.torvald.terrarum.toInt
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,11 +44,6 @@ class UIItemTextButtonList(
|
|||||||
val highlightBackBlendMode: String = BlendMode.NORMAL,
|
val highlightBackBlendMode: String = BlendMode.NORMAL,
|
||||||
/** Colour on normal status */
|
/** Colour on normal status */
|
||||||
val inactiveCol: Color = Toolkit.Theme.COL_LIST_DEFAULT,
|
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 leftPadding: Int = 0,
|
||||||
val rightPadding: Int = 0,
|
val rightPadding: Int = 0,
|
||||||
@@ -83,7 +79,7 @@ class UIItemTextButtonList(
|
|||||||
val lh = itemHitboxSize
|
val lh = itemHitboxSize
|
||||||
val vertOff = lineHeight * i
|
val vertOff = lineHeight * i
|
||||||
|
|
||||||
if (!kinematic) {
|
// if (!kinematic) {
|
||||||
UIItemTextButton(
|
UIItemTextButton(
|
||||||
parentUI, s,
|
parentUI, s,
|
||||||
initialX = posX,
|
initialX = posX,
|
||||||
@@ -97,37 +93,34 @@ class UIItemTextButtonList(
|
|||||||
highlightBackCol = highlightBackCol,
|
highlightBackCol = highlightBackCol,
|
||||||
highlightBackBlendMode = highlightBackBlendMode,
|
highlightBackBlendMode = highlightBackBlendMode,
|
||||||
inactiveCol = inactiveCol,
|
inactiveCol = inactiveCol,
|
||||||
backgroundCol = backgroundCol,
|
|
||||||
backgroundBlendMode = backgroundBlendMode,
|
|
||||||
paddingLeft = pregap,
|
paddingLeft = pregap,
|
||||||
paddingRight = postgap,
|
paddingRight = postgap,
|
||||||
alignment = alignment,
|
alignment = alignment,
|
||||||
hitboxSize = itemHitboxSize,
|
hitboxSize = itemHitboxSize,
|
||||||
tags = tagsCollection[i]
|
tags = tagsCollection[i]
|
||||||
)
|
)
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
UIItemTextButton(
|
// UIItemTextButton(
|
||||||
parentUI, s,
|
// parentUI, s,
|
||||||
initialX = posX,
|
// initialX = posX,
|
||||||
initialY = posY + vertOff,
|
// initialY = posY + vertOff,
|
||||||
width = width,
|
// width = width,
|
||||||
readFromLang = readFromLang,
|
// readFromLang = readFromLang,
|
||||||
activeCol = activeCol,
|
// activeCol = activeCol,
|
||||||
activeBackCol = activeBackCol,
|
// activeBackCol = activeBackCol,
|
||||||
activeBackBlendMode = activeBackBlendMode,
|
// activeBackBlendMode = activeBackBlendMode,
|
||||||
highlightCol = highlightCol,
|
// highlightCol = highlightCol,
|
||||||
highlightBackCol = activeBackCol, // we are using custom highlighter
|
// highlightBackCol = activeBackCol, // we are using custom highlighter
|
||||||
highlightBackBlendMode = activeBackBlendMode, // we are using custom highlighter
|
// highlightBackBlendMode = activeBackBlendMode, // we are using custom highlighter
|
||||||
backgroundCol = Color(0),
|
// inactiveCol = inactiveCol,
|
||||||
inactiveCol = inactiveCol,
|
// paddingLeft = pregap,
|
||||||
paddingLeft = pregap,
|
// paddingRight = postgap,
|
||||||
paddingRight = postgap,
|
// alignment = alignment,
|
||||||
alignment = alignment,
|
// hitboxSize = itemHitboxSize,
|
||||||
hitboxSize = itemHitboxSize,
|
// tags = tagsCollection[i]
|
||||||
tags = tagsCollection[i]
|
// )
|
||||||
)
|
// }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -203,16 +196,16 @@ class UIItemTextButtonList(
|
|||||||
if (!clickLatched && btn.mousePushed && index != selectedIndex) {
|
if (!clickLatched && btn.mousePushed && index != selectedIndex) {
|
||||||
val oldIndex = selectedIndex
|
val oldIndex = selectedIndex
|
||||||
|
|
||||||
if (kinematic) {
|
// if (kinematic) {
|
||||||
selectedIndex = index
|
// selectedIndex = index
|
||||||
highlighterYStart = buttons[selectedIndex!!].posY.toFloat()
|
// highlighterYStart = buttons[selectedIndex!!].posY.toFloat()
|
||||||
highlighterMoving = true
|
// highlighterMoving = true
|
||||||
highlighterYEnd = buttons[selectedIndex!!].posY.toFloat()
|
// highlighterYEnd = buttons[selectedIndex!!].posY.toFloat()
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
selectedIndex = index
|
selectedIndex = index
|
||||||
highlightY = buttons[selectedIndex!!].posY.toFloat()
|
highlightY = buttons[selectedIndex!!].posY.toFloat()
|
||||||
}
|
// }
|
||||||
|
|
||||||
selectionChangeListener?.invoke(oldIndex, index)
|
selectionChangeListener?.invoke(oldIndex, index)
|
||||||
}
|
}
|
||||||
@@ -229,7 +222,7 @@ class UIItemTextButtonList(
|
|||||||
|
|
||||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||||
|
|
||||||
if (kinematic) {
|
/*if (kinematic) {
|
||||||
batch.color = backgroundCol
|
batch.color = backgroundCol
|
||||||
BlendMode.resolve(backgroundBlendMode, batch)
|
BlendMode.resolve(backgroundBlendMode, batch)
|
||||||
Toolkit.fillArea(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
Toolkit.fillArea(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||||
@@ -239,7 +232,7 @@ class UIItemTextButtonList(
|
|||||||
if (highlightY != null) {
|
if (highlightY != null) {
|
||||||
Toolkit.fillArea(batch, posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), itemHitboxSize.toFloat())
|
Toolkit.fillArea(batch, posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), itemHitboxSize.toFloat())
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
buttons.forEach { it.render(batch, camera) }
|
buttons.forEach { it.render(batch, camera) }
|
||||||
|
|
||||||
@@ -253,7 +246,7 @@ class UIItemTextButtonList(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.color = backgroundCol
|
// batch.color = backgroundCol
|
||||||
}
|
}
|
||||||
|
|
||||||
fun select(index: Int) {
|
fun select(index: Int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user