mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
cut-down version of crafting ui wip
This commit is contained in:
@@ -11,6 +11,7 @@ import net.torvald.terrarum.gameparticles.ParticleVanishingSprite
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
|
||||
import net.torvald.terrarum.modulebasegame.ui.UICrafting
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
@@ -23,7 +24,8 @@ class FixtureFurnaceAndAnvil : FixtureBase, CraftingStation {
|
||||
|
||||
constructor() : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 3, 2), // temporary value, will be overwritten by spawn()
|
||||
nameFun = { Lang["ITEM_FURNACE_AND_ANVIL"] }
|
||||
nameFun = { Lang["ITEM_FURNACE_AND_ANVIL"] },
|
||||
mainUI = UICrafting(null)
|
||||
) {
|
||||
CommonResourcePool.addToLoadingList("particles-tiki_smoke.tga") {
|
||||
TextureRegionPack(ModMgr.getGdxFile("basegame", "particles/bigger_smoke.tga"), 16, 16)
|
||||
@@ -45,10 +47,6 @@ class FixtureFurnaceAndAnvil : FixtureBase, CraftingStation {
|
||||
}
|
||||
|
||||
actorValue[AVKey.BASEMASS] = 100.0
|
||||
|
||||
mainUIopenFun = { ui ->
|
||||
(mainUI as? UIInventoryFull)?.openCrafting(mainUI!!.handler)
|
||||
}
|
||||
}
|
||||
|
||||
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 0.0, TerrarumAppConfiguration.TILE_SIZED * 2, TerrarumAppConfiguration.TILE_SIZED * 2), Cvec(0.5f, 0.18f, 0f, 0f)))
|
||||
@@ -70,16 +68,7 @@ class FixtureFurnaceAndAnvil : FixtureBase, CraftingStation {
|
||||
private var nextDelay = 0.25f
|
||||
private var spawnTimer = 0f
|
||||
|
||||
@Transient private var mainUIhookHackInstalled = false
|
||||
override fun update(delta: Float) {
|
||||
// adding UI to the fixture as players may right-click on the workbenches instead of pressing a keyboard key
|
||||
(INGAME as? TerrarumIngame)?.let { ingame ->
|
||||
if (!mainUIhookHackInstalled && ingame.uiInventoryPlayerReady) {
|
||||
mainUIhookHackInstalled = true
|
||||
this.mainUI = ingame.uiInventoryPlayer // this field is initialised only after a full load so this hack is necessary
|
||||
}
|
||||
}
|
||||
|
||||
super.update(delta)
|
||||
|
||||
|
||||
|
||||
@@ -28,10 +28,13 @@ import kotlin.math.min
|
||||
*
|
||||
* Created by minjaesong on 2022-03-10.
|
||||
*/
|
||||
class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
class UICrafting(val full: UIInventoryFull?) : UICanvas(
|
||||
toggleKeyLiteral = if (full == null) "control_key_inventory" else null,
|
||||
toggleButtonLiteral = if (full == null) "control_gamepad_start" else null
|
||||
), HasInventory {
|
||||
|
||||
private val catBar: UIItemCatBar
|
||||
get() = full.catBar
|
||||
private val catBarx: UIItemCatBar?
|
||||
get() = full?.catBar
|
||||
|
||||
override var width = App.scr.width
|
||||
override var height = App.scr.height
|
||||
@@ -230,7 +233,6 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
// crafting list to the left
|
||||
itemListCraftable = UIItemCraftingCandidateGrid(
|
||||
this,
|
||||
catBar,
|
||||
thisOffsetX,
|
||||
thisOffsetY,
|
||||
6, UIInventoryFull.CELLS_VRT - 2, // decrease the internal height so that craft/cancel button would fit in
|
||||
@@ -457,48 +459,52 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
// control hints
|
||||
val controlHintXPos = thisOffsetX + 2f
|
||||
blendNormalStraightAlpha(batch)
|
||||
App.fontGame.draw(batch, controlHelp, controlHintXPos, full.yEnd - 20)
|
||||
App.fontGame.draw(batch, controlHelp, controlHintXPos, UIInventoryFull.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 + 36
|
||||
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
|
||||
blendNormalStraightAlpha(batch)
|
||||
val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f)
|
||||
val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening
|
||||
batch.color = encumbBack
|
||||
Toolkit.fillArea(batch,
|
||||
if (full != null) {
|
||||
//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 + 36
|
||||
val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText)
|
||||
val encumbBarYPos = UIInventoryFull.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
|
||||
blendNormalStraightAlpha(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,
|
||||
)
|
||||
// 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
|
||||
min(UIInventoryCells.weightBarWidth, max(1f, UIInventoryCells.weightBarWidth * encumbrancePerc)),
|
||||
UIInventoryFull.controlHelpHeight - 6f
|
||||
)
|
||||
// debug text
|
||||
batch.color = Color.LIGHT_GRAY
|
||||
if (App.IS_DEVELOPMENT_BUILD) {
|
||||
App.fontSmallNumbers.draw(batch,
|
||||
)
|
||||
// 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
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -118,15 +118,15 @@ internal class UIInventoryCells(
|
||||
val controlHintXPos = full.offsetX - 34
|
||||
blendNormalStraightAlpha(batch)
|
||||
batch.color = Color.WHITE
|
||||
App.fontGame.draw(batch, full.listControlHelp, controlHintXPos, full.yEnd - 20)
|
||||
App.fontGame.draw(batch, full.listControlHelp, controlHintXPos, UIInventoryFull.yEnd - 20)
|
||||
|
||||
|
||||
// encumbrance meter
|
||||
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
|
||||
// encumbrance bar will go one row down if control help message is too long
|
||||
val encumbBarXPos = full.xEnd - weightBarWidth
|
||||
val encumbBarXPos = UIInventoryFull.xEnd - weightBarWidth
|
||||
val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText)
|
||||
val encumbBarYPos = full.yEnd-20 + 3f +
|
||||
val encumbBarYPos = UIInventoryFull.yEnd-20 + 3f +
|
||||
if (App.fontGame.getWidth(full.listControlHelp) + 2 + controlHintXPos >= encumbBarTextXPos)
|
||||
App.fontGame.lineHeight
|
||||
else 0f
|
||||
|
||||
@@ -195,18 +195,18 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
||||
private val screenRenders = arrayOf(
|
||||
{ frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera ->
|
||||
// control hints
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, full.yEnd - 20)
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, UIInventoryFull.yEnd - 20)
|
||||
// text buttons
|
||||
gameMenuButtons.render(frameDelta, batch, camera)
|
||||
},
|
||||
{ frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera ->
|
||||
// control hints
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, full.yEnd - 20)
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, UIInventoryFull.yEnd - 20)
|
||||
keyboardSetupUI.render(frameDelta, batch, camera)
|
||||
},
|
||||
{ frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera ->
|
||||
// control hints
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, full.yEnd - 20)
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, UIInventoryFull.yEnd - 20)
|
||||
areYouSureMainMenuButtons.render(frameDelta, batch, camera)
|
||||
},
|
||||
{ frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera ->
|
||||
@@ -214,22 +214,22 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
||||
},
|
||||
{ frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera ->
|
||||
// control hints
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, full.yEnd - 20)
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, UIInventoryFull.yEnd - 20)
|
||||
keyConfigUI.render(frameDelta, batch, camera)
|
||||
},
|
||||
{ frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera ->
|
||||
// control hints
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, full.yEnd - 20)
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, UIInventoryFull.yEnd - 20)
|
||||
languageUI.render(frameDelta, batch, camera)
|
||||
},
|
||||
{ frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera ->
|
||||
// control hints
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, full.yEnd - 20)
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, UIInventoryFull.yEnd - 20)
|
||||
shareUI.render(frameDelta, batch, camera)
|
||||
},
|
||||
{ frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera ->
|
||||
// control hints
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, full.yEnd - 20)
|
||||
App.fontGame.draw(batch, full.gameMenuControlHelp, controlHintX, UIInventoryFull.yEnd - 20)
|
||||
audioUI.render(frameDelta, batch, camera)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -136,6 +136,11 @@ class UIInventoryFull(
|
||||
batch.draw(backdrop01.get(0, 4), 0f, hTopRem + 280f + hMid, w, hTopRem)
|
||||
|
||||
}
|
||||
|
||||
internal var xEnd = (Toolkit.drawWidth + internalWidth).div(2).toFloat()
|
||||
private set
|
||||
internal var yEnd = -YPOS_CORRECTION + (App.scr.height + internalHeight).div(2).toFloat()
|
||||
private set
|
||||
}
|
||||
|
||||
//val REQUIRED_MARGIN: Int = 138 // hard-coded value. Don't know the details. Range: [91-146]. I chose MAX-8 because cell gap is 8
|
||||
@@ -342,10 +347,6 @@ class UIInventoryFull(
|
||||
//private val gradEndCol = Color(0x000000_70)
|
||||
//private val gradHeight = 48f
|
||||
|
||||
internal var xEnd = (width + internalWidth).div(2).toFloat()
|
||||
private set
|
||||
internal var yEnd = -YPOS_CORRECTION + (App.scr.height + internalHeight).div(2).toFloat()
|
||||
private set
|
||||
|
||||
override fun renderUI(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||
* Created by minjaesong on 2022-06-28.
|
||||
*/
|
||||
class UIItemCraftingCandidateGrid(
|
||||
parentUI: UICrafting, catBar: UIItemCatBar,
|
||||
parentUI: UICrafting,
|
||||
initialX: Int, initialY: Int,
|
||||
horizontalCells: Int, verticalCells: Int,
|
||||
drawScrollOnRightside: Boolean = false,
|
||||
|
||||
@@ -66,7 +66,7 @@ class UIWorldPortalDelete(private val full: UIWorldPortal) : UICanvas() {
|
||||
|
||||
// control hints
|
||||
batch.color = Color.WHITE
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, (Toolkit.drawWidth - width)/2 + 2, (full.yEnd - 20).toInt())
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, (Toolkit.drawWidth - width)/2 + 2, (UIInventoryFull.yEnd - 20).toInt())
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
|
||||
@@ -459,7 +459,7 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
|
||||
|
||||
// control hints
|
||||
batch.color = Color.WHITE
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, screencapX + 2, (full.yEnd - 20).toInt())
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, screencapX + 2, (UIInventoryFull.yEnd - 20).toInt())
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
|
||||
@@ -83,7 +83,7 @@ class UIWorldPortalRename(private val full: UIWorldPortal) : UICanvas() {
|
||||
|
||||
// control hints
|
||||
batch.color = Color.WHITE
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, (Toolkit.drawWidth - width)/2 + 2, (full.yEnd - 20).toInt())
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, (Toolkit.drawWidth - width)/2 + 2, (UIInventoryFull.yEnd - 20).toInt())
|
||||
|
||||
uiItems.forEach { it.render(frameDelta, batch, camera) }
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() {
|
||||
|
||||
// control hints
|
||||
batch.color = Color.WHITE
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, 2 + (Toolkit.drawWidth - 560)/2 + 2, (full.yEnd - 20).toInt())
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, 2 + (Toolkit.drawWidth - 560)/2 + 2, (UIInventoryFull.yEnd - 20).toInt())
|
||||
|
||||
uiItems.forEach { it.render(frameDelta, batch, camera) }
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ class UIWorldPortalShare(private val full: UIWorldPortal) : UICanvas() {
|
||||
App.fontUITitle.draw(batch, titlestr, drawX + (width - App.fontUITitle.getWidth(titlestr)).div(2).toFloat(), UIInventoryFull.INVENTORY_CELLS_OFFSET_Y() - 36f)
|
||||
|
||||
// control hints
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, (Toolkit.drawWidth - width)/2 + 2, (full.yEnd - 20).toInt())
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, (Toolkit.drawWidth - width)/2 + 2, (UIInventoryFull.yEnd - 20).toInt())
|
||||
|
||||
uiItems.forEach { it.render(frameDelta, batch, camera) }
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ class UIWorldPortalUseInvitation(val full: UIWorldPortal) : UICanvas() {
|
||||
App.fontGame.draw(batch, Lang["CREDITS_CODE"], drawX - 4, drawY + sizeSelY)
|
||||
|
||||
// control hints
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, 2 + (Toolkit.drawWidth - 560)/2 + 2, (full.yEnd - 20).toInt())
|
||||
App.fontGame.draw(batch, full.portalListingControlHelp, 2 + (Toolkit.drawWidth - 560)/2 + 2, (UIInventoryFull.yEnd - 20).toInt())
|
||||
|
||||
uiItems.forEach { it.render(frameDelta, batch, camera) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user