Cog + Fix stale plugins

This commit is contained in:
downthecrop 2025-08-14 00:20:52 -07:00
parent 7a5b0f76b4
commit 8fb06c88f8
3 changed files with 52 additions and 13 deletions

View file

@ -17,8 +17,10 @@ import plugin.PluginRepository
import java.awt.* import java.awt.*
import java.awt.event.MouseAdapter import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent import java.awt.event.MouseEvent
import java.awt.image.BufferedImage
import java.util.* import java.util.*
import java.util.Timer import java.util.Timer
import javax.imageio.ImageIO
import javax.swing.* import javax.swing.*
import javax.swing.border.AbstractBorder import javax.swing.border.AbstractBorder
import kotlin.math.ceil import kotlin.math.ceil
@ -38,6 +40,22 @@ object ReflectiveEditorView {
const val PLUGIN_LIST_VIEW = "PLUGIN_LIST" const val PLUGIN_LIST_VIEW = "PLUGIN_LIST"
const val PLUGIN_DETAIL_VIEW = "PLUGIN_DETAIL" const val PLUGIN_DETAIL_VIEW = "PLUGIN_DETAIL"
// Store the cog icon to be reused
private var cogIcon: Icon? = null
private fun loadCogIcon() {
try {
val imageStream = this::class.java.getResourceAsStream("res/cog.png")
if (imageStream != null) {
val image: BufferedImage = ImageIO.read(imageStream)
val scaledImage = image.getScaledInstance(12, 12, Image.SCALE_SMOOTH)
cogIcon = ImageIcon(scaledImage)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
// Card layout for switching between views within the reflective editor view // Card layout for switching between views within the reflective editor view
private lateinit var cardLayout: CardLayout private lateinit var cardLayout: CardLayout
private lateinit var mainPanel: JPanel private lateinit var mainPanel: JPanel
@ -45,6 +63,9 @@ object ReflectiveEditorView {
private var currentPlugin: Plugin? = null private var currentPlugin: Plugin? = null
fun createReflectiveEditorView() { fun createReflectiveEditorView() {
// Load the cog icon once
loadCogIcon()
// Create the main panel with card layout // Create the main panel with card layout
cardLayout = CardLayout() cardLayout = CardLayout()
mainPanel = JPanel(cardLayout) mainPanel = JPanel(cardLayout)
@ -73,8 +94,9 @@ object ReflectiveEditorView {
val panel = JPanel() val panel = JPanel()
panel.layout = BoxLayout(panel, BoxLayout.Y_AXIS) panel.layout = BoxLayout(panel, BoxLayout.Y_AXIS)
panel.background = VIEW_BACKGROUND_COLOR panel.background = VIEW_BACKGROUND_COLOR
try { try {
panel.add(Box.createVerticalStrut(10)) // Spacer
val loadedPluginsField = PluginRepository::class.java.getDeclaredField("loadedPlugins") val loadedPluginsField = PluginRepository::class.java.getDeclaredField("loadedPlugins")
loadedPluginsField.isAccessible = true loadedPluginsField.isAccessible = true
val loadedPlugins = loadedPluginsField.get(null) as HashMap<*, *> val loadedPlugins = loadedPluginsField.get(null) as HashMap<*, *>
@ -139,7 +161,6 @@ object ReflectiveEditorView {
val container = JPanel(BorderLayout()) val container = JPanel(BorderLayout())
container.background = VIEW_BACKGROUND_COLOR container.background = VIEW_BACKGROUND_COLOR
//container.border = BorderFactory.createEmptyBorder(10, 5, 10, 5)
container.add(scrollablePanel, BorderLayout.CENTER) container.add(scrollablePanel, BorderLayout.CENTER)
return container return container
@ -150,12 +171,10 @@ object ReflectiveEditorView {
panel.background = WIDGET_COLOR panel.background = WIDGET_COLOR
panel.border = BorderFactory.createEmptyBorder(10, 10, 10, 10) panel.border = BorderFactory.createEmptyBorder(10, 10, 10, 10)
panel.maximumSize = Dimension(220, 60) panel.maximumSize = Dimension(220, 60)
// Remove fixed preferredSize to allow flexible width
// panel.preferredSize = Dimension(220, 60)
// Plugin name and version (using package name as in original implementation) // Plugin name and version (using package name as in original implementation)
val packageName = plugin.javaClass.`package`.name val packageName = plugin.javaClass.`package`.name
val nameLabel = JLabel("$packageName") val nameLabel = JLabel(packageName)
nameLabel.foreground = secondaryColor nameLabel.foreground = secondaryColor
nameLabel.font = Font("RuneScape Small", Font.PLAIN, 16) nameLabel.font = Font("RuneScape Small", Font.PLAIN, 16)
@ -168,7 +187,12 @@ object ReflectiveEditorView {
// Edit button (only show if plugin has exposed attributes) // Edit button (only show if plugin has exposed attributes)
val editButton = if (exposedFields.isNotEmpty()) { val editButton = if (exposedFields.isNotEmpty()) {
val button = JButton("Edit") val button = JButton()
if (cogIcon != null) {
button.icon = cogIcon
} else {
button.text = "Edit"
}
button.background = TITLE_BAR_COLOR button.background = TITLE_BAR_COLOR
button.foreground = secondaryColor button.foreground = secondaryColor
button.font = Font("RuneScape Small", Font.PLAIN, 14) button.font = Font("RuneScape Small", Font.PLAIN, 14)
@ -467,10 +491,25 @@ object ReflectiveEditorView {
} }
fun addPlugins(reflectiveEditorView: JPanel) { fun addPlugins(reflectiveEditorView: JPanel) {
// This function is now deprecated with the new view system // Refresh the plugin list by recreating the plugin list view
// but kept for compatibility
// In the new system, we don't need to do anything here // Remove the existing plugin list view
// as the views are managed by our internal card layout val existingListView = mainPanel.components.find { it.name == PLUGIN_LIST_VIEW }
if (existingListView != null) {
mainPanel.remove(existingListView)
}
// Create a new plugin list view
val pluginListView = createPluginListView()
pluginListView.name = PLUGIN_LIST_VIEW
mainPanel.add(pluginListView, PLUGIN_LIST_VIEW)
// Revalidate and repaint the main panel
mainPanel.revalidate()
mainPanel.repaint()
// Show the plugin list view
cardLayout.show(mainPanel, PLUGIN_LIST_VIEW)
} }
var customToolTipWindow: JWindow? = null var customToolTipWindow: JWindow? = null

View file

@ -27,9 +27,9 @@ class ToggleSwitch : JPanel() {
} }
}) })
cursor = Cursor(Cursor.HAND_CURSOR) cursor = Cursor(Cursor.HAND_CURSOR)
preferredSize = Dimension(40, 20) preferredSize = Dimension(32, 20)
maximumSize = Dimension(40, 20) maximumSize = Dimension(32, 20)
minimumSize = Dimension(40, 20) minimumSize = Dimension(32, 20)
isOpaque = false // Make the panel background transparent isOpaque = false // Make the panel background transparent
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 893 B