sign engraver wip 3

This commit is contained in:
minjaesong
2024-03-22 21:15:39 +09:00
parent 8e1c586a5c
commit 4d1ea45a0f
4 changed files with 25 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ class MakeSign : ConsoleCommand {
}
val text = args[1]
val textLen = App.fontGame.getWidth(text)
val textLen = App.fontGame.getWidth(text) + 4
val panelCount = (args.getOrNull(2)?.toInt() ?: (textLen / TILE_SIZEF).ceilToInt()).coerceAtLeast(2)
val actorInventory = INGAME.actorNowPlaying!!.inventory

View File

@@ -173,7 +173,7 @@ class FixtureTextSignCopper : Electric {
batch.inUse { _ ->
blendNormalStraightAlpha(batch)
val tw = App.fontGame.getWidth(text)
App.fontGame.draw(batch, text, 0 + (it.width - tw) / 2, 3)
App.fontGame.draw(batch, text, 1 + (it.width - tw) / 2, 3)
blendAlphaMask(batch)

View File

@@ -58,7 +58,17 @@ class UIEngravingTextSign : UICanvas(
private val ingredientsWidth = UIItemInventoryElemSimple.height * 3 + 16
private val inputX = drawX + internalWidth - inputWidth + 5
private val textInput = UIItemTextLineInput(this, inputX, row0, inputWidth)
private val textInput = UIItemTextLineInput(this, inputX, row0, inputWidth).also {
it.textCommitListener = { text ->
val textLen = App.fontGame.getWidth(text) + 4
val panelCountMin = (textLen / TILE_SIZEF).ceilToInt()
updateMinimumLen(panelCountMin)
panelCount = panelCountSpinner.value.toInt()
updatePanelText(text, panelCount)
}
}
private val COPPER_BULB = "item@basegame:35"
private val ROCK_TILE = Block.STONE_TILE_WHITE
@@ -71,6 +81,13 @@ class UIEngravingTextSign : UICanvas(
private var fboBatch = SpriteBatch()
private var fboCamera = OrthographicCamera(1f, 1f)
private fun updateMinimumLen(mlen0: Int) {
val mlen = mlen0.coerceAtLeast(2).toDouble()
val delta = maxOf(panelCount.toDouble(), mlen) - panelCount.toDouble()
panelCountSpinner.changeValueBy(delta.toInt())
setIngredient(panelCountSpinner.value.toInt())
}
private fun updatePanelText(text: String, panelCount: Int) {
fboText.dispose()
fboText = FrameBuffer(Pixmap.Format.RGBA8888, panelCount*TILE_SIZE, 2*TILE_SIZE, false)
@@ -105,7 +122,7 @@ class UIEngravingTextSign : UICanvas(
}
// text
batch.draw(fboText.colorBufferTexture, xStart, yStart, fboText.width * panelZoom, fboText.height * panelZoom)
batch.draw(fboText.colorBufferTexture, xStart + panelZoom, yStart, fboText.width * panelZoom, fboText.height * panelZoom)
}
private fun setIngredient(num: Int) {
@@ -187,7 +204,6 @@ class UIEngravingTextSign : UICanvas(
private var panelCount = panelCountSpinner.value.toInt()
override fun updateImpl(delta: Float) {
panelCount = panelCountSpinner.value.toInt()
updatePanelText("Hello, world!", panelCount)
uiItems.forEach { it.update(delta) }
}

View File

@@ -18,9 +18,9 @@ class UIItemSpinner(
parentUI: UICanvas,
initialX: Int, initialY: Int,
private var initialValue: Number,
val min: Number,
val max: Number,
val step: Number,
var min: Number,
var max: Number,
var step: Number,
override val width: Int,
private val drawBorder: Boolean = true,
private val numberToTextFunction: (Number) -> String = { "$it" }
@@ -86,6 +86,7 @@ class UIItemSpinner(
fun changeValueBy(diff: Int) {
currentIndex = (currentIndex + diff).coerceIn(values.indices)
value = values[currentIndex]
fboUpdateLatch = true
}
override fun update(delta: Float) {