mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
q&d fix for spinner initialise to blank label on crafting ui
This commit is contained in:
@@ -1226,6 +1226,13 @@ public class App implements ApplicationListener {
|
|||||||
*/
|
*/
|
||||||
public static int getConfigInt(String key) {
|
public static int getConfigInt(String key) {
|
||||||
Object cfg = getConfigMaster(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);
|
return ((int) cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,13 @@ emph {
|
|||||||
printStream.println("</ul>")
|
printStream.println("</ul>")
|
||||||
|
|
||||||
printStream.println("<h3>OpenGL Info</h3>")
|
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("<h3>Module Info</h3>")
|
||||||
printStream.println("<h4>Load Order</h4>")
|
printStream.println("<h4>Load Order</h4>")
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class UIItemInventoryElemSimple(
|
|||||||
}
|
}
|
||||||
// cell border
|
// cell border
|
||||||
batch.color = if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
|
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
|
else Toolkit.Theme.COL_INVENTORY_CELL_BORDER
|
||||||
Toolkit.drawBoxBorder(batch, posX, posY, width, height)
|
Toolkit.drawBoxBorder(batch, posX, posY, width, height)
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ class UIItemInventoryElemSimple(
|
|||||||
// highlight item count (blocks/walls) if the item is equipped
|
// highlight item count (blocks/walls) if the item is equipped
|
||||||
batch.color = item!!.nameColour mul (
|
batch.color = item!!.nameColour mul (
|
||||||
if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
|
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
|
else Color.WHITE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class UIItemInventoryElemWide(
|
|||||||
}
|
}
|
||||||
// cell border
|
// cell border
|
||||||
batch.color = if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
|
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
|
else Toolkit.Theme.COL_INVENTORY_CELL_BORDER
|
||||||
Toolkit.drawBoxBorder(batch, posX, posY, width, height)
|
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
|
// highlight item name and count (blocks/walls) if the item is equipped
|
||||||
batch.color = item!!.nameColour mul (
|
batch.color = item!!.nameColour mul (
|
||||||
if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
|
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
|
else Color.WHITE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,7 @@ import net.torvald.terrarum.ui.UIItemTextButton
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2022-03-10.
|
* Created by minjaesong on 2022-03-10.
|
||||||
*/
|
*/
|
||||||
class UICrafting(val full: UIInventoryFull) : UICanvas(
|
class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||||
toggleKeyLiteral = App.getConfigInt("control_key_inventory"),
|
|
||||||
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
|
|
||||||
), HasInventory {
|
|
||||||
|
|
||||||
private val catBar: UIItemInventoryCatBar
|
private val catBar: UIItemInventoryCatBar
|
||||||
get() = full.catBar
|
get() = full.catBar
|
||||||
@@ -115,9 +112,9 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
|||||||
}
|
}
|
||||||
itemListUpdate()*/
|
itemListUpdate()*/
|
||||||
|
|
||||||
val playerInventory = getPlayerInventory()
|
|
||||||
|
|
||||||
(recipe0 as? CraftingCodex.CraftingRecipe)?.let { recipe ->
|
(recipe0 as? CraftingCodex.CraftingRecipe)?.let { recipe ->
|
||||||
|
val playerInventory = getPlayerInventory()
|
||||||
ingredients.clear()
|
ingredients.clear()
|
||||||
recipeClicked = recipe
|
recipeClicked = recipe
|
||||||
// printdbg(this, "Recipe selected: $recipe")
|
// printdbg(this, "Recipe selected: $recipe")
|
||||||
@@ -137,17 +134,17 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
|||||||
ingredients.add(ingredient.key, ingredient.qty)
|
ingredients.add(ingredient.key, ingredient.qty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
itemListIngredients.rebuild(catAll)
|
itemListIngredients.rebuild(catAll)
|
||||||
highlightCraftingCandidateButton(button)
|
highlightCraftingCandidateButton(button)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
buttonCraft = UIItemTextButton(this, "GAME_ACTION_CRAFT", thisOffsetX + 3 + buttonWidth + listGap, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
|
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 = { _,_,_,_ ->
|
buttonCraft.touchDownListener = { _,_,_,_ ->
|
||||||
printdbg(this, "Craft!")
|
printdbg(this, "Recipe to go: ${recipeClicked}")
|
||||||
}
|
}
|
||||||
// make grid mode buttons work together
|
// make grid mode buttons work together
|
||||||
// itemListCraftable.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
|
// itemListCraftable.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
|
||||||
@@ -184,13 +181,20 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
|||||||
addUIitem(buttonCraft)
|
addUIitem(buttonCraft)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun highlightCraftingCandidateButton(button: UIItemInventoryCellBase) { // a proxy function
|
private fun highlightCraftingCandidateButton(button: UIItemInventoryCellBase?) { // a proxy function
|
||||||
itemListCraftable.highlightButton(button)
|
itemListCraftable.highlightButton(button)
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset whatever player has selected to null and bring UI to its initial state
|
// reset whatever player has selected to null and bring UI to its initial state
|
||||||
fun resetUI() {
|
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
|
private var openingClickLatched = false
|
||||||
@@ -201,8 +205,14 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
|||||||
|
|
||||||
openingClickLatched = Terrarum.mouseDown
|
openingClickLatched = Terrarum.mouseDown
|
||||||
|
|
||||||
spinnerCraftCount.value = 1
|
// reset spinner
|
||||||
|
/*spinnerCraftCount.value = 1
|
||||||
spinnerCraftCount.fboUpdateLatch = true
|
spinnerCraftCount.fboUpdateLatch = true
|
||||||
|
// reset selected recipe status
|
||||||
|
recipeClicked = null
|
||||||
|
highlightCraftingCandidateButton(null)
|
||||||
|
ingredients.clear()
|
||||||
|
itemListIngredients.rebuild(catAll)*/
|
||||||
|
|
||||||
UIItemInventoryItemGrid.tooltipShowing.clear()
|
UIItemInventoryItemGrid.tooltipShowing.clear()
|
||||||
INGAME.setTooltipMessage(null)
|
INGAME.setTooltipMessage(null)
|
||||||
@@ -319,23 +329,22 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun doOpening(delta: Float) {
|
override fun doOpening(delta: Float) {
|
||||||
// INGAME.pause()
|
resetUI()
|
||||||
|
|
||||||
INGAME.setTooltipMessage(null)
|
INGAME.setTooltipMessage(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doClosing(delta: Float) {
|
override fun doClosing(delta: Float) {
|
||||||
// INGAME.resume()
|
|
||||||
INGAME.setTooltipMessage(null)
|
INGAME.setTooltipMessage(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endOpening(delta: Float) {
|
override fun endOpening(delta: Float) {
|
||||||
|
UIItemInventoryItemGrid.tooltipShowing.clear()
|
||||||
|
INGAME.setTooltipMessage(null) // required!
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endClosing(delta: Float) {
|
override fun endClosing(delta: Float) {
|
||||||
|
resetUI()
|
||||||
spinnerCraftCount.value = 1 // hide() is required as show() is not called unless the parent's panel number has changed (?)
|
|
||||||
spinnerCraftCount.fboUpdateLatch = true
|
|
||||||
|
|
||||||
UIItemInventoryItemGrid.tooltipShowing.clear()
|
UIItemInventoryItemGrid.tooltipShowing.clear()
|
||||||
INGAME.setTooltipMessage(null) // required!
|
INGAME.setTooltipMessage(null) // required!
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
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 }
|
items.forEach { it.forceHighlighted = false }
|
||||||
button.forceHighlighted = true
|
button?.forceHighlighted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun rebuild(filter: Array<String>) {
|
override fun rebuild(filter: Array<String>) {
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package net.torvald.terrarum.ui
|
package net.torvald.terrarum.ui
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Camera
|
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.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
import net.torvald.terrarum.App
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
|
import net.torvald.terrarum.Terrarum
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2021-10-23.
|
* Created by minjaesong on 2021-10-23.
|
||||||
@@ -32,7 +30,9 @@ class UIItemSpinner(
|
|||||||
override val height = 24
|
override val height = 24
|
||||||
private val buttonW = 30
|
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 value = initialValue.toDouble().coerceIn(min.toDouble(), max.toDouble()) as Number
|
||||||
var fboUpdateLatch = true
|
var fboUpdateLatch = true
|
||||||
@@ -63,20 +63,26 @@ class UIItemSpinner(
|
|||||||
else if (!Terrarum.mouseDown) mouseLatched = false
|
else if (!Terrarum.mouseDown) mouseLatched = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var textCache = ""
|
||||||
|
private var textCacheLen = 0
|
||||||
|
|
||||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||||
|
|
||||||
batch.end()
|
batch.end()
|
||||||
|
|
||||||
if (fboUpdateLatch) {
|
if (fboUpdateLatch) {
|
||||||
|
// printdbg(this, "FBO Latched")
|
||||||
fboUpdateLatch = false
|
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)
|
gdxClearAndSetBlend(0f, 0f, 0f, 0f)
|
||||||
|
|
||||||
it.color = Color.WHITE
|
it.color = Color.WHITE
|
||||||
val t = numberToTextFunction(value)
|
val t = numberToTextFunction(value)
|
||||||
val tw = App.fontGame.getWidth(t)
|
val tw = App.fontGame.getWidth(t)
|
||||||
App.fontGameFBO.draw(it, t, (fbo.width - tw) / 2, 0)
|
App.fontGameFBO.draw(it, t, (fbo.width - tw) / 2, 0)
|
||||||
} }
|
} }*/
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.begin()
|
batch.begin()
|
||||||
@@ -125,8 +131,8 @@ class UIItemSpinner(
|
|||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
batch.color = UIItemTextLineInput.TEXTINPUT_COL_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)
|
super.render(batch, camera)
|
||||||
}
|
}
|
||||||
@@ -148,6 +154,6 @@ class UIItemSpinner(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
fbo.dispose()
|
// fbo.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user