mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-18 06:24:06 +09:00
text input pane wip
This commit is contained in:
@@ -300,7 +300,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
||||
val histogramMax = histogram.screen_tiles.toFloat()
|
||||
|
||||
batch.color = uiColour
|
||||
batch.fillRect(x.toFloat(), y.toFloat(), w.plus(1), h)
|
||||
Toolkit.fillArea(batch, x.toFloat(), y.toFloat(), w.plus(1), h)
|
||||
batch.color = Color.GRAY
|
||||
App.fontSmallNumbers.draw(batch, "0", x.toFloat(), y.toFloat() + h + 2)
|
||||
App.fontSmallNumbers.draw(batch, "255", x.toFloat() + w + 1 - 8 * 3, y.toFloat() + h + 2)
|
||||
@@ -322,7 +322,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
||||
val bar_w = 1f
|
||||
|
||||
batch.color = barColour[c]
|
||||
batch.fillRect(bar_x, bar_y, bar_w, -bar_h)
|
||||
Toolkit.fillArea(batch, bar_x, bar_y, bar_w, -bar_h)
|
||||
}
|
||||
}
|
||||
blendNormal(batch)
|
||||
|
||||
@@ -5,7 +5,10 @@ import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.EMDASH
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration
|
||||
import net.torvald.terrarum.ccE
|
||||
import net.torvald.terrarum.console.Authenticator
|
||||
import net.torvald.terrarum.console.CommandInterpreter
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
@@ -73,8 +76,8 @@ class ConsoleWindow : UICanvas() {
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
// background
|
||||
batch.color = UIColour
|
||||
batch.fillRect(drawOffX, drawOffY, width.toFloat(), height.toFloat())
|
||||
batch.fillRect(drawOffX, drawOffY, width.toFloat(), LINE_HEIGHT.toFloat())
|
||||
Toolkit.fillArea(batch, drawOffX, drawOffY, width.toFloat(), height.toFloat())
|
||||
Toolkit.fillArea(batch, drawOffX, drawOffY, width.toFloat(), LINE_HEIGHT.toFloat())
|
||||
|
||||
val input = commandInputPool!!.toString()
|
||||
val inputDrawWidth = App.fontGame.getWidth(input)
|
||||
@@ -85,9 +88,9 @@ class ConsoleWindow : UICanvas() {
|
||||
App.fontGame.draw(batch, input, 1f + drawOffX, drawOffY)
|
||||
|
||||
batch.color = Color(0x7f7f7f_ff)
|
||||
batch.fillRect(inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 2f, inputDrawHeight)
|
||||
Toolkit.fillArea(batch, inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 2f, inputDrawHeight)
|
||||
batch.color = Color.WHITE
|
||||
batch.fillRect(inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 1f, inputDrawHeight - 1)
|
||||
Toolkit.fillArea(batch, inputDrawWidth.toFloat() + drawOffX + 1, drawOffY, 1f, inputDrawHeight - 1)
|
||||
|
||||
|
||||
// messages
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import org.lwjgl.opengl.GL20
|
||||
@@ -30,10 +29,15 @@ object Toolkit : Disposable {
|
||||
|
||||
val baloonTile = TextureRegionPack("assets/graphics/gui/message_black_tileable.tga", 36, 36, flipY = true)
|
||||
|
||||
val textureWhiteSquare = Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga"))
|
||||
val textureWhiteCircle = Texture(Gdx.files.internal("assets/graphics/circle_512.tga"))
|
||||
|
||||
init {
|
||||
App.disposables.add(this)
|
||||
|
||||
textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
textureWhiteCircle.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
|
||||
|
||||
CommonResourcePool.addToLoadingList("toolkit_box_border") {
|
||||
TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/box_border_flat_tileable.tga"), 1, 1)
|
||||
}
|
||||
@@ -44,6 +48,8 @@ object Toolkit : Disposable {
|
||||
|
||||
override fun dispose() {
|
||||
baloonTile.dispose()
|
||||
textureWhiteSquare.dispose()
|
||||
textureWhiteCircle.dispose()
|
||||
}
|
||||
|
||||
val drawWidth: Int
|
||||
@@ -72,7 +78,19 @@ object Toolkit : Disposable {
|
||||
}
|
||||
|
||||
fun fillArea(batch: SpriteBatch, x: Int, y: Int, w: Int, h: Int) {
|
||||
batch.fillRect(x.toFloat(), y.toFloat(), w.toFloat(), h.toFloat())
|
||||
batch.draw(textureWhiteSquare, x.toFloat(), y.toFloat(), w.toFloat(), h.toFloat())
|
||||
}
|
||||
fun fillArea(batch: SpriteBatch, x: Float, y: Float, w: Float, h: Float) {
|
||||
batch.draw(textureWhiteSquare, x, y, w, h)
|
||||
}
|
||||
fun fillCircle(batch: SpriteBatch, x: Int, y: Int, w: Int, h: Int) {
|
||||
batch.draw(textureWhiteCircle, x.toFloat(), y.toFloat(), w.toFloat(), h.toFloat())
|
||||
}
|
||||
fun drawStraightLine(batch: SpriteBatch, x: Int, y: Int, otherEnd: Int, thickness: Int, isVertical: Boolean) {
|
||||
if (!isVertical)
|
||||
fillArea(batch, x, y, otherEnd - x, thickness)
|
||||
else
|
||||
fillArea(batch, x, y, thickness, otherEnd - y)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.fillRect
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-07-16.
|
||||
@@ -48,17 +47,17 @@ open class UIItemImageButton(
|
||||
if (highlighted) {
|
||||
BlendMode.resolve(highlightBackBlendMode, batch)
|
||||
batch.color = highlightBackCol
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
Toolkit.fillArea(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
}
|
||||
else if (mouseUp) {
|
||||
BlendMode.resolve(activeBackBlendMode, batch)
|
||||
batch.color = activeBackCol
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
Toolkit.fillArea(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
}
|
||||
else {
|
||||
batch.color = backgroundCol
|
||||
BlendMode.resolve(backgroundBlendMode, batch)
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
Toolkit.fillArea(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.fillRect
|
||||
|
||||
|
||||
/**
|
||||
@@ -107,12 +106,12 @@ class UIItemList<Item: UIItem>(
|
||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||
batch.color = backgroundCol
|
||||
BlendMode.resolve(backgroundBlendMode, batch)
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
Toolkit.fillArea(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
|
||||
batch.color = highlightBackCol
|
||||
BlendMode.resolve(highlightBackBlendMode, batch)
|
||||
if (highlightY != null) {
|
||||
batch.fillRect(posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), UIItemTextButton.height.toFloat())
|
||||
Toolkit.fillArea(batch, posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), UIItemTextButton.height.toFloat())
|
||||
}
|
||||
|
||||
itemList.forEach { it.render(batch, camera) }
|
||||
|
||||
@@ -84,17 +84,17 @@ open class UIItemTextButton(
|
||||
/*if (highlighted) {
|
||||
BlendMode.resolve(highlightBackBlendMode, batch)
|
||||
batch.color = highlightBackCol
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
Toolkit.fillArea(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
}
|
||||
else if (mouseUp) {
|
||||
BlendMode.resolve(activeBackBlendMode, batch)
|
||||
batch.color = activeBackCol
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
Toolkit.fillArea(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
}
|
||||
else {
|
||||
batch.color = backgroundCol
|
||||
BlendMode.resolve(backgroundBlendMode, batch)
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
Toolkit.fillArea(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
@@ -232,12 +232,12 @@ class UIItemTextButtonList(
|
||||
if (kinematic) {
|
||||
batch.color = backgroundCol
|
||||
BlendMode.resolve(backgroundBlendMode, batch)
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
Toolkit.fillArea(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
|
||||
batch.color = highlightBackCol
|
||||
BlendMode.resolve(highlightBackBlendMode, batch)
|
||||
if (highlightY != null) {
|
||||
batch.fillRect(posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), itemHitboxSize.toFloat())
|
||||
Toolkit.fillArea(batch, posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), itemHitboxSize.toFloat())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import java.awt.Color
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gamecontroller.IngameController
|
||||
|
||||
/**
|
||||
* @param width width of the text input where the text gets drawn, not the entire item
|
||||
@@ -19,7 +20,7 @@ class UIItemTextLineInput(
|
||||
parentUI: UICanvas,
|
||||
initialX: Int, initialY: Int,
|
||||
override val width: Int,
|
||||
override val height: Int,
|
||||
override val height: Int = 24,
|
||||
var placeholder: String? = null,
|
||||
val enablePasteButton: Boolean = true,
|
||||
val enableLanguageButton: Boolean = false
|
||||
@@ -28,33 +29,96 @@ class UIItemTextLineInput(
|
||||
companion object {
|
||||
val TEXTINPUT_COL_TEXT = Color.WHITE
|
||||
val TEXTINPUT_COL_GREY = Color.GRAY
|
||||
|
||||
val TEXTINPUT_COL_BACKGROUND = Color(0x28282888)
|
||||
const val CURSOR_BLINK_TIME = 1f / 3f
|
||||
}
|
||||
|
||||
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width, height, true)
|
||||
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 4, height - 4, true)
|
||||
|
||||
var isActive = true
|
||||
var isGreyedOut = false
|
||||
|
||||
val cursorX = 0
|
||||
var cursorX = 0 // 1 per code point
|
||||
var cursorDrawX = 0 // pixelwise point
|
||||
var cursorBlinkCounter = 0f
|
||||
var cursorOn = true
|
||||
|
||||
val keybuf = StringBuilder()
|
||||
|
||||
private var fboUpdateLatch = false
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
if (Terrarum.mouseDown) {
|
||||
isActive = mouseUp
|
||||
//isActive = mouseUp
|
||||
}
|
||||
|
||||
// process keypresses
|
||||
if (isActive) {
|
||||
IngameController.withKeyboardEvent { (_, char, _, keycodes) ->
|
||||
fboUpdateLatch = true
|
||||
|
||||
if (keycodes.contains(Input.Keys.BACKSPACE) && cursorX > 0) {
|
||||
cursorX -= 1
|
||||
val charLen = Character.charCount(keybuf.codePointAt(cursorX))
|
||||
keybuf.delete(keybuf.length - charLen, keybuf.length)
|
||||
cursorDrawX = App.fontGame.getWidth("$keybuf")
|
||||
}
|
||||
// accept:
|
||||
// - literal "<"
|
||||
// - keysymbol that does not start with "<" (not always has length of 1 because UTF-16)
|
||||
else if (char != null && char[0].code >= 32 && (char == "<" || !char.startsWith("<"))) {
|
||||
keybuf.append(char)
|
||||
cursorDrawX = App.fontGame.getWidth("$keybuf")
|
||||
cursorX += 1
|
||||
}
|
||||
}
|
||||
|
||||
cursorBlinkCounter += delta
|
||||
|
||||
while (cursorBlinkCounter >= CURSOR_BLINK_TIME) {
|
||||
cursorBlinkCounter -= CURSOR_BLINK_TIME
|
||||
cursorOn = !cursorOn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
batch.end()
|
||||
|
||||
if (fboUpdateLatch) {
|
||||
fboUpdateLatch = false
|
||||
fbo.inAction(camera as OrthographicCamera, batch) { batch.inUse {
|
||||
gdxClearAndSetBlend(0f, 0f, 0f, 0f)
|
||||
|
||||
it.color = Color.WHITE
|
||||
App.fontGame.draw(it, "$keybuf", 0f, 0f)
|
||||
} }
|
||||
}
|
||||
|
||||
batch.begin()
|
||||
|
||||
batch.color = TEXTINPUT_COL_BACKGROUND
|
||||
Toolkit.fillArea(batch, posX, posY, width, height)
|
||||
|
||||
batch.color = if (isActive) TEXTINPUT_COL_TEXT else TEXTINPUT_COL_GREY
|
||||
Toolkit.drawBoxBorder(batch, posX - 1, posY - 1, width + 2, height + 2)
|
||||
batch.draw(fbo.colorBufferTexture, posX + 2f, posY + 2f, fbo.width.toFloat(), fbo.height.toFloat())
|
||||
|
||||
if (cursorOn) {
|
||||
val oldBatchCol = batch.color.cpy()
|
||||
|
||||
batch.color = batch.color.mul(0.5f,0.5f,0.5f,1f)
|
||||
Toolkit.fillArea(batch, posX + cursorDrawX + 3, posY, 2, 24)
|
||||
|
||||
batch.color = oldBatchCol
|
||||
Toolkit.fillArea(batch, posX + cursorDrawX + 3, posY, 1, 23)
|
||||
}
|
||||
|
||||
|
||||
super.render(batch, camera)
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ class UINSMenu(
|
||||
// draw title bar
|
||||
batch.color = titleBackCol
|
||||
BlendMode.resolve(titleBlendMode, batch)
|
||||
batch.fillRect(it.ui.posX.toFloat(), it.ui.posY.toFloat() - LINE_HEIGHT, it.ui.width.toFloat(), LINE_HEIGHT.toFloat())
|
||||
Toolkit.fillArea(batch, it.ui.posX.toFloat(), it.ui.posY.toFloat() - LINE_HEIGHT, it.ui.width.toFloat(), LINE_HEIGHT.toFloat())
|
||||
|
||||
batch.color = titleTextCol
|
||||
blendNormal(batch)
|
||||
|
||||
Reference in New Issue
Block a user