more crafting ui wip but i'm going to need 1 new beeeg uiitem

This commit is contained in:
minjaesong
2022-06-27 22:09:38 +09:00
parent 6e4677352d
commit d56fb81bcf
3 changed files with 100 additions and 54 deletions

3
.gitignore vendored
View File

@@ -5,6 +5,9 @@ build/*
.gradle/*
TerrarumBuild.jar
buildapp/out/Terrarum*
buildapp/TerrarumLinux.*
buildapp/TerrarumMac.*
buildapp/TerrarumWindows.*
assets/mods/dwarventech/ModuleComputers.jar
# Java native errors

View File

@@ -32,11 +32,13 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
override var openCloseTime: Second = 0.0f
private val itemListPlayer: UIItemInventoryItemGrid
private val itemListCraftable: UIItemInventoryItemGrid
private val itemListCraftable: UIItemInventoryItemGrid // might be changed to something else
private val itemListIngredients: UIItemInventoryItemGrid // this one is definitely not to be changed
private val buttonCraft: UIItemTextButton
private val spinnerCraftCount: UIItemSpinner
private val fakeInventory = FixtureInventory()
private val craftables = FixtureInventory() // might be changed to something else
private val ingredients = FixtureInventory() // this one is definitely not to be changed
private val negotiator = object : InventoryNegotiator() {
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Long) {
@@ -49,7 +51,8 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
}
override fun getNegotiator() = negotiator
override fun getFixtureInventory(): FixtureInventory = fakeInventory
override fun getFixtureInventory(): FixtureInventory = craftables
override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
private var halfSlotOffset = (UIItemInventoryElemSimple.height + listGap) / 2
@@ -59,6 +62,9 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
private val thisXend = thisOffsetX + (listGap + UIItemInventoryElemWide.height) * 13 - listGap
private val thisOffsetY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y()
private val TEXT_GAP = 26
private val LAST_LINE_IN_GRID = ((UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 2)) + 22//359 // TEMPORARY VALUE!
init {
val craftButtonsY = thisOffsetY + 23 + (UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 1)
val buttonWidth = (UIItemInventoryElemWide.height + listGap) * 3 - listGap - 2
@@ -67,23 +73,22 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
itemListCraftable = UIItemInventoryItemGrid(
this,
catBar,
{ getFixtureInventory() },
{ craftables },
thisOffsetX,
thisOffsetY,
6, UIInventoryFull.CELLS_VRT - 1, // decrease the internal height so that craft/cancel button would fit in
6, UIInventoryFull.CELLS_VRT - 2, // decrease the internal height so that craft/cancel button would fit in
drawScrollOnRightside = false,
drawWallet = false,
keyDownFun = { _, _, _ -> Unit },
keyDownFun = { _, _, _ -> },
touchDownFun = { gameItem, amount, _ ->
if (gameItem != null) {
negotiator.reject(getFixtureInventory(), getPlayerInventory(), gameItem, amount)
/*if (gameItem != null) {
negotiator.reject(craftables, getPlayerInventory(), gameItem, amount)
}
itemListUpdate()
itemListUpdate()*/
}
)
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)
spinnerCraftCount = UIItemSpinner(this, thisOffsetX + 1, craftButtonsY, 1, 1, 100, 1, buttonWidth, numberToTextFunction = {"${it.toInt()}"})
buttonCraft.touchDownListener = { _,_,_,_ ->
printdbg(this, "Craft!")
@@ -93,6 +98,26 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
itemListCraftable.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
itemListCraftable.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) }
// ingredient list
itemListIngredients = UIItemInventoryItemGrid(
this,
catBar,
{ ingredients },
thisOffsetX,
thisOffsetY + LAST_LINE_IN_GRID,
6, 1,
drawScrollOnRightside = false,
drawWallet = false,
hideSidebar = true,
keyDownFun = { _, _, _ -> },
touchDownFun = { _, _, _ -> }
)
// make sure grid buttons for ingredients do nothing (even if they are hidden!)
itemListIngredients.gridModeButtons[0].touchDownListener = { _,_,_,_ -> }
itemListIngredients.gridModeButtons[1].touchDownListener = { _,_,_,_ -> }
itemListIngredients.isCompactMode = true
// player inventory to the right
itemListPlayer = UIItemInventoryItemGrid(
this,
@@ -103,12 +128,12 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
6, UIInventoryFull.CELLS_VRT,
drawScrollOnRightside = true,
drawWallet = false,
keyDownFun = { _, _, _ -> Unit },
keyDownFun = { _, _, _ -> },
touchDownFun = { gameItem, amount, _ ->
if (gameItem != null) {
/*if (gameItem != null) {
negotiator.accept(getPlayerInventory(), getFixtureInventory(), gameItem, amount)
}
itemListUpdate()
itemListUpdate()*/
}
)
itemListPlayer.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
@@ -117,6 +142,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
handler.allowESCtoClose = true
addUIitem(itemListCraftable)
addUIitem(itemListIngredients)
addUIitem(itemListPlayer)
addUIitem(spinnerCraftCount)
addUIitem(buttonCraft)
@@ -145,6 +171,13 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
private var encumbrancePerc = 0f
private fun itemListUpdate() {
// fill in craftables
getFixtureInventory().let {
it.itemList.clear()
it.itemList.add(InventoryPair("basegame:18", 1))
}
// let itemlists be sorted
itemListCraftable.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
encumbrancePerc = getPlayerInventory().let {
@@ -189,8 +222,9 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
batch.color = Color.WHITE
// text label for two inventory grids
App.fontGame.draw(batch, Lang["GAME_CRAFTING"], thisOffsetX + 2, thisOffsetY - 30)
App.fontGame.draw(batch, Lang["GAME_INVENTORY"], thisOffsetX2 + 2, thisOffsetY - 30)
App.fontGame.draw(batch, Lang["GAME_CRAFTING"], thisOffsetX + 2, thisOffsetY - TEXT_GAP)
App.fontGame.draw(batch, Lang["GAME_INVENTORY_INGREDIENTS"], thisOffsetX + 2, thisOffsetY + LAST_LINE_IN_GRID - TEXT_GAP)
App.fontGame.draw(batch, Lang["GAME_INVENTORY"], thisOffsetX2 + 2, thisOffsetY - TEXT_GAP)
// control hints

View File

@@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitems.GameItem
@@ -42,6 +41,7 @@ class UIItemInventoryItemGrid(
val verticalCells: Int,
val drawScrollOnRightside: Boolean = false,
val drawWallet: Boolean = true,
val hideSidebar: Boolean = false,
keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
) : UIItem(parentUI, initialX, initialY) {
@@ -265,6 +265,7 @@ class UIItemInventoryItemGrid(
init {
// initially highlight grid mode buttons
if (!hideSidebar) {
gridModeButtons[if (isCompactMode) 1 else 0].highlighted = true
@@ -294,6 +295,7 @@ class UIItemInventoryItemGrid(
// if (is.mouseUp) handled by this.touchDown()
}
}
private val upDownButtonGapToDots = 7 // apparent gap may vary depend on the texture itself
@@ -302,9 +304,11 @@ class UIItemInventoryItemGrid(
val posXDelta = posX - oldPosX
itemGrid.forEach { it.posX += posXDelta }
itemList.forEach { it.posX += posXDelta }
if (!hideSidebar) {
gridModeButtons.forEach { it.posX += posXDelta }
scrollUpButton.posX += posXDelta
scrollDownButton.posX += posXDelta
}
fun getScrollDotYHeight(i: Int) = scrollUpButton.posY + 10 + upDownButtonGapToDots + 10 * i
@@ -316,9 +320,11 @@ class UIItemInventoryItemGrid(
items.forEach { it.render(batch, camera) }
if (!hideSidebar) {
gridModeButtons.forEach { it.render(batch, camera) }
scrollUpButton.render(batch, camera)
scrollDownButton.render(batch, camera)
}
// draw scroll dots
for (i in 0 until itemPageCount) {
@@ -384,11 +390,12 @@ class UIItemInventoryItemGrid(
}
if (!hideSidebar) {
gridModeButtons.forEach { it.update(delta) }
scrollUpButton.update(delta)
scrollDownButton.update(delta)
}
}
internal fun rebuild(filter: Array<String>) {
@@ -482,9 +489,11 @@ class UIItemInventoryItemGrid(
super.touchDown(screenX, screenY, pointer, button)
items.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) }
if (!hideSidebar) {
gridModeButtons.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) }
if (scrollUpButton.mouseUp) scrollUpButton.touchDown(screenX, screenY, pointer, button)
if (scrollDownButton.mouseUp) scrollDownButton.touchDown(screenX, screenY, pointer, button)
}
return true
}