crafting ui nearly complete

This commit is contained in:
minjaesong
2022-07-02 23:28:33 +09:00
parent 4eb3ad07f3
commit 523dd458ce
12 changed files with 189 additions and 64 deletions

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.modulebasegame.ui.InventoryCellColourTheme
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
@@ -31,7 +32,8 @@ class UIItemInventoryElemWide(
keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, self
touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Button, extra info, self
extraInfo: Any? = null,
highlightEquippedItem: Boolean = true // for some UIs that only cares about getting equipped slot number but not highlighting
highlightEquippedItem: Boolean = true, // for some UIs that only cares about getting equipped slot number but not highlighting
var colourTheme: InventoryCellColourTheme = UIItemInventoryCellCommonRes.defaultInventoryCellTheme
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun, extraInfo, highlightEquippedItem) {
companion object {
@@ -63,20 +65,35 @@ class UIItemInventoryElemWide(
}
}
private val fwsp = 0x3000.toChar()
private var highlightToMainCol = false
private var highlightToSubCol = false
var cellHighlightMainCol = Toolkit.Theme.COL_HIGHLIGHT
var cellHighlightSubCol = Toolkit.Theme.COL_LIST_DEFAULT
var cellHighlightMouseUpCol = Toolkit.Theme.COL_ACTIVE
var cellHighlightNormalCol = Toolkit.Theme.COL_INVENTORY_CELL_BORDER
var textHighlightMainCol = Toolkit.Theme.COL_HIGHLIGHT
var textHighlightSubCol = Color.WHITE
var textHighlightMouseUpCol = Toolkit.Theme.COL_ACTIVE
var textHighlightNormalCol = Color.WHITE
override fun render(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
highlightToMainCol = customHighlightRuleMain?.invoke(this) ?: (equippedSlot != null && highlightEquippedItem) || forceHighlighted
highlightToSubCol = customHighlightRule2?.invoke(this) ?: false
// cell background
if (item != null || drawBackOnNull) {
batch.color = Toolkit.Theme.COL_CELL_FILL
Toolkit.fillArea(batch, posX, posY, width, height)
}
// cell border
batch.color = if ((equippedSlot != null && highlightEquippedItem) || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseUp && item != null) Toolkit.Theme.COL_ACTIVE
else Toolkit.Theme.COL_INVENTORY_CELL_BORDER
batch.color = if (highlightToMainCol) colourTheme.cellHighlightMainCol
else if (highlightToSubCol) colourTheme.cellHighlightSubCol
else if (mouseUp && item != null) colourTheme.cellHighlightMouseUpCol
else colourTheme.cellHighlightNormalCol
Toolkit.drawBoxBorder(batch, posX, posY, width, height)
@@ -92,15 +109,15 @@ class UIItemInventoryElemWide(
// if mouse is over, text lights up
// highlight item name and count (blocks/walls) if the item is equipped
batch.color = item!!.nameColour mul (
if ((equippedSlot != null && highlightEquippedItem) || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseUp && item != null) Toolkit.Theme.COL_ACTIVE
else Color.WHITE
)
if (highlightToMainCol) colourTheme.textHighlightMainCol
else if (highlightToSubCol) colourTheme.textHighlightSubCol
else if (mouseUp && item != null) colourTheme.textHighlightMouseUpCol
else colourTheme.textHighlightNormalCol)
// draw name of the item
App.fontGame.draw(batch,
// print name and amount in parens
item!!.name + (if (amount > 0 && item!!.stackable) "$fwsp($amountString)" else if (amount != 1L) "$fwsp!!$amountString!!" else ""),
item!!.name + (if (amount > 0 && item!!.stackable) "\u3000($amountString)" else if (amount != 1L) "\u3000!!$amountString!!" else ""),
posX + textOffsetX,
posY + textOffsetY