mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-10 10:20:44 -07:00
Cog + Fix stale plugins
This commit is contained in:
parent
7a5b0f76b4
commit
8fb06c88f8
3 changed files with 52 additions and 13 deletions
|
|
@ -17,8 +17,10 @@ import plugin.PluginRepository
|
|||
import java.awt.*
|
||||
import java.awt.event.MouseAdapter
|
||||
import java.awt.event.MouseEvent
|
||||
import java.awt.image.BufferedImage
|
||||
import java.util.*
|
||||
import java.util.Timer
|
||||
import javax.imageio.ImageIO
|
||||
import javax.swing.*
|
||||
import javax.swing.border.AbstractBorder
|
||||
import kotlin.math.ceil
|
||||
|
|
@ -38,6 +40,22 @@ object ReflectiveEditorView {
|
|||
const val PLUGIN_LIST_VIEW = "PLUGIN_LIST"
|
||||
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
|
||||
private lateinit var cardLayout: CardLayout
|
||||
private lateinit var mainPanel: JPanel
|
||||
|
|
@ -45,6 +63,9 @@ object ReflectiveEditorView {
|
|||
private var currentPlugin: Plugin? = null
|
||||
|
||||
fun createReflectiveEditorView() {
|
||||
// Load the cog icon once
|
||||
loadCogIcon()
|
||||
|
||||
// Create the main panel with card layout
|
||||
cardLayout = CardLayout()
|
||||
mainPanel = JPanel(cardLayout)
|
||||
|
|
@ -73,8 +94,9 @@ object ReflectiveEditorView {
|
|||
val panel = JPanel()
|
||||
panel.layout = BoxLayout(panel, BoxLayout.Y_AXIS)
|
||||
panel.background = VIEW_BACKGROUND_COLOR
|
||||
|
||||
|
||||
try {
|
||||
panel.add(Box.createVerticalStrut(10)) // Spacer
|
||||
val loadedPluginsField = PluginRepository::class.java.getDeclaredField("loadedPlugins")
|
||||
loadedPluginsField.isAccessible = true
|
||||
val loadedPlugins = loadedPluginsField.get(null) as HashMap<*, *>
|
||||
|
|
@ -139,7 +161,6 @@ object ReflectiveEditorView {
|
|||
|
||||
val container = JPanel(BorderLayout())
|
||||
container.background = VIEW_BACKGROUND_COLOR
|
||||
//container.border = BorderFactory.createEmptyBorder(10, 5, 10, 5)
|
||||
container.add(scrollablePanel, BorderLayout.CENTER)
|
||||
|
||||
return container
|
||||
|
|
@ -150,12 +171,10 @@ object ReflectiveEditorView {
|
|||
panel.background = WIDGET_COLOR
|
||||
panel.border = BorderFactory.createEmptyBorder(10, 10, 10, 10)
|
||||
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)
|
||||
val packageName = plugin.javaClass.`package`.name
|
||||
val nameLabel = JLabel("$packageName")
|
||||
val nameLabel = JLabel(packageName)
|
||||
nameLabel.foreground = secondaryColor
|
||||
nameLabel.font = Font("RuneScape Small", Font.PLAIN, 16)
|
||||
|
||||
|
|
@ -168,7 +187,12 @@ object ReflectiveEditorView {
|
|||
|
||||
// Edit button (only show if plugin has exposed attributes)
|
||||
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.foreground = secondaryColor
|
||||
button.font = Font("RuneScape Small", Font.PLAIN, 14)
|
||||
|
|
@ -467,10 +491,25 @@ object ReflectiveEditorView {
|
|||
}
|
||||
|
||||
fun addPlugins(reflectiveEditorView: JPanel) {
|
||||
// This function is now deprecated with the new view system
|
||||
// but kept for compatibility
|
||||
// In the new system, we don't need to do anything here
|
||||
// as the views are managed by our internal card layout
|
||||
// Refresh the plugin list by recreating the plugin list view
|
||||
|
||||
// Remove the existing plugin list view
|
||||
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
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ class ToggleSwitch : JPanel() {
|
|||
}
|
||||
})
|
||||
cursor = Cursor(Cursor.HAND_CURSOR)
|
||||
preferredSize = Dimension(40, 20)
|
||||
maximumSize = Dimension(40, 20)
|
||||
minimumSize = Dimension(40, 20)
|
||||
preferredSize = Dimension(32, 20)
|
||||
maximumSize = Dimension(32, 20)
|
||||
minimumSize = Dimension(32, 20)
|
||||
isOpaque = false // Make the panel background transparent
|
||||
}
|
||||
|
||||
|
|
|
|||
BIN
plugin-playground/src/main/kotlin/KondoKit/res/cog.png
Normal file
BIN
plugin-playground/src/main/kotlin/KondoKit/res/cog.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 893 B |
Loading…
Add table
Add a link
Reference in a new issue