mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
smelter gui behav is now a factory
This commit is contained in:
@@ -336,6 +336,11 @@ class InventoryPair : Comparable<InventoryPair> {
|
|||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return if (qty == -1L) "$itm" else "$itm ($qty)"
|
return if (qty == -1L) "$itm" else "$itm ($qty)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun set(itm: ItemID, qty: Long) {
|
||||||
|
this.itm = itm
|
||||||
|
this.qty = qty
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class InventoryTransactionFailedError(msg: String) : Error(msg)
|
class InventoryTransactionFailedError(msg: String) : Error(msg)
|
||||||
@@ -18,6 +18,7 @@ import net.torvald.terrarum.gameactors.AVKey
|
|||||||
import net.torvald.terrarum.gameactors.Hitbox
|
import net.torvald.terrarum.gameactors.Hitbox
|
||||||
import net.torvald.terrarum.gameactors.Lightbox
|
import net.torvald.terrarum.gameactors.Lightbox
|
||||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||||
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
import net.torvald.terrarum.gameparticles.ParticleVanishingSprite
|
import net.torvald.terrarum.gameparticles.ParticleVanishingSprite
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
@@ -25,8 +26,20 @@ import net.torvald.terrarum.modulebasegame.ui.UISmelterBasic
|
|||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No GUI yet!
|
* Created by minjaesong on 2024-03-09.
|
||||||
*
|
*/
|
||||||
|
interface SmelterItemStatus {
|
||||||
|
fun set(itm: ItemID, qty: Long)
|
||||||
|
fun changeCount(delta: Long)
|
||||||
|
fun nullify()
|
||||||
|
fun isNull(): Boolean
|
||||||
|
fun isNotNull(): Boolean = !isNull()
|
||||||
|
val itm: ItemID?
|
||||||
|
val qty: Long?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
* Created by minjaesong on 2023-12-04.
|
* Created by minjaesong on 2023-12-04.
|
||||||
*/
|
*/
|
||||||
class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
||||||
@@ -36,9 +49,76 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
|||||||
var temperature = 0f // 0f..1f
|
var temperature = 0f // 0f..1f
|
||||||
var progress = 0f // 0f..1f
|
var progress = 0f // 0f..1f
|
||||||
|
|
||||||
var oreItem: InventoryPair? = null
|
internal var oreItem: InventoryPair? = null
|
||||||
var fireboxItem: InventoryPair? = null
|
internal var fireboxItem: InventoryPair? = null
|
||||||
var productItem: InventoryPair? = null
|
internal var productItem: InventoryPair? = null
|
||||||
|
|
||||||
|
@Transient val oreItemStatus = object : SmelterItemStatus {
|
||||||
|
override fun set(itm: ItemID, qty: Long) {
|
||||||
|
if (oreItem != null) oreItem!!.set(itm, qty)
|
||||||
|
else oreItem = InventoryPair(itm, qty)
|
||||||
|
}
|
||||||
|
override fun changeCount(delta: Long) {
|
||||||
|
oreItem!!.qty += delta
|
||||||
|
if (oreItem!!.qty <= 0L) {
|
||||||
|
oreItem = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override fun nullify() {
|
||||||
|
oreItem = null
|
||||||
|
}
|
||||||
|
override fun isNull(): Boolean {
|
||||||
|
return oreItem == null
|
||||||
|
}
|
||||||
|
override val itm: ItemID?
|
||||||
|
get() = oreItem?.itm
|
||||||
|
override val qty: Long?
|
||||||
|
get() = oreItem?.qty
|
||||||
|
}
|
||||||
|
@Transient val fireboxItemStatus = object : SmelterItemStatus {
|
||||||
|
override fun set(itm: ItemID, qty: Long) {
|
||||||
|
if (fireboxItem != null) fireboxItem!!.set(itm, qty)
|
||||||
|
else fireboxItem = InventoryPair(itm, qty)
|
||||||
|
}
|
||||||
|
override fun changeCount(delta: Long) {
|
||||||
|
fireboxItem!!.qty += delta
|
||||||
|
if (fireboxItem!!.qty <= 0L) {
|
||||||
|
fireboxItem = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override fun nullify() {
|
||||||
|
fireboxItem = null
|
||||||
|
}
|
||||||
|
override fun isNull(): Boolean {
|
||||||
|
return fireboxItem == null
|
||||||
|
}
|
||||||
|
override val itm: ItemID?
|
||||||
|
get() = fireboxItem?.itm
|
||||||
|
override val qty: Long?
|
||||||
|
get() = fireboxItem?.qty
|
||||||
|
}
|
||||||
|
@Transient val productItemStatus = object : SmelterItemStatus {
|
||||||
|
override fun set(itm: ItemID, qty: Long) {
|
||||||
|
if (productItem != null) productItem!!.set(itm, qty)
|
||||||
|
else productItem = InventoryPair(itm, qty)
|
||||||
|
}
|
||||||
|
override fun changeCount(delta: Long) {
|
||||||
|
productItem!!.qty += delta
|
||||||
|
if (productItem!!.qty <= 0L) {
|
||||||
|
productItem = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override fun nullify() {
|
||||||
|
productItem = null
|
||||||
|
}
|
||||||
|
override fun isNull(): Boolean {
|
||||||
|
return productItem == null
|
||||||
|
}
|
||||||
|
override val itm: ItemID?
|
||||||
|
get() = productItem?.itm
|
||||||
|
override val qty: Long?
|
||||||
|
get() = productItem?.qty
|
||||||
|
}
|
||||||
|
|
||||||
override val canBeDespawned: Boolean
|
override val canBeDespawned: Boolean
|
||||||
get() = oreItem == null && fireboxItem == null && productItem == null
|
get() = oreItem == null && fireboxItem == null && productItem == null
|
||||||
@@ -112,27 +192,6 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
|||||||
|
|
||||||
@Transient private val RNG = HQRNG()
|
@Transient private val RNG = HQRNG()
|
||||||
|
|
||||||
fun changeFireboxItemCount(delta: Long) {
|
|
||||||
fireboxItem!!.qty += delta
|
|
||||||
if (fireboxItem!!.qty <= 0L) {
|
|
||||||
fireboxItem = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun changeOreItemCount(delta: Long) {
|
|
||||||
oreItem!!.qty += delta
|
|
||||||
if (oreItem!!.qty <= 0L) {
|
|
||||||
oreItem = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun changeProductItemCount(delta: Long) {
|
|
||||||
productItem!!.qty += delta
|
|
||||||
if (productItem!!.qty <= 0L) {
|
|
||||||
productItem = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun drawEmissive(frameDelta: Float, batch: SpriteBatch) {
|
override fun drawEmissive(frameDelta: Float, batch: SpriteBatch) {
|
||||||
if (isVisible && spriteEmissive != null) {
|
if (isVisible && spriteEmissive != null) {
|
||||||
BlendMode.resolve(drawMode, batch)
|
BlendMode.resolve(drawMode, batch)
|
||||||
@@ -215,7 +274,7 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
|||||||
nextDelayBase = fuelItemProp.smokiness
|
nextDelayBase = fuelItemProp.smokiness
|
||||||
nextDelay = (nextDelayBase * (1.0 + RNG.nextTriangularBal() * 0.1)).toFloat()
|
nextDelay = (nextDelayBase * (1.0 + RNG.nextTriangularBal() * 0.1)).toFloat()
|
||||||
|
|
||||||
changeFireboxItemCount(-1)
|
fireboxItemStatus.changeCount(-1)
|
||||||
}
|
}
|
||||||
// no item on the slot
|
// no item on the slot
|
||||||
else if (fuelCaloriesNow <= 0f && fireboxItem == null) {
|
else if (fuelCaloriesNow <= 0f && fireboxItem == null) {
|
||||||
@@ -261,10 +320,10 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
|||||||
if (productItem == null)
|
if (productItem == null)
|
||||||
productItem = InventoryPair(smeltingProduct, 1L)
|
productItem = InventoryPair(smeltingProduct, 1L)
|
||||||
else
|
else
|
||||||
changeProductItemCount(1)
|
productItemStatus.changeCount(1)
|
||||||
|
|
||||||
// take the ore item
|
// take the ore item
|
||||||
changeOreItemCount(-1)
|
oreItemStatus.changeCount(-1)
|
||||||
|
|
||||||
progress = 0f
|
progress = 0f
|
||||||
}
|
}
|
||||||
|
|||||||
363
src/net/torvald/terrarum/modulebasegame/ui/SmelterCommon.kt
Normal file
363
src/net/torvald/terrarum/modulebasegame/ui/SmelterCommon.kt
Normal file
@@ -0,0 +1,363 @@
|
|||||||
|
package net.torvald.terrarum.modulebasegame.ui
|
||||||
|
|
||||||
|
import net.torvald.terrarum.App
|
||||||
|
import net.torvald.terrarum.ItemCodex
|
||||||
|
import net.torvald.terrarum.gameitems.GameItem
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.SmelterItemStatus
|
||||||
|
import net.torvald.terrarum.ui.UIItemInventoryElemSimple
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2024-03-09.
|
||||||
|
*/
|
||||||
|
object SmelterCommon {
|
||||||
|
|
||||||
|
fun getPlayerSlotTouchDownFun(
|
||||||
|
clickedOnState: AtomicInteger,
|
||||||
|
|
||||||
|
fireboxItem: SmelterItemStatus,
|
||||||
|
oreItem: SmelterItemStatus,
|
||||||
|
|
||||||
|
getPlayerInventory: () -> ActorInventory,
|
||||||
|
|
||||||
|
itemListUpdateKeepCurrentFilter: () -> Unit
|
||||||
|
|
||||||
|
): (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, mouseButton: Int, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
|
||||||
|
val playerInventory = getPlayerInventory()
|
||||||
|
val amount = if (mouseButton == App.getConfigInt("config_mouseprimary"))
|
||||||
|
amount
|
||||||
|
else if (mouseButton == App.getConfigInt("config_mousesecondary"))
|
||||||
|
1
|
||||||
|
else
|
||||||
|
null
|
||||||
|
|
||||||
|
// oreslot
|
||||||
|
if (amount != null && gameItem != null) {
|
||||||
|
if (clickedOnState.get() == 1) {
|
||||||
|
if (oreItem.itm == gameItem.dynamicID) {
|
||||||
|
playerInventory.remove(gameItem.dynamicID, amount)
|
||||||
|
oreItem.changeCount(amount)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
playerInventory.remove(gameItem.dynamicID, amount)
|
||||||
|
oreItem.set(gameItem.dynamicID, amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// firebox
|
||||||
|
else if (clickedOnState.get() == 2) {
|
||||||
|
if (fireboxItem.isNull()) {
|
||||||
|
playerInventory.remove(gameItem.dynamicID, amount)
|
||||||
|
fireboxItem.set(gameItem.dynamicID, amount)
|
||||||
|
}
|
||||||
|
else if (fireboxItem.itm == gameItem.dynamicID) {
|
||||||
|
playerInventory.remove(gameItem.dynamicID, amount)
|
||||||
|
fireboxItem.changeCount(amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
} }
|
||||||
|
|
||||||
|
|
||||||
|
fun getPlayerSlotWheelFun(
|
||||||
|
clickedOnState: AtomicInteger,
|
||||||
|
|
||||||
|
fireboxItem: SmelterItemStatus,
|
||||||
|
oreItem: SmelterItemStatus,
|
||||||
|
|
||||||
|
getPlayerInventory: () -> ActorInventory,
|
||||||
|
|
||||||
|
itemListUpdateKeepCurrentFilter: () -> Unit
|
||||||
|
): (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, scrollX: Float, scrollY: Float, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
|
||||||
|
val playerInventory = getPlayerInventory()
|
||||||
|
val scrollY = -scrollY
|
||||||
|
if (gameItem != null) {
|
||||||
|
val addCount1 = scrollY.toLong()
|
||||||
|
|
||||||
|
if (clickedOnState.get() == 1 && (oreItem.isNull() || oreItem.itm == gameItem.dynamicID)) {
|
||||||
|
val itemToUse = oreItem.itm ?: gameItem.dynamicID
|
||||||
|
|
||||||
|
val addCount2 = scrollY.toLong().coerceIn(
|
||||||
|
-(playerInventory.searchByID(itemToUse)?.qty ?: 0L),
|
||||||
|
oreItem.qty ?: 0L,
|
||||||
|
)
|
||||||
|
|
||||||
|
// add to the inventory slot
|
||||||
|
if (oreItem.isNotNull() && addCount1 >= 1L) {
|
||||||
|
playerInventory.add(oreItem.itm!!, addCount2)
|
||||||
|
oreItem.changeCount(-addCount2)
|
||||||
|
}
|
||||||
|
// remove from the inventory slot
|
||||||
|
else if (addCount1 <= -1L) {
|
||||||
|
playerInventory.remove(itemToUse, -addCount2)
|
||||||
|
if (oreItem.isNull())
|
||||||
|
oreItem.set(itemToUse, -addCount2)
|
||||||
|
else
|
||||||
|
oreItem.changeCount(-addCount2)
|
||||||
|
}
|
||||||
|
if (oreItem.qty == 0L) oreItem.nullify()
|
||||||
|
else if (oreItem.isNotNull() && oreItem.qty!! < 0L) throw Error("Item removal count is larger than what was on the slot")
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
else if (clickedOnState.get() == 2 && (fireboxItem.isNull() || fireboxItem.itm == gameItem.dynamicID)) {
|
||||||
|
val itemToUse = fireboxItem.itm ?: gameItem.dynamicID
|
||||||
|
|
||||||
|
val addCount2 = scrollY.toLong().coerceIn(
|
||||||
|
-(playerInventory.searchByID(itemToUse)?.qty ?: 0L),
|
||||||
|
fireboxItem.qty ?: 0L,
|
||||||
|
)
|
||||||
|
|
||||||
|
// add to the inventory slot
|
||||||
|
if (fireboxItem.isNotNull() && addCount1 >= 1L) {
|
||||||
|
playerInventory.add(fireboxItem.itm!!, addCount2)
|
||||||
|
fireboxItem.changeCount(-addCount2)
|
||||||
|
}
|
||||||
|
// remove from the inventory slot
|
||||||
|
else if (addCount1 <= -1L) {
|
||||||
|
playerInventory.remove(itemToUse, -addCount2)
|
||||||
|
if (fireboxItem.isNull())
|
||||||
|
fireboxItem.set(itemToUse, -addCount2)
|
||||||
|
else
|
||||||
|
fireboxItem.changeCount(-addCount2)
|
||||||
|
}
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fun getOreItemSlotTouchDownFun(
|
||||||
|
clickedOnState: AtomicInteger,
|
||||||
|
|
||||||
|
getFireboxItemSlot: () -> UIItemInventoryElemSimple,
|
||||||
|
|
||||||
|
playerThings: UITemplateHalfInventory,
|
||||||
|
|
||||||
|
oreItem: SmelterItemStatus,
|
||||||
|
|
||||||
|
getPlayerInventory: () -> ActorInventory,
|
||||||
|
|
||||||
|
itemListUpdate: ((InventoryPair) -> Boolean) -> Unit,
|
||||||
|
itemListUpdateKeepCurrentFilter: () -> Unit
|
||||||
|
|
||||||
|
): (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, mouseButton: Int, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
|
||||||
|
if (clickedOnState.get() != 1) {
|
||||||
|
clickedOnState.set(1)
|
||||||
|
theButton.forceHighlighted = true
|
||||||
|
getFireboxItemSlot().forceHighlighted = false
|
||||||
|
playerThings.itemList.itemPage = 0
|
||||||
|
itemListUpdate { ItemCodex.hasTag(it.itm, "SMELTABLE") }
|
||||||
|
}
|
||||||
|
else if (oreItem.isNotNull()) {
|
||||||
|
val removeCount = if (mouseButton == App.getConfigInt("config_mouseprimary"))
|
||||||
|
oreItem.qty
|
||||||
|
else if (mouseButton == App.getConfigInt("config_mousesecondary"))
|
||||||
|
1L
|
||||||
|
else
|
||||||
|
null
|
||||||
|
|
||||||
|
if (removeCount != null) {
|
||||||
|
getPlayerInventory().add(oreItem.itm!!, removeCount)
|
||||||
|
oreItem.changeCount(-removeCount)
|
||||||
|
}
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
|
||||||
|
fun getOreItemSlotWheelFun(
|
||||||
|
clickedOnState: AtomicInteger,
|
||||||
|
|
||||||
|
oreItem: SmelterItemStatus,
|
||||||
|
|
||||||
|
getPlayerInventory: () -> ActorInventory,
|
||||||
|
|
||||||
|
itemListUpdateKeepCurrentFilter: () -> Unit
|
||||||
|
|
||||||
|
): (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, scrollX: Float, scrollY: Float, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
|
||||||
|
val playerInventory = getPlayerInventory()
|
||||||
|
val scrollY = -scrollY
|
||||||
|
if (clickedOnState.get() == 1 && oreItem.isNotNull()) {
|
||||||
|
val removeCount1 = scrollY.toLong()
|
||||||
|
val removeCount2 = scrollY.toLong().coerceIn(
|
||||||
|
-oreItem.qty!!,
|
||||||
|
playerInventory.searchByID(oreItem.itm)?.qty ?: 0L,
|
||||||
|
)
|
||||||
|
|
||||||
|
// add to the slot
|
||||||
|
if (removeCount1 >= 1L) {
|
||||||
|
playerInventory.remove(oreItem.itm!!, removeCount2)
|
||||||
|
oreItem.changeCount(removeCount2)
|
||||||
|
}
|
||||||
|
// remove from the slot
|
||||||
|
else if (removeCount1 <= -1L) {
|
||||||
|
playerInventory.add(oreItem.itm!!, -removeCount2)
|
||||||
|
oreItem.changeCount(removeCount2)
|
||||||
|
}
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fun getFireboxItemSlotTouchDownFun(
|
||||||
|
clickedOnState: AtomicInteger,
|
||||||
|
|
||||||
|
getOreItemSlot: () -> UIItemInventoryElemSimple,
|
||||||
|
|
||||||
|
playerThings: UITemplateHalfInventory,
|
||||||
|
|
||||||
|
fireboxItem: SmelterItemStatus,
|
||||||
|
|
||||||
|
getPlayerInventory: () -> ActorInventory,
|
||||||
|
|
||||||
|
itemListUpdate: ((InventoryPair) -> Boolean) -> Unit,
|
||||||
|
itemListUpdateKeepCurrentFilter: () -> Unit
|
||||||
|
|
||||||
|
): (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, mouseButton: Int, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
|
||||||
|
if (clickedOnState.get() != 2) {
|
||||||
|
clickedOnState.set(2)
|
||||||
|
theButton.forceHighlighted = true
|
||||||
|
getOreItemSlot().forceHighlighted = false
|
||||||
|
playerThings.itemList.itemPage = 0
|
||||||
|
itemListUpdate { ItemCodex.hasTag(it.itm, "COMBUSTIBLE") }
|
||||||
|
}
|
||||||
|
else if (fireboxItem.isNotNull()) {
|
||||||
|
val removeCount = if (mouseButton == App.getConfigInt("config_mouseprimary"))
|
||||||
|
fireboxItem.qty
|
||||||
|
else if (mouseButton == App.getConfigInt("config_mousesecondary"))
|
||||||
|
1L
|
||||||
|
else
|
||||||
|
null
|
||||||
|
|
||||||
|
if (removeCount != null) {
|
||||||
|
getPlayerInventory().add(fireboxItem.itm!!, removeCount)
|
||||||
|
fireboxItem.changeCount(-removeCount)
|
||||||
|
}
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
|
||||||
|
fun getFireboxItemSlotWheelFun(
|
||||||
|
clickedOnState: AtomicInteger,
|
||||||
|
|
||||||
|
fireboxItem: SmelterItemStatus,
|
||||||
|
|
||||||
|
getPlayerInventory: () -> ActorInventory,
|
||||||
|
|
||||||
|
itemListUpdateKeepCurrentFilter: () -> Unit
|
||||||
|
|
||||||
|
): (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, scrollX: Float, scrollY: Float, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
|
||||||
|
val playerInventory = getPlayerInventory()
|
||||||
|
val scrollY = -scrollY
|
||||||
|
if (clickedOnState.get() == 2 && fireboxItem.isNotNull()) {
|
||||||
|
val removeCount1 = scrollY.toLong()
|
||||||
|
val removeCount2 = scrollY.toLong().coerceIn(
|
||||||
|
-fireboxItem.qty!!,
|
||||||
|
playerInventory.searchByID(fireboxItem.itm)?.qty ?: 0L,
|
||||||
|
)
|
||||||
|
|
||||||
|
// add to the slot
|
||||||
|
if (removeCount1 >= 1L) {
|
||||||
|
playerInventory.remove(fireboxItem.itm!!, removeCount2)
|
||||||
|
fireboxItem.changeCount(removeCount2)
|
||||||
|
}
|
||||||
|
// remove from the slot
|
||||||
|
else if (removeCount1 <= -1L) {
|
||||||
|
playerInventory.add(fireboxItem.itm!!, -removeCount2)
|
||||||
|
fireboxItem.changeCount(removeCount2)
|
||||||
|
}
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fun getProductItemSlotTouchDownFun(
|
||||||
|
clickedOnState: AtomicInteger,
|
||||||
|
|
||||||
|
getOreItemSlot: () -> UIItemInventoryElemSimple,
|
||||||
|
getFireboxItemSlot: () -> UIItemInventoryElemSimple,
|
||||||
|
|
||||||
|
playerThings: UITemplateHalfInventory,
|
||||||
|
|
||||||
|
productItem: SmelterItemStatus,
|
||||||
|
|
||||||
|
getPlayerInventory: () -> ActorInventory,
|
||||||
|
|
||||||
|
itemListUpdate: () -> Unit,
|
||||||
|
itemListUpdateKeepCurrentFilter: () -> Unit
|
||||||
|
|
||||||
|
): (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, mouseButton: Int, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
|
||||||
|
if (clickedOnState.get() != 0) {
|
||||||
|
clickedOnState.set(0)
|
||||||
|
getOreItemSlot().forceHighlighted = false
|
||||||
|
getFireboxItemSlot().forceHighlighted = false
|
||||||
|
playerThings.itemList.itemPage = 0
|
||||||
|
itemListUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (productItem.isNotNull()) {
|
||||||
|
val removeCount = if (mouseButton == App.getConfigInt("config_mouseprimary"))
|
||||||
|
productItem.qty
|
||||||
|
else if (mouseButton == App.getConfigInt("config_mousesecondary"))
|
||||||
|
1L
|
||||||
|
else
|
||||||
|
null
|
||||||
|
|
||||||
|
if (removeCount != null) {
|
||||||
|
getPlayerInventory().add(productItem.itm!!, removeCount)
|
||||||
|
productItem.changeCount(-removeCount)
|
||||||
|
}
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
|
||||||
|
fun getProductItemSlotWheelFun(
|
||||||
|
productItem: SmelterItemStatus,
|
||||||
|
|
||||||
|
getPlayerInventory: () -> ActorInventory,
|
||||||
|
|
||||||
|
itemListUpdateKeepCurrentFilter: () -> Unit
|
||||||
|
|
||||||
|
): (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, scrollX: Float, scrollY: Float, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
|
||||||
|
val scrollY = -scrollY
|
||||||
|
if (productItem.isNotNull()) {
|
||||||
|
val removeCount1 = scrollY.toLong()
|
||||||
|
val removeCount2 = scrollY.toLong().coerceIn(
|
||||||
|
-productItem.qty!!,
|
||||||
|
0L,
|
||||||
|
)
|
||||||
|
|
||||||
|
// remove from the slot
|
||||||
|
if (removeCount1 <= -1L) {
|
||||||
|
getPlayerInventory().add(productItem.itm!!, -removeCount2)
|
||||||
|
productItem.changeCount(removeCount2)
|
||||||
|
}
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
itemListUpdateKeepCurrentFilter()
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
}
|
||||||
@@ -5,13 +5,10 @@ import com.badlogic.gdx.graphics.OrthographicCamera
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.colourutil.cieluv_getGradient
|
import net.torvald.colourutil.cieluv_getGradient
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.App.printdbg
|
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureSmelterBasic
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureSmelterBasic
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||||
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
|
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.tooltipShowing
|
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.tooltipShowing
|
||||||
import net.torvald.terrarum.ui.*
|
import net.torvald.terrarum.ui.*
|
||||||
import net.torvald.terrarum.ui.UIItemCatBar.Companion.FILTER_CAT_ALL
|
import net.torvald.terrarum.ui.UIItemCatBar.Companion.FILTER_CAT_ALL
|
||||||
@@ -19,6 +16,7 @@ import net.torvald.terrarum.ui.UIItemInventoryElemWide.Companion.UNIQUE_ITEM_HAS
|
|||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
import net.torvald.unicode.getKeycapPC
|
import net.torvald.unicode.getKeycapPC
|
||||||
import net.torvald.unicode.getMouseButton
|
import net.torvald.unicode.getMouseButton
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,107 +30,27 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
|||||||
override var width = Toolkit.drawWidth
|
override var width = Toolkit.drawWidth
|
||||||
override var height = App.scr.height
|
override var height = App.scr.height
|
||||||
|
|
||||||
|
private var clickedOnState = AtomicInteger(0) // Used to set inventory filter and its behaviour. 0: default, 1: oreslot, 2: firebox
|
||||||
|
|
||||||
private val playerThings = UITemplateHalfInventory(this, false).also {
|
private val playerThings = UITemplateHalfInventory(this, false).also {
|
||||||
it.itemListTouchDownFun = { gameItem, amount, button, _, _ ->
|
it.itemListTouchDownFun = SmelterCommon.getPlayerSlotTouchDownFun(
|
||||||
val amount = if (button == App.getConfigInt("config_mouseprimary"))
|
clickedOnState,
|
||||||
amount
|
smelter.fireboxItemStatus,
|
||||||
else if (button == App.getConfigInt("config_mousesecondary"))
|
smelter.oreItemStatus,
|
||||||
1
|
{ getPlayerInventory() },
|
||||||
else
|
{ itemListUpdateKeepCurrentFilter() }
|
||||||
null
|
)
|
||||||
|
it.itemListWheelFun = SmelterCommon.getPlayerSlotWheelFun(
|
||||||
// oreslot
|
clickedOnState,
|
||||||
if (amount != null && gameItem != null) {
|
smelter.fireboxItemStatus,
|
||||||
if (clickedOn == 1) {
|
smelter.oreItemStatus,
|
||||||
if (smelter.oreItem == null) {
|
{ getPlayerInventory() },
|
||||||
getPlayerInventory().remove(gameItem.dynamicID, amount)
|
{ itemListUpdateKeepCurrentFilter() }
|
||||||
smelter.oreItem = InventoryPair(gameItem.dynamicID, amount)
|
)
|
||||||
}
|
|
||||||
else if (smelter.oreItem!!.itm == gameItem.dynamicID) {
|
|
||||||
getPlayerInventory().remove(gameItem.dynamicID, amount)
|
|
||||||
smelter.changeOreItemCount(amount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// firebox
|
|
||||||
else if (clickedOn == 2) {
|
|
||||||
if (smelter.fireboxItem == null) {
|
|
||||||
getPlayerInventory().remove(gameItem.dynamicID, amount)
|
|
||||||
smelter.fireboxItem = InventoryPair(gameItem.dynamicID, amount)
|
|
||||||
}
|
|
||||||
else if (smelter.fireboxItem!!.itm == gameItem.dynamicID) {
|
|
||||||
getPlayerInventory().remove(gameItem.dynamicID, amount)
|
|
||||||
smelter.changeFireboxItemCount(amount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
it.itemListWheelFun = { gameItem, _, _, scrollY, _, _ ->
|
|
||||||
val scrollY = -scrollY
|
|
||||||
if (gameItem != null) {
|
|
||||||
val playerInventory = getPlayerInventory()
|
|
||||||
val addCount1 = scrollY.toLong()
|
|
||||||
|
|
||||||
if (clickedOn == 1 && (smelter.oreItem == null || smelter.oreItem!!.itm == gameItem.dynamicID)) {
|
|
||||||
val itemToUse = smelter.oreItem?.itm ?: gameItem.dynamicID
|
|
||||||
|
|
||||||
val addCount2 = scrollY.toLong().coerceIn(
|
|
||||||
-(playerInventory.searchByID(itemToUse)?.qty ?: 0L),
|
|
||||||
smelter.oreItem?.qty ?: 0L,
|
|
||||||
)
|
|
||||||
|
|
||||||
// add to the inventory slot
|
|
||||||
if (smelter.oreItem != null && addCount1 >= 1L) {
|
|
||||||
getPlayerInventory().add(smelter.oreItem!!.itm, addCount2)
|
|
||||||
smelter.changeOreItemCount(-addCount2)
|
|
||||||
}
|
|
||||||
// remove from the inventory slot
|
|
||||||
else if (addCount1 <= -1L) {
|
|
||||||
playerInventory.remove(itemToUse, -addCount2)
|
|
||||||
if (smelter.oreItem == null)
|
|
||||||
smelter.oreItem = InventoryPair(itemToUse, -addCount2)
|
|
||||||
else
|
|
||||||
smelter.changeOreItemCount(-addCount2)
|
|
||||||
}
|
|
||||||
if (smelter.oreItem != null && smelter.oreItem!!.qty == 0L) smelter.oreItem = null
|
|
||||||
else if (smelter.oreItem != null && smelter.oreItem!!.qty < 0L) throw Error("Item removal count is larger than what was on the slot")
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
else if (clickedOn == 2 && (smelter.fireboxItem == null || smelter.fireboxItem!!.itm == gameItem.dynamicID)) {
|
|
||||||
val itemToUse = smelter.fireboxItem?.itm ?: gameItem.dynamicID
|
|
||||||
|
|
||||||
val addCount2 = scrollY.toLong().coerceIn(
|
|
||||||
-(playerInventory.searchByID(itemToUse)?.qty ?: 0L),
|
|
||||||
smelter.fireboxItem?.qty ?: 0L,
|
|
||||||
)
|
|
||||||
|
|
||||||
// add to the inventory slot
|
|
||||||
if (smelter.fireboxItem != null && addCount1 >= 1L) {
|
|
||||||
getPlayerInventory().add(smelter.fireboxItem!!.itm, addCount2)
|
|
||||||
smelter.changeFireboxItemCount(-addCount2)
|
|
||||||
}
|
|
||||||
// remove from the inventory slot
|
|
||||||
else if (addCount1 <= -1L) {
|
|
||||||
playerInventory.remove(itemToUse, -addCount2)
|
|
||||||
if (smelter.fireboxItem == null)
|
|
||||||
smelter.fireboxItem = InventoryPair(itemToUse, -addCount2)
|
|
||||||
else
|
|
||||||
smelter.changeFireboxItemCount(-addCount2)
|
|
||||||
}
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPlayerInventory(): ActorInventory = INGAME.actorNowPlaying!!.inventory
|
fun getPlayerInventory(): ActorInventory = INGAME.actorNowPlaying!!.inventory
|
||||||
|
|
||||||
private var listModeButtonPushed = false
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
CommonResourcePool.addToLoadingList("basegame_gui_smelter_icons") {
|
CommonResourcePool.addToLoadingList("basegame_gui_smelter_icons") {
|
||||||
TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/smelter_icons.tga"), 20, 20)
|
TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/smelter_icons.tga"), 20, 20)
|
||||||
@@ -184,172 +102,67 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
|||||||
ButtonSecondary: use only one item
|
ButtonSecondary: use only one item
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private var clickedOn = 0 // Used to set inventory filter and its behaviour. 0: default, 1: oreslot, 2: firebox
|
|
||||||
|
|
||||||
private val oreItemSlot: UIItemInventoryElemSimple = UIItemInventoryElemSimple(
|
private val oreItemSlot: UIItemInventoryElemSimple = UIItemInventoryElemSimple(
|
||||||
this, oreX.toInt(), oreY.toInt(),
|
this, oreX.toInt(), oreY.toInt(),
|
||||||
updateOnNull = true,
|
updateOnNull = true,
|
||||||
emptyCellIcon = smelterCellIcons.get(1, 1),
|
emptyCellIcon = smelterCellIcons.get(1, 1),
|
||||||
keyDownFun = { _, _, _, _, _ -> },
|
keyDownFun = { _, _, _, _, _ -> },
|
||||||
touchDownFun = { _, _, button, _, self ->
|
touchDownFun = SmelterCommon.getOreItemSlotTouchDownFun(
|
||||||
if (clickedOn != 1) {
|
clickedOnState,
|
||||||
clickedOn = 1
|
{ fireboxItemSlot },
|
||||||
self.forceHighlighted = true
|
playerThings,
|
||||||
fireboxItemSlot.forceHighlighted = false
|
smelter.oreItemStatus,
|
||||||
playerThings.itemList.itemPage = 0
|
{ getPlayerInventory() },
|
||||||
itemListUpdate { ItemCodex.hasTag(it.itm, "SMELTABLE") }
|
{ filter -> itemListUpdate(filter) },
|
||||||
}
|
{ itemListUpdateKeepCurrentFilter() }
|
||||||
else if (smelter.oreItem != null) {
|
),
|
||||||
val removeCount = if (button == App.getConfigInt("config_mouseprimary"))
|
wheelFun = SmelterCommon.getOreItemSlotWheelFun(
|
||||||
smelter.oreItem!!.qty
|
clickedOnState,
|
||||||
else if (button == App.getConfigInt("config_mousesecondary"))
|
smelter.oreItemStatus,
|
||||||
1L
|
{ getPlayerInventory() },
|
||||||
else
|
{ itemListUpdateKeepCurrentFilter() }
|
||||||
null
|
)
|
||||||
|
|
||||||
if (removeCount != null) {
|
|
||||||
getPlayerInventory().add(smelter.oreItem!!.itm, removeCount)
|
|
||||||
smelter.changeOreItemCount(-removeCount)
|
|
||||||
}
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
wheelFun = { _, _, _, scrollY, _, _ ->
|
|
||||||
val scrollY = -scrollY
|
|
||||||
if (clickedOn == 1 && smelter.oreItem != null) {
|
|
||||||
val playerInventory = getPlayerInventory()
|
|
||||||
val removeCount1 = scrollY.toLong()
|
|
||||||
val removeCount2 = scrollY.toLong().coerceIn(
|
|
||||||
-smelter.oreItem!!.qty,
|
|
||||||
playerInventory.searchByID(smelter.oreItem!!.itm)?.qty ?: 0L,
|
|
||||||
)
|
|
||||||
|
|
||||||
// add to the slot
|
|
||||||
if (removeCount1 >= 1L) {
|
|
||||||
playerInventory.remove(smelter.oreItem!!.itm, removeCount2)
|
|
||||||
smelter.changeOreItemCount(removeCount2)
|
|
||||||
}
|
|
||||||
// remove from the slot
|
|
||||||
else if (removeCount1 <= -1L) {
|
|
||||||
getPlayerInventory().add(smelter.oreItem!!.itm, -removeCount2)
|
|
||||||
smelter.changeOreItemCount(removeCount2)
|
|
||||||
}
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
private val fireboxItemSlot: UIItemInventoryElemSimple = UIItemInventoryElemSimple(
|
private val fireboxItemSlot: UIItemInventoryElemSimple = UIItemInventoryElemSimple(
|
||||||
this, fireboxX.toInt(), fireboxY.toInt(),
|
this, fireboxX.toInt(), fireboxY.toInt(),
|
||||||
emptyCellIcon = smelterCellIcons.get(0, 0),
|
emptyCellIcon = smelterCellIcons.get(0, 0),
|
||||||
updateOnNull = true,
|
updateOnNull = true,
|
||||||
keyDownFun = { _, _, _, _, _ -> },
|
keyDownFun = { _, _, _, _, _ -> },
|
||||||
touchDownFun = { _, _, button, _, self ->
|
touchDownFun = SmelterCommon.getFireboxItemSlotTouchDownFun(
|
||||||
if (clickedOn != 2) {
|
clickedOnState,
|
||||||
clickedOn = 2
|
{ oreItemSlot },
|
||||||
self.forceHighlighted = true
|
playerThings,
|
||||||
oreItemSlot.forceHighlighted = false
|
smelter.fireboxItemStatus,
|
||||||
playerThings.itemList.itemPage = 0
|
{ getPlayerInventory() },
|
||||||
itemListUpdate { ItemCodex.hasTag(it.itm, "COMBUSTIBLE") }
|
{ filter -> itemListUpdate(filter) },
|
||||||
}
|
{ itemListUpdateKeepCurrentFilter() }
|
||||||
else if (smelter.fireboxItem != null) {
|
),
|
||||||
val removeCount = if (button == App.getConfigInt("config_mouseprimary"))
|
wheelFun = SmelterCommon.getFireboxItemSlotWheelFun(
|
||||||
smelter.fireboxItem!!.qty
|
clickedOnState,
|
||||||
else if (button == App.getConfigInt("config_mousesecondary"))
|
smelter.fireboxItemStatus,
|
||||||
1L
|
{ getPlayerInventory() },
|
||||||
else
|
{ itemListUpdateKeepCurrentFilter() }
|
||||||
null
|
)
|
||||||
|
|
||||||
if (removeCount != null) {
|
|
||||||
getPlayerInventory().add(smelter.fireboxItem!!.itm, removeCount)
|
|
||||||
smelter.changeFireboxItemCount(-removeCount)
|
|
||||||
}
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
wheelFun = { _, _, _, scrollY, _, _ ->
|
|
||||||
val scrollY = -scrollY
|
|
||||||
if (clickedOn == 2 && smelter.fireboxItem != null) {
|
|
||||||
val playerInventory = getPlayerInventory()
|
|
||||||
val removeCount1 = scrollY.toLong()
|
|
||||||
val removeCount2 = scrollY.toLong().coerceIn(
|
|
||||||
-smelter.fireboxItem!!.qty,
|
|
||||||
playerInventory.searchByID(smelter.fireboxItem!!.itm)?.qty ?: 0L,
|
|
||||||
)
|
|
||||||
|
|
||||||
// add to the slot
|
|
||||||
if (removeCount1 >= 1L) {
|
|
||||||
playerInventory.remove(smelter.fireboxItem!!.itm, removeCount2)
|
|
||||||
smelter.changeFireboxItemCount(removeCount2)
|
|
||||||
}
|
|
||||||
// remove from the slot
|
|
||||||
else if (removeCount1 <= -1L) {
|
|
||||||
getPlayerInventory().add(smelter.fireboxItem!!.itm, -removeCount2)
|
|
||||||
smelter.changeFireboxItemCount(removeCount2)
|
|
||||||
}
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
private val productItemslot: UIItemInventoryElemSimple = UIItemInventoryElemSimple(
|
private val productItemslot: UIItemInventoryElemSimple = UIItemInventoryElemSimple(
|
||||||
this, productX.toInt(), productY.toInt(),
|
this, productX.toInt(), productY.toInt(),
|
||||||
emptyCellIcon = smelterCellIcons.get(1, 0),
|
emptyCellIcon = smelterCellIcons.get(1, 0),
|
||||||
keyDownFun = { _, _, _, _, _ -> },
|
keyDownFun = { _, _, _, _, _ -> },
|
||||||
touchDownFun = { _, _, button, _, self ->
|
touchDownFun = SmelterCommon.getProductItemSlotTouchDownFun(
|
||||||
if (clickedOn != 0) {
|
clickedOnState,
|
||||||
clickedOn = 0
|
{ oreItemSlot },
|
||||||
oreItemSlot.forceHighlighted = false
|
{ fireboxItemSlot },
|
||||||
fireboxItemSlot.forceHighlighted = false
|
playerThings,
|
||||||
playerThings.itemList.itemPage = 0
|
smelter.productItemStatus,
|
||||||
itemListUpdate()
|
{ getPlayerInventory() },
|
||||||
}
|
{ itemListUpdate() },
|
||||||
|
{ itemListUpdateKeepCurrentFilter() }
|
||||||
if (smelter.productItem != null) {
|
),
|
||||||
val removeCount = if (button == App.getConfigInt("config_mouseprimary"))
|
wheelFun = SmelterCommon.getProductItemSlotWheelFun(
|
||||||
smelter.productItem!!.qty
|
smelter.productItemStatus,
|
||||||
else if (button == App.getConfigInt("config_mousesecondary"))
|
{ getPlayerInventory() },
|
||||||
1L
|
{ itemListUpdateKeepCurrentFilter() }
|
||||||
else
|
)
|
||||||
null
|
|
||||||
|
|
||||||
if (removeCount != null) {
|
|
||||||
getPlayerInventory().add(smelter.productItem!!.itm, removeCount)
|
|
||||||
smelter.changeProductItemCount(-removeCount)
|
|
||||||
}
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
wheelFun = { _, _, _, scrollY, _, _ ->
|
|
||||||
val scrollY = -scrollY
|
|
||||||
if (smelter.productItem != null) {
|
|
||||||
val removeCount1 = scrollY.toLong()
|
|
||||||
val removeCount2 = scrollY.toLong().coerceIn(
|
|
||||||
-smelter.productItem!!.qty,
|
|
||||||
0L,
|
|
||||||
)
|
|
||||||
|
|
||||||
// remove from the slot
|
|
||||||
if (removeCount1 <= -1L) {
|
|
||||||
getPlayerInventory().add(smelter.productItem!!.itm, -removeCount2)
|
|
||||||
smelter.changeProductItemCount(removeCount2)
|
|
||||||
}
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
itemListUpdateKeepCurrentFilter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private var encumbrancePerc = 0f
|
private var encumbrancePerc = 0f
|
||||||
@@ -386,7 +199,7 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
|||||||
override fun show() {
|
override fun show() {
|
||||||
super.show()
|
super.show()
|
||||||
|
|
||||||
clickedOn = 0
|
clickedOnState.set(0)
|
||||||
oreItemSlot.forceHighlighted = false
|
oreItemSlot.forceHighlighted = false
|
||||||
fireboxItemSlot.forceHighlighted = false
|
fireboxItemSlot.forceHighlighted = false
|
||||||
|
|
||||||
@@ -423,7 +236,7 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
|||||||
!playerThings.itemList.navRemoCon.mouseUp
|
!playerThings.itemList.navRemoCon.mouseUp
|
||||||
) {
|
) {
|
||||||
|
|
||||||
clickedOn = 0
|
clickedOnState.set(0)
|
||||||
|
|
||||||
oreItemSlot.forceHighlighted = false
|
oreItemSlot.forceHighlighted = false
|
||||||
fireboxItemSlot.forceHighlighted = false
|
fireboxItemSlot.forceHighlighted = false
|
||||||
@@ -496,6 +309,9 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
|||||||
|
|
||||||
|
|
||||||
override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
|
override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
|
||||||
|
val clickedOn = clickedOnState.get()
|
||||||
|
|
||||||
|
|
||||||
batch.color = backdropColour
|
batch.color = backdropColour
|
||||||
// batch.draw(smelterBackdrops.get(1,0), backdropX, backdropY, smelterBackdrops.tileW * 6f, smelterBackdrops.tileH * 6f)
|
// batch.draw(smelterBackdrops.get(1,0), backdropX, backdropY, smelterBackdrops.tileW * 6f, smelterBackdrops.tileH * 6f)
|
||||||
// batch.color = backdropColour mul Color(1f, 1f, 1f, smelter.temperature)
|
// batch.color = backdropColour mul Color(1f, 1f, 1f, smelter.temperature)
|
||||||
|
|||||||
Reference in New Issue
Block a user