diff --git a/src/net/torvald/terrarum/App.java b/src/net/torvald/terrarum/App.java
index 91c64feda..29339f7cf 100644
--- a/src/net/torvald/terrarum/App.java
+++ b/src/net/torvald/terrarum/App.java
@@ -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);
}
diff --git a/src/net/torvald/terrarum/GameCrashHandler.kt b/src/net/torvald/terrarum/GameCrashHandler.kt
index 7537280da..2a8b0d6c8 100644
--- a/src/net/torvald/terrarum/GameCrashHandler.kt
+++ b/src/net/torvald/terrarum/GameCrashHandler.kt
@@ -135,7 +135,13 @@ emph {
printStream.println("")
printStream.println("
OpenGL Info
")
- printStream.println("- ${Gdx.graphics.glVersion.debugVersionString.replace("\n","
- ")}
")
+
+ try {
+ printStream.println("- ${Gdx.graphics.glVersion.debugVersionString.replace("\n", "
- ")}
")
+ }
+ catch (e: NullPointerException) {
+ printStream.println("GL not initialised
")
+ }
printStream.println("Module Info
")
printStream.println("Load Order
")
diff --git a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt
index ae9314142..2d8e962e1 100644
--- a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt
+++ b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt
@@ -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
)
diff --git a/src/net/torvald/terrarum/UIItemInventoryElemWide.kt b/src/net/torvald/terrarum/UIItemInventoryElemWide.kt
index 5f582d2de..a04df6e66 100644
--- a/src/net/torvald/terrarum/UIItemInventoryElemWide.kt
+++ b/src/net/torvald/terrarum/UIItemInventoryElemWide.kt
@@ -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
)
diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt
index 6498c41a9..c0649b928 100644
--- a/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt
+++ b/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt
@@ -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!
}
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt
index 00277b09d..e5b4ab322 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt
@@ -37,9 +37,9 @@ class UIItemCraftingCandidateGrid(
internal val recipesSortList = ArrayList() // 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) {
diff --git a/src/net/torvald/terrarum/ui/UIItemSpinner.kt b/src/net/torvald/terrarum/ui/UIItemSpinner.kt
index 6487f22ea..bb9990915 100644
--- a/src/net/torvald/terrarum/ui/UIItemSpinner.kt
+++ b/src/net/torvald/terrarum/ui/UIItemSpinner.kt
@@ -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()
}
}