Skip to content

Commit

Permalink
add defines editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Koishi-Satori committed Oct 3, 2023
1 parent 0ab46c7 commit 840dbd2
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 46 deletions.
10 changes: 8 additions & 2 deletions designer/designer_ui_en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
lab.add.value: Path
# const
const.defines.gfx: Texture Defines
const.defines.sounds: Audio Defines
22 changes: 11 additions & 11 deletions output.log
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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]
1 change: 0 additions & 1 deletion src/main/kotlin/top/kkoishi/stg/Resources.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
128 changes: 96 additions & 32 deletions src/main/kotlin/top/kkoishi/stg/boot/ui/DanmakuDesigner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -192,6 +192,9 @@ object DanmakuDesigner : JFrame() {
private val tabbed = JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT)
private val addedTabs = ArrayDeque<String>(8)

private val gfxEditor = JTextPane()
private val soundsEditor = JTextPane()

private fun createImage(): BufferedImage {
val texture = Texture(ImageIO.read(Resources.getEngineResources<InputStream>()))
val op = texture.averageConvolve33(0.2f)
Expand All @@ -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,
Expand All @@ -231,42 +253,63 @@ 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)
pane.dividerSize = 1
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))
}

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}

0 comments on commit 840dbd2

Please sign in to comment.