mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
buttons for crafting/techtree transition
This commit is contained in:
@@ -3,11 +3,12 @@ package net.torvald.terrarum.modulebasegame.ui
|
|||||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.App
|
import net.torvald.terrarum.App
|
||||||
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.INGAME
|
import net.torvald.terrarum.INGAME
|
||||||
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
|
import net.torvald.terrarum.Second
|
||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.*
|
||||||
import net.torvald.terrarum.ui.UIItemHorizontalFadeSlide
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2024-03-02.
|
* Created by minjaesong on 2024-03-02.
|
||||||
@@ -17,6 +18,15 @@ class UICrafting(val full: UIInventoryFull?) : UICanvas(
|
|||||||
toggleButtonLiteral = if (full == null) "control_gamepad_start" else null
|
toggleButtonLiteral = if (full == null) "control_gamepad_start" else null
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
internal val LAST_LINE_IN_GRID = ((UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 2)) + 22//359 // TEMPORARY VALUE!
|
||||||
|
|
||||||
|
val panelToggleBarY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y() + LAST_LINE_IN_GRID
|
||||||
|
val panelToggleBarWidth = UIItemListNavBarVertical.WIDTH
|
||||||
|
val panelToggleBarHeight = 82 // a magic number
|
||||||
|
val catIconHeight = CommonResourcePool.getAsTextureRegionPack("inventory_category").tileH
|
||||||
|
}
|
||||||
|
|
||||||
override var width = Toolkit.drawWidth
|
override var width = Toolkit.drawWidth
|
||||||
override var height = App.scr.height
|
override var height = App.scr.height
|
||||||
|
|
||||||
@@ -35,21 +45,65 @@ class UICrafting(val full: UIInventoryFull?) : UICanvas(
|
|||||||
|
|
||||||
private val uis = listOf(transitionalCraftingUI, transitionalTechtreePanel)
|
private val uis = listOf(transitionalCraftingUI, transitionalTechtreePanel)
|
||||||
|
|
||||||
|
val panelToggleBarX = transitionalCraftingUI.itemListCraftable.navRemoCon.posX + 12
|
||||||
|
|
||||||
|
fun getIconPosY(index: Int) = (panelToggleBarY + ((index*2+1)/4f) * panelToggleBarHeight).roundToInt() - catIconHeight/2
|
||||||
|
|
||||||
|
private val catIcons = CommonResourcePool.getAsTextureRegionPack("inventory_category")
|
||||||
|
|
||||||
|
val menuButtonTechView = UIItemImageButton(
|
||||||
|
this, catIcons.get(20, 1),
|
||||||
|
initialX = panelToggleBarX,
|
||||||
|
initialY = getIconPosY(0),
|
||||||
|
highlightable = true
|
||||||
|
).also {
|
||||||
|
it.clickOnceListener = { _, _ ->
|
||||||
|
showTechViewUI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val menuButtonCraft = UIItemImageButton(
|
||||||
|
this, catIcons.get(19, 1),
|
||||||
|
initialX = panelToggleBarX,
|
||||||
|
initialY = getIconPosY(1),
|
||||||
|
highlightable = true
|
||||||
|
).also {
|
||||||
|
it.clickOnceListener = { _, _ ->
|
||||||
|
showCraftingUI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun resetUI() {
|
fun resetUI() {
|
||||||
transitionalCraftingUI.resetUI()
|
transitionalCraftingUI.resetUI()
|
||||||
transitionalTechtreePanel.resetUI()
|
transitionalTechtreePanel.resetUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showCraftingUI() {
|
|
||||||
transitionPanel.setLeftUIto(0)
|
|
||||||
transitionalCraftingUI.show()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun showTechViewUI() {
|
fun showTechViewUI() {
|
||||||
transitionPanel.setLeftUIto(1)
|
transitionPanel.setLeftUIto(1)
|
||||||
transitionalTechtreePanel.show()
|
transitionalTechtreePanel.show()
|
||||||
|
menuButtonTechView.highlighted = true
|
||||||
|
menuButtonCraft.highlighted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showCraftingUI() {
|
||||||
|
transitionPanel.setLeftUIto(0)
|
||||||
|
transitionalCraftingUI.show()
|
||||||
|
menuButtonTechView.highlighted = false
|
||||||
|
menuButtonCraft.highlighted = true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun showCraftingUIwithoutAnim() {
|
||||||
|
transitionPanel.setLeftUIto(0)
|
||||||
|
transitionalCraftingUI.show()
|
||||||
|
menuButtonTechView.highlighted = false
|
||||||
|
menuButtonCraft.highlighted = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private val specialUIitems = listOf(
|
||||||
|
menuButtonCraft, menuButtonTechView
|
||||||
|
)
|
||||||
|
|
||||||
override fun updateImpl(delta: Float) {
|
override fun updateImpl(delta: Float) {
|
||||||
uiItems.forEach { it.update(delta) }
|
uiItems.forEach { it.update(delta) }
|
||||||
|
|
||||||
@@ -59,15 +113,43 @@ class UICrafting(val full: UIInventoryFull?) : UICanvas(
|
|||||||
it.posX = full.transitionPanel.getOffX(0)
|
it.posX = full.transitionPanel.getOffX(0)
|
||||||
it.opacity = full.transitionPanel.getOpacity(0)
|
it.opacity = full.transitionPanel.getOpacity(0)
|
||||||
}
|
}
|
||||||
|
specialUIitems.forEach {
|
||||||
|
it.posX = it.initialX + full.transitionPanel.getOffX(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val cellHighlightNormalCol2 = UIItemInventoryCellCommonRes.defaultInventoryCellTheme.cellHighlightNormalCol.cpy().also { it.a /= 2f }
|
||||||
|
|
||||||
|
private val shader = App.loadShaderInline(UIHandler.SHADER_PROG_VERT, UIHandler.SHADER_PROG_FRAG)
|
||||||
|
|
||||||
override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
|
override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
|
||||||
|
batch.shader = null
|
||||||
|
|
||||||
if (full == null) {
|
if (full == null) {
|
||||||
UIInventoryFull.drawBackground(batch, opacity)
|
UIInventoryFull.drawBackground(batch, opacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
uiItems.forEach { it.render(frameDelta, batch, camera) }
|
// draw fake navbar //
|
||||||
|
// draw the tray
|
||||||
|
batch.color = Toolkit.Theme.COL_CELL_FILL
|
||||||
|
Toolkit.fillArea(batch, panelToggleBarX - 4, panelToggleBarY, panelToggleBarWidth, panelToggleBarHeight)
|
||||||
|
// cell border
|
||||||
|
batch.color = UIItemInventoryCellCommonRes.defaultInventoryCellTheme.cellHighlightNormalCol
|
||||||
|
Toolkit.drawBoxBorder(batch, panelToggleBarX - 4, panelToggleBarY, panelToggleBarWidth, panelToggleBarHeight)
|
||||||
|
// cell divider
|
||||||
|
batch.color = cellHighlightNormalCol2
|
||||||
|
Toolkit.drawStraightLine(batch, panelToggleBarX - 2, panelToggleBarY + panelToggleBarHeight/2, panelToggleBarX-2 + panelToggleBarWidth-4, 1, false)
|
||||||
|
|
||||||
|
|
||||||
|
transitionPanel.render(frameDelta, batch, camera)
|
||||||
|
|
||||||
|
// make transparency work for button
|
||||||
|
batch.shader = shader
|
||||||
|
shader.setUniformf("opacity", opacity)
|
||||||
|
specialUIitems.forEach {
|
||||||
|
it.render(frameDelta, batch, camera)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
@@ -76,11 +158,18 @@ class UICrafting(val full: UIInventoryFull?) : UICanvas(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
addUIitem(transitionPanel)
|
addUIitem(transitionPanel)
|
||||||
|
addUIitem(menuButtonTechView)
|
||||||
|
addUIitem(menuButtonCraft)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setPosition(x: Int, y: Int) {
|
/*override fun setPosition(x: Int, y: Int) {
|
||||||
transitionalCraftingUI.setPosition(x, y)
|
transitionalCraftingUI.setPosition(x, y)
|
||||||
transitionalTechtreePanel.setPosition(x, y)
|
transitionalTechtreePanel.setPosition(x, y)
|
||||||
|
}*/
|
||||||
|
|
||||||
|
override fun show() {
|
||||||
|
super.show()
|
||||||
|
showCraftingUIwithoutAnim() // default to the crafting UI. ALso highlights the right button initially
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doOpening(delta: Float) {
|
override fun doOpening(delta: Float) {
|
||||||
|
|||||||
@@ -123,8 +123,6 @@ 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
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
private val controlHelp: String
|
private val controlHelp: String
|
||||||
@@ -153,7 +151,7 @@ class UICraftingWorkbench(val inventoryUI: UIInventoryFull?, val parentContainer
|
|||||||
this,
|
this,
|
||||||
{ ingredients },
|
{ ingredients },
|
||||||
thisOffsetX,
|
thisOffsetX,
|
||||||
thisOffsetY + LAST_LINE_IN_GRID,
|
UICrafting.panelToggleBarY,
|
||||||
6, 1,
|
6, 1,
|
||||||
drawScrollOnRightside = false,
|
drawScrollOnRightside = false,
|
||||||
drawWallet = false,
|
drawWallet = false,
|
||||||
@@ -321,43 +319,11 @@ 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(
|
|
||||||
this, catIcons.get(20, 1),
|
|
||||||
initialX = itemListCraftable.navRemoCon.posX + 12,
|
|
||||||
initialY = getIconPosY2(0),
|
|
||||||
highlightable = true
|
|
||||||
).also {
|
|
||||||
it.clickOnceListener = { _, _ ->
|
|
||||||
parentContainer.showTechViewUI()
|
|
||||||
it.highlighted = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val menuButtonCraft = UIItemImageButton(
|
|
||||||
this, catIcons.get(19, 1),
|
|
||||||
initialX = itemListCraftable.navRemoCon.posX + 12,
|
|
||||||
initialY = getIconPosY2(1),
|
|
||||||
activeCol = Toolkit.Theme.COL_SELECTED,
|
|
||||||
inactiveCol = Toolkit.Theme.COL_SELECTED,
|
|
||||||
highlightable = true
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
addUIitem(itemListCraftable)
|
addUIitem(itemListCraftable)
|
||||||
addUIitem(itemListIngredients)
|
addUIitem(itemListIngredients)
|
||||||
addUIitem(playerThings)
|
addUIitem(playerThings)
|
||||||
addUIitem(spinnerCraftCount)
|
addUIitem(spinnerCraftCount)
|
||||||
addUIitem(buttonCraft)
|
addUIitem(buttonCraft)
|
||||||
// temporarily disabled for 0.4 release
|
|
||||||
if (TerrarumAppConfiguration.VERSION_RAW >= 0x0000_000005_000000) {
|
|
||||||
addUIitem(menuButtonCraft)
|
|
||||||
addUIitem(menuButtonTechView)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun filterPlayerListUsing(recipe: CraftingCodex.CraftingRecipe?) {
|
private fun filterPlayerListUsing(recipe: CraftingCodex.CraftingRecipe?) {
|
||||||
@@ -487,7 +453,7 @@ class UICraftingWorkbench(val inventoryUI: UIInventoryFull?, val parentContainer
|
|||||||
val ingredientsLabel = Lang["GAME_INVENTORY_INGREDIENTS"]
|
val ingredientsLabel = Lang["GAME_INVENTORY_INGREDIENTS"]
|
||||||
|
|
||||||
App.fontGame.draw(batch, craftingLabel, thisOffsetX + (cellsWidth - App.fontGame.getWidth(craftingLabel)) / 2, thisOffsetY - INVENTORY_NAME_TEXT_GAP)
|
App.fontGame.draw(batch, craftingLabel, thisOffsetX + (cellsWidth - App.fontGame.getWidth(craftingLabel)) / 2, thisOffsetY - INVENTORY_NAME_TEXT_GAP)
|
||||||
App.fontGame.draw(batch, ingredientsLabel, thisOffsetX + (cellsWidth - App.fontGame.getWidth(ingredientsLabel)) / 2, thisOffsetY + LAST_LINE_IN_GRID - INVENTORY_NAME_TEXT_GAP)
|
App.fontGame.draw(batch, ingredientsLabel, thisOffsetX + (cellsWidth - App.fontGame.getWidth(ingredientsLabel)) / 2, thisOffsetY + UICrafting.LAST_LINE_IN_GRID - INVENTORY_NAME_TEXT_GAP)
|
||||||
|
|
||||||
|
|
||||||
// control hints
|
// control hints
|
||||||
@@ -527,6 +493,7 @@ class UICraftingWorkbench(val inventoryUI: UIInventoryFull?, val parentContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
data class RecipeIngredientRecord(
|
data class RecipeIngredientRecord(
|
||||||
val selectedItem: ItemID,
|
val selectedItem: ItemID,
|
||||||
val howManyPlayerHas: Long,
|
val howManyPlayerHas: Long,
|
||||||
|
|||||||
@@ -39,59 +39,13 @@ class UITechView(val inventoryUI: UIInventoryFull?, val parentContainer: UICraft
|
|||||||
private val panelHeight = parentContainer.transitionalCraftingUI.itemListCraftable.height +
|
private val panelHeight = parentContainer.transitionalCraftingUI.itemListCraftable.height +
|
||||||
parentContainer.transitionalCraftingUI.itemListIngredients.height + 64 // 64 is a magic number
|
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 menuButtonTechView = UIItemImageButton(
|
|
||||||
this, catIcons.get(20, 1),
|
|
||||||
initialX = navbarX,
|
|
||||||
initialY = getIconPosY(0),
|
|
||||||
activeCol = Toolkit.Theme.COL_SELECTED,
|
|
||||||
inactiveCol = Toolkit.Theme.COL_SELECTED,
|
|
||||||
highlightable = false
|
|
||||||
)
|
|
||||||
private val menuButtonCraft = UIItemImageButton(
|
|
||||||
this, catIcons.get(19, 1),
|
|
||||||
initialX = navbarX,
|
|
||||||
initialY = getIconPosY(1),
|
|
||||||
highlightable = true
|
|
||||||
).also {
|
|
||||||
it.clickOnceListener = { _, _ ->
|
|
||||||
parentContainer.showCraftingUI()
|
|
||||||
it.highlighted = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getIconPosY(index: Int) = (fakeNavbarY + ((index*2+1)/4f) * navbarHeight).roundToInt() - catIcons.tileH/2
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
addUIitem(menuButtonCraft)
|
|
||||||
addUIitem(menuButtonTechView)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 the tray
|
|
||||||
batch.color = Toolkit.Theme.COL_CELL_FILL
|
|
||||||
Toolkit.fillArea(batch, navbarX - 4, navbarY, navbarWidth, navbarHeight)
|
|
||||||
// cell border
|
|
||||||
batch.color = colourTheme.cellHighlightNormalCol
|
|
||||||
Toolkit.drawBoxBorder(batch, navbarX - 4, navbarY, navbarWidth, navbarHeight)
|
|
||||||
// cell divider
|
|
||||||
batch.color = cellHighlightNormalCol2
|
|
||||||
Toolkit.drawStraightLine(batch, navbarX - 2, navbarY + navbarHeight/2, navbarX-2 + navbarWidth-4, 1, false)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// draw window //
|
// draw window //
|
||||||
batch.color = Toolkit.Theme.COL_CELL_FILL
|
batch.color = Toolkit.Theme.COL_CELL_FILL
|
||||||
Toolkit.fillArea(batch, panelX, panelY, panelWidth, panelHeight)
|
Toolkit.fillArea(batch, panelX, panelY, panelWidth, panelHeight)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class UIHandler(//var UI: UICanvas,
|
|||||||
var alwaysUpdate = false
|
var alwaysUpdate = false
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val SHADER_PROG_FRAG = """
|
val SHADER_PROG_FRAG = """
|
||||||
#ifdef GL_ES
|
#ifdef GL_ES
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
#endif
|
#endif
|
||||||
@@ -55,7 +55,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
private val SHADER_PROG_VERT = """
|
val SHADER_PROG_VERT = """
|
||||||
in vec4 a_position;
|
in vec4 a_position;
|
||||||
in vec4 a_color;
|
in vec4 a_color;
|
||||||
in vec4 a_generic;
|
in vec4 a_generic;
|
||||||
|
|||||||
Reference in New Issue
Block a user