From 840dbd2a07c59c6ef605074c79df1ea51c24a750 Mon Sep 17 00:00:00 2001 From: Koishi-Satori <88583686+Koishi-Satori@users.noreply.github.com> Date: Tue, 3 Oct 2023 23:20:48 +0800 Subject: [PATCH] add defines editor --- designer/designer_ui_en_US.yml | 10 +- output.log | 22 +-- src/main/kotlin/top/kkoishi/stg/Resources.kt | 1 - .../kkoishi/stg/boot/ui/DanmakuDesigner.kt | 128 +++++++++++++----- 4 files changed, 115 insertions(+), 46 deletions(-) diff --git a/designer/designer_ui_en_US.yml b/designer/designer_ui_en_US.yml index 81acc16..23c8b6a 100644 --- a/designer/designer_ui_en_US.yml +++ b/designer/designer_ui_en_US.yml @@ -9,6 +9,8 @@ tree.root.gfx: GFX Resources tree.root.sounds: Sounds Resources tree.root.file: File Resources tree.node.defines: Defines +tree.node.defines.gfx: Textures +tree.node.defines.sounds: Sounds tree.node.impl: Implementations # function localizations func.manage.resource: Manage Resource @@ -18,11 +20,15 @@ func.add.sounds: Add Sound func.manage.sounds: Sounds # tabs tabs.title.default: Default Editor -tabs.tooltip.default: An default editor. +tabs.tooltip.default: An editor. +tab.title.editor.defines: %s Editor # buttons btn.close.tooltip: Close. btn.confirm.title: Confirm btn.cancel.title: Cancel # labels lab.add.key: Key -lab.add.value: Path \ No newline at end of file +lab.add.value: Path +# const +const.defines.gfx: Texture Defines +const.defines.sounds: Audio Defines \ No newline at end of file diff --git a/output.log b/output.log index a123859..7a2cf5c 100644 --- a/output.log +++ b/output.log @@ -1,12 +1,12 @@ -[10:39:01 PM] [main<-Threads/INFO]: Set workdir to D:\ProjectKotlin\KStg\. -[10:39:01 PM] [main<-DanmakuDesigner/INFO]: Try to get engine resources, CallerClass: class top.kkoishi.stg.boot.ui.DanmakuDesigner -[10:39:01 PM] [main<-GFX/INFO]: Try to get engine resources, CallerClass: class top.kkoishi.stg.gfx.GFX -[10:39:02 PM] [main<-GFX/INFO]: Init TEXTURE_NOT_FOUND -[10:39:02 PM] [main<-Sounds/INFO]: Try to get engine resources, CallerClass: class top.kkoishi.stg.audio.Sounds -[10:39:02 PM] [main<-DanmakuDesigner/INFO]: Load font size: 12 -[10:39:02 PM] [main<-DanmakuDesigner/INFO]: Load font style: PLAIN -[10:39:02 PM] [main<-DanmakuDesigner/INFO]: Load font path: D:\ProjectKotlin\KStg\designer\fonts\JetBrainsMono-Medium.ttf -[10:39:02 PM] [main<-DanmakuDesigner/TRACE]: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel +[11:18:27 PM] [main<-Threads/INFO]: Set workdir to D:\ProjectKotlin\KStg\. +[11:18:27 PM] [main<-DanmakuDesigner/INFO]: Try to get engine resources, CallerClass: class top.kkoishi.stg.boot.ui.DanmakuDesigner +[11:18:27 PM] [main<-GFX/INFO]: Try to get engine resources, CallerClass: class top.kkoishi.stg.gfx.GFX +[11:18:27 PM] [main<-GFX/INFO]: Init TEXTURE_NOT_FOUND +[11:18:27 PM] [main<-Sounds/INFO]: Try to get engine resources, CallerClass: class top.kkoishi.stg.audio.Sounds +[11:18:27 PM] [main<-DanmakuDesigner/INFO]: Load font size: 12 +[11:18:27 PM] [main<-DanmakuDesigner/INFO]: Load font style: PLAIN +[11:18:27 PM] [main<-DanmakuDesigner/INFO]: Load font path: D:\ProjectKotlin\KStg\designer\fonts\JetBrainsMono-Medium.ttf +[11:18:27 PM] [main<-DanmakuDesigner/TRACE]: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel java.lang.ClassNotFoundException: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182) @@ -17,5 +17,5 @@ java.lang.ClassNotFoundException: com.sun.java.swing.plaf.nimbus.NimbusLookAndFe at java.desktop/javax.swing.UIManager.setLookAndFeel(UIManager.java:637) at top.kkoishi.stg.boot.ui.DanmakuDesigner.main(DanmakuDesigner.kt:133) -[10:39:02 PM] [main<-DesignerPanel/INFO]: Try to get engine resources, CallerClass: class top.kkoishi.stg.boot.ui.DanmakuDesigner$DesignerPanel -[10:39:02 PM] [main<-Texture/INFO]: Constructing a convolve kernel with [0.022222223, 0.022222223, 0.022222223, 0.022222223, 0.022222223, 0.022222223, 0.022222223, 0.022222223, 0.022222223] +[11:18:28 PM] [main<-DesignerPanel/INFO]: Try to get engine resources, CallerClass: class top.kkoishi.stg.boot.ui.DanmakuDesigner$DesignerPanel +[11:18:28 PM] [main<-Texture/INFO]: Constructing a convolve kernel with [0.022222223, 0.022222223, 0.022222223, 0.022222223, 0.022222223, 0.022222223, 0.022222223, 0.022222223, 0.022222223] diff --git a/src/main/kotlin/top/kkoishi/stg/Resources.kt b/src/main/kotlin/top/kkoishi/stg/Resources.kt index 55284ca..0b8abb7 100644 --- a/src/main/kotlin/top/kkoishi/stg/Resources.kt +++ b/src/main/kotlin/top/kkoishi/stg/Resources.kt @@ -7,7 +7,6 @@ import top.kkoishi.stg.exceptions.CrashReportGenerator import top.kkoishi.stg.exceptions.FailedLoadingResourceException import top.kkoishi.stg.gfx.GFX import top.kkoishi.stg.logic.InfoSystem.Companion.logger -import java.io.InputStream /** * An interface declared that the class which implements this, is used to manage the game resources diff --git a/src/main/kotlin/top/kkoishi/stg/boot/ui/DanmakuDesigner.kt b/src/main/kotlin/top/kkoishi/stg/boot/ui/DanmakuDesigner.kt index 61014b0..6065c9f 100644 --- a/src/main/kotlin/top/kkoishi/stg/boot/ui/DanmakuDesigner.kt +++ b/src/main/kotlin/top/kkoishi/stg/boot/ui/DanmakuDesigner.kt @@ -11,8 +11,8 @@ import top.kkoishi.stg.logic.GenericSystem import top.kkoishi.stg.logic.InfoSystem.Companion.logger import top.kkoishi.stg.logic.Threads import java.awt.* +import java.awt.event.MouseAdapter import java.awt.event.MouseEvent -import java.awt.event.MouseListener import java.awt.geom.AffineTransform import java.awt.image.AffineTransformOp import java.awt.image.BufferedImage @@ -192,6 +192,9 @@ object DanmakuDesigner : JFrame() { private val tabbed = JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT) private val addedTabs = ArrayDeque(8) + private val gfxEditor = JTextPane() + private val soundsEditor = JTextPane() + private fun createImage(): BufferedImage { val texture = Texture(ImageIO.read(Resources.getEngineResources())) val op = texture.averageConvolve33(0.2f) @@ -202,19 +205,38 @@ object DanmakuDesigner : JFrame() { init { isOpaque = false - editor.background = Color.BLACK - editor.caretColor = Color.WHITE - editor.foreground = Color.WHITE - editor.isOpaque = false - editor.autoscrolls = true - - val default = createBackgroundPanel() - default.isOpaque = false - default.background = Color.BLACK + with(editor) { + background = Color.BLACK + caretColor = Color.WHITE + foreground = Color.WHITE + isOpaque = false + autoscrolls = true + } + with(gfxEditor) { + background = Color.BLACK + caretColor = Color.WHITE + foreground = Color.WHITE + isOpaque = false + autoscrolls = true + } + with(soundsEditor) { + background = Color.BLACK + caretColor = Color.WHITE + foreground = Color.WHITE + isOpaque = false + autoscrolls = true + } + + val default = createBackgroundPanel().apply { isOpaque = false }.apply { background = Color.BLACK } val scroll = JScrollPane(editor) - scroll.isOpaque = false - scroll.viewport.isOpaque = false - default.add(scroll, BorderLayout.CENTER) + default.add(scroll.apply { isOpaque = false }.apply { viewport.isOpaque = false }, BorderLayout.CENTER) + + val gfx = createBackgroundPanel().apply { isOpaque = false }.apply { background = Color.BLACK } + val gfxScroll = JScrollPane(gfxEditor) + gfx.add(gfxScroll.apply { isOpaque = false }.apply { viewport.isOpaque = false }, BorderLayout.CENTER) + val sounds = createBackgroundPanel().apply { isOpaque = false }.apply { background = Color.BLACK } + val soundsScroll = JScrollPane(soundsEditor) + sounds.add(soundsScroll.apply { isOpaque = false }.apply { viewport.isOpaque = false }, BorderLayout.CENTER) tabbed.insertTab( DesignerLocalization.TAB_TITLE_DEFAULT, @@ -231,25 +253,12 @@ object DanmakuDesigner : JFrame() { SOUNDS_NODE = addNode(SourceTree.Node(16, DesignerLocalization.TREE_ROOT_SOUNDS)) FILE_NODE = addNode(SourceTree.Node(16, DesignerLocalization.TREE_ROOT_FILE)) val tree = SourceTree(this) - tree.addMouseListener(object : MouseListener { + tree.addMouseListener(object : MouseAdapter() { override fun mouseClicked(e: MouseEvent) { tree.getPathForLocation(e.x, e.y)?.let { it.lastPathComponent.castApply { node: SourceTree.Node -> node(e.button, e.clickCount) } } } - - override fun mousePressed(e: MouseEvent?) { - } - - override fun mouseReleased(e: MouseEvent?) { - } - - override fun mouseEntered(e: MouseEvent?) { - } - - override fun mouseExited(e: MouseEvent?) { - } - }) val view = JScrollPane(tree) val pane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT, view, tabbed) @@ -257,16 +266,50 @@ object DanmakuDesigner : JFrame() { pane.isOneTouchExpandable = true add(pane, BorderLayout.CENTER) } - GFX_NODE.addNode(SourceTree.Node(0, "NOT_FOUND", false, action = { btn, count -> + GFX_NODE.addNode(SourceTree.Node(0, "NOT_FOUND", false) { btn, count -> if (btn == 1 && count == 2 && !addedTabs.contains("NOT_FOUND")) { val insertPos = tabbed.tabCount tabbed.insertTab("NOT_FOUND", ICON, TextureDisplayPanel(GFX.notFound()), "", insertPos) tabbed.setTabComponentAt(insertPos, CloseableTab("NOT_FOUND", tabbed)) addedTabs.add("NOT_FOUND") + tabbed.selectedIndex = insertPos } - })) + }) SOUNDS_NODE.addNode(SourceTree.Node(0, "NOT_FOUND", false)) - FILE_NODE.addNode(SourceTree.Node(2, DesignerLocalization.TREE_NODE_DEFINES)) + FILE_NODE.addNode(SourceTree.Node(2, DesignerLocalization.TREE_NODE_DEFINES)).apply { + addNode(SourceTree.Node(0, DesignerLocalization.TREE_NODE_DEFINES_GFX, false) { btn, count -> + val key = DesignerLocalization.TAB_TITLE_EDITOR_DEFINES.format(DesignerLocalization.CONST_DEFINES_GFX) + if (btn == 1 && count == 2 && !addedTabs.contains(key)) { + val insertPos = tabbed.tabCount + tabbed.insertTab( + key, + ICON, + gfx, + DesignerLocalization.TAB_TOOLTIP_DEFAULT, + insertPos + ) + tabbed.setTabComponentAt(insertPos, CloseableTab(key, tabbed)) + addedTabs.add(key) + tabbed.selectedIndex = insertPos + } + }) + addNode(SourceTree.Node(0, DesignerLocalization.TREE_NODE_DEFINES_SOUNDS, false) { btn, count -> + val key = DesignerLocalization.TAB_TITLE_EDITOR_DEFINES.format(DesignerLocalization.CONST_DEFINES_SOUNDS) + if (btn == 1 && count == 2 && !addedTabs.contains(key)) { + val insertPos = tabbed.tabCount + tabbed.insertTab( + key, + ICON, + sounds, + DesignerLocalization.TAB_TOOLTIP_DEFAULT, + insertPos + ) + tabbed.setTabComponentAt(insertPos, CloseableTab(key, tabbed)) + addedTabs.add(key) + tabbed.selectedIndex = insertPos + } + }) + } FILE_NODE.addNode(SourceTree.Node(2, DesignerLocalization.TREE_NODE_IMPL)) } @@ -308,14 +351,14 @@ object DanmakuDesigner : JFrame() { return false GFX.loadTexture(key, path) val texture = GFX[key] - GFX_NODE.addNode(SourceTree.Node(0, key, false, action = { btn, count -> + GFX_NODE.addNode(SourceTree.Node(0, key, false) { btn, count -> if (btn == 1 && count == 2) { val insertPos = tabbed.tabCount tabbed.insertTab(key, ICON, TextureDisplayPanel(texture), path, insertPos) tabbed.setTabComponentAt(insertPos, CloseableTab(key, tabbed)) addedTabs.add(key) } - })) + }) return true } } @@ -541,6 +584,14 @@ object DanmakuDesigner : JFrame() { @field: LocalizationKey("tree.node.defines") lateinit var TREE_NODE_DEFINES: String + @JvmStatic + @field: LocalizationKey("tree.node.defines.gfx") + lateinit var TREE_NODE_DEFINES_GFX: String + + @JvmStatic + @field: LocalizationKey("tree.node.defines.sounds") + lateinit var TREE_NODE_DEFINES_SOUNDS: String + @JvmStatic @field: LocalizationKey("tree.node.impl") lateinit var TREE_NODE_IMPL: String @@ -569,6 +620,10 @@ object DanmakuDesigner : JFrame() { @field: LocalizationKey("tabs.tooltip.default") lateinit var TAB_TOOLTIP_DEFAULT: String + @JvmStatic + @field: LocalizationKey("tab.title.editor.defines") + lateinit var TAB_TITLE_EDITOR_DEFINES: String + @JvmStatic @field: LocalizationKey("btn.close.tooltip") lateinit var BTN_CLOSE_TOOLTIP: String @@ -588,5 +643,14 @@ object DanmakuDesigner : JFrame() { @JvmStatic @field: LocalizationKey("lab.add.value") lateinit var LAB_ADD_VALUE: String + + @JvmStatic + @field: LocalizationKey("const.defines.gfx") + lateinit var CONST_DEFINES_GFX: String + + + @JvmStatic + @field: LocalizationKey("const.defines.sounds") + lateinit var CONST_DEFINES_SOUNDS: String } } \ No newline at end of file