[Editor] Make SelectGraphicAssetView generic
This commit is contained in:
@@ -1,24 +1,23 @@
|
|||||||
package com.bartlomiejpluta.base.editor.asset.view.select
|
package com.bartlomiejpluta.base.editor.asset.view.select
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
||||||
import javafx.beans.property.ObjectProperty
|
|
||||||
import javafx.beans.property.SimpleObjectProperty
|
import javafx.beans.property.SimpleObjectProperty
|
||||||
import javafx.collections.ObservableList
|
import javafx.collections.ObservableList
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
class SelectGraphicAssetFragment : Fragment("Select Asset") {
|
class SelectGraphicAssetFragment<T : Asset> : Fragment("Select Asset") {
|
||||||
val assets: ObservableList<Asset> by param()
|
val assets: ObservableList<T> by param()
|
||||||
|
|
||||||
private val asset = SimpleObjectProperty<Asset>()
|
private val asset = SimpleObjectProperty<T>()
|
||||||
|
|
||||||
private val selectGraphicAssetView = find<SelectGraphicAssetView>(
|
private val selectGraphicAssetView = find<SelectGraphicAssetView<T>>(
|
||||||
SelectGraphicAssetView::assets to assets,
|
SelectGraphicAssetView<T>::assets to assets,
|
||||||
SelectGraphicAssetView::asset to asset
|
SelectGraphicAssetView<T>::asset to asset
|
||||||
)
|
)
|
||||||
|
|
||||||
private var onCompleteConsumer: ((Asset) -> Unit)? = null
|
private var onCompleteConsumer: ((T) -> Unit)? = null
|
||||||
|
|
||||||
fun onComplete(onCompleteConsumer: ((Asset) -> Unit)) {
|
fun onComplete(onCompleteConsumer: ((T) -> Unit)) {
|
||||||
this.onCompleteConsumer = onCompleteConsumer
|
this.onCompleteConsumer = onCompleteConsumer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import javafx.scene.image.Image
|
|||||||
import javafx.scene.image.WritableImage
|
import javafx.scene.image.WritableImage
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
class SelectGraphicAssetView : View() {
|
class SelectGraphicAssetView<T : Asset> : View() {
|
||||||
val assets: ObservableList<Asset> by param()
|
val assets: ObservableList<T> by param()
|
||||||
val asset: ObjectProperty<Asset> by param()
|
val asset: ObjectProperty<T> by param()
|
||||||
|
|
||||||
private var assetsListView: ListView<Asset> by singleAssign()
|
private var assetsListView: ListView<T> by singleAssign()
|
||||||
|
|
||||||
private val image = createObjectBinding({
|
private val image = createObjectBinding({
|
||||||
asset.value?.file?.inputStream()?.use { Image(it) } ?: PLACEHOLDER_IMAGE
|
asset.value?.file?.inputStream()?.use { Image(it) } ?: PLACEHOLDER_IMAGE
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ class GraphicAssetParameter<T : Asset>(
|
|||||||
|
|
||||||
addEventHandler(MouseEvent.MOUSE_CLICKED) {
|
addEventHandler(MouseEvent.MOUSE_CLICKED) {
|
||||||
if (it.button == MouseButton.PRIMARY) {
|
if (it.button == MouseButton.PRIMARY) {
|
||||||
find<SelectGraphicAssetFragment>(Scope(), SelectGraphicAssetFragment::assets to assets).apply {
|
find<SelectGraphicAssetFragment<T>>(Scope(), SelectGraphicAssetFragment<T>::assets to assets).apply {
|
||||||
onComplete { asset ->
|
onComplete { asset ->
|
||||||
editorValueProperty.value = asset as T
|
editorValueProperty.value = asset
|
||||||
commit()
|
commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,17 +86,12 @@ class MapLayersView : View() {
|
|||||||
item("Image Layer", graphic = FontIcon("fa-image")) {
|
item("Image Layer", graphic = FontIcon("fa-image")) {
|
||||||
action {
|
action {
|
||||||
val scope = UndoableScope()
|
val scope = UndoableScope()
|
||||||
find<SelectGraphicAssetFragment>(scope, SelectGraphicAssetFragment::assets to projectContext.project?.images!!).apply {
|
find<SelectGraphicAssetFragment<ImageAsset>>(
|
||||||
|
scope,
|
||||||
|
SelectGraphicAssetFragment<ImageAsset>::assets to projectContext.project?.images!!
|
||||||
|
).apply {
|
||||||
onComplete {
|
onComplete {
|
||||||
val layer =
|
val layer = ImageLayer("Layer ${mapVM.layers.size + 1}", it, 0, 0, ImageLayerMode.NORMAL, 100)
|
||||||
ImageLayer(
|
|
||||||
"Layer ${mapVM.layers.size + 1}",
|
|
||||||
it as ImageAsset,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
ImageLayerMode.NORMAL,
|
|
||||||
100
|
|
||||||
)
|
|
||||||
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)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.bartlomiejpluta.base.editor.map.view.wizard
|
|||||||
import com.bartlomiejpluta.base.editor.asset.view.select.SelectGraphicAssetView
|
import com.bartlomiejpluta.base.editor.asset.view.select.SelectGraphicAssetView
|
||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapBuilderVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapBuilderVM
|
||||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||||
|
import com.bartlomiejpluta.base.editor.tileset.asset.TileSetAsset
|
||||||
import tornadofx.View
|
import tornadofx.View
|
||||||
|
|
||||||
class MapTileSetSelectionView : View("Tile Set") {
|
class MapTileSetSelectionView : View("Tile Set") {
|
||||||
@@ -10,9 +11,9 @@ class MapTileSetSelectionView : View("Tile Set") {
|
|||||||
|
|
||||||
private val projectContext: ProjectContext by di()
|
private val projectContext: ProjectContext by di()
|
||||||
|
|
||||||
private val selectGraphicAssetView = find<SelectGraphicAssetView>(
|
private val selectGraphicAssetView = find<SelectGraphicAssetView<TileSetAsset>>(
|
||||||
SelectGraphicAssetView::assets to projectContext.project!!.tileSets,
|
SelectGraphicAssetView<TileSetAsset>::assets to projectContext.project!!.tileSets,
|
||||||
SelectGraphicAssetView::asset to mapBuilderVM.tileSetAssetProperty
|
SelectGraphicAssetView<TileSetAsset>::asset to mapBuilderVM.tileSetAssetProperty
|
||||||
)
|
)
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
|
|||||||
Reference in New Issue
Block a user