[Editor] Create SelectGraphicAssetView and *Fragment
This commit is contained in:
@@ -1,7 +1,16 @@
|
|||||||
package com.bartlomiejpluta.base.editor.asset.model
|
package com.bartlomiejpluta.base.editor.asset.model
|
||||||
|
|
||||||
interface Asset {
|
import javafx.beans.binding.Bindings.createObjectBinding
|
||||||
val uid: String
|
import javafx.beans.property.ObjectProperty
|
||||||
val source: String
|
import javafx.beans.property.SimpleStringProperty
|
||||||
var name: String
|
import tornadofx.getValue
|
||||||
|
import tornadofx.setValue
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
abstract class Asset(directory: ObjectProperty<File>, val uid: String, val source: String, name: String) {
|
||||||
|
val nameProperty = SimpleStringProperty(name)
|
||||||
|
var name by nameProperty
|
||||||
|
|
||||||
|
val fileProperty = createObjectBinding({ File(directory.value, source) }, directory)
|
||||||
|
val file by fileProperty
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.asset.view.select
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
||||||
|
import javafx.beans.property.ObjectProperty
|
||||||
|
import javafx.collections.ObservableList
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
|
class SelectGraphicAssetFragment : Fragment("Select Asset") {
|
||||||
|
val assets: ObservableList<Asset> by param()
|
||||||
|
val asset: ObjectProperty<Asset> by param()
|
||||||
|
|
||||||
|
private val selectGraphicAssetView = find<SelectGraphicAssetView>(
|
||||||
|
SelectGraphicAssetView::assets to assets,
|
||||||
|
SelectGraphicAssetView::asset to asset
|
||||||
|
)
|
||||||
|
|
||||||
|
private var onCompleteConsumer: ((Asset) -> Unit)? = null
|
||||||
|
|
||||||
|
fun onComplete(onCompleteConsumer: ((Asset) -> Unit)) {
|
||||||
|
this.onCompleteConsumer = onCompleteConsumer
|
||||||
|
}
|
||||||
|
|
||||||
|
override val root = form {
|
||||||
|
fieldset {
|
||||||
|
this += selectGraphicAssetView.root
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonbar {
|
||||||
|
button("Ok") {
|
||||||
|
enableWhen(asset.isNotNull)
|
||||||
|
|
||||||
|
action {
|
||||||
|
onCompleteConsumer?.let { it(asset.value) }
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button("Cancel") {
|
||||||
|
action { close() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.asset.view.select
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
||||||
|
import javafx.beans.binding.Bindings.createObjectBinding
|
||||||
|
import javafx.beans.property.ObjectProperty
|
||||||
|
import javafx.collections.ObservableList
|
||||||
|
import javafx.scene.control.ListView
|
||||||
|
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()
|
||||||
|
|
||||||
|
private var assetsListView: ListView<Asset> by singleAssign()
|
||||||
|
|
||||||
|
private val image = createObjectBinding({
|
||||||
|
asset.value?.file?.inputStream()?.use { Image(it) } ?: PLACEHOLDER_IMAGE
|
||||||
|
}, asset)
|
||||||
|
|
||||||
|
override val root = hbox {
|
||||||
|
|
||||||
|
assetsListView = listview(assets) {
|
||||||
|
cellFormat { text = it.name }
|
||||||
|
bindSelected(asset)
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollpane {
|
||||||
|
prefWidth = 480.0
|
||||||
|
prefHeight = 480.0
|
||||||
|
imageview(image)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val PLACEHOLDER_IMAGE = WritableImage(100, 100)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
package com.bartlomiejpluta.base.editor.map.asset
|
package com.bartlomiejpluta.base.editor.map.asset
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
||||||
import javafx.beans.property.SimpleStringProperty
|
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||||
import tornadofx.getValue
|
|
||||||
import tornadofx.setValue
|
|
||||||
|
|
||||||
class GameMapAsset(override val uid: String, name: String) : Asset {
|
class GameMapAsset(project: Project, uid: String, name: String) :
|
||||||
override val source = "$uid.dat"
|
Asset(project.mapsDirectoryProperty, uid, "$uid.dat", name)
|
||||||
|
|
||||||
val nameProperty = SimpleStringProperty(name)
|
|
||||||
override var name by nameProperty
|
|
||||||
}
|
|
||||||
@@ -69,7 +69,7 @@ class DefaultProjectContext : ProjectContext {
|
|||||||
override fun importMap(name: String, map: GameMap) {
|
override fun importMap(name: String, map: GameMap) {
|
||||||
project?.let {
|
project?.let {
|
||||||
UID.next(it.maps.map(Asset::uid)).let { uid ->
|
UID.next(it.maps.map(Asset::uid)).let { uid ->
|
||||||
val asset = GameMapAsset(uid, name)
|
val asset = GameMapAsset(it, uid, name)
|
||||||
map.uid = uid
|
map.uid = uid
|
||||||
it.maps += asset
|
it.maps += asset
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ class DefaultProjectContext : ProjectContext {
|
|||||||
val source = "$uid.${builder.file.extension}"
|
val source = "$uid.${builder.file.extension}"
|
||||||
val targetFile = File(it.tileSetsDirectory, source)
|
val targetFile = File(it.tileSetsDirectory, source)
|
||||||
builder.file.copyTo(targetFile)
|
builder.file.copyTo(targetFile)
|
||||||
it.tileSets += TileSetAsset(uid, source, builder.name, builder.rows, builder.columns)
|
it.tileSets += TileSetAsset(it, uid, source, builder.name, builder.rows, builder.columns)
|
||||||
|
|
||||||
save()
|
save()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,15 +14,20 @@ class ProtobufProjectDeserializer : ProjectDeserializer {
|
|||||||
val proto = ProjectProto.Project.parseFrom(input)
|
val proto = ProjectProto.Project.parseFrom(input)
|
||||||
val project = Project()
|
val project = Project()
|
||||||
project.name = proto.name
|
project.name = proto.name
|
||||||
project.maps.addAll(proto.mapsList.map(this::deserializeMap))
|
project.maps.addAll(proto.mapsList.map { deserializeMap(project, it) })
|
||||||
project.tileSets.addAll(proto.tileSetsList.map(this::deserializeTileSet))
|
project.tileSets.addAll(proto.tileSetsList.map { deserializeTileSet(project, it) })
|
||||||
|
|
||||||
return project
|
return project
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeMap(map: ProjectProto.GameMapAsset) = GameMapAsset(uid = map.uid, name = map.name)
|
private fun deserializeMap(project: Project, map: ProjectProto.GameMapAsset) = GameMapAsset(
|
||||||
|
project = project,
|
||||||
|
uid = map.uid,
|
||||||
|
name = map.name
|
||||||
|
)
|
||||||
|
|
||||||
private fun deserializeTileSet(tileSet: ProjectProto.TileSetAsset) = TileSetAsset(
|
private fun deserializeTileSet(project: Project, tileSet: ProjectProto.TileSetAsset) = TileSetAsset(
|
||||||
|
project = project,
|
||||||
uid = tileSet.uid,
|
uid = tileSet.uid,
|
||||||
source = tileSet.source,
|
source = tileSet.source,
|
||||||
name = tileSet.name,
|
name = tileSet.name,
|
||||||
|
|||||||
@@ -1,16 +1,7 @@
|
|||||||
package com.bartlomiejpluta.base.editor.tileset.asset
|
package com.bartlomiejpluta.base.editor.tileset.asset
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
||||||
import javafx.beans.property.SimpleStringProperty
|
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||||
import tornadofx.*
|
|
||||||
|
|
||||||
class TileSetAsset(
|
class TileSetAsset(project: Project, uid: String, source: String, name: String, val rows: Int, val columns: Int) :
|
||||||
override val uid: String,
|
Asset(project.tileSetsDirectoryProperty, uid, source, name)
|
||||||
override val source: String,
|
|
||||||
name: String,
|
|
||||||
val rows: Int,
|
|
||||||
val columns: Int
|
|
||||||
) : Asset {
|
|
||||||
val nameProperty = SimpleStringProperty(name)
|
|
||||||
override var name by nameProperty
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user