mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
crafting ui nearly complete
This commit is contained in:
@@ -4,7 +4,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
|
||||
interface HasInventory {
|
||||
|
||||
fun getNegotiator(): InventoryNegotiator
|
||||
fun getNegotiator(): InventoryTransactionNegotiator
|
||||
fun getFixtureInventory(): FixtureInventory
|
||||
fun getPlayerInventory(): FixtureInventory
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
/**
|
||||
* Created by minjaesong on 2021-03-12.
|
||||
*/
|
||||
abstract class InventoryNegotiator {
|
||||
abstract class InventoryTransactionNegotiator {
|
||||
/** Retrieve item filter to be used to show only the acceptable items when player's own inventory is being displayed */
|
||||
open fun getItemFilter(): List<String> = listOf(CAT_ALL) // GameItem.Category
|
||||
/** Accepts item from the player and pass it to right inventory (object), slot (UI), etc... */
|
||||
@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.GdxColorMap
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
import kotlin.math.absoluteValue
|
||||
@@ -34,6 +35,14 @@ abstract class UIItemInventoryCellBase(
|
||||
abstract override fun update(delta: Float)
|
||||
abstract override fun render(batch: SpriteBatch, camera: Camera)
|
||||
|
||||
/** Custom highlight rule to highlight tihs button to primary accent colour (blue by default).
|
||||
* Set to `null` to use default rule:
|
||||
*
|
||||
* "`equippedSlot` defined and set to `highlightEquippedItem`" or "`forceHighlighted`" */
|
||||
var customHighlightRuleMain: ((UIItemInventoryCellBase) -> Boolean)? = null
|
||||
/** Custom highlight rule to highlight this button to secondary accent colour (yellow by default). Set to `null` to use default rule (which does nothing). */
|
||||
var customHighlightRule2: ((UIItemInventoryCellBase) -> Boolean)? = null
|
||||
|
||||
var forceHighlighted = false
|
||||
/*set(value) {
|
||||
if (field != value) {
|
||||
@@ -85,4 +94,26 @@ object UIItemInventoryCellCommonRes {
|
||||
|
||||
// -2.14B
|
||||
}
|
||||
}
|
||||
|
||||
val defaultInventoryCellTheme = InventoryCellColourTheme(
|
||||
Toolkit.Theme.COL_HIGHLIGHT,
|
||||
Toolkit.Theme.COL_LIST_DEFAULT,
|
||||
Toolkit.Theme.COL_ACTIVE,
|
||||
Toolkit.Theme.COL_INVENTORY_CELL_BORDER,
|
||||
Toolkit.Theme.COL_HIGHLIGHT,
|
||||
Color.WHITE,
|
||||
Toolkit.Theme.COL_ACTIVE,
|
||||
Color.WHITE,
|
||||
)
|
||||
}
|
||||
|
||||
data class InventoryCellColourTheme(
|
||||
val cellHighlightMainCol: Color,
|
||||
val cellHighlightSubCol: Color,
|
||||
val cellHighlightMouseUpCol: Color,
|
||||
val cellHighlightNormalCol: Color,
|
||||
val textHighlightMainCol: Color,
|
||||
val textHighlightSubCol: Color,
|
||||
val textHighlightMouseUpCol: Color,
|
||||
val textHighlightNormalCol: Color,
|
||||
)
|
||||
@@ -14,6 +14,7 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
@@ -46,7 +47,8 @@ open class UIItemInventoryItemGrid(
|
||||
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
|
||||
protected val useHighlightingManager: Boolean = true, // only used by UIItemCraftingCandidateGrid which addresses buttons directly to set highlighting
|
||||
open protected val highlightEquippedItem: Boolean = true // for some UIs that only cares about getting equipped slot number but not highlighting
|
||||
open protected val highlightEquippedItem: Boolean = true, // for some UIs that only cares about getting equipped slot number but not highlighting
|
||||
colourTheme: InventoryCellColourTheme = defaultInventoryCellTheme
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
@@ -186,7 +188,8 @@ open class UIItemInventoryItemGrid(
|
||||
drawBackOnNull = true,
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun,
|
||||
highlightEquippedItem = highlightEquippedItem
|
||||
highlightEquippedItem = highlightEquippedItem,
|
||||
colourTheme = colourTheme
|
||||
)
|
||||
}
|
||||
// automatically determine how much columns are needed. Minimum Width = 5 grids
|
||||
@@ -205,7 +208,8 @@ open class UIItemInventoryItemGrid(
|
||||
drawBackOnNull = true,
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun,
|
||||
highlightEquippedItem = highlightEquippedItem
|
||||
highlightEquippedItem = highlightEquippedItem,
|
||||
colourTheme = colourTheme
|
||||
)
|
||||
}
|
||||
|
||||
@@ -266,6 +270,16 @@ open class UIItemInventoryItemGrid(
|
||||
highlightable = false
|
||||
)
|
||||
|
||||
fun setCustomHighlightRuleMain(predicate: ((UIItemInventoryCellBase) -> Boolean)?) {
|
||||
itemGrid.forEach { it.customHighlightRuleMain = predicate }
|
||||
itemList.forEach { it.customHighlightRuleMain = predicate }
|
||||
}
|
||||
|
||||
fun setCustomHighlightRuleSub(predicate: ((UIItemInventoryCellBase) -> Boolean)?) {
|
||||
itemGrid.forEach { it.customHighlightRule2 = predicate }
|
||||
itemList.forEach { it.customHighlightRule2 = predicate }
|
||||
}
|
||||
|
||||
fun scrollItemPage(relativeAmount: Int) {
|
||||
itemPage = if (itemPageCount == 0) 0 else (itemPage + relativeAmount).fmod(itemPageCount)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user