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/* .gradle/*
TerrarumBuild.jar TerrarumBuild.jar
buildapp/out/Terrarum* buildapp/out/Terrarum*
buildapp/TerrarumLinux.*
buildapp/TerrarumMac.*
buildapp/TerrarumWindows.*
assets/mods/dwarventech/ModuleComputers.jar assets/mods/dwarventech/ModuleComputers.jar
# Java native errors # Java native errors

View File

@@ -32,11 +32,13 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
override var openCloseTime: Second = 0.0f override var openCloseTime: Second = 0.0f
private val itemListPlayer: UIItemInventoryItemGrid 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 buttonCraft: UIItemTextButton
private val spinnerCraftCount: UIItemSpinner 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() { private val negotiator = object : InventoryNegotiator() {
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Long) { 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 getNegotiator() = negotiator
override fun getFixtureInventory(): FixtureInventory = fakeInventory override fun getFixtureInventory(): FixtureInventory = craftables
override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
private var halfSlotOffset = (UIItemInventoryElemSimple.height + listGap) / 2 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 thisXend = thisOffsetX + (listGap + UIItemInventoryElemWide.height) * 13 - listGap
private val thisOffsetY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y() 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 { init {
val craftButtonsY = thisOffsetY + 23 + (UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 1) val craftButtonsY = thisOffsetY + 23 + (UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 1)
val buttonWidth = (UIItemInventoryElemWide.height + listGap) * 3 - listGap - 2 val buttonWidth = (UIItemInventoryElemWide.height + listGap) * 3 - listGap - 2
@@ -67,23 +73,22 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
itemListCraftable = UIItemInventoryItemGrid( itemListCraftable = UIItemInventoryItemGrid(
this, this,
catBar, catBar,
{ getFixtureInventory() }, { craftables },
thisOffsetX, thisOffsetX,
thisOffsetY, 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, drawScrollOnRightside = false,
drawWallet = false, drawWallet = false,
keyDownFun = { _, _, _ -> Unit }, keyDownFun = { _, _, _ -> },
touchDownFun = { gameItem, amount, _ -> touchDownFun = { gameItem, amount, _ ->
if (gameItem != null) { /*if (gameItem != null) {
negotiator.reject(getFixtureInventory(), getPlayerInventory(), gameItem, amount) 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) 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 = { _,_,_,_ -> buttonCraft.touchDownListener = { _,_,_,_ ->
printdbg(this, "Craft!") printdbg(this, "Craft!")
@@ -93,6 +98,26 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
itemListCraftable.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) } itemListCraftable.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
itemListCraftable.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) } 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 // player inventory to the right
itemListPlayer = UIItemInventoryItemGrid( itemListPlayer = UIItemInventoryItemGrid(
this, this,
@@ -103,12 +128,12 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
6, UIInventoryFull.CELLS_VRT, 6, UIInventoryFull.CELLS_VRT,
drawScrollOnRightside = true, drawScrollOnRightside = true,
drawWallet = false, drawWallet = false,
keyDownFun = { _, _, _ -> Unit }, keyDownFun = { _, _, _ -> },
touchDownFun = { gameItem, amount, _ -> touchDownFun = { gameItem, amount, _ ->
if (gameItem != null) { /*if (gameItem != null) {
negotiator.accept(getPlayerInventory(), getFixtureInventory(), gameItem, amount) negotiator.accept(getPlayerInventory(), getFixtureInventory(), gameItem, amount)
} }
itemListUpdate() itemListUpdate()*/
} }
) )
itemListPlayer.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) } itemListPlayer.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
@@ -117,6 +142,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
handler.allowESCtoClose = true handler.allowESCtoClose = true
addUIitem(itemListCraftable) addUIitem(itemListCraftable)
addUIitem(itemListIngredients)
addUIitem(itemListPlayer) addUIitem(itemListPlayer)
addUIitem(spinnerCraftCount) addUIitem(spinnerCraftCount)
addUIitem(buttonCraft) addUIitem(buttonCraft)
@@ -145,6 +171,13 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
private var encumbrancePerc = 0f private var encumbrancePerc = 0f
private fun itemListUpdate() { 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]) itemListCraftable.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon]) itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
encumbrancePerc = getPlayerInventory().let { encumbrancePerc = getPlayerInventory().let {
@@ -189,8 +222,9 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
batch.color = Color.WHITE batch.color = Color.WHITE
// text label for two inventory grids // text label for two inventory grids
App.fontGame.draw(batch, Lang["GAME_CRAFTING"], thisOffsetX + 2, thisOffsetY - 30) App.fontGame.draw(batch, Lang["GAME_CRAFTING"], thisOffsetX + 2, thisOffsetY - TEXT_GAP)
App.fontGame.draw(batch, Lang["GAME_INVENTORY"], thisOffsetX2 + 2, thisOffsetY - 30) 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 // 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.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.GameItem
@@ -42,6 +41,7 @@ class UIItemInventoryItemGrid(
val verticalCells: Int, val verticalCells: Int,
val drawScrollOnRightside: Boolean = false, val drawScrollOnRightside: Boolean = false,
val drawWallet: Boolean = true, val drawWallet: Boolean = true,
val hideSidebar: Boolean = false,
keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
) : UIItem(parentUI, initialX, initialY) { ) : UIItem(parentUI, initialX, initialY) {
@@ -265,34 +265,36 @@ class UIItemInventoryItemGrid(
init { init {
// initially highlight grid mode buttons // initially highlight grid mode buttons
gridModeButtons[if (isCompactMode) 1 else 0].highlighted = true if (!hideSidebar) {
gridModeButtons[if (isCompactMode) 1 else 0].highlighted = true
gridModeButtons[0].touchDownListener = { _, _, _, _ -> gridModeButtons[0].touchDownListener = { _, _, _, _ ->
isCompactMode = false isCompactMode = false
gridModeButtons[0].highlighted = true gridModeButtons[0].highlighted = true
gridModeButtons[1].highlighted = false gridModeButtons[1].highlighted = false
itemPage = 0 itemPage = 0
rebuild(currentFilter) rebuild(currentFilter)
} }
gridModeButtons[1].touchDownListener = { _, _, _, _ -> gridModeButtons[1].touchDownListener = { _, _, _, _ ->
isCompactMode = true isCompactMode = true
gridModeButtons[0].highlighted = false gridModeButtons[0].highlighted = false
gridModeButtons[1].highlighted = true gridModeButtons[1].highlighted = true
itemPage = 0 itemPage = 0
rebuild(currentFilter) rebuild(currentFilter)
} }
scrollUpButton.clickOnceListener = { _, _, _ -> scrollUpButton.clickOnceListener = { _, _, _ ->
scrollUpButton.highlighted = false scrollUpButton.highlighted = false
scrollItemPage(-1) scrollItemPage(-1)
} }
scrollDownButton.clickOnceListener = { _, _, _ -> scrollDownButton.clickOnceListener = { _, _, _ ->
scrollDownButton.highlighted = false scrollDownButton.highlighted = false
scrollItemPage(1) scrollItemPage(1)
} }
// if (is.mouseUp) handled by this.touchDown() // if (is.mouseUp) handled by this.touchDown()
}
} }
@@ -302,9 +304,11 @@ class UIItemInventoryItemGrid(
val posXDelta = posX - oldPosX val posXDelta = posX - oldPosX
itemGrid.forEach { it.posX += posXDelta } itemGrid.forEach { it.posX += posXDelta }
itemList.forEach { it.posX += posXDelta } itemList.forEach { it.posX += posXDelta }
gridModeButtons.forEach { it.posX += posXDelta } if (!hideSidebar) {
scrollUpButton.posX += posXDelta gridModeButtons.forEach { it.posX += posXDelta }
scrollDownButton.posX += posXDelta scrollUpButton.posX += posXDelta
scrollDownButton.posX += posXDelta
}
fun getScrollDotYHeight(i: Int) = scrollUpButton.posY + 10 + upDownButtonGapToDots + 10 * i fun getScrollDotYHeight(i: Int) = scrollUpButton.posY + 10 + upDownButtonGapToDots + 10 * i
@@ -316,9 +320,11 @@ class UIItemInventoryItemGrid(
items.forEach { it.render(batch, camera) } items.forEach { it.render(batch, camera) }
gridModeButtons.forEach { it.render(batch, camera) } if (!hideSidebar) {
scrollUpButton.render(batch, camera) gridModeButtons.forEach { it.render(batch, camera) }
scrollDownButton.render(batch, camera) scrollUpButton.render(batch, camera)
scrollDownButton.render(batch, camera)
}
// draw scroll dots // draw scroll dots
for (i in 0 until itemPageCount) { for (i in 0 until itemPageCount) {
@@ -384,10 +390,11 @@ class UIItemInventoryItemGrid(
} }
if (!hideSidebar) {
gridModeButtons.forEach { it.update(delta) } gridModeButtons.forEach { it.update(delta) }
scrollUpButton.update(delta) scrollUpButton.update(delta)
scrollDownButton.update(delta) scrollDownButton.update(delta)
}
} }
@@ -482,9 +489,11 @@ class UIItemInventoryItemGrid(
super.touchDown(screenX, screenY, pointer, button) super.touchDown(screenX, screenY, pointer, button)
items.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) } items.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) }
gridModeButtons.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) } if (!hideSidebar) {
if (scrollUpButton.mouseUp) scrollUpButton.touchDown(screenX, screenY, pointer, button) gridModeButtons.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) }
if (scrollDownButton.mouseUp) scrollDownButton.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 return true
} }