y u wont render :(

This commit is contained in:
minjaesong
2021-12-04 17:50:31 +09:00
parent c0b2f4c8df
commit 43ed388615
4 changed files with 40 additions and 33 deletions

View File

@@ -2,10 +2,10 @@ package net.torvald.terrarum.modulecomputers.gameactors
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.badlogic.gdx.math.Matrix4
import com.badlogic.gdx.utils.Disposable import com.badlogic.gdx.utils.Disposable
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@@ -92,42 +92,48 @@ internal class UIHomeComputer : UICanvas(
private val drawOffX = (width - 560).div(2).toFloat() private val drawOffX = (width - 560).div(2).toFloat()
private val drawOffY = (height - 448).div(2).toFloat() private val drawOffY = (height - 448).div(2).toFloat()
private lateinit var batch: SpriteBatch private var batch: SpriteBatch
private lateinit var camera: OrthographicCamera private var camera: OrthographicCamera
internal lateinit var vm: VM internal lateinit var vm: VM
init { init {
batch = SpriteBatch() batch = SpriteBatch()
camera = OrthographicCamera(width.toFloat(), height.toFloat()) camera = OrthographicCamera(560f, 448f)
camera.setToOrtho(false) //val m = Matrix4()
camera.update() //m.setToOrtho2D(0f, 0f, width.toFloat(), height.toFloat())
batch.projectionMatrix = camera.combined batch.projectionMatrix = camera.combined
} }
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, 560, 448, true)
override fun updateUI(delta: Float) { override fun updateUI(delta: Float) {
} }
override fun renderUI(otherBatch: SpriteBatch, camera: Camera) { override fun renderUI(otherBatch: SpriteBatch, otherCamera: Camera) {
otherBatch.end() otherBatch.end()
setCameraPosition(0f, 0f) fbo.inAction(otherCamera as OrthographicCamera, otherBatch) {
(vm.peripheralTable[1].peripheral as? GraphicsAdapter)?.let { gpu -> (vm.peripheralTable[1].peripheral as? GraphicsAdapter)?.let { gpu ->
val clearCol = gpu.getBackgroundColour() val clearCol = gpu.getBackgroundColour()
Gdx.gl.glClearColor(clearCol.r, clearCol.g, clearCol.b, clearCol.a) Gdx.gl.glClearColor(0f,0f,0f,0f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) //Gdx.gl.glClearColor(clearCol.r, clearCol.g, clearCol.b, clearCol.a)
gpu.render(Gdx.graphics.deltaTime, batch, posX + drawOffX, posY + drawOffY) //Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
gpu.render(Gdx.graphics.deltaTime, otherBatch, 0f, 0f, true)
}
} }
otherBatch.begin() otherBatch.begin()
otherBatch.color = Color.WHITE
otherBatch.draw(fbo.colorBufferTexture, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
otherBatch.color = Toolkit.Theme.COL_INACTIVE otherBatch.color = Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(otherBatch, posX - 1, posY - 1, width + 2, height + 2) Toolkit.drawBoxBorder(otherBatch, posX - 1, posY - 1, width + 2, height + 2)
} }
private fun setCameraPosition(newX: Float, newY: Float) { private fun setCameraPosition(newX: Float, newY: Float) {
camera.position.set((-newX + width / 2), (-newY + height / 2), 0f) // deliberate integer division // camera.position.set((-newX + width / 2), (-newY + height / 2), 0f) // deliberate integer division
camera.update() // camera.update()
batch.projectionMatrix = camera.combined // batch.projectionMatrix = camera.combined
} }
override fun doOpening(delta: Float) { override fun doOpening(delta: Float) {
@@ -143,6 +149,7 @@ internal class UIHomeComputer : UICanvas(
} }
override fun dispose() { override fun dispose() {
fbo.dispose()
} }
} }

View File

@@ -241,10 +241,7 @@ class UIItemTextLineInput(
if (!maxLen.exceeds(textbuf, codepoints)) { if (!maxLen.exceeds(textbuf, codepoints)) {
textbuf.addAll(cursorX, codepoints) textbuf.addAll(cursorX, codepoints)
cursorX += codepoints.size moveCursorToEnd(codepoints.size)
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
tryCursorBack()
} }
} }
} }
@@ -320,10 +317,7 @@ class UIItemTextLineInput(
if (!maxLen.exceeds(textbuf, codepoints)) { if (!maxLen.exceeds(textbuf, codepoints)) {
textbuf.addAll(cursorX, codepoints) textbuf.addAll(cursorX, codepoints)
cursorX += codepoints.size moveCursorToEnd(codepoints.size)
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
tryCursorBack()
} }
} }
else if (keycodes.containsSome(Input.Keys.ENTER, Input.Keys.NUMPAD_ENTER)) { else if (keycodes.containsSome(Input.Keys.ENTER, Input.Keys.NUMPAD_ENTER)) {
@@ -423,10 +417,7 @@ class UIItemTextLineInput(
actuallyInserted.removeAt(0) actuallyInserted.removeAt(0)
textbuf.addAll(cursorX, actuallyInserted) moveCursorToEnd(actuallyInserted.size)
cursorX += actuallyInserted.size
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
tryCursorBack() tryCursorBack()
@@ -441,6 +432,13 @@ class UIItemTextLineInput(
return textbuf.toJavaString() return textbuf.toJavaString()
} }
private fun moveCursorToEnd(stride: Int) {
cursorX += stride
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
tryCursorBack()
}
override fun render(batch: SpriteBatch, camera: Camera) { override fun render(batch: SpriteBatch, camera: Camera) {
val ime = getIME(true) val ime = getIME(true)
@@ -609,10 +607,12 @@ class UIItemTextLineInput(
} }
fun setText(s: String) { fun setText(s: String) {
clearText() clearText()
textbuf.addAll(s.toCodePoints()) appendText(s)
} }
fun appendText(s: String) { fun appendText(s: String) {
textbuf.addAll(s.toCodePoints()) val c = s.toCodePoints()
textbuf.addAll(c)
moveCursorToEnd(c.size)
} }
override fun dispose() { override fun dispose() {
fbo.dispose() fbo.dispose()