diff --git a/src/net/torvald/terrarum/blockstats/MinimapComposer.kt b/src/net/torvald/terrarum/blockstats/MinimapComposer.kt index 878e7a2fb..c2eb1c2ea 100644 --- a/src/net/torvald/terrarum/blockstats/MinimapComposer.kt +++ b/src/net/torvald/terrarum/blockstats/MinimapComposer.kt @@ -16,6 +16,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIInventoryMinimap.Companion.MINIM import net.torvald.terrarum.modulebasegame.ui.UIInventoryMinimap.Companion.MINIMAP_WIDTH import net.torvald.terrarum.sqr import net.torvald.terrarum.toInt +import net.torvald.terrarum.worlddrawer.CreateTileAtlas.Companion.WALL_OVERLAY_COLOUR import java.util.concurrent.Callable import java.util.concurrent.atomic.AtomicInteger import kotlin.math.absoluteValue @@ -150,7 +151,7 @@ object MinimapComposer : Disposable { val tileTerr = world.getTileFromTerrain(x, y) val wallTerr = world.getTileFromWall(x, y) val colTerr = App.tileMaker.terrainTileColourMap.get(tileTerr)!!.toGdxColor() - val colWall = App.tileMaker.terrainTileColourMap.get(wallTerr)!!.toGdxColor().mul(App.tileMaker.wallOverlayColour) + val colWall = App.tileMaker.terrainTileColourMap.get(wallTerr)!!.toGdxColor().mul(WALL_OVERLAY_COLOUR) var outCol = if (y < 0) oobColTop diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/SledgehammerCore.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/SledgehammerCore.kt index 71c6ca608..62233dcb8 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/SledgehammerCore.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/SledgehammerCore.kt @@ -17,6 +17,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem import net.torvald.terrarum.modulebasegame.gameitems.SledgehammerCore.BASE_MASS_AND_SIZE import net.torvald.terrarum.modulebasegame.gameitems.SledgehammerCore.TOOL_DURABILITY_BASE import net.torvald.terrarum.worlddrawer.CreateTileAtlas +import net.torvald.terrarum.worlddrawer.CreateTileAtlas.Companion.WALL_OVERLAY_COLOUR import org.dyn4j.geometry.Vector2 import kotlin.math.roundToInt @@ -102,12 +103,12 @@ object SledgehammerCore { if (drop.isNotBlank()) { INGAME.queueActorAddition(DroppedItem("wall@$drop", (x + 0.5) * TILE_SIZED, (y + 1.0) * TILE_SIZED)) } - PickaxeCore.makeDust(wall, x, y, 9, App.tileMaker.wallOverlayColour) + PickaxeCore.makeDust(wall, x, y, 9, WALL_OVERLAY_COLOUR) } } // tile not busted if (Math.random() < actionInterval) { - PickaxeCore.makeDust(wall, x, y, 1, App.tileMaker.wallOverlayColour) + PickaxeCore.makeDust(wall, x, y, 1, WALL_OVERLAY_COLOUR) } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerBlockChooser.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerBlockChooser.kt index b8b4f068b..2a2bcb1d5 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerBlockChooser.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerBlockChooser.kt @@ -9,6 +9,7 @@ import net.torvald.terrarum.modulebasegame.BuildingMaker import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_WHITE import net.torvald.terrarum.ui.* import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_BACKGROUNDCOL +import net.torvald.terrarum.worlddrawer.CreateTileAtlas.Companion.WALL_OVERLAY_COLOUR import kotlin.math.roundToInt /** @@ -32,16 +33,30 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { override var height = HEIGHT override var openCloseTime = 0f - val palette = ArrayList() + val paletteTerrain = ArrayList() + val paletteWall = ArrayList() + + private val palettes = listOf( + paletteTerrain, paletteWall + ) + + var currentPaletteSelection = 0 + val currentPalette: ArrayList + get() = palettes[currentPaletteSelection] // TODO scrolling of the palette, as the old method flat out won't work with The Flattening private val tabs = UIItemTextButtonList( - this, 36, arrayOf("Terrain", "Wall", "Wire"), // TODO use inventory icons + this, 36, arrayOf("Terrain", "Wall"), // TODO use inventory icons 0, 0, textAreaWidth = MENUBAR_SIZE, width = MENUBAR_SIZE, defaultSelection = 0, backgroundCol = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL - ) + ).also { + it.selectionChangeListener = { _, new -> + resetScroll() + currentPaletteSelection = new + } + } private val closeButton = UIItemTextButtonList( this, 36, arrayOf("Close"), 0, this.height - UIItemTextButtonList.DEFAULT_LINE_HEIGHT, @@ -51,6 +66,17 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { private var scroll = 0 + private fun paletteScroll(delta: Int) { + currentPalette.forEach { + it.posY -= delta * TILESREGION_SIZE + } + } + + private fun resetScroll() { + scrollBar.scrolledForce(0f, scroll * -1f) + scroll = 0 + } + private val List.visible: List get() = this.subList( TILES_X * scroll, @@ -78,16 +104,30 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { activeCol = Color.WHITE, backgroundCol = Color(0) ) + val paletteItem2 = UIItemImageButton( + this, ItemCodex.getItemImage(prop.id)!!, + initialX = MENUBAR_SIZE + (index % TILES_X) * TILESREGION_SIZE, + initialY = (index / TILES_X) * TILESREGION_SIZE, + highlightable = false, + width = TILESREGION_SIZE, + height = TILESREGION_SIZE, + highlightCol = Color.WHITE, + activeCol = WALL_OVERLAY_COLOUR, + inactiveCol = WALL_OVERLAY_COLOUR, + backgroundCol = Color(0) + ) - paletteItem.clickOnceListener = { _, _ -> - parent.setPencilColour(prop.id) - } + paletteItem.clickOnceListener = { _, _ -> parent.setPencilColour(prop.id) } + paletteItem2.clickOnceListener = { _, _ -> parent.setPencilColour("wall@"+prop.id) } + + paletteTerrain.add(paletteItem) + if (prop.isWallable) paletteWall.add(paletteItem2) - palette.add(paletteItem) } } - private val scrollOverflowSize = ((palette.size - TILES_X * TILES_Y).toDouble() / TILES_X).ceilToDouble().coerceAtLeast(0.0) + private val scrollOverflowSize: Double + get() = ((currentPalette.size - TILES_X * TILES_Y).toDouble() / TILES_X).ceilToDouble().coerceAtLeast(0.0) private val scrollBar = UIItemVertSlider( this, WIDTH - UIItemVertSlider.WIDTH, 0, 0.0, 0.0, scrollOverflowSize, height, (height * TILES_Y / (scrollOverflowSize + TILES_Y)).ceilToInt() @@ -98,16 +138,13 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { it.selectionChangeListener = { value -> val oldScroll = scroll scroll = value.roundToInt() - - palette.forEach { - it.posY -= (scroll - oldScroll) * TILESREGION_SIZE - } + paletteScroll(scroll - oldScroll) } } override fun updateUI(delta: Float) { - if (!scrollBar.mouseUp) palette.forEach { it.update(delta) } + if (!scrollBar.mouseUp) currentPalette.forEach { it.update(delta) } tabs.update(delta) closeButton.update(delta) if (closeButton.mousePushed) { @@ -115,7 +152,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { closeGracefully() } - palette.visible.forEach { + currentPalette.visible.forEach { it.update(delta) } @@ -150,7 +187,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { tabs.render(batch, camera) closeButton.render(batch, camera) - palette.visible.forEach { + currentPalette.visible.forEach { it.render(batch, camera) } @@ -187,7 +224,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { dragForReal = false } - palette.visible.forEach { + currentPalette.visible.forEach { it.touchDown(screenX, screenY, pointer, button) } diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt index a856f56dd..89e1bde78 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt @@ -15,6 +15,7 @@ import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.fmod +import net.torvald.terrarum.worlddrawer.CreateTileAtlas.Companion.WALL_OVERLAY_COLOUR import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import kotlin.math.roundToInt @@ -669,7 +670,7 @@ internal object BlocksDrawer { } val vertexColour = when (mode) { TERRAIN, /*WIRE,*/ ORES, FLUID, OCCLUSION -> Color.WHITE - WALL -> App.tileMaker.wallOverlayColour + WALL -> WALL_OVERLAY_COLOUR else -> throw IllegalArgumentException() } diff --git a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt index 1d7d9d47e..599412df8 100644 --- a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt +++ b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt @@ -31,6 +31,10 @@ import kotlin.math.sqrt */ class CreateTileAtlas { + companion object { + val WALL_OVERLAY_COLOUR = Color(.65f, .65f, .65f, 1f) + } + var MAX_TEX_SIZE = App.getConfigInt("atlastexsize").coerceIn(1024, App.glInfo.GL_MAX_TEXTURE_SIZE); private set var TILES_IN_X = MAX_TEX_SIZE / TILE_SIZE; private set @@ -38,8 +42,6 @@ class CreateTileAtlas { private var TOTAL_TILES = TILES_IN_X * TILES_IN_X - val wallOverlayColour = Color(.65f, .65f, .65f, 1f) - lateinit var atlasPrevernal: Pixmap lateinit var atlasVernal: Pixmap lateinit var atlasAestival: Pixmap @@ -250,9 +252,9 @@ class CreateTileAtlas { // darken things for the wall for (y in 0 until itemWallPixmap.height) { for (x in 0 until itemWallPixmap.width) { - val c1 = Color(itemWallPixmap.getPixel(x, y)).mulAndAssign(wallOverlayColour).toRGBA() + val c1 = Color(itemWallPixmap.getPixel(x, y)).mulAndAssign(WALL_OVERLAY_COLOUR).toRGBA() itemWallPixmap.drawPixel(x, y, c1) - val c2 = Color(itemWallPixmapGlow.getPixel(x, y)).mulAndAssign(wallOverlayColour).toRGBA() + val c2 = Color(itemWallPixmapGlow.getPixel(x, y)).mulAndAssign(WALL_OVERLAY_COLOUR).toRGBA() itemWallPixmapGlow.drawPixel(x, y, c2) } }