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