crafting ui is on the inventory menu now

This commit is contained in:
minjaesong
2022-03-11 11:34:33 +09:00
parent d09befee6f
commit f9f9aa414a
10 changed files with 132 additions and 50 deletions

Binary file not shown.

View File

@@ -13,5 +13,8 @@
"MENU_LABEL_MENU": "Menu",
"CONTEXT_GENERATOR_SEED": "Seed",
"GAME_ACTION_GRAPPLE": "Grapple",
"GAME_ACTION_QUICKSEL": "Quick Select"
"GAME_ACTION_QUICKSEL": "Quick Select",
"MENU_LABEL_CRAFT": "Craft",
"MENU_LABEL_CRAFTING": "Crafting",
"GAME_CRAFTABLE_ITEMS": "Craftable Items"
}

View File

@@ -14,5 +14,8 @@
"CONTEXT_ITEM_MAP": "지도",
"CONTEXT_GENERATOR_SEED": "시드",
"GAME_ACTION_GRAPPLE": "매달리기",
"GAME_ACTION_QUICKSEL": "빠른 선택"
"GAME_ACTION_QUICKSEL": "빠른 선택",
"MENU_LABEL_CRAFT": "제작하기",
"MENU_LABEL_CRAFTING": "제작",
"GAME_CRAFTABLE_ITEMS": "제작 가능한 아이템"
}

View File

@@ -69,6 +69,7 @@ object DefaultConfig {
"control_key_zoom" to Input.Keys.Z,
"control_key_gamemenu" to Input.Keys.TAB,
"control_key_crafting" to Input.Keys.W,
"control_key_quicksel" to Input.Keys.SHIFT_LEFT, // pie menu is now LShift because CapsLock is actually used by the my bespoke keyboard input
"control_mouse_quicksel" to Input.Buttons.MIDDLE, // middle click to open pie menu

View File

@@ -84,7 +84,12 @@ class UIItemInventoryCatBar(
// determine gaps: hacky way exploiting that we already know the catbar is always at the c of the ui
val relativeStartX = posX - (uiInternalWidth - width) / 2
val sideButtonsGap = (((uiInternalWidth - width) / 2) - 2f * catIcons.tileW) / 3f
val iconIndex = arrayOf(12, 16, 17, 13)
val iconIndex = arrayOf(
catIcons.get(9,1),
catIcons.get(16,0),
catIcons.get(17,0),
catIcons.get(13,0)
)
//println("[UIItemInventoryCatBar] relativeStartX: $relativeStartX")
@@ -99,7 +104,7 @@ class UIItemInventoryCatBar(
UIItemImageButton(
inventoryUI,
catIcons.get(iconIndex[index], 0),
iconIndex[index],
activeBackCol = Color(0),
backgroundCol = Color(0),
highlightBackCol = Color(0),

View File

@@ -4,6 +4,7 @@ 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.gameitems.GameItem
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.ui.*
@@ -18,59 +19,57 @@ import net.torvald.terrarum.ui.UIItemTextButton
*
* Created by minjaesong on 2022-03-10.
*/
class UICrafting : UICanvas(
class UICrafting(val full: UIInventoryFull) : UICanvas(
toggleKeyLiteral = App.getConfigInt("control_key_inventory"),
toggleButtonLiteral = App.getConfigInt("control_gamepad_start"),
), HasInventory {
private val catBar: UIItemInventoryCatBar
get() = full.catBar
override var width = App.scr.width
override var height = App.scr.height
override var openCloseTime: Second = 0.0f
private val catBar: UIItemInventoryCatBar
private val itemListPlayer: UIItemInventoryItemGrid
private val itemListCraftable: UIItemInventoryItemGrid
private val buttonCraft: UIItemTextButton
private val buttonCancel: UIItemTextButton
private val fakeInventory = FixtureInventory()
private val negotiator = object : InventoryNegotiator() {
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Long) {
TODO()
// TODO()
}
override fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Long) {
TODO()
// TODO()
}
}
override fun getNegotiator() = negotiator
override fun getFixtureInventory(): FixtureInventory = TODO()
override fun getFixtureInventory(): FixtureInventory = fakeInventory
override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
private var halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap) / 2
private var halfSlotOffset = (UIItemInventoryElemSimple.height + listGap) / 2
private val thisOffsetX = UIInventoryFull.INVENTORY_CELLS_OFFSET_X() - halfSlotOffset
private val thisOffsetX2 = thisOffsetX + (listGap + UIItemInventoryElemWide.height) * 7
private val thisXend = thisOffsetX + (listGap + UIItemInventoryElemWide.height) * 13 - listGap
private val thisOffsetY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y()
init {
catBar = UIItemInventoryCatBar(
this,
(App.scr.width - UIInventoryFull.catBarWidth) / 2,
42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2,
UIInventoryFull.internalWidth,
UIInventoryFull.catBarWidth,
false
)
catBar.selectionChangeListener = { old, new -> itemListUpdate() }
val craftableX = UIInventoryFull.INVENTORY_CELLS_OFFSET_X() - halfSlotOffset + (UIItemInventoryItemGrid.listGap + UIItemInventoryElemWide.height) * 7
val craftableY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y()
val craftButtonsY = craftableY + (UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 1)
val gridWidth = (UIItemInventoryItemGrid.listGap + UIItemInventoryElemWide.height) * 7
val buttonWidth = (gridWidth - listGap) / 2
val craftButtonsY = thisOffsetY + 23 + (UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 1)
val buttonWidth = (UIItemInventoryElemWide.height + listGap) * 3 - listGap - 2
// crafting list to the left
itemListCraftable = UIItemInventoryItemGrid(
this,
catBar,
{ getFixtureInventory() },
craftableX, craftableY,
thisOffsetX,
thisOffsetY,
6, UIInventoryFull.CELLS_VRT - 1, // decrease the internal height so that craft/cancel button would fit in
drawScrollOnRightside = false,
drawWallet = false,
@@ -83,26 +82,27 @@ class UICrafting : UICanvas(
}
)
buttonCraft = UIItemTextButton(this, "MENU_LABEL_CRAFT", craftableX, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
buttonCancel = UIItemTextButton(this, "MENU_LABEL_CANCEL", craftableX + buttonWidth + listGap, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
buttonCancel = UIItemTextButton(this, "MENU_LABEL_CANCEL", thisOffsetX + 1, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
buttonCraft = UIItemTextButton(this, "MENU_LABEL_CRAFT", thisOffsetX + 3 + buttonWidth + listGap, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
buttonCraft.touchDownListener = { _,_,_,_ ->
TODO()
printdbg(this, "Craft!")
}
buttonCancel.touchDownListener = { _,_,_,_ ->
TODO()
printdbg(this, "Cancel!")
}
// make grid mode buttons work together
itemListCraftable.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
itemListCraftable.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) }
// player inventory to the right
itemListPlayer = UIItemInventoryItemGrid(
this,
catBar,
{ INGAME.actorNowPlaying!!.inventory }, // literally a player's inventory
UIInventoryFull.INVENTORY_CELLS_OFFSET_X() - halfSlotOffset,
craftableY,
thisOffsetX2,
thisOffsetY,
6, UIInventoryFull.CELLS_VRT,
drawScrollOnRightside = true,
drawWallet = false,
@@ -119,11 +119,16 @@ class UICrafting : UICanvas(
handler.allowESCtoClose = true
addUIitem(catBar)
addUIitem(itemListCraftable)
addUIitem(itemListPlayer)
addUIitem(buttonCancel)
addUIitem(buttonCraft)
}
// reset whatever player has selected to null and bring UI to its initial state
fun resetUI() {
}
private var openingClickLatched = false
@@ -135,9 +140,14 @@ class UICrafting : UICanvas(
openingClickLatched = Terrarum.mouseDown
}
private var encumbrancePerc = 0f
private fun itemListUpdate() {
itemListCraftable.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
encumbrancePerc = getPlayerInventory().let {
it.capacity.toFloat() / it.maxCapacity
}
}
private fun setCompact(yes: Boolean) {
@@ -172,15 +182,62 @@ class UICrafting : UICanvas(
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// background fill
UIInventoryFull.drawBackground(batch)
// NO super.render due to an infinite recursion
this.uiItems.forEach { it.render(batch, camera) }
// UI items
batch.color = Color.WHITE
catBar.render(batch, camera)
itemListCraftable.render(batch, camera)
itemListPlayer.render(batch, camera)
// text label for two inventory grids
App.fontGame.draw(batch, Lang["GAME_CRAFTABLE_ITEMS"], thisOffsetX + 2, thisOffsetY - 30)
App.fontGame.draw(batch, Lang["GAME_INVENTORY"], thisOffsetX2 + 2, thisOffsetY - 30)
// control hints
val controlHintXPos = thisOffsetX.toFloat()
blendNormal(batch)
App.fontGame.draw(batch, full.listControlHelp, controlHintXPos, full.yEnd - 20)
//draw player encumb
// encumbrance meter
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
// encumbrance bar will go one row down if control help message is too long
val encumbBarXPos = thisXend - UIInventoryCells.weightBarWidth
val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText)
val encumbBarYPos = full.yEnd-20 + 3f +
if (App.fontGame.getWidth(full.listControlHelp) + 2 + controlHintXPos >= encumbBarTextXPos)
App.fontGame.lineHeight
else 0f
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
// encumbrance bar background
blendNormal(batch)
val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f)
val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening
batch.color = encumbBack
Toolkit.fillArea(batch,
encumbBarXPos, encumbBarYPos,
UIInventoryCells.weightBarWidth, UIInventoryFull.controlHelpHeight - 6f
)
// encumbrance bar
batch.color = encumbCol
Toolkit.fillArea(batch,
encumbBarXPos, encumbBarYPos,
if (full.actor.inventory.capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
1f
else // make sure 1px is always be seen
minOf(UIInventoryCells.weightBarWidth, maxOf(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
UIInventoryFull.controlHelpHeight - 6f
)
// debug text
batch.color = Color.LIGHT_GRAY
if (App.IS_DEVELOPMENT_BUILD) {
App.fontSmallNumbers.draw(batch,
"${full.actor.inventory.capacity}/${full.actor.inventory.maxCapacity}",
encumbBarTextXPos,
encumbBarYPos + UIInventoryFull.controlHelpHeight - 4f
)
}
blendNormal(batch)

View File

@@ -107,11 +107,7 @@ internal class UIInventoryCells(
else 0f
// Companion.encumbBarYPos = encumbBarYPos // q&d hack to share some numbers
App.fontGame.draw(batch,
encumbranceText,
encumbBarTextXPos,
encumbBarYPos - 3f
)
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
// encumbrance bar background
blendNormal(batch)

View File

@@ -8,6 +8,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.App.*
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.gameactors.UICrafting
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemHorizontalFadeSlide
@@ -161,7 +162,8 @@ class UIInventoryFull(
)
private val transitionalMinimap = UIInventoryMinimap(this) // PLACEHOLDER
// private val transitionalMinimap = UIInventoryMinimap(this) // PLACEHOLDER
private val transitionalCraftingUI = UICrafting(this) // PLACEHOLDER
private val transitionalItemCells = UIInventoryCells(this)
private val transitionalEscMenu = UIInventoryEscMenu(this)
private val transitionPanel = UIItemHorizontalFadeSlide(
@@ -171,7 +173,7 @@ class UIInventoryFull(
width,
App.scr.height,
1f,
transitionalMinimap, transitionalItemCells, transitionalEscMenu
transitionalCraftingUI, transitionalItemCells, transitionalEscMenu
)
@@ -198,7 +200,7 @@ class UIInventoryFull(
setAsClose()
}
// allow "control_key_gamemenu" to open this UI
// allow "control_key_gamemenu" to open this UI and bring system menu immediately
this.handler.toggleKeyExtra.add { App.getConfigInt("control_key_gamemenu") }
this.handler.toggleKeyExtraAction.add {
if (it.isClosed) {
@@ -212,10 +214,23 @@ class UIInventoryFull(
setAsClose()
}
// allow "control_key_crafting" to open this UI and bring system menu immediately
this.handler.toggleKeyExtra.add { App.getConfigInt("control_key_crafting") }
this.handler.toggleKeyExtraAction.add {
if (it.isClosed) {
INGAME.setTooltipMessage(null)
transitionPanel.forcePosition(0)
catBar.setSelectedPanel(0)
transitionalCraftingUI.resetUI()
it.setAsOpen()
}
else if (it.isOpened)
setAsClose()
}
rebuildList()
}
internal var offsetX = ((width - internalWidth) / 2).toFloat()

View File

@@ -204,7 +204,7 @@ void main() {
toggleKeyExtra.forEachIndexed { index, getKey ->
if (Gdx.input.isKeyJustPressed(getKey())) {
toggleKeyExtraAction[0].invoke(this)
toggleKeyExtraAction[index].invoke(this)
}
}

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.ui
import com.jme3.math.FastMath
import net.torvald.terrarum.INGAME
import kotlin.math.absoluteValue
import kotlin.math.roundToInt
@@ -40,5 +41,6 @@ class UIItemHorizontalFadeSlide(
it.posY = it.initialY
it.opacity = getOpacity(index)
}
INGAME.setTooltipMessage(null)
}
}