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