buildingmaker working terrain/wall palette

This commit is contained in:
minjaesong
2023-10-21 20:03:03 +09:00
parent e88b595320
commit 6e90d3521b
5 changed files with 66 additions and 24 deletions

View File

@@ -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

View File

@@ -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)
}
}

View File

@@ -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<UIItemImageButton>()
val paletteTerrain = ArrayList<UIItemImageButton>()
val paletteWall = ArrayList<UIItemImageButton>()
private val palettes = listOf(
paletteTerrain, paletteWall
)
var currentPaletteSelection = 0
val currentPalette: ArrayList<UIItemImageButton>
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 <E> List<E>.visible: List<E>
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)
}

View File

@@ -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()
}

View File

@@ -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)
}
}