From 9fa28760fa4625cda2d6e09080965ba41749dcc0 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 30 Jan 2024 01:37:03 +0900 Subject: [PATCH] all the gauges for uismelter --- src/net/torvald/colourutil/CIELuvUtil.kt | 3 +- .../gameactors/FixtureSmelterBasic.kt | 2 +- .../modulebasegame/ui/UIInventoryCells.kt | 2 +- .../modulebasegame/ui/UISmelterBasic.kt | 85 +++++++++++++++++-- 4 files changed, 83 insertions(+), 9 deletions(-) diff --git a/src/net/torvald/colourutil/CIELuvUtil.kt b/src/net/torvald/colourutil/CIELuvUtil.kt index 08cb966d0..1bdd76067 100644 --- a/src/net/torvald/colourutil/CIELuvUtil.kt +++ b/src/net/torvald/colourutil/CIELuvUtil.kt @@ -30,7 +30,6 @@ fun Color.darkerLuv(scale: Float): Color { return luv.toColor() } -/** Tend to have more vivid (or saturated) colour */ fun cieluv_getGradient(scale: Float, fromCol: Color, toCol: Color): Color { val from = fromCol.toLuv() val to = toCol.toLuv() @@ -39,7 +38,7 @@ fun cieluv_getGradient(scale: Float, fromCol: Color, toCol: Color): Color { val newV = FastMath.interpolateLinear(scale, from.v, to.v) val newAlpha = FastMath.interpolateLinear(scale, from.alpha, to.alpha) - return CIELab(newL, newU, newV, newAlpha).toColor() + return CIELuv(newL, newU, newV, newAlpha).toColor() } /** diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSmelterBasic.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSmelterBasic.kt index de7d81bee..a8840f27e 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSmelterBasic.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSmelterBasic.kt @@ -27,7 +27,7 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation { var fuelCaloriesNow = 0f var fuelCaloriesMax: Float? = null var temperature = 0f // 0f..1f - var progress = 0f + var progress = 0f // 0f..1f var oreItem: InventoryPair? = null var fireboxItem: InventoryPair? = null diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt index f42046fe3..15b31fbd4 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt @@ -48,7 +48,7 @@ internal class UIInventoryCells( // encumbrance bar background blendNormalStraightAlpha(batch) val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f) - val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening + val encumbBack = Toolkit.Theme.COL_CELL_FILL batch.color = encumbBack Toolkit.fillArea( batch, diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UISmelterBasic.kt b/src/net/torvald/terrarum/modulebasegame/ui/UISmelterBasic.kt index 97f32cef4..bb7ca84a6 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UISmelterBasic.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UISmelterBasic.kt @@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.colourutil.cieluv_getGradient import net.torvald.terrarum.* import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.langpack.Lang @@ -88,15 +89,18 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas( private val backdropX = (leftPanelX + (leftPanelWidth - smelterBackdrop.regionWidth * backdropZoom) / 2).toFloat() private val backdropY = (leftPanelY + (leftPanelHeight - smelterBackdrop.regionHeight * backdropZoom) / 2).toFloat() - private val oreX = backdropX + 12 * backdropZoom + 3 + private val oreX = backdropX + 12 * backdropZoom + 6 private val oreY = backdropY + 23 * backdropZoom + 3 - private val fireboxX = backdropX + 12 * backdropZoom + 3 + private val fireboxX = backdropX + 12 * backdropZoom + 6 private val fireboxY = backdropY + 39 * backdropZoom + 3 private val productX = backdropX + 37 * backdropZoom + 3 private val productY = backdropY + 39 * backdropZoom + 3 + private val thermoX = (backdropX + 28 * backdropZoom + 1).toInt() + private val thermoY = (backdropY + 39 * backdropZoom + 3).toInt() + /* Click on the button when item is there: ButtonPrimary: take all the item @@ -182,7 +186,6 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas( private val productItemslot: UIItemInventoryElemSimple = UIItemInventoryElemSimple( this, productX.toInt(), productY.toInt(), emptyCellIcon = smelterCellIcons.get(1, 0), - updateOnNull = true, keyDownFun = { _, _, _, _, _ -> }, touchDownFun = { _, _, button, _, self -> if (smelter.productItem != null) { @@ -295,7 +298,9 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas( uiItems.forEach { it.render(frameDelta, batch, camera) } - + drawProgressGauge(batch, oreItemSlot.posX, oreItemSlot.posY, smelter.progress) + drawProgressGauge(batch, fireboxItemSlot.posX, fireboxItemSlot.posY, smelter.fuelCaloriesNow / (smelter.fuelCaloriesMax ?: Float.POSITIVE_INFINITY)) + drawThermoGauge(batch, thermoX, thermoY, smelter.temperature) // control hints @@ -316,10 +321,80 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas( blendNormalStraightAlpha(batch) } - override fun dispose() { + private val colProgress = Color(0xbbbbbbff.toInt()) + private val colTemp1 = Color(0x99000bff.toInt()) + private val colTemp2 = Color(0xffe200ff.toInt()) + + + + /** + * @param x x-position of the inventory cell that will have the gauge + * @param y y-position of the inventory cell that will have the gauge + */ + private fun drawProgressGauge(batch: SpriteBatch, x: Int, y: Int, percentage: Float) { + batch.color = Toolkit.Theme.COL_CELL_FILL + Toolkit.fillArea(batch, x - 7, y, 6, UIItemInventoryElemSimple.height) + + batch.color = Toolkit.Theme.COL_INVENTORY_CELL_BORDER + Toolkit.drawStraightLine(batch, x - 7, y - 1, x - 1, 1, false) + Toolkit.drawStraightLine(batch, x - 7, y + UIItemInventoryElemSimple.height, x - 1, 1, false) + Toolkit.drawStraightLine(batch, x - 8, y, y + UIItemInventoryElemSimple.height, 1, true) + + batch.color = colProgress + Toolkit.fillArea(batch, x - 7, y + UIItemInventoryElemSimple.height, 6, -(percentage * UIItemInventoryElemSimple.height).roundToInt()) + } + + private fun drawThermoGauge(batch: SpriteBatch, x: Int, y: Int, percentage: Float) { + batch.color = Toolkit.Theme.COL_INVENTORY_CELL_BORDER + Toolkit.drawStraightLine(batch, x, y - 1, x + 4, 1, false) + Toolkit.drawStraightLine(batch, x, y + UIItemInventoryElemSimple.height + 7, x + 4, 1, false) + + Toolkit.drawStraightLine(batch, x - 1, y, y + UIItemInventoryElemSimple.height, 1, true) + Toolkit.drawStraightLine(batch, x + 4, y, y + UIItemInventoryElemSimple.height, 1, true) + Toolkit.drawStraightLine(batch, x - 1, y + UIItemInventoryElemSimple.height + 6, y + UIItemInventoryElemSimple.height + 7, 1, true) + Toolkit.drawStraightLine(batch, x + 4, y + UIItemInventoryElemSimple.height + 6, y + UIItemInventoryElemSimple.height + 7, 1, true) + + Toolkit.drawStraightLine(batch, x - 2, y + UIItemInventoryElemSimple.height, y + UIItemInventoryElemSimple.height + 1, 1, true) + Toolkit.drawStraightLine(batch, x + 5, y + UIItemInventoryElemSimple.height, y + UIItemInventoryElemSimple.height + 1, 1, true) + Toolkit.drawStraightLine(batch, x - 2, y + UIItemInventoryElemSimple.height + 5, y + UIItemInventoryElemSimple.height + 6, 1, true) + Toolkit.drawStraightLine(batch, x + 5, y + UIItemInventoryElemSimple.height + 5, y + UIItemInventoryElemSimple.height + 6, 1, true) + + Toolkit.drawStraightLine(batch, x - 3, y + UIItemInventoryElemSimple.height + 1, y + UIItemInventoryElemSimple.height + 5, 1, true) + Toolkit.drawStraightLine(batch, x + 6, y + UIItemInventoryElemSimple.height + 1, y + UIItemInventoryElemSimple.height + 5, 1, true) + + + batch.color = cieluv_getGradient(percentage, colTemp1, colTemp2) + Toolkit.fillArea(batch, x, y + UIItemInventoryElemSimple.height, 4, -(percentage * UIItemInventoryElemSimple.height).roundToInt()) + + Toolkit.fillArea(batch, x, y + UIItemInventoryElemSimple.height, 4, 6) + Toolkit.fillArea(batch, x - 1, y + UIItemInventoryElemSimple.height + 1, 6, 4) } + override fun doOpening(delta: Float) { + super.doOpening(delta) + INGAME.disablePlayerControl() + INGAME.setTooltipMessage(null) + } + + override fun doClosing(delta: Float) { + super.doClosing(delta) + INGAME.resumePlayerControl() + INGAME.setTooltipMessage(null) + } + + override fun endOpening(delta: Float) { + super.endOpening(delta) + } + + override fun endClosing(delta: Float) { + super.endClosing(delta) + UIItemInventoryItemGrid.tooltipShowing.clear() + INGAME.setTooltipMessage(null) // required! + } + + override fun dispose() { + } } \ No newline at end of file