diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt index f35f217b..bd8076bc 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt @@ -1,6 +1,6 @@ package com.bartlomiejpluta.base.editor.map.canvas -import com.bartlomiejpluta.base.editor.map.model.layer.ImageLayer +import com.bartlomiejpluta.base.editor.map.model.layer.ColorLayer import com.bartlomiejpluta.base.editor.map.model.layer.Layer import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer @@ -51,7 +51,7 @@ class MapCanvas(val map: GameMapVM, private val editorStateVM: EditorStateVM, pr when (layer) { is TileLayer -> renderTileLayer(gc, layer) is ObjectLayer -> renderObjectPassageMap(gc, layer) - is ImageLayer -> renderImageLayer(gc, layer) + is ColorLayer -> renderColorLayer(gc, layer) } } @@ -86,12 +86,12 @@ class MapCanvas(val map: GameMapVM, private val editorStateVM: EditorStateVM, pr } } - private fun renderImageLayer(gc: GraphicsContext, imageLayer: ImageLayer) { + private fun renderColorLayer(gc: GraphicsContext, colorLayer: ColorLayer) { val alpha = gc.globalAlpha val color = gc.fill - gc.globalAlpha = imageLayer.alpha / 100.0 - gc.fill = Color.color(imageLayer.red / 100.0, imageLayer.green / 100.0, imageLayer.blue / 100.0) + gc.globalAlpha = colorLayer.alpha / 100.0 + gc.fill = Color.color(colorLayer.red / 100.0, colorLayer.green / 100.0, colorLayer.blue / 100.0) gc.fillRect(0.0, 0.0, map.width, map.height) gc.globalAlpha = alpha diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/layer/ImageLayer.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/layer/ColorLayer.kt similarity index 94% rename from editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/layer/ImageLayer.kt rename to editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/layer/ColorLayer.kt index b0de9d33..d6d88258 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/layer/ImageLayer.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/layer/ColorLayer.kt @@ -5,7 +5,7 @@ import javafx.beans.property.SimpleStringProperty import tornadofx.getValue import tornadofx.setValue -class ImageLayer(name: String) : Layer { +class ColorLayer(name: String) : Layer { override val nameProperty = SimpleStringProperty(name) override var name by nameProperty diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/parameter/layer/ImageLayerParametersBinder.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/parameter/layer/ColorLayerParametersBinder.kt similarity index 85% rename from editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/parameter/layer/ImageLayerParametersBinder.kt rename to editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/parameter/layer/ColorLayerParametersBinder.kt index 628de902..b643c5bf 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/parameter/layer/ImageLayerParametersBinder.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/parameter/layer/ColorLayerParametersBinder.kt @@ -2,13 +2,13 @@ package com.bartlomiejpluta.base.editor.map.parameter.layer import com.bartlomiejpluta.base.editor.common.parameter.model.IntegerParameter import com.bartlomiejpluta.base.editor.common.parameter.model.Parameter -import com.bartlomiejpluta.base.editor.map.model.layer.ImageLayer +import com.bartlomiejpluta.base.editor.map.model.layer.ColorLayer import javafx.collections.ObservableList import org.springframework.stereotype.Component @Component -class ImageLayerParametersBinder : LayerParametersBinder { - override fun bind(layer: ImageLayer, parameters: ObservableList>, onCommit: () -> Unit) { +class ColorLayerParametersBinder : LayerParametersBinder { + override fun bind(layer: ColorLayer, parameters: ObservableList>, onCommit: () -> Unit) { val red = IntegerParameter("red", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() } val green = IntegerParameter("green", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() } val blue = IntegerParameter("blue", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() } @@ -22,7 +22,7 @@ class ImageLayerParametersBinder : LayerParametersBinder { parameters.addAll(red, green, blue, alpha) } - override fun unbind(layer: ImageLayer, parameters: ObservableList>) { + override fun unbind(layer: ColorLayer, parameters: ObservableList>) { (parameters[0] as IntegerParameter).valueProperty.unbindBidirectional(layer.redProperty) (parameters[1] as IntegerParameter).valueProperty.unbindBidirectional(layer.greenProperty) (parameters[2] as IntegerParameter).valueProperty.unbindBidirectional(layer.blueProperty) diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt index f4b86828..a87e96b0 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt @@ -1,7 +1,7 @@ package com.bartlomiejpluta.base.editor.map.serial import com.bartlomiejpluta.base.editor.map.model.enumeration.PassageAbility -import com.bartlomiejpluta.base.editor.map.model.layer.ImageLayer +import com.bartlomiejpluta.base.editor.map.model.layer.ColorLayer import com.bartlomiejpluta.base.editor.map.model.layer.Layer import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer @@ -39,7 +39,7 @@ class ProtobufMapDeserializer : MapDeserializer { return when { proto.hasTileLayer() -> deserializeTileLayer(rows, columns, tileSet, proto) proto.hasObjectLayer() -> deserializeObjectLayer(rows, columns, proto) - proto.hasImageLayer() -> deserializeImageLayer(proto) + proto.hasColorLayer() -> deserializeColorLayer(proto) else -> throw IllegalStateException("Not supported layer type") } @@ -76,7 +76,7 @@ class ProtobufMapDeserializer : MapDeserializer { return ObjectLayer(proto.name, rows, columns, passageMap) } - private fun deserializeImageLayer(proto: GameMapProto.Layer): Layer { - return ImageLayer(proto.name) + private fun deserializeColorLayer(proto: GameMapProto.Layer): Layer { + return ColorLayer(proto.name) } } \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapSerializer.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapSerializer.kt index 900e613b..602090fd 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapSerializer.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapSerializer.kt @@ -1,7 +1,7 @@ package com.bartlomiejpluta.base.editor.map.serial import com.bartlomiejpluta.base.editor.map.model.enumeration.PassageAbility -import com.bartlomiejpluta.base.editor.map.model.layer.ImageLayer +import com.bartlomiejpluta.base.editor.map.model.layer.ColorLayer import com.bartlomiejpluta.base.editor.map.model.layer.Layer import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer @@ -48,9 +48,9 @@ class ProtobufMapSerializer : MapSerializer { .build() .let { GameMapProto.Layer.newBuilder().setName(layer.name).setObjectLayer(it).build() } - is ImageLayer -> GameMapProto.ImageLayer.newBuilder() + is ColorLayer -> GameMapProto.ColorLayer.newBuilder() .build() - .let { GameMapProto.Layer.newBuilder().setName(layer.name).setImageLayer(it).build() } + .let { GameMapProto.Layer.newBuilder().setName(layer.name).setColorLayer(it).build() } else -> throw IllegalStateException("Not supported layer type") } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayerParameters.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayerParameters.kt index 3c450309..ab28dabb 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayerParameters.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayerParameters.kt @@ -3,8 +3,8 @@ package com.bartlomiejpluta.base.editor.map.view.editor import com.bartlomiejpluta.base.editor.common.parameter.model.Parameter import com.bartlomiejpluta.base.editor.common.parameter.view.ParametersTableFragment import com.bartlomiejpluta.base.editor.event.RedrawMapRequestEvent -import com.bartlomiejpluta.base.editor.map.model.layer.ImageLayer -import com.bartlomiejpluta.base.editor.map.parameter.layer.ImageLayerParametersBinder +import com.bartlomiejpluta.base.editor.map.model.layer.ColorLayer +import com.bartlomiejpluta.base.editor.map.parameter.layer.ColorLayerParametersBinder import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM import tornadofx.View import tornadofx.observableListOf @@ -14,20 +14,20 @@ class MapLayerParameters : View() { // For some reason Spring does not want to autowire a list of beans // of LayerParametersBinder<> type - private val imageLayerParametersBinder: ImageLayerParametersBinder by di() + private val colorLayerParametersBinder: ColorLayerParametersBinder by di() private val parameters = observableListOf>() init { editorStateVM.selectedLayerProperty.addListener { _, previousLayer, layer -> when (previousLayer) { - is ImageLayer -> imageLayerParametersBinder.unbind(previousLayer, parameters) + is ColorLayer -> colorLayerParametersBinder.unbind(previousLayer, parameters) } parameters.clear() when (layer) { - is ImageLayer -> imageLayerParametersBinder.bind(layer, parameters) { fire(RedrawMapRequestEvent) } + is ColorLayer -> colorLayerParametersBinder.bind(layer, parameters) { fire(RedrawMapRequestEvent) } } } } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayersView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayersView.kt index 91638882..64f9d779 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayersView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayersView.kt @@ -7,7 +7,7 @@ import com.bartlomiejpluta.base.editor.command.model.map.RemoveLayerCommand import com.bartlomiejpluta.base.editor.command.model.map.RenameLayerCommand import com.bartlomiejpluta.base.editor.command.service.UndoRedoService import com.bartlomiejpluta.base.editor.event.RedrawMapRequestEvent -import com.bartlomiejpluta.base.editor.map.model.layer.ImageLayer +import com.bartlomiejpluta.base.editor.map.model.layer.ColorLayer import com.bartlomiejpluta.base.editor.map.model.layer.Layer import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer @@ -50,7 +50,7 @@ class MapLayersView : View() { bottom = toolbar { menubutton(graphic = FontIcon("fa-plus")) { - item("Tile Layer", graphic = FontIcon("fa-th")) { + item("Tile Layer", graphic = FontIcon("fa-th-large")) { action { val layer = TileLayer("Layer ${mapVM.layers.size + 1}", mapVM.rows, mapVM.columns) val command = CreateLayerCommand(mapVM.item, layer) @@ -70,9 +70,9 @@ class MapLayersView : View() { } } - item("Image Layer", graphic = FontIcon("fa-image")) { + item("Color Layer", graphic = FontIcon("fa-paint-brush")) { action { - val layer = ImageLayer("Layer ${mapVM.layers.size + 1}") + val layer = ColorLayer("Layer ${mapVM.layers.size + 1}") val command = CreateLayerCommand(mapVM.item, layer) command.execute() layersPane.selectionModel.select(mapVM.layers.size - 1) @@ -161,9 +161,9 @@ class MapLayersView : View() { text = item.name graphic = when (item) { - is TileLayer -> FontIcon("fa-th") + is TileLayer -> FontIcon("fa-th-large") is ObjectLayer -> FontIcon("fa-cube") - is ImageLayer -> FontIcon("fa-image") + is ColorLayer -> FontIcon("fa-paint-brush") else -> throw IllegalStateException("Unknown layer type") } } diff --git a/game/src/main/java/com/bartlomiejpluta/base/game/map/serial/ProtobufMapDeserializer.java b/game/src/main/java/com/bartlomiejpluta/base/game/map/serial/ProtobufMapDeserializer.java index db28da45..a441fa01 100644 --- a/game/src/main/java/com/bartlomiejpluta/base/game/map/serial/ProtobufMapDeserializer.java +++ b/game/src/main/java/com/bartlomiejpluta/base/game/map/serial/ProtobufMapDeserializer.java @@ -34,6 +34,8 @@ public class ProtobufMapDeserializer extends MapDeserializer { deserializeTileLayer(map, proto); } else if (proto.hasObjectLayer()) { deserializeObjectLayer(map, proto); + } else if (proto.hasColorLayer()) { + deserializeColorLayer(map, proto); } else if (proto.hasImageLayer()) { deserializeImageLayer(map, proto); } else { @@ -74,6 +76,10 @@ public class ProtobufMapDeserializer extends MapDeserializer { } } + private void deserializeColorLayer(GameMap map, GameMapProto.Layer proto) { + // TODO(return new ColorLayer(...)) + } + private void deserializeImageLayer(GameMap map, GameMapProto.Layer proto) { // TODO(return new ImageLayer(...)) } diff --git a/proto/src/main/proto/map.proto b/proto/src/main/proto/map.proto index c7136b33..582c8743 100644 --- a/proto/src/main/proto/map.proto +++ b/proto/src/main/proto/map.proto @@ -17,7 +17,8 @@ message Layer { oneof layer { TileLayer tileLayer = 2; ObjectLayer objectLayer = 3; - ImageLayer imageLayer = 4; + ColorLayer colorLayer = 4; + ImageLayer imageLayer = 5; } } @@ -39,6 +40,10 @@ enum PassageAbility { } message ImageLayer { - // TODO optional imageUID // TODO r, g, b, alpha +} + +message ColorLayer { + // TODO imageUID + // TODO imageMode } \ No newline at end of file