[Editor] Add tiled background to tileset

This commit is contained in:
2021-02-05 08:31:32 +01:00
parent eb14c98baf
commit 85e4d7ac02
2 changed files with 12 additions and 3 deletions

View File

@@ -8,8 +8,9 @@ import com.bartlomiejpluta.base.editor.render.model.Renderable
import javafx.scene.canvas.GraphicsContext
import javafx.scene.input.MouseButton
import javafx.scene.input.MouseEvent
import javafx.scene.paint.Color
class TileSetCanvas(tileSet: TileSet, selectionCallback: (Array<Array<Tile>>) -> Unit) : Renderable, MapMouseEventHandler {
class TileSetCanvas(private val tileSet: TileSet, selectionCallback: (Array<Array<Tile>>) -> Unit) : Renderable, MapMouseEventHandler {
private val tiles = tileSet.tiles
private var selection = TileSetSelection(tileSet, selectionCallback)
@@ -26,6 +27,8 @@ class TileSetCanvas(tileSet: TileSet, selectionCallback: (Array<Array<Tile>>) ->
private fun renderTiles(gc: GraphicsContext) {
for ((row, columns) in tiles.withIndex()) {
for ((column, tile) in columns.withIndex()) {
gc.fill = if((row+column) % 2 == 0) BACKGROUND_COLOR1 else BACKGROUND_COLOR2
gc.fillRect(column * tile.image.width, row * tile.image.height, tileSet.tileWidth.toDouble(), tileSet.tileHeight.toDouble())
gc.drawImage(tile.image, column * tile.image.width, row * tile.image.height)
}
}
@@ -59,4 +62,10 @@ class TileSetCanvas(tileSet: TileSet, selectionCallback: (Array<Array<Tile>>) ->
selection.finish(event.row.toDouble(), event.column.toDouble())
}
}
companion object {
private val BACKGROUND_COLOR1 = Color.color(1.0, 1.0, 1.0, 1.0)
private val BACKGROUND_COLOR2 = Color.color(0.95, 0.95, 0.95, 0.95)
private const val BACKGROUND_TILE_SIZE_FACTOR = 4.0
}
}

View File

@@ -52,7 +52,7 @@ class MapFragment : Fragment() {
}
right = drawer(multiselect = true) {
item("Layers") {
item("Layers", expanded = true) {
borderpane {
center = listview(observableListOf("Layer 1", "Layer 2", "Layer 3", "Layer 4", "Layer 5", "Layer 6"))
bottom = hbox {
@@ -64,7 +64,7 @@ class MapFragment : Fragment() {
}
}
item("Tile Set") {
item("Tile Set", expanded = true) {
scrollpane {
maxHeightProperty().bind(this@item.heightProperty())
this += tileSetPane