[Editor] Create project structure panel scaffolding
This commit is contained in:
@@ -13,6 +13,7 @@ class MainView : View("BASE Game Editor") {
|
|||||||
private val projectContext: ProjectContext by di()
|
private val projectContext: ProjectContext by di()
|
||||||
|
|
||||||
private val mainMenuView = find<MainMenuView>()
|
private val mainMenuView = find<MainMenuView>()
|
||||||
|
private val projectStructureView = find<ProjectStructureView>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
projectContext.projectProperty.addListener { _, _, project ->
|
projectContext.projectProperty.addListener { _, _, project ->
|
||||||
@@ -35,5 +36,7 @@ class MainView : View("BASE Game Editor") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
left = projectStructureView.root
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.main.view
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||||
|
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||||
|
import com.bartlomiejpluta.base.editor.util.fx.BindingUtil
|
||||||
|
import javafx.beans.property.SimpleStringProperty
|
||||||
|
import javafx.collections.ObservableList
|
||||||
|
import javafx.scene.control.TreeItem
|
||||||
|
import org.kordamp.ikonli.javafx.FontIcon
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectStructureView : View() {
|
||||||
|
private val projectContext: ProjectContext by di()
|
||||||
|
|
||||||
|
private val structureMaps = StructureCategory("Maps")
|
||||||
|
|
||||||
|
private val structureRoot = StructureCategory(name = "Project", items = observableListOf(structureMaps))
|
||||||
|
|
||||||
|
init {
|
||||||
|
projectContext.projectProperty.addListener { _, _, project ->
|
||||||
|
project?.let {
|
||||||
|
structureRoot.nameProperty.bind(it.nameProperty)
|
||||||
|
BindingUtil.bindMapValues(structureMaps.items, project.maps)
|
||||||
|
root.refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val root = treeview<Any> {
|
||||||
|
root = TreeItem(structureRoot)
|
||||||
|
|
||||||
|
cellFormat {
|
||||||
|
graphic = when(it) {
|
||||||
|
structureRoot -> FontIcon("fa-cog")
|
||||||
|
is StructureCategory -> FontIcon("fa-folder")
|
||||||
|
is GameMapAsset -> FontIcon("fa-map")
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
text = when (it) {
|
||||||
|
is StructureCategory -> it.name
|
||||||
|
is GameMapAsset -> it.name
|
||||||
|
else -> throw IllegalStateException("Unsupported structure item type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
populate {
|
||||||
|
when (val value = it.value) {
|
||||||
|
is StructureCategory -> value.items
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class StructureCategory(name: String = "", var items: ObservableList<out Any> = observableListOf()) {
|
||||||
|
val nameProperty = SimpleStringProperty(name)
|
||||||
|
val name by nameProperty
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.util.fx
|
||||||
|
|
||||||
|
import javafx.beans.binding.Bindings
|
||||||
|
import javafx.collections.MapChangeListener
|
||||||
|
import javafx.collections.ObservableList
|
||||||
|
import javafx.collections.ObservableMap
|
||||||
|
import tornadofx.observableListOf
|
||||||
|
|
||||||
|
object BindingUtil {
|
||||||
|
fun <K, V> observableMapValues(map: ObservableMap<out K, out V>) = observableListOf<V>().apply {
|
||||||
|
addAll(map.values)
|
||||||
|
|
||||||
|
// FIXME:
|
||||||
|
// It's not really efficient way to track map updates by clearing all
|
||||||
|
// and putting it all over again, however it preserves the original map order.
|
||||||
|
// The efficiency should be sufficient for the project purposes (there are no any expectations
|
||||||
|
// to store a very large collections in here - if the need arose it should be immediately improved).
|
||||||
|
map.addListener(MapChangeListener {
|
||||||
|
clear()
|
||||||
|
addAll(map.values)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <K, V> bindMapValues(target: ObservableList<out V>, map: ObservableMap<out K, out V>) {
|
||||||
|
Bindings.bindContent(target, observableMapValues(map))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user