[Editor] Split ImageLayer to ColorLayer and ImageLayer
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package com.bartlomiejpluta.base.editor.map.canvas
|
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.Layer
|
||||||
import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer
|
import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer
|
||||||
import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer
|
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) {
|
when (layer) {
|
||||||
is TileLayer -> renderTileLayer(gc, layer)
|
is TileLayer -> renderTileLayer(gc, layer)
|
||||||
is ObjectLayer -> renderObjectPassageMap(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 alpha = gc.globalAlpha
|
||||||
val color = gc.fill
|
val color = gc.fill
|
||||||
|
|
||||||
gc.globalAlpha = imageLayer.alpha / 100.0
|
gc.globalAlpha = colorLayer.alpha / 100.0
|
||||||
gc.fill = Color.color(imageLayer.red / 100.0, imageLayer.green / 100.0, imageLayer.blue / 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.fillRect(0.0, 0.0, map.width, map.height)
|
||||||
|
|
||||||
gc.globalAlpha = alpha
|
gc.globalAlpha = alpha
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import javafx.beans.property.SimpleStringProperty
|
|||||||
import tornadofx.getValue
|
import tornadofx.getValue
|
||||||
import tornadofx.setValue
|
import tornadofx.setValue
|
||||||
|
|
||||||
class ImageLayer(name: String) : Layer {
|
class ColorLayer(name: String) : Layer {
|
||||||
override val nameProperty = SimpleStringProperty(name)
|
override val nameProperty = SimpleStringProperty(name)
|
||||||
|
|
||||||
override var name by nameProperty
|
override var name by nameProperty
|
||||||
@@ -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.IntegerParameter
|
||||||
import com.bartlomiejpluta.base.editor.common.parameter.model.Parameter
|
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 javafx.collections.ObservableList
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class ImageLayerParametersBinder : LayerParametersBinder<ImageLayer> {
|
class ColorLayerParametersBinder : LayerParametersBinder<ColorLayer> {
|
||||||
override fun bind(layer: ImageLayer, parameters: ObservableList<Parameter<*>>, onCommit: () -> Unit) {
|
override fun bind(layer: ColorLayer, parameters: ObservableList<Parameter<*>>, onCommit: () -> Unit) {
|
||||||
val red = IntegerParameter("red", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() }
|
val red = IntegerParameter("red", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() }
|
||||||
val green = IntegerParameter("green", 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() }
|
val blue = IntegerParameter("blue", 100, 0, 100, autocommit = true) { _, _, _ -> onCommit() }
|
||||||
@@ -22,7 +22,7 @@ class ImageLayerParametersBinder : LayerParametersBinder<ImageLayer> {
|
|||||||
parameters.addAll(red, green, blue, alpha)
|
parameters.addAll(red, green, blue, alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unbind(layer: ImageLayer, parameters: ObservableList<Parameter<*>>) {
|
override fun unbind(layer: ColorLayer, parameters: ObservableList<Parameter<*>>) {
|
||||||
(parameters[0] as IntegerParameter).valueProperty.unbindBidirectional(layer.redProperty)
|
(parameters[0] as IntegerParameter).valueProperty.unbindBidirectional(layer.redProperty)
|
||||||
(parameters[1] as IntegerParameter).valueProperty.unbindBidirectional(layer.greenProperty)
|
(parameters[1] as IntegerParameter).valueProperty.unbindBidirectional(layer.greenProperty)
|
||||||
(parameters[2] as IntegerParameter).valueProperty.unbindBidirectional(layer.blueProperty)
|
(parameters[2] as IntegerParameter).valueProperty.unbindBidirectional(layer.blueProperty)
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.bartlomiejpluta.base.editor.map.serial
|
package com.bartlomiejpluta.base.editor.map.serial
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.map.model.enumeration.PassageAbility
|
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.Layer
|
||||||
import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer
|
import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer
|
||||||
import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer
|
import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer
|
||||||
@@ -39,7 +39,7 @@ class ProtobufMapDeserializer : MapDeserializer {
|
|||||||
return when {
|
return when {
|
||||||
proto.hasTileLayer() -> deserializeTileLayer(rows, columns, tileSet, proto)
|
proto.hasTileLayer() -> deserializeTileLayer(rows, columns, tileSet, proto)
|
||||||
proto.hasObjectLayer() -> deserializeObjectLayer(rows, columns, proto)
|
proto.hasObjectLayer() -> deserializeObjectLayer(rows, columns, proto)
|
||||||
proto.hasImageLayer() -> deserializeImageLayer(proto)
|
proto.hasColorLayer() -> deserializeColorLayer(proto)
|
||||||
|
|
||||||
else -> throw IllegalStateException("Not supported layer type")
|
else -> throw IllegalStateException("Not supported layer type")
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ class ProtobufMapDeserializer : MapDeserializer {
|
|||||||
return ObjectLayer(proto.name, rows, columns, passageMap)
|
return ObjectLayer(proto.name, rows, columns, passageMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeImageLayer(proto: GameMapProto.Layer): Layer {
|
private fun deserializeColorLayer(proto: GameMapProto.Layer): Layer {
|
||||||
return ImageLayer(proto.name)
|
return ColorLayer(proto.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.bartlomiejpluta.base.editor.map.serial
|
package com.bartlomiejpluta.base.editor.map.serial
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.map.model.enumeration.PassageAbility
|
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.Layer
|
||||||
import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer
|
import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer
|
||||||
import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer
|
import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer
|
||||||
@@ -48,9 +48,9 @@ class ProtobufMapSerializer : MapSerializer {
|
|||||||
.build()
|
.build()
|
||||||
.let { GameMapProto.Layer.newBuilder().setName(layer.name).setObjectLayer(it).build() }
|
.let { GameMapProto.Layer.newBuilder().setName(layer.name).setObjectLayer(it).build() }
|
||||||
|
|
||||||
is ImageLayer -> GameMapProto.ImageLayer.newBuilder()
|
is ColorLayer -> GameMapProto.ColorLayer.newBuilder()
|
||||||
.build()
|
.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")
|
else -> throw IllegalStateException("Not supported layer type")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.model.Parameter
|
||||||
import com.bartlomiejpluta.base.editor.common.parameter.view.ParametersTableFragment
|
import com.bartlomiejpluta.base.editor.common.parameter.view.ParametersTableFragment
|
||||||
import com.bartlomiejpluta.base.editor.event.RedrawMapRequestEvent
|
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.parameter.layer.ImageLayerParametersBinder
|
import com.bartlomiejpluta.base.editor.map.parameter.layer.ColorLayerParametersBinder
|
||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
||||||
import tornadofx.View
|
import tornadofx.View
|
||||||
import tornadofx.observableListOf
|
import tornadofx.observableListOf
|
||||||
@@ -14,20 +14,20 @@ class MapLayerParameters : View() {
|
|||||||
|
|
||||||
// For some reason Spring does not want to autowire a list of beans
|
// For some reason Spring does not want to autowire a list of beans
|
||||||
// of LayerParametersBinder<> type
|
// of LayerParametersBinder<> type
|
||||||
private val imageLayerParametersBinder: ImageLayerParametersBinder by di()
|
private val colorLayerParametersBinder: ColorLayerParametersBinder by di()
|
||||||
|
|
||||||
private val parameters = observableListOf<Parameter<*>>()
|
private val parameters = observableListOf<Parameter<*>>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
editorStateVM.selectedLayerProperty.addListener { _, previousLayer, layer ->
|
editorStateVM.selectedLayerProperty.addListener { _, previousLayer, layer ->
|
||||||
when (previousLayer) {
|
when (previousLayer) {
|
||||||
is ImageLayer -> imageLayerParametersBinder.unbind(previousLayer, parameters)
|
is ColorLayer -> colorLayerParametersBinder.unbind(previousLayer, parameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters.clear()
|
parameters.clear()
|
||||||
|
|
||||||
when (layer) {
|
when (layer) {
|
||||||
is ImageLayer -> imageLayerParametersBinder.bind(layer, parameters) { fire(RedrawMapRequestEvent) }
|
is ColorLayer -> colorLayerParametersBinder.bind(layer, parameters) { fire(RedrawMapRequestEvent) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.model.map.RenameLayerCommand
|
||||||
import com.bartlomiejpluta.base.editor.command.service.UndoRedoService
|
import com.bartlomiejpluta.base.editor.command.service.UndoRedoService
|
||||||
import com.bartlomiejpluta.base.editor.event.RedrawMapRequestEvent
|
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.Layer
|
||||||
import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer
|
import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer
|
||||||
import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer
|
import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer
|
||||||
@@ -50,7 +50,7 @@ class MapLayersView : View() {
|
|||||||
|
|
||||||
bottom = toolbar {
|
bottom = toolbar {
|
||||||
menubutton(graphic = FontIcon("fa-plus")) {
|
menubutton(graphic = FontIcon("fa-plus")) {
|
||||||
item("Tile Layer", graphic = FontIcon("fa-th")) {
|
item("Tile Layer", graphic = FontIcon("fa-th-large")) {
|
||||||
action {
|
action {
|
||||||
val layer = TileLayer("Layer ${mapVM.layers.size + 1}", mapVM.rows, mapVM.columns)
|
val layer = TileLayer("Layer ${mapVM.layers.size + 1}", mapVM.rows, mapVM.columns)
|
||||||
val command = CreateLayerCommand(mapVM.item, layer)
|
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 {
|
action {
|
||||||
val layer = ImageLayer("Layer ${mapVM.layers.size + 1}")
|
val layer = ColorLayer("Layer ${mapVM.layers.size + 1}")
|
||||||
val command = CreateLayerCommand(mapVM.item, layer)
|
val command = CreateLayerCommand(mapVM.item, layer)
|
||||||
command.execute()
|
command.execute()
|
||||||
layersPane.selectionModel.select(mapVM.layers.size - 1)
|
layersPane.selectionModel.select(mapVM.layers.size - 1)
|
||||||
@@ -161,9 +161,9 @@ class MapLayersView : View() {
|
|||||||
text = item.name
|
text = item.name
|
||||||
|
|
||||||
graphic = when (item) {
|
graphic = when (item) {
|
||||||
is TileLayer -> FontIcon("fa-th")
|
is TileLayer -> FontIcon("fa-th-large")
|
||||||
is ObjectLayer -> FontIcon("fa-cube")
|
is ObjectLayer -> FontIcon("fa-cube")
|
||||||
is ImageLayer -> FontIcon("fa-image")
|
is ColorLayer -> FontIcon("fa-paint-brush")
|
||||||
else -> throw IllegalStateException("Unknown layer type")
|
else -> throw IllegalStateException("Unknown layer type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public class ProtobufMapDeserializer extends MapDeserializer {
|
|||||||
deserializeTileLayer(map, proto);
|
deserializeTileLayer(map, proto);
|
||||||
} else if (proto.hasObjectLayer()) {
|
} else if (proto.hasObjectLayer()) {
|
||||||
deserializeObjectLayer(map, proto);
|
deserializeObjectLayer(map, proto);
|
||||||
|
} else if (proto.hasColorLayer()) {
|
||||||
|
deserializeColorLayer(map, proto);
|
||||||
} else if (proto.hasImageLayer()) {
|
} else if (proto.hasImageLayer()) {
|
||||||
deserializeImageLayer(map, proto);
|
deserializeImageLayer(map, proto);
|
||||||
} else {
|
} 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) {
|
private void deserializeImageLayer(GameMap map, GameMapProto.Layer proto) {
|
||||||
// TODO(return new ImageLayer(...))
|
// TODO(return new ImageLayer(...))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ message Layer {
|
|||||||
oneof layer {
|
oneof layer {
|
||||||
TileLayer tileLayer = 2;
|
TileLayer tileLayer = 2;
|
||||||
ObjectLayer objectLayer = 3;
|
ObjectLayer objectLayer = 3;
|
||||||
ImageLayer imageLayer = 4;
|
ColorLayer colorLayer = 4;
|
||||||
|
ImageLayer imageLayer = 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +40,10 @@ enum PassageAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message ImageLayer {
|
message ImageLayer {
|
||||||
// TODO optional imageUID
|
|
||||||
// TODO r, g, b, alpha
|
// TODO r, g, b, alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ColorLayer {
|
||||||
|
// TODO imageUID
|
||||||
|
// TODO imageMode
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user