mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 10:04:05 +09:00
fix: reopening crafting would reset the visible mult to 1 but internally wouldn't
This commit is contained in:
@@ -391,8 +391,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun resetSpinner(value: Long = 1L) {
|
private fun resetSpinner(value: Long = 1L) {
|
||||||
spinnerCraftCount.value = value
|
spinnerCraftCount.resetToSmallest()
|
||||||
spinnerCraftCount.fboUpdateLatch = true
|
|
||||||
itemListIngredients.numberMultiplier = value
|
itemListIngredients.numberMultiplier = value
|
||||||
itemListCraftable.numberMultiplier = value
|
itemListCraftable.numberMultiplier = value
|
||||||
}
|
}
|
||||||
@@ -541,7 +540,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
|||||||
* For each ingredient of the recipe, returns list of (ingredient, how many the player has the ingredient, how many the recipe wants)
|
* For each ingredient of the recipe, returns list of (ingredient, how many the player has the ingredient, how many the recipe wants)
|
||||||
*/
|
*/
|
||||||
fun recipeToIngredientRecord(inventory: FixtureInventory, recipe: CraftingCodex.CraftingRecipe, nearbyCraftingStations: List<String>): List<RecipeIngredientRecord> {
|
fun recipeToIngredientRecord(inventory: FixtureInventory, recipe: CraftingCodex.CraftingRecipe, nearbyCraftingStations: List<String>): List<RecipeIngredientRecord> {
|
||||||
val hasStation = if (recipe.workbench.isEmpty()) true else nearbyCraftingStations.contains(recipe.workbench)
|
val hasStation = if (recipe.workbench.isBlank()) true else nearbyCraftingStations.contains(recipe.workbench)
|
||||||
return recipe.ingredients.map { ingredient ->
|
return recipe.ingredients.map { ingredient ->
|
||||||
val selectedItem = if (ingredient.keyMode == CraftingCodex.CraftingItemKeyMode.TAG) {
|
val selectedItem = if (ingredient.keyMode == CraftingCodex.CraftingItemKeyMode.TAG) {
|
||||||
// If the player has the required item, use it; otherwise, will take an item from the ItemCodex
|
// If the player has the required item, use it; otherwise, will take an item from the ItemCodex
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package net.torvald.terrarum.ui
|
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.OrthographicCamera
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
@@ -9,7 +7,6 @@ import net.torvald.terrarum.CommonResourcePool
|
|||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.ceilToInt
|
import net.torvald.terrarum.ceilToInt
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal properties, namely initialValue, min, max, step; have the type of [Double] regardless of their input type.
|
* Internal properties, namely initialValue, min, max, step; have the type of [Double] regardless of their input type.
|
||||||
@@ -38,6 +35,29 @@ class UIItemSpinner(
|
|||||||
init {
|
init {
|
||||||
// println("valueType=${valueType.canonicalName} for UI ${parentUI.javaClass.canonicalName}")
|
// println("valueType=${valueType.canonicalName} for UI ${parentUI.javaClass.canonicalName}")
|
||||||
|
|
||||||
|
resetToInitial()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val valueType = initialValue.javaClass // should be java.lang.Double or java.lang.Integer
|
||||||
|
|
||||||
|
private val labels = CommonResourcePool.getAsTextureRegionPack("inventory_category")
|
||||||
|
|
||||||
|
override val height = 24
|
||||||
|
private val buttonW = 30
|
||||||
|
|
||||||
|
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; private set
|
||||||
|
var fboUpdateLatch = true
|
||||||
|
|
||||||
|
private var mouseOnButton = 0 // 0: nothing, 1: left, 2: right
|
||||||
|
|
||||||
|
var selectionChangeListener: (Number) -> Unit = {}
|
||||||
|
private var currentIndex = values.indexOfFirst { it == initialValue.toDouble() }
|
||||||
|
|
||||||
|
fun resetToInitial() {
|
||||||
// if the initial value cannot be derived from the settings, round to nearest
|
// if the initial value cannot be derived from the settings, round to nearest
|
||||||
if (values.indexOfFirst { it == initialValue.toDouble() } < 0) {
|
if (values.indexOfFirst { it == initialValue.toDouble() } < 0) {
|
||||||
// throw IllegalArgumentException("Initial value $initialValue cannot be derived from given ($min..$max step $step) settings")
|
// throw IllegalArgumentException("Initial value $initialValue cannot be derived from given ($min..$max step $step) settings")
|
||||||
@@ -54,27 +74,14 @@ class UIItemSpinner(
|
|||||||
else -> intermediate
|
else -> intermediate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fboUpdateLatch = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private val valueType = initialValue.javaClass // should be java.lang.Double or java.lang.Integer
|
fun resetToSmallest() {
|
||||||
|
currentIndex = 0
|
||||||
private val labels = CommonResourcePool.getAsTextureRegionPack("inventory_category")
|
value = values[currentIndex]
|
||||||
|
fboUpdateLatch = true
|
||||||
override val height = 24
|
}
|
||||||
private val buttonW = 30
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
private var mouseOnButton = 0 // 0: nothing, 1: left, 2: right
|
|
||||||
|
|
||||||
var selectionChangeListener: (Number) -> Unit = {}
|
|
||||||
private var currentIndex = values.indexOfFirst { it == initialValue.toDouble() }
|
|
||||||
|
|
||||||
|
|
||||||
private fun changeValueBy(diff: Int) {
|
private fun changeValueBy(diff: Int) {
|
||||||
currentIndex = (currentIndex + diff).coerceIn(values.indices)
|
currentIndex = (currentIndex + diff).coerceIn(values.indices)
|
||||||
|
|||||||
Reference in New Issue
Block a user