tech tree view wip

This commit is contained in:
minjaesong
2024-11-25 23:50:28 +09:00
parent 661c4cdc4d
commit 95af4e8f53
4 changed files with 38 additions and 23 deletions

View File

@@ -86,7 +86,7 @@ internal object SavegameMigrator {
if (worldVersion == playerVersion) { if (worldVersion == playerVersion) {
this::class.declaredFunctions.filter { this::class.declaredFunctions.filter {
annotationMatches(worldVersion, it.findAnnotation()) annotationMatches(worldVersion, it.findAnnotation())
}.forEach { func -> }.sortedBy { it.name }.forEach { func ->
printdbg(this, func.toString()) printdbg(this, func.toString())
actors0.forEach { actor -> func.call(this, actor) } actors0.forEach { actor -> func.call(this, actor) }
} }
@@ -122,7 +122,7 @@ internal object SavegameMigrator {
@AppliedVersion("all") @AppliedVersion("all")
fun mergeUnlitBlocks(actor: Actor) { fun b_mergeUnlitBlocksAndFillInInventory(actor: Actor) {
if (ItemCodex.isEmpty()) throw Error("ItemCodex is empty") if (ItemCodex.isEmpty()) throw Error("ItemCodex is empty")
if (actor is Pocketed) { if (actor is Pocketed) {
@@ -164,7 +164,7 @@ internal object SavegameMigrator {
@AppliedVersion("0.4.0") @AppliedVersion("0.4.0")
fun updatePlayerEncumbrance(actor: Actor) { fun a_updatePlayerEncumbrance(actor: Actor) {
if (actor is IngamePlayer && actor.actorValue.getAsInt("encumbrance") == 1000) { if (actor is IngamePlayer && actor.actorValue.getAsInt("encumbrance") == 1000) {
actor.actorValue.set("encumbrance", 50000) actor.actorValue.set("encumbrance", 50000)
} }

View File

@@ -130,6 +130,12 @@ open class FixtureInventory() {
updateEncumbrance() updateEncumbrance()
} }
open fun removeEntryForced(itemID: ItemID) {
searchByID(itemID)?.let {
itemList.remove(it)
}
}
open fun remove(itemID: ItemID, count: Long) = remove(ItemCodex[itemID]!!, count) {} open fun remove(itemID: ItemID, count: Long) = remove(ItemCodex[itemID]!!, count) {}
open fun remove(item: GameItem, count: Long = 1L) = remove(item, count) {} open fun remove(item: GameItem, count: Long = 1L) = remove(item, count) {}

View File

@@ -20,6 +20,7 @@ import net.torvald.terrarum.modulebasegame.ui.UITemplateHalfInventory.Companion.
import net.torvald.terrarum.ui.* import net.torvald.terrarum.ui.*
import net.torvald.terrarum.ui.UIItemCatBar.Companion.FILTER_CAT_ALL import net.torvald.terrarum.ui.UIItemCatBar.Companion.FILTER_CAT_ALL
import net.torvald.unicode.getKeycapPC import net.torvald.unicode.getKeycapPC
import kotlin.math.roundToInt
/** /**
* This UI has inventory, but it's just there to display all craftable items and should not be serialised. * This UI has inventory, but it's just there to display all craftable items and should not be serialised.
@@ -122,7 +123,7 @@ class UICraftingWorkbench(val inventoryUI: UIInventoryFull?, val parentContainer
private val thisOffsetY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y() private val thisOffsetY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y()
private val cellsWidth = (listGap + UIItemInventoryElemWide.height) * 6 - listGap private val cellsWidth = (listGap + UIItemInventoryElemWide.height) * 6 - listGap
private val LAST_LINE_IN_GRID = ((UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 2)) + 22//359 // TEMPORARY VALUE! internal val LAST_LINE_IN_GRID = ((UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 2)) + 22//359 // TEMPORARY VALUE!
private var recipeClicked: CraftingCodex.CraftingRecipe? = null private var recipeClicked: CraftingCodex.CraftingRecipe? = null
@@ -321,10 +322,14 @@ class UICraftingWorkbench(val inventoryUI: UIInventoryFull?, val parentContainer
handler.allowESCtoClose = true handler.allowESCtoClose = true
val navbarHeight = 82 // a magic number
val fakeNavbarY = itemListIngredients.posY
fun getIconPosY2(index: Int) = (fakeNavbarY + ((index*2+1)/4f) * navbarHeight).roundToInt() - catIcons.tileH/2
val menuButtonTechView = UIItemImageButton( val menuButtonTechView = UIItemImageButton(
this, catIcons.get(20, 1), this, catIcons.get(20, 1),
initialX = itemListCraftable.navRemoCon.posX + 12, initialX = itemListCraftable.navRemoCon.posX + 12,
initialY = itemListCraftable.navRemoCon.getIconPosY(-2) - 8, initialY = getIconPosY2(0),
highlightable = true highlightable = true
).also { ).also {
it.clickOnceListener = { _, _ -> it.clickOnceListener = { _, _ ->
@@ -336,7 +341,7 @@ class UICraftingWorkbench(val inventoryUI: UIInventoryFull?, val parentContainer
val menuButtonCraft = UIItemImageButton( val menuButtonCraft = UIItemImageButton(
this, catIcons.get(19, 1), this, catIcons.get(19, 1),
initialX = itemListCraftable.navRemoCon.posX + 12, initialX = itemListCraftable.navRemoCon.posX + 12,
initialY = itemListCraftable.navRemoCon.getIconPosY(-1) - 8, initialY = getIconPosY2(1),
activeCol = Toolkit.Theme.COL_SELECTED, activeCol = Toolkit.Theme.COL_SELECTED,
inactiveCol = Toolkit.Theme.COL_SELECTED, inactiveCol = Toolkit.Theme.COL_SELECTED,
highlightable = true highlightable = true

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemImageButton import net.torvald.terrarum.ui.UIItemImageButton
import net.torvald.terrarum.ui.UIItemInventoryElemSimple import net.torvald.terrarum.ui.UIItemInventoryElemSimple
import net.torvald.unicode.getKeycapPC import net.torvald.unicode.getKeycapPC
import kotlin.math.roundToInt
/** /**
* Created by minjaesong on 2024-02-18. * Created by minjaesong on 2024-02-18.
@@ -32,24 +33,25 @@ class UITechView(val inventoryUI: UIInventoryFull?, val parentContainer: UICraft
private val posX1 = posX0 - UIItemListNavBarVertical.LIST_TO_CONTROL_GAP - UIItemListNavBarVertical.WIDTH - 4 private val posX1 = posX0 - UIItemListNavBarVertical.LIST_TO_CONTROL_GAP - UIItemListNavBarVertical.WIDTH - 4
private val posY1 = posY0 private val posY1 = posY0
// private val navbarX = posX1 + UIItemListNavBarVertical.LIST_TO_CONTROL_GAP private val panelX = 32 + parentContainer.transitionalCraftingUI.itemListCraftable.navRemoCon.posX + 12
// private val navbarY = posY1 private val panelY = parentContainer.transitionalCraftingUI.itemListCraftable.navRemoCon.posY - 8
private val navbarX = parentContainer.transitionalCraftingUI.itemListCraftable.navRemoCon.posX + 12
private val navbarY = parentContainer.transitionalCraftingUI.itemListCraftable.navRemoCon.posY - 8
private val navbarWidth = UIItemListNavBarVertical.WIDTH
private val navbarHeight = parentContainer.transitionalCraftingUI.itemListCraftable.height
private val panelX = 32 + navbarX
private val panelY = navbarY
private val panelWidth = 720 private val panelWidth = 720
private val panelHeight = navbarHeight private val panelHeight = parentContainer.transitionalCraftingUI.itemListCraftable.height +
parentContainer.transitionalCraftingUI.itemListIngredients.height + 64 // 64 is a magic number
private val navbarWidth = UIItemListNavBarVertical.WIDTH
private val navbarHeight = 82 // a magic number
private val navbarX = panelX - 32 // also a magic number
private val navbarY = panelY + panelHeight - navbarHeight
private val fakeNavbarY = parentContainer.transitionalCraftingUI.itemListIngredients.posY
private val catIcons = CommonResourcePool.getAsTextureRegionPack("inventory_category") private val catIcons = CommonResourcePool.getAsTextureRegionPack("inventory_category")
private val menuButtonTechView = UIItemImageButton( private val menuButtonTechView = UIItemImageButton(
this, catIcons.get(20, 1), this, catIcons.get(20, 1),
initialX = navbarX, initialX = navbarX,
initialY = getIconPosY(-2), initialY = getIconPosY(0),
activeCol = Toolkit.Theme.COL_SELECTED, activeCol = Toolkit.Theme.COL_SELECTED,
inactiveCol = Toolkit.Theme.COL_SELECTED, inactiveCol = Toolkit.Theme.COL_SELECTED,
highlightable = false highlightable = false
@@ -57,7 +59,7 @@ class UITechView(val inventoryUI: UIInventoryFull?, val parentContainer: UICraft
private val menuButtonCraft = UIItemImageButton( private val menuButtonCraft = UIItemImageButton(
this, catIcons.get(19, 1), this, catIcons.get(19, 1),
initialX = navbarX, initialX = navbarX,
initialY = getIconPosY(-1), initialY = getIconPosY(1),
highlightable = true highlightable = true
).also { ).also {
it.clickOnceListener = { _, _ -> it.clickOnceListener = { _, _ ->
@@ -66,11 +68,7 @@ class UITechView(val inventoryUI: UIInventoryFull?, val parentContainer: UICraft
} }
} }
fun getIconPosY(index: Int) = fun getIconPosY(index: Int) = (fakeNavbarY + ((index*2+1)/4f) * navbarHeight).roundToInt() - catIcons.tileH/2
if (index >= 0)
posY1 + 26 * index
else
(posY1 + navbarHeight) + (26 * index)
init { init {
addUIitem(menuButtonCraft) addUIitem(menuButtonCraft)
@@ -78,6 +76,8 @@ class UITechView(val inventoryUI: UIInventoryFull?, val parentContainer: UICraft
} }
private val thisOffsetX = UIInventoryFull.INVENTORY_CELLS_OFFSET_X() + UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap - halfSlotOffset private val thisOffsetX = UIInventoryFull.INVENTORY_CELLS_OFFSET_X() + UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap - halfSlotOffset
private val cellHighlightNormalCol2 = colourTheme.cellHighlightNormalCol.cpy().also { it.a /= 2f }
override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) { override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
// draw fake navbar // // draw fake navbar //
// draw the tray // draw the tray
@@ -86,6 +86,10 @@ class UITechView(val inventoryUI: UIInventoryFull?, val parentContainer: UICraft
// cell border // cell border
batch.color = colourTheme.cellHighlightNormalCol batch.color = colourTheme.cellHighlightNormalCol
Toolkit.drawBoxBorder(batch, navbarX - 4, navbarY, navbarWidth, navbarHeight) Toolkit.drawBoxBorder(batch, navbarX - 4, navbarY, navbarWidth, navbarHeight)
// cell divider
batch.color = cellHighlightNormalCol2
Toolkit.drawStraightLine(batch, navbarX - 3, navbarY + navbarHeight/2, navbarX-3 + navbarWidth-2, 1, false)
// draw window // // draw window //