mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
wip 2
This commit is contained in:
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.BuildingMaker
|
||||
@@ -14,6 +15,7 @@ import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItemImageButton
|
||||
import net.torvald.terrarum.ui.UIItemTextButtonList
|
||||
import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_BACKGROUNDCOL
|
||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
@@ -37,19 +39,10 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
||||
override var height = HEIGHT
|
||||
override var openCloseTime = 0f
|
||||
|
||||
private val palette = Array<UIItemImageButton>(TILES_X * TILES_Y) {
|
||||
// initialise with terrain blocks
|
||||
UIItemImageButton(
|
||||
this, ItemCodex.getItemImage(it),
|
||||
initialX = MENUBAR_SIZE + (it % 16) * TILESREGION_SIZE,
|
||||
initialY = (it / 16) * TILESREGION_SIZE,
|
||||
highlightable = false,
|
||||
width = TILESREGION_SIZE,
|
||||
height = TILESREGION_SIZE,
|
||||
highlightCol = Color.WHITE,
|
||||
activeCol = Color.WHITE
|
||||
)
|
||||
}
|
||||
val palette = ArrayList<UIItemImageButton>()
|
||||
|
||||
// TODO scrolling of the palette, as the old method flat out won't work with The Flattening
|
||||
|
||||
private val tabs = UIItemTextButtonList(
|
||||
this, arrayOf("Terrain", "Wall", "Wire"),
|
||||
0, 0, textAreaWidth = MENUBAR_SIZE, width = MENUBAR_SIZE,
|
||||
@@ -62,12 +55,25 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
||||
)
|
||||
|
||||
init {
|
||||
palette.forEachIndexed { index, it ->
|
||||
uiItems.add(it)
|
||||
|
||||
it.clickOnceListener = { _, _, _ ->
|
||||
parent.setPencilColour(paletteScroll * 16 + index)
|
||||
BlockCodex.getAll().forEachIndexed { index, prop ->
|
||||
val paletteItem = UIItemImageButton(
|
||||
this, ItemCodex.getItemImage(prop.id)!!,
|
||||
initialX = MENUBAR_SIZE + (index % 16) * TILESREGION_SIZE,
|
||||
initialY = (index / 16) * TILESREGION_SIZE,
|
||||
highlightable = false,
|
||||
width = TILESREGION_SIZE,
|
||||
height = TILESREGION_SIZE,
|
||||
highlightCol = Color.WHITE,
|
||||
activeCol = Color.WHITE
|
||||
)
|
||||
|
||||
paletteItem.clickOnceListener = { _, _, _ ->
|
||||
parent.setPencilColour(prop.id)
|
||||
}
|
||||
|
||||
uiItems.add(paletteItem)
|
||||
palette.add(paletteItem)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,9 +125,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
||||
}
|
||||
|
||||
private fun rebuildPalette() {
|
||||
palette.forEachIndexed { index, it ->
|
||||
it.image = ItemCodex.getItemImage(paletteScroll * 16 + index)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
@@ -153,7 +153,7 @@ class UIBuildingMakerPenMenu(val parent: BuildingMaker): UICanvas() {
|
||||
|
||||
// draw blocks slot
|
||||
batch.color = blockCellCol
|
||||
val slotConfig = AppLoader.getConfigIntArray("buildingmakerfavs")
|
||||
val slotConfig = AppLoader.getConfigStringArray("buildingmakerfavs")
|
||||
for (i in 0 until PALETTE_SIZE) {
|
||||
val x = blockCellPos[i].x.roundToInt().toFloat()
|
||||
val y = blockCellPos[i].y.roundToInt().toFloat()
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.gameitem.ItemID
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.BuildingMaker
|
||||
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
|
||||
@@ -31,8 +32,8 @@ class UIPaletteSelector(val parent: BuildingMaker) : UICanvas() {
|
||||
fun mouseOnTitleBar() =
|
||||
relativeMouseX in 0 until width && relativeMouseY in 0 until LINE_HEIGHT
|
||||
|
||||
var fore = Block.STONE_BRICKS
|
||||
var back = Block.GLASS_CRUDE
|
||||
var fore: ItemID = Block.STONE_BRICKS
|
||||
var back: ItemID = Block.GLASS_CRUDE
|
||||
|
||||
private val titleText = "Pal."
|
||||
|
||||
@@ -102,10 +103,9 @@ class UIPaletteSelector(val parent: BuildingMaker) : UICanvas() {
|
||||
}
|
||||
|
||||
fun swapForeAndBack() {
|
||||
// xor used, because why not?
|
||||
fore = fore xor back
|
||||
back = back xor fore
|
||||
fore = fore xor back
|
||||
val t = fore
|
||||
fore = back
|
||||
back = t
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
|
||||
Reference in New Issue
Block a user