mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
smelter ui wip
This commit is contained in:
@@ -7,42 +7,63 @@ import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureSmelterBasic
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
|
||||
import net.torvald.terrarum.ui.*
|
||||
import net.torvald.terrarum.ui.UIItemCatBar.Companion.FILTER_CAT_ALL
|
||||
import net.torvald.terrarum.ui.UIItemInventoryElemWide.Companion.UNIQUE_ITEM_HAS_NO_AMOUNT
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import net.torvald.unicode.getKeycapPC
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-01-29.
|
||||
*/
|
||||
class UISmelterBasic() : UICanvas(
|
||||
class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
||||
toggleKeyLiteral = "control_key_inventory",
|
||||
toggleButtonLiteral = "control_gamepad_start"
|
||||
), HasInventory {
|
||||
) {
|
||||
|
||||
override var width = Toolkit.drawWidth
|
||||
override var height = App.scr.height
|
||||
|
||||
private val playerThings = UITemplateHalfInventory(this, false).also {
|
||||
it.itemListTouchDownFun = { gameItem, _, _, _, _ ->
|
||||
it.itemListTouchDownFun = { gameItem, amount, button, _, _ ->
|
||||
val amount = if (button == App.getConfigInt("config_mouseprimary"))
|
||||
amount
|
||||
else if (button == App.getConfigInt("config_mousesecondary"))
|
||||
1
|
||||
else
|
||||
null
|
||||
|
||||
// oreslot
|
||||
if (amount != null && gameItem != null) {
|
||||
if (clickedOn == 1) {
|
||||
getPlayerInventory().remove(gameItem.dynamicID, amount)
|
||||
|
||||
if (smelter.oreItem == null)
|
||||
smelter.oreItem = InventoryPair(gameItem.dynamicID, amount)
|
||||
else
|
||||
smelter.oreItem!!.qty += amount
|
||||
}
|
||||
// firebox
|
||||
else if (clickedOn == 2) {
|
||||
getPlayerInventory().remove(gameItem.dynamicID, amount)
|
||||
|
||||
if (smelter.fireboxItem == null)
|
||||
smelter.fireboxItem = InventoryPair(gameItem.dynamicID, amount)
|
||||
else
|
||||
smelter.fireboxItem!!.qty += amount
|
||||
}
|
||||
}
|
||||
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
}
|
||||
|
||||
private val negotiator = object : InventoryTransactionNegotiator() {
|
||||
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Long) {
|
||||
// TODO()
|
||||
}
|
||||
|
||||
override fun refund(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
|
||||
// TODO()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getNegotiator() = negotiator
|
||||
override fun getFixtureInventory(): FixtureInventory = TODO()
|
||||
override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
|
||||
fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
|
||||
|
||||
init {
|
||||
CommonResourcePool.addToLoadingList("basegame_gui_smelter_icons") {
|
||||
@@ -56,19 +77,13 @@ class UISmelterBasic() : UICanvas(
|
||||
private var smelterBackdrop =
|
||||
FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/smelter_tall.tga")
|
||||
|
||||
private var fuelCaloriesNow = 0f
|
||||
private var fuelCaloriesMax: Float? = null
|
||||
|
||||
private var temperature = 0f // 0f..1f
|
||||
private var progress = 0f
|
||||
|
||||
|
||||
private val leftPanelWidth = playerThings.width
|
||||
private val leftPanelHeight = playerThings.height
|
||||
private val leftPanelX = playerThings.posX - leftPanelWidth - UIItemInventoryItemGrid.listGap - UIItemInventoryElemWide.height
|
||||
private val leftPanelY = playerThings.posY
|
||||
|
||||
private val backdropColour = Color(0x7f7f7fff)
|
||||
private val backdropColour = Color(0x999999_c8.toInt())
|
||||
private val backdropZoom = 6
|
||||
private val backdropX = (leftPanelX + (leftPanelWidth - smelterBackdrop.regionWidth * backdropZoom) / 2).toFloat()
|
||||
private val backdropY = (leftPanelY + (leftPanelHeight - smelterBackdrop.regionHeight * backdropZoom) / 2).toFloat()
|
||||
@@ -82,31 +97,137 @@ class UISmelterBasic() : UICanvas(
|
||||
private val productX = backdropX + 37 * backdropZoom + 3
|
||||
private val productY = backdropY + 39 * backdropZoom + 3
|
||||
|
||||
private val oreItemSlot = UIItemInventoryElemSimple(
|
||||
/*
|
||||
Click on the button when item is there:
|
||||
ButtonPrimary: take all the item
|
||||
ButtonSecondary: take only one item (or show radial menu?)
|
||||
|
||||
Click on the button when item is not there:
|
||||
ButtonPrimary: apply filter to the inventory
|
||||
|
||||
Click on the area that has no UIitem:
|
||||
ButtonPrimary: reset the inventory filter
|
||||
|
||||
Click on the inventory list:
|
||||
ButtonPrimary: use all the 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(
|
||||
this, oreX.toInt(), oreY.toInt(),
|
||||
updateOnNull = true,
|
||||
emptyCellIcon = smelterCellIcons.get(1, 1),
|
||||
keyDownFun = { _, _, _, _, _ -> },
|
||||
touchDownFun = { item, amount, _, _, _ -> }
|
||||
touchDownFun = { _, _, button, _, self ->
|
||||
if (clickedOn != 1) {
|
||||
clickedOn = 1
|
||||
self.forceHighlighted = true
|
||||
fireboxItemSlot.forceHighlighted = false
|
||||
itemListUpdate { ItemCodex.hasTag(it.itm, "SMELTABLE") }
|
||||
}
|
||||
else if (smelter.oreItem != null) {
|
||||
val removeCount = if (button == App.getConfigInt("config_mouseprimary"))
|
||||
smelter.oreItem!!.qty
|
||||
else if (button == App.getConfigInt("config_mousesecondary"))
|
||||
1L
|
||||
else
|
||||
null
|
||||
|
||||
if (removeCount != null) {
|
||||
getPlayerInventory().add(smelter.oreItem!!.itm, removeCount)
|
||||
smelter.oreItem!!.qty -= removeCount
|
||||
if (smelter.oreItem!!.qty == 0L) smelter.oreItem = null
|
||||
}
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
else {
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
}
|
||||
)
|
||||
private val fireboxItemSlot = UIItemInventoryElemSimple(
|
||||
private val fireboxItemSlot: UIItemInventoryElemSimple = UIItemInventoryElemSimple(
|
||||
this, fireboxX.toInt(), fireboxY.toInt(),
|
||||
emptyCellIcon = smelterCellIcons.get(0, 0),
|
||||
updateOnNull = true,
|
||||
keyDownFun = { _, _, _, _, _ -> },
|
||||
touchDownFun = { item, amount, _, _, _ -> }
|
||||
touchDownFun = { _, _, button, _, self ->
|
||||
if (clickedOn != 2) {
|
||||
clickedOn = 2
|
||||
self.forceHighlighted = true
|
||||
oreItemSlot.forceHighlighted = false
|
||||
itemListUpdate { ItemCodex.hasTag(it.itm, "BURNABLE") }
|
||||
}
|
||||
else if (smelter.fireboxItem != null) {
|
||||
val removeCount = if (button == App.getConfigInt("config_mouseprimary"))
|
||||
smelter.fireboxItem!!.qty
|
||||
else if (button == App.getConfigInt("config_mousesecondary"))
|
||||
1L
|
||||
else
|
||||
null
|
||||
|
||||
if (removeCount != null) {
|
||||
getPlayerInventory().add(smelter.fireboxItem!!.itm, removeCount)
|
||||
smelter.fireboxItem!!.qty -= removeCount
|
||||
if (smelter.fireboxItem!!.qty == 0L) smelter.fireboxItem = null
|
||||
}
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
else {
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
}
|
||||
)
|
||||
private val productItemslot = UIItemInventoryElemSimple(
|
||||
private val productItemslot: UIItemInventoryElemSimple = UIItemInventoryElemSimple(
|
||||
this, productX.toInt(), productY.toInt(),
|
||||
emptyCellIcon = smelterCellIcons.get(1, 0),
|
||||
updateOnNull = true,
|
||||
keyDownFun = { _, _, _, _, _ -> },
|
||||
touchDownFun = { item, amount, _, _, _ -> }
|
||||
touchDownFun = { _, _, button, _, self ->
|
||||
if (smelter.productItem != null) {
|
||||
val removeCount = if (button == App.getConfigInt("config_mouseprimary"))
|
||||
smelter.productItem!!.qty
|
||||
else if (button == App.getConfigInt("config_mousesecondary"))
|
||||
1L
|
||||
else
|
||||
null
|
||||
|
||||
if (removeCount != null) {
|
||||
getPlayerInventory().add(smelter.productItem!!.itm, removeCount)
|
||||
smelter.productItem!!.qty -= removeCount
|
||||
if (smelter.productItem!!.qty == 0L) smelter.productItem = null
|
||||
}
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
private var encumbrancePerc = 0f
|
||||
|
||||
private fun itemListUpdate() {
|
||||
// let itemlists be sorted
|
||||
// itemListCraftable.rebuild(UIItemCatBar.FILTER_CAT_ALL)
|
||||
playerThings.rebuild(UIItemCatBar.FILTER_CAT_ALL)
|
||||
inventoryFilter = { _: InventoryPair -> true }
|
||||
playerThings.rebuild(FILTER_CAT_ALL)
|
||||
encumbrancePerc = getPlayerInventory().let {
|
||||
it.capacity.toFloat() / it.maxCapacity
|
||||
}
|
||||
}
|
||||
|
||||
private var inventoryFilter = { _: InventoryPair -> true }
|
||||
|
||||
private fun itemListUpdate(filter: (InventoryPair) -> Boolean) {
|
||||
// let itemlists be sorted
|
||||
inventoryFilter = filter
|
||||
playerThings.rebuild(filter)
|
||||
encumbrancePerc = getPlayerInventory().let {
|
||||
it.capacity.toFloat() / it.maxCapacity
|
||||
}
|
||||
}
|
||||
|
||||
private fun itemListUpdateKeepCurrentFilter() {
|
||||
// let itemlists be sorted
|
||||
playerThings.rebuild(inventoryFilter)
|
||||
encumbrancePerc = getPlayerInventory().let {
|
||||
it.capacity.toFloat() / it.maxCapacity
|
||||
}
|
||||
@@ -114,13 +235,18 @@ class UISmelterBasic() : UICanvas(
|
||||
|
||||
init {
|
||||
addUIitem(playerThings)
|
||||
addUIitem(fireboxItemSlot)
|
||||
addUIitem(oreItemSlot)
|
||||
addUIitem(fireboxItemSlot)
|
||||
addUIitem(productItemslot)
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
super.show()
|
||||
|
||||
clickedOn = 0
|
||||
oreItemSlot.forceHighlighted = false
|
||||
fireboxItemSlot.forceHighlighted = false
|
||||
|
||||
playerThings.setGetInventoryFun { INGAME.actorNowPlaying!!.inventory }
|
||||
itemListUpdate()
|
||||
|
||||
@@ -130,6 +256,31 @@ class UISmelterBasic() : UICanvas(
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
uiItems.forEach { it.update(delta) }
|
||||
|
||||
oreItemSlot.item = ItemCodex[smelter.oreItem?.itm]
|
||||
oreItemSlot.itemImage = ItemCodex.getItemImage(smelter.oreItem?.itm)
|
||||
oreItemSlot.amount = smelter.oreItem?.qty ?: UNIQUE_ITEM_HAS_NO_AMOUNT
|
||||
|
||||
fireboxItemSlot.item = ItemCodex[smelter.fireboxItem?.itm]
|
||||
fireboxItemSlot.itemImage = ItemCodex.getItemImage(smelter.fireboxItem?.itm)
|
||||
fireboxItemSlot.amount = smelter.fireboxItem?.qty ?: UNIQUE_ITEM_HAS_NO_AMOUNT
|
||||
|
||||
productItemslot.item = ItemCodex[smelter.productItem?.itm]
|
||||
productItemslot.itemImage = ItemCodex.getItemImage(smelter.productItem?.itm)
|
||||
productItemslot.amount = smelter.productItem?.qty ?: UNIQUE_ITEM_HAS_NO_AMOUNT
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
super.touchDown(screenX, screenY, pointer, button)
|
||||
|
||||
if (!oreItemSlot.mouseUp && !fireboxItemSlot.mouseUp && !productItemslot.mouseUp && !playerThings.itemList.mouseUp) {
|
||||
clickedOn = 0
|
||||
oreItemSlot.forceHighlighted = false
|
||||
fireboxItemSlot.forceHighlighted = false
|
||||
itemListUpdate()
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private val controlHelp: String
|
||||
|
||||
@@ -98,7 +98,14 @@ internal class UIStorageChest : UICanvas(
|
||||
itemListChest = UITemplateHalfInventory(this, true, { getFixtureInventory() }, { chestNameFun() }).also {
|
||||
it.itemListKeyDownFun = { _, _, _, _, _ -> Unit }
|
||||
it.itemListTouchDownFun = { gameItem, amount, button, _, _ ->
|
||||
if (button == App.getConfigInt("config_mouseprimary")) {
|
||||
val amount = if (button == App.getConfigInt("config_mouseprimary"))
|
||||
amount
|
||||
else if (button == App.getConfigInt("config_mousesecondary"))
|
||||
1
|
||||
else
|
||||
null
|
||||
|
||||
if (amount != null) {
|
||||
if (gameItem != null) {
|
||||
negotiator.refund(getFixtureInventory(), getPlayerInventory(), gameItem, amount)
|
||||
}
|
||||
@@ -114,7 +121,14 @@ internal class UIStorageChest : UICanvas(
|
||||
itemListPlayer = UITemplateHalfInventory(this, false).also {
|
||||
it.itemListKeyDownFun = { _, _, _, _, _ -> Unit }
|
||||
it.itemListTouchDownFun = { gameItem, amount, button, _, _ ->
|
||||
if (button == App.getConfigInt("config_mouseprimary")) {
|
||||
val amount = if (button == App.getConfigInt("config_mouseprimary"))
|
||||
amount
|
||||
else if (button == App.getConfigInt("config_mousesecondary"))
|
||||
1
|
||||
else
|
||||
null
|
||||
|
||||
if (amount != null) {
|
||||
if (gameItem != null) {
|
||||
negotiator.accept(getPlayerInventory(), getFixtureInventory(), gameItem, amount)
|
||||
}
|
||||
|
||||
@@ -66,23 +66,23 @@ class UITemplateHalfInventory(
|
||||
|
||||
}
|
||||
|
||||
inline fun rebuild(category: Array<String>) {
|
||||
fun rebuild(category: Array<String>) {
|
||||
itemList.rebuild(category)
|
||||
}
|
||||
|
||||
inline fun rebuild(noinline predicate: (InventoryPair) -> Boolean) {
|
||||
fun rebuild(predicate: (InventoryPair) -> Boolean) {
|
||||
itemList.rebuild(predicate)
|
||||
}
|
||||
|
||||
inline fun rebuild(noinline predicate: (InventoryPair) -> Boolean, appendix: ItemID) {
|
||||
fun rebuild(predicate: (InventoryPair) -> Boolean, appendix: ItemID) {
|
||||
itemList.rebuild(predicate, appendix)
|
||||
}
|
||||
|
||||
inline fun removeFromForceHighlightList(items: List<ItemID>) {
|
||||
fun removeFromForceHighlightList(items: List<ItemID>) {
|
||||
itemList.removeFromForceHighlightList(items)
|
||||
}
|
||||
|
||||
inline fun setGetInventoryFun(noinline getter: () -> ActorInventory) {
|
||||
fun setGetInventoryFun(getter: () -> ActorInventory) {
|
||||
itemList.getInventory = getter
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user