[Editor] Enable clearing tiles and passage abilities with right mouse button
This commit is contained in:
@@ -5,6 +5,7 @@ import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||
import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
||||
import javafx.scene.input.MouseButton
|
||||
|
||||
class ImagePositionPaintingTrace(val map: GameMapVM, override val commandName: String) : PaintingTrace {
|
||||
private var layerIndex = 0
|
||||
@@ -65,4 +66,6 @@ class ImagePositionPaintingTrace(val map: GameMapVM, override val commandName: S
|
||||
layer.x = newX.toInt()
|
||||
layer.y = newY.toInt()
|
||||
}
|
||||
|
||||
override val supportedButtons = arrayOf(MouseButton.PRIMARY)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
||||
import com.bartlomiejpluta.base.editor.render.input.MapMouseEventHandler
|
||||
import com.bartlomiejpluta.base.editor.render.model.Renderable
|
||||
import javafx.scene.canvas.GraphicsContext
|
||||
import javafx.scene.input.MouseButton
|
||||
import javafx.scene.input.MouseEvent
|
||||
|
||||
class MapPainter(
|
||||
@@ -56,29 +55,27 @@ class MapPainter(
|
||||
}
|
||||
|
||||
private fun beginTrace(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY && editorStateVM.selectedLayerIndex >= 0) {
|
||||
if (currentTrace == null && editorStateVM.selectedLayerIndex >= 0) {
|
||||
currentTrace = when (editorStateVM.selectedLayer) {
|
||||
is TileLayer -> TilePaintingTrace(mapVM, "Paint trace")
|
||||
is ObjectLayer -> ObjectPaintingTrace(mapVM, "Toggle passage")
|
||||
is ImageLayer -> ImagePositionPaintingTrace(mapVM, "Move Image Layer")
|
||||
else -> null
|
||||
}?.apply { beginTrace(editorStateVM, brushVM, event) }
|
||||
}
|
||||
?.takeIf { event.button in it.supportedButtons }
|
||||
?.apply { beginTrace(editorStateVM, brushVM, event) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun proceedTrace(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
currentTrace?.proceedTrace(editorStateVM, brushVM, event)
|
||||
}
|
||||
}
|
||||
private fun proceedTrace(event: MapMouseEvent) = currentTrace
|
||||
?.takeIf { event.button in it.supportedButtons }
|
||||
?.proceedTrace(editorStateVM, brushVM, event)
|
||||
|
||||
private fun commitTrace(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
currentTrace?.let {
|
||||
private fun commitTrace(event: MapMouseEvent) = currentTrace
|
||||
?.takeIf { event.button in it.supportedButtons }
|
||||
?.let {
|
||||
it.commitTrace(editorStateVM, brushVM, event)
|
||||
paintingCallback(it)
|
||||
currentTrace = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||
import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
||||
import javafx.scene.input.MouseButton
|
||||
|
||||
class ObjectPaintingTrace(val map: GameMapVM, override val commandName: String) : PaintingTrace {
|
||||
private var layerIndex = 0
|
||||
@@ -38,11 +39,17 @@ class ObjectPaintingTrace(val map: GameMapVM, override val commandName: String)
|
||||
|
||||
formerPassageAbility = layer.passageMap[row][column]
|
||||
|
||||
passageAbility = when (brushVM.mode!!) {
|
||||
passageAbility = when (mouseEvent.button) {
|
||||
MouseButton.PRIMARY -> when (brushVM.mode!!) {
|
||||
BrushMode.PAINTING_MODE -> PassageAbility.values()[(formerPassageAbility.ordinal + 1) % PassageAbility.values().size]
|
||||
BrushMode.ERASING_MODE -> PassageAbility.ALLOW
|
||||
}
|
||||
|
||||
MouseButton.SECONDARY -> PassageAbility.ALLOW
|
||||
|
||||
else -> throw IllegalStateException("Unsupported mouse button")
|
||||
}
|
||||
|
||||
layer.passageMap[row][column] = passageAbility
|
||||
}
|
||||
|
||||
@@ -53,4 +60,6 @@ class ObjectPaintingTrace(val map: GameMapVM, override val commandName: String)
|
||||
override fun redo() {
|
||||
layer.passageMap[row][column] = passageAbility
|
||||
}
|
||||
|
||||
override val supportedButtons = arrayOf(MouseButton.PRIMARY, MouseButton.SECONDARY)
|
||||
}
|
||||
@@ -4,9 +4,12 @@ import com.bartlomiejpluta.base.editor.command.model.base.Undoable
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
||||
import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
||||
import javafx.scene.input.MouseButton
|
||||
|
||||
interface PaintingTrace : Undoable {
|
||||
fun beginTrace(editorStateVM: EditorStateVM, brushVM: BrushVM, mouseEvent: MapMouseEvent)
|
||||
fun proceedTrace(editorStateVM: EditorStateVM, brushVM: BrushVM, mouseEvent: MapMouseEvent)
|
||||
fun commitTrace(editorStateVM: EditorStateVM, brushVM: BrushVM, mouseEvent: MapMouseEvent)
|
||||
|
||||
val supportedButtons: Array<MouseButton>
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||
import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
||||
import com.bartlomiejpluta.base.editor.tileset.model.Tile
|
||||
import javafx.scene.input.MouseButton
|
||||
|
||||
|
||||
data class TilePaintingTrace(val map: GameMapVM, override val commandName: String) : PaintingTrace {
|
||||
@@ -40,7 +41,10 @@ data class TilePaintingTrace(val map: GameMapVM, override val commandName: Strin
|
||||
editorStateVM.selectedLayerIndex,
|
||||
editorStateVM.cursorRow - centerRow + row,
|
||||
editorStateVM.cursorColumn - centerColumn + column,
|
||||
tile
|
||||
when (mouseEvent.button) {
|
||||
MouseButton.PRIMARY -> tile
|
||||
else -> null
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -51,7 +55,10 @@ data class TilePaintingTrace(val map: GameMapVM, override val commandName: Strin
|
||||
editorStateVM.selectedLayerIndex,
|
||||
editorStateVM.cursorRow - centerRow + row,
|
||||
editorStateVM.cursorColumn - centerColumn + column,
|
||||
tile
|
||||
when (mouseEvent.button) {
|
||||
MouseButton.PRIMARY -> tile
|
||||
else -> null
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -81,4 +88,6 @@ data class TilePaintingTrace(val map: GameMapVM, override val commandName: Strin
|
||||
val tile: Tile?
|
||||
)
|
||||
}
|
||||
|
||||
override val supportedButtons = arrayOf(MouseButton.PRIMARY, MouseButton.SECONDARY)
|
||||
}
|
||||
Reference in New Issue
Block a user