[Editor] Rename ProjectStructure and CodeStructure to Assets and ScriptFiles
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
package com.bartlomiejpluta.base.editor.main.component
|
||||
package com.bartlomiejpluta.base.editor.asset.component
|
||||
|
||||
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
||||
import com.bartlomiejpluta.base.editor.main.model.StructureCategory
|
||||
import com.bartlomiejpluta.base.editor.asset.model.AssetCategory
|
||||
import javafx.scene.control.TreeCell
|
||||
import javafx.util.StringConverter
|
||||
|
||||
class StructureItemStringConverter(
|
||||
class AssetStringConverter(
|
||||
private val cell: TreeCell<Any>,
|
||||
private val onUpdate: (item: Asset, name: String) -> Asset
|
||||
) : StringConverter<Any>() {
|
||||
override fun toString(item: Any?): String = when (item) {
|
||||
is StructureCategory -> item.name
|
||||
is AssetCategory -> item.name
|
||||
is Asset -> item.name
|
||||
else -> ""
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class StructureItemStringConverter(
|
||||
// That's why we are running the submission logic in the converter.
|
||||
override fun fromString(string: String?): Any = when (val item = cell.item) {
|
||||
is Asset -> string?.let { onUpdate(item, it) } ?: ""
|
||||
is StructureCategory -> item.name
|
||||
is AssetCategory -> item.name
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.bartlomiejpluta.base.editor.main.component
|
||||
package com.bartlomiejpluta.base.editor.asset.component
|
||||
|
||||
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
||||
import com.bartlomiejpluta.base.editor.asset.model.AssetCategory
|
||||
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
||||
import com.bartlomiejpluta.base.editor.main.model.StructureCategory
|
||||
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||
import com.bartlomiejpluta.base.editor.tileset.asset.TileSetAsset
|
||||
import javafx.scene.control.ContextMenu
|
||||
@@ -11,12 +11,12 @@ import javafx.scene.control.cell.TextFieldTreeCell
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
import tornadofx.action
|
||||
|
||||
class StructureItemTreeCell(renameAsset: (asset: Asset, name: String) -> Asset, deleteAsset: (asset: Asset) -> Unit) :
|
||||
class AssetTreeCell(renameAsset: (asset: Asset, name: String) -> Asset, deleteAsset: (asset: Asset) -> Unit) :
|
||||
TextFieldTreeCell<Any>() {
|
||||
private val assetMenu = ContextMenu()
|
||||
|
||||
init {
|
||||
converter = StructureItemStringConverter(this, renameAsset)
|
||||
converter = AssetStringConverter(this, renameAsset)
|
||||
MenuItem("Rename").apply {
|
||||
action {
|
||||
treeView.isEditable = true
|
||||
@@ -47,18 +47,18 @@ class StructureItemTreeCell(renameAsset: (asset: Asset, name: String) -> Asset,
|
||||
|
||||
contextMenu = when (item) {
|
||||
is Asset -> if (isEditing) null else assetMenu
|
||||
is StructureCategory -> item.menu
|
||||
is AssetCategory -> item.menu
|
||||
else -> null
|
||||
}
|
||||
|
||||
text = when (item) {
|
||||
is StructureCategory -> item.name
|
||||
is AssetCategory -> item.name
|
||||
is Asset -> item.name
|
||||
else -> null
|
||||
}
|
||||
|
||||
graphic = when (item) {
|
||||
is StructureCategory -> FontIcon("fa-folder")
|
||||
is AssetCategory -> FontIcon("fa-folder")
|
||||
is GameMapAsset -> FontIcon("fa-map")
|
||||
is TileSetAsset -> FontIcon("fa-th")
|
||||
is ImageAsset -> FontIcon("fa-image")
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bartlomiejpluta.base.editor.main.model
|
||||
package com.bartlomiejpluta.base.editor.asset.model
|
||||
|
||||
import javafx.collections.ObservableList
|
||||
import javafx.scene.Node
|
||||
@@ -9,7 +9,7 @@ import tornadofx.getValue
|
||||
import tornadofx.observableListOf
|
||||
import tornadofx.toProperty
|
||||
|
||||
class StructureCategory(name: String = "", var items: ObservableList<in Any> = observableListOf()) {
|
||||
class AssetCategory(name: String = "", var items: ObservableList<in Any> = observableListOf()) {
|
||||
val nameProperty = name.toProperty()
|
||||
val name by nameProperty
|
||||
val menu = ContextMenu()
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.bartlomiejpluta.base.editor.main.view
|
||||
package com.bartlomiejpluta.base.editor.asset.view.list
|
||||
|
||||
import com.bartlomiejpluta.base.editor.asset.component.AssetTreeCell
|
||||
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
||||
import com.bartlomiejpluta.base.editor.main.component.StructureItemTreeCell
|
||||
import com.bartlomiejpluta.base.editor.asset.model.AssetCategory
|
||||
import com.bartlomiejpluta.base.editor.main.controller.MainController
|
||||
import com.bartlomiejpluta.base.editor.main.model.StructureCategory
|
||||
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||
import javafx.beans.binding.Bindings
|
||||
@@ -11,57 +11,56 @@ import javafx.scene.control.TreeItem
|
||||
import javafx.scene.control.TreeView
|
||||
import tornadofx.*
|
||||
|
||||
|
||||
class ProjectStructureView : View() {
|
||||
class AssetsListView : View() {
|
||||
private val projectContext: ProjectContext by di()
|
||||
private val mainController: MainController by di()
|
||||
|
||||
private val structureMaps = StructureCategory("Maps").apply {
|
||||
private val maps = AssetCategory("Maps").apply {
|
||||
menuitem("New Map...") { mainController.createEmptyMap() }
|
||||
}
|
||||
|
||||
private val structureTileSets = StructureCategory("Tile Sets").apply {
|
||||
private val tileSets = AssetCategory("Tile Sets").apply {
|
||||
menuitem("Import Tile Set...") { mainController.importTileSet() }
|
||||
}
|
||||
|
||||
private val structureImages = StructureCategory("Images").apply {
|
||||
private val images = AssetCategory("Images").apply {
|
||||
menuitem("Import Image...") { mainController.importImage() }
|
||||
}
|
||||
|
||||
private val structureRoot = StructureCategory(
|
||||
private val rootItem = AssetCategory(
|
||||
name = "Project", items = observableListOf(
|
||||
structureMaps,
|
||||
structureTileSets,
|
||||
structureImages
|
||||
maps,
|
||||
tileSets,
|
||||
images
|
||||
)
|
||||
)
|
||||
|
||||
init {
|
||||
projectContext.projectProperty.addListener { _, _, project ->
|
||||
project?.let {
|
||||
structureRoot.nameProperty.bind(it.nameProperty)
|
||||
Bindings.bindContent(structureMaps.items, it.maps)
|
||||
Bindings.bindContent(structureTileSets.items, it.tileSets)
|
||||
Bindings.bindContent(structureImages.items, it.images)
|
||||
rootItem.nameProperty.bind(it.nameProperty)
|
||||
Bindings.bindContent(maps.items, it.maps)
|
||||
Bindings.bindContent(tileSets.items, it.tileSets)
|
||||
Bindings.bindContent(images.items, it.images)
|
||||
root.root.expandAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val treeView: TreeView<Any> = treeview<Any> {
|
||||
root = TreeItem(structureRoot)
|
||||
root = TreeItem(rootItem)
|
||||
|
||||
isShowRoot = false
|
||||
|
||||
populate {
|
||||
when (val value = it.value) {
|
||||
is StructureCategory -> value.items
|
||||
is AssetCategory -> value.items
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
setCellFactory {
|
||||
StructureItemTreeCell(this@ProjectStructureView::renameAsset, this@ProjectStructureView::deleteAsset)
|
||||
AssetTreeCell(this@AssetsListView::renameAsset, this@AssetsListView::deleteAsset)
|
||||
}
|
||||
|
||||
setOnMouseClicked { event ->
|
||||
@@ -4,7 +4,7 @@ import com.bartlomiejpluta.base.editor.code.model.FileSystemNode
|
||||
import javafx.scene.control.TreeCell
|
||||
import javafx.util.StringConverter
|
||||
|
||||
class CodeStructureItemStringConverter(
|
||||
class ScriptFileStringConverter(
|
||||
private val cell: TreeCell<FileSystemNode>,
|
||||
private val onUpdate: (item: FileSystemNode, name: String) -> FileSystemNode
|
||||
) : StringConverter<FileSystemNode>() {
|
||||
@@ -9,7 +9,7 @@ import tornadofx.enableWhen
|
||||
import tornadofx.item
|
||||
import tornadofx.toProperty
|
||||
|
||||
class CodeStructureItemTreeCell(onCreate: (FileSystemNode) -> Unit, onDelete: (FileSystemNode) -> Unit) :
|
||||
class ScriptFileTreeCell(onCreate: (FileSystemNode) -> Unit, onDelete: (FileSystemNode) -> Unit) :
|
||||
TextFieldTreeCell<FileSystemNode>() {
|
||||
private val isRoot = true.toProperty()
|
||||
private val isNotRoot = isRoot.not()
|
||||
@@ -65,7 +65,7 @@ class CodeStructureItemTreeCell(onCreate: (FileSystemNode) -> Unit, onDelete: (F
|
||||
}
|
||||
|
||||
init {
|
||||
converter = CodeStructureItemStringConverter(this, this::renameFile)
|
||||
converter = ScriptFileStringConverter(this, this::renameFile)
|
||||
}
|
||||
|
||||
private fun renameFile(file: FileSystemNode, name: String) = file.apply {
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.bartlomiejpluta.base.editor.code.view
|
||||
|
||||
import com.bartlomiejpluta.base.editor.code.component.CodeStructureItemTreeCell
|
||||
import com.bartlomiejpluta.base.editor.code.component.ScriptFileTreeCell
|
||||
import com.bartlomiejpluta.base.editor.code.model.FileSystemNode
|
||||
import com.bartlomiejpluta.base.editor.main.controller.MainController
|
||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||
@@ -14,7 +14,7 @@ import tornadofx.populate
|
||||
import tornadofx.treeview
|
||||
import java.io.File
|
||||
|
||||
class CodeStructureView : View() {
|
||||
class ScriptFilesView : View() {
|
||||
private val projectContext: ProjectContext by di()
|
||||
private val mainController: MainController by di()
|
||||
|
||||
@@ -30,7 +30,7 @@ class CodeStructureView : View() {
|
||||
|
||||
private val treeView: TreeView<FileSystemNode> = treeview {
|
||||
setCellFactory {
|
||||
CodeStructureItemTreeCell(this@CodeStructureView::onCreate, mainController::closeScript)
|
||||
ScriptFileTreeCell(this@ScriptFilesView::onCreate, mainController::closeScript)
|
||||
}
|
||||
|
||||
setOnMouseClicked { event ->
|
||||
@@ -57,8 +57,4 @@ class CodeStructureView : View() {
|
||||
.map { fsNode.createNode(it) }
|
||||
.ifPresent { mainController.openScript(it) }
|
||||
}
|
||||
|
||||
private fun onDelete(fsNode: FileSystemNode) {
|
||||
mainController.closeScript(fsNode)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.bartlomiejpluta.base.editor.main.view
|
||||
|
||||
import com.bartlomiejpluta.base.editor.asset.view.list.AssetsListView
|
||||
import com.bartlomiejpluta.base.editor.code.model.Code
|
||||
import com.bartlomiejpluta.base.editor.code.view.CodeEditorFragment
|
||||
import com.bartlomiejpluta.base.editor.code.view.CodeStructureView
|
||||
import com.bartlomiejpluta.base.editor.code.view.ScriptFilesView
|
||||
import com.bartlomiejpluta.base.editor.code.viewmodel.CodeVM
|
||||
import com.bartlomiejpluta.base.editor.main.controller.MainController
|
||||
import com.bartlomiejpluta.base.editor.map.model.map.GameMap
|
||||
@@ -20,8 +21,8 @@ class MainView : View("BASE Game Editor") {
|
||||
private val projectContext: ProjectContext by di()
|
||||
|
||||
private val mainMenuView = find<MainMenuView>()
|
||||
private val projectStructureView = find<ProjectStructureView>()
|
||||
private val codeStructure = find<CodeStructureView>()
|
||||
private val assetsView = find<AssetsListView>()
|
||||
private val scriptFilesView = find<ScriptFilesView>()
|
||||
|
||||
private val openTabs = mutableMapOf<Scope, Tab>()
|
||||
|
||||
@@ -57,12 +58,12 @@ class MainView : View("BASE Game Editor") {
|
||||
}
|
||||
|
||||
left = drawer(multiselect = true) {
|
||||
item("Code Structure", expanded = true) {
|
||||
this += codeStructure
|
||||
item("Code", expanded = true) {
|
||||
this += scriptFilesView
|
||||
}
|
||||
|
||||
item("Project Structure", expanded = true) {
|
||||
this += projectStructureView
|
||||
item("Assets", expanded = true) {
|
||||
this += assetsView
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user