q&d fix for spinner initialise to blank label on crafting ui

This commit is contained in:
minjaesong
2022-06-29 02:53:17 +09:00
parent 9edfc90ad8
commit 068721376f
7 changed files with 65 additions and 37 deletions

View File

@@ -1226,6 +1226,13 @@ public class App implements ApplicationListener {
*/
public static int getConfigInt(String key) {
Object cfg = getConfigMaster(key);
if (cfg instanceof Integer) return ((int) cfg);
double value = (double) cfg;
if (Math.abs(value % 1.0) < 0.00000001)
return (int) Math.round(value);
return ((int) cfg);
}

View File

@@ -135,7 +135,13 @@ emph {
printStream.println("</ul>")
printStream.println("<h3>OpenGL Info</h3>")
printStream.println("<ul><li>${Gdx.graphics.glVersion.debugVersionString.replace("\n","</li><li>")}</li></ul>")
try {
printStream.println("<ul><li>${Gdx.graphics.glVersion.debugVersionString.replace("\n", "</li><li>")}</li></ul>")
}
catch (e: NullPointerException) {
printStream.println("<p><emph>GL not initialised</emph></p>")
}
printStream.println("<h3>Module Info</h3>")
printStream.println("<h4>Load Order</h4>")

View File

@@ -56,7 +56,7 @@ class UIItemInventoryElemSimple(
}
// cell border
batch.color = if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseUp) Toolkit.Theme.COL_ACTIVE
else if (mouseUp && item != null) Toolkit.Theme.COL_ACTIVE
else Toolkit.Theme.COL_INVENTORY_CELL_BORDER
Toolkit.drawBoxBorder(batch, posX, posY, width, height)
@@ -96,7 +96,7 @@ class UIItemInventoryElemSimple(
// highlight item count (blocks/walls) if the item is equipped
batch.color = item!!.nameColour mul (
if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseUp) Toolkit.Theme.COL_ACTIVE
else if (mouseUp && item != null) Toolkit.Theme.COL_ACTIVE
else Color.WHITE
)

View File

@@ -74,7 +74,7 @@ class UIItemInventoryElemWide(
}
// cell border
batch.color = if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseUp) Toolkit.Theme.COL_ACTIVE
else if (mouseUp && item != null) Toolkit.Theme.COL_ACTIVE
else Toolkit.Theme.COL_INVENTORY_CELL_BORDER
Toolkit.drawBoxBorder(batch, posX, posY, width, height)
@@ -92,7 +92,7 @@ class UIItemInventoryElemWide(
// highlight item name and count (blocks/walls) if the item is equipped
batch.color = item!!.nameColour mul (
if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseUp) Toolkit.Theme.COL_ACTIVE
else if (mouseUp && item != null) Toolkit.Theme.COL_ACTIVE
else Color.WHITE
)

View File

@@ -21,10 +21,7 @@ import net.torvald.terrarum.ui.UIItemTextButton
*
* Created by minjaesong on 2022-03-10.
*/
class UICrafting(val full: UIInventoryFull) : UICanvas(
toggleKeyLiteral = App.getConfigInt("control_key_inventory"),
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
), HasInventory {
class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
private val catBar: UIItemInventoryCatBar
get() = full.catBar
@@ -115,9 +112,9 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
}
itemListUpdate()*/
val playerInventory = getPlayerInventory()
(recipe0 as? CraftingCodex.CraftingRecipe)?.let { recipe ->
val playerInventory = getPlayerInventory()
ingredients.clear()
recipeClicked = recipe
// printdbg(this, "Recipe selected: $recipe")
@@ -137,17 +134,17 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
ingredients.add(ingredient.key, ingredient.qty)
}
}
}
itemListIngredients.rebuild(catAll)
highlightCraftingCandidateButton(button)
itemListIngredients.rebuild(catAll)
highlightCraftingCandidateButton(button)
}
}
)
buttonCraft = UIItemTextButton(this, "GAME_ACTION_CRAFT", thisOffsetX + 3 + buttonWidth + listGap, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
spinnerCraftCount = UIItemSpinner(this, thisOffsetX + 1, craftButtonsY, 1, 1, 100, 1, buttonWidth, numberToTextFunction = {"${it.toInt()}"})
spinnerCraftCount = UIItemSpinner(this, thisOffsetX + 1, craftButtonsY, 1, 1, 100, 1, buttonWidth, numberToTextFunction = {"×\u200A${it.toInt()}"})
buttonCraft.touchDownListener = { _,_,_,_ ->
printdbg(this, "Craft!")
printdbg(this, "Recipe to go: ${recipeClicked}")
}
// make grid mode buttons work together
// itemListCraftable.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
@@ -184,13 +181,20 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
addUIitem(buttonCraft)
}
private fun highlightCraftingCandidateButton(button: UIItemInventoryCellBase) { // a proxy function
private fun highlightCraftingCandidateButton(button: UIItemInventoryCellBase?) { // a proxy function
itemListCraftable.highlightButton(button)
}
// reset whatever player has selected to null and bring UI to its initial state
fun resetUI() {
// reset spinner
spinnerCraftCount.value = 1
spinnerCraftCount.fboUpdateLatch = true
// reset selected recipe status
recipeClicked = null
highlightCraftingCandidateButton(null)
ingredients.clear()
itemListIngredients.rebuild(catAll)
}
private var openingClickLatched = false
@@ -201,8 +205,14 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
openingClickLatched = Terrarum.mouseDown
spinnerCraftCount.value = 1
// reset spinner
/*spinnerCraftCount.value = 1
spinnerCraftCount.fboUpdateLatch = true
// reset selected recipe status
recipeClicked = null
highlightCraftingCandidateButton(null)
ingredients.clear()
itemListIngredients.rebuild(catAll)*/
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null)
@@ -319,23 +329,22 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
}
override fun doOpening(delta: Float) {
// INGAME.pause()
resetUI()
INGAME.setTooltipMessage(null)
}
override fun doClosing(delta: Float) {
// INGAME.resume()
INGAME.setTooltipMessage(null)
}
override fun endOpening(delta: Float) {
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null) // required!
}
override fun endClosing(delta: Float) {
spinnerCraftCount.value = 1 // hide() is required as show() is not called unless the parent's panel number has changed (?)
spinnerCraftCount.fboUpdateLatch = true
resetUI()
UIItemInventoryItemGrid.tooltipShowing.clear()
INGAME.setTooltipMessage(null) // required!
}

View File

@@ -37,9 +37,9 @@ class UIItemCraftingCandidateGrid(
internal val recipesSortList = ArrayList<CraftingCodex.CraftingRecipe>() // a dual to the [inventorySortList] which contains the actual recipes instead of crafting recipes
fun highlightButton(button: UIItemInventoryCellBase) {
fun highlightButton(button: UIItemInventoryCellBase?) {
items.forEach { it.forceHighlighted = false }
button.forceHighlighted = true
button?.forceHighlighted = true
}
override fun rebuild(filter: Array<String>) {

View File

@@ -1,12 +1,10 @@
package net.torvald.terrarum.ui
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.*
import net.torvald.terrarum.App
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.Terrarum
/**
* Created by minjaesong on 2021-10-23.
@@ -32,7 +30,9 @@ class UIItemSpinner(
override val height = 24
private val buttonW = 30
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, false)
private val fboWidth = width - 2*buttonW - 6
private val fboHeight = height - 4
// private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, false)
var value = initialValue.toDouble().coerceIn(min.toDouble(), max.toDouble()) as Number
var fboUpdateLatch = true
@@ -63,20 +63,26 @@ class UIItemSpinner(
else if (!Terrarum.mouseDown) mouseLatched = false
}
private var textCache = ""
private var textCacheLen = 0
override fun render(batch: SpriteBatch, camera: Camera) {
batch.end()
if (fboUpdateLatch) {
// printdbg(this, "FBO Latched")
fboUpdateLatch = false
fbo.inAction(camera as OrthographicCamera, batch) { batch.inUse {
textCache = numberToTextFunction(value)
textCacheLen = App.fontGame.getWidth(textCache)
/*fbo.inAction(camera as OrthographicCamera, batch) { batch.inUse {
gdxClearAndSetBlend(0f, 0f, 0f, 0f)
it.color = Color.WHITE
val t = numberToTextFunction(value)
val tw = App.fontGame.getWidth(t)
App.fontGameFBO.draw(it, t, (fbo.width - tw) / 2, 0)
} }
} }*/
}
batch.begin()
@@ -125,8 +131,8 @@ class UIItemSpinner(
// draw text
batch.color = UIItemTextLineInput.TEXTINPUT_COL_TEXT
batch.draw(fbo.colorBufferTexture, posX + buttonW + 3f, posY + 2f, fbo.width.toFloat(), fbo.height.toFloat())
// batch.draw(fbo.colorBufferTexture, posX + buttonW + 3f, posY + 2f, fbo.width.toFloat(), fbo.height.toFloat())
App.fontGame.draw(batch, textCache, posX + buttonW + 3f + (fboWidth - textCacheLen).div(2), posY + 2f)
super.render(batch, camera)
}
@@ -148,6 +154,6 @@ class UIItemSpinner(
}
override fun dispose() {
fbo.dispose()
// fbo.dispose()
}
}