mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-10 10:20:44 -07:00
Design/Layout
This commit is contained in:
parent
f386c464f4
commit
2cee659582
2 changed files with 95 additions and 57 deletions
|
|
@ -79,8 +79,48 @@ object ReflectiveEditorView {
|
|||
loadedPluginsField.isAccessible = true
|
||||
val loadedPlugins = loadedPluginsField.get(null) as HashMap<*, *>
|
||||
|
||||
// Separate plugins with and without exposed attributes
|
||||
val pluginsWithExposed = mutableListOf<Pair<PluginInfo, Plugin>>()
|
||||
val pluginsWithoutExposed = mutableListOf<Pair<PluginInfo, Plugin>>()
|
||||
|
||||
for ((pluginInfo, plugin) in loadedPlugins) {
|
||||
val pluginPanel = createPluginItemPanel(pluginInfo as PluginInfo, plugin as Plugin)
|
||||
val exposedFields = (plugin as Plugin).javaClass.declaredFields.filter { field ->
|
||||
field.annotations.any { annotation ->
|
||||
annotation.annotationClass.simpleName == "Exposed"
|
||||
}
|
||||
}
|
||||
|
||||
if (exposedFields.isNotEmpty()) {
|
||||
pluginsWithExposed.add(pluginInfo as PluginInfo to plugin as Plugin)
|
||||
} else {
|
||||
pluginsWithoutExposed.add(pluginInfo as PluginInfo to plugin as Plugin)
|
||||
}
|
||||
}
|
||||
|
||||
// Sort both lists by package name
|
||||
pluginsWithExposed.sortBy { it.second.javaClass.`package`.name }
|
||||
pluginsWithoutExposed.sortBy { it.second.javaClass.`package`.name }
|
||||
|
||||
// Add plugins with exposed attributes first
|
||||
for ((pluginInfo, plugin) in pluginsWithExposed) {
|
||||
val pluginPanel = createPluginItemPanel(pluginInfo, plugin)
|
||||
panel.add(pluginPanel)
|
||||
panel.add(Box.createVerticalStrut(5))
|
||||
}
|
||||
|
||||
// Add a separator if we have plugins with exposed attributes
|
||||
if (pluginsWithExposed.isNotEmpty() && pluginsWithoutExposed.isNotEmpty()) {
|
||||
val separator = JPanel()
|
||||
separator.background = VIEW_BACKGROUND_COLOR
|
||||
separator.preferredSize = Dimension(Int.MAX_VALUE, 1)
|
||||
separator.maximumSize = Dimension(Int.MAX_VALUE, 1)
|
||||
panel.add(separator)
|
||||
panel.add(Box.createVerticalStrut(5))
|
||||
}
|
||||
|
||||
// Add plugins without exposed attributes
|
||||
for ((pluginInfo, plugin) in pluginsWithoutExposed) {
|
||||
val pluginPanel = createPluginItemPanel(pluginInfo, plugin)
|
||||
panel.add(pluginPanel)
|
||||
panel.add(Box.createVerticalStrut(5))
|
||||
}
|
||||
|
|
@ -119,18 +159,30 @@ object ReflectiveEditorView {
|
|||
nameLabel.foreground = secondaryColor
|
||||
nameLabel.font = Font("RuneScape Small", Font.BOLD, 16)
|
||||
|
||||
// Check if plugin has exposed attributes
|
||||
val exposedFields = plugin.javaClass.declaredFields.filter { field ->
|
||||
field.annotations.any { annotation ->
|
||||
annotation.annotationClass.simpleName == "Exposed"
|
||||
}
|
||||
}
|
||||
|
||||
// Edit button (only show if plugin has exposed attributes)
|
||||
val editButton = if (exposedFields.isNotEmpty()) {
|
||||
val button = JButton("Edit")
|
||||
button.background = TITLE_BAR_COLOR
|
||||
button.foreground = secondaryColor
|
||||
button.font = Font("RuneScape Small", Font.PLAIN, 14)
|
||||
button.addActionListener {
|
||||
showPluginDetails(pluginInfo, plugin)
|
||||
}
|
||||
button
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
// Plugin toggle switch (iOS style)
|
||||
val toggleSwitch = createToggleSwitch(plugin, pluginInfo)
|
||||
|
||||
// Edit button
|
||||
val editButton = JButton("Edit")
|
||||
editButton.background = TITLE_BAR_COLOR
|
||||
editButton.foreground = secondaryColor
|
||||
editButton.font = Font("RuneScape Small", Font.PLAIN, 14)
|
||||
editButton.addActionListener {
|
||||
showPluginDetails(pluginInfo, plugin)
|
||||
}
|
||||
|
||||
// Layout
|
||||
val infoPanel = JPanel(BorderLayout())
|
||||
infoPanel.background = WIDGET_COLOR
|
||||
|
|
@ -138,8 +190,12 @@ object ReflectiveEditorView {
|
|||
|
||||
val controlsPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 5, 0))
|
||||
controlsPanel.background = WIDGET_COLOR
|
||||
|
||||
// Add edit button first (left side of controls)
|
||||
editButton?.let { controlsPanel.add(it) }
|
||||
|
||||
// Add toggle switch second (right side of controls)
|
||||
controlsPanel.add(toggleSwitch)
|
||||
controlsPanel.add(editButton)
|
||||
|
||||
panel.add(infoPanel, BorderLayout.CENTER)
|
||||
panel.add(controlsPanel, BorderLayout.EAST)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ class ToggleSwitch : JPanel() {
|
|||
private var borderColor = Color(50, 50, 50)
|
||||
private var activeSwitch = Color(0, 125, 255)
|
||||
private var puffer: BufferedImage? = null
|
||||
private var borderRadius = 10
|
||||
private var g: Graphics2D? = null
|
||||
|
||||
var onToggleListener: ((Boolean) -> Unit)? = null
|
||||
|
|
@ -28,9 +27,10 @@ class ToggleSwitch : JPanel() {
|
|||
}
|
||||
})
|
||||
cursor = Cursor(Cursor.HAND_CURSOR)
|
||||
preferredSize = Dimension(41, 21)
|
||||
maximumSize = Dimension(41, 21)
|
||||
minimumSize = Dimension(41, 21)
|
||||
preferredSize = Dimension(40, 20)
|
||||
maximumSize = Dimension(40, 20)
|
||||
minimumSize = Dimension(40, 20)
|
||||
isOpaque = false // Make the panel background transparent
|
||||
}
|
||||
|
||||
override fun paint(gr: Graphics) {
|
||||
|
|
@ -44,37 +44,33 @@ class ToggleSwitch : JPanel() {
|
|||
g?.setRenderingHints(rh)
|
||||
}
|
||||
|
||||
g?.color = if (activated) activeSwitch else switchColor
|
||||
g?.fillRoundRect(0, 0, width - 1, height - 1, 5, borderRadius)
|
||||
g?.color = borderColor
|
||||
g?.drawRoundRect(0, 0, width - 1, height - 1, 5, borderRadius)
|
||||
g?.color = buttonColor
|
||||
// Clear the buffer with transparent background
|
||||
g?.color = Color(0, 0, 0, 0)
|
||||
g?.fillRect(0, 0, width, height)
|
||||
|
||||
if (activated) {
|
||||
g?.fillRoundRect(
|
||||
width / 2, 1,
|
||||
(width - 1) / 2 - 2, (height - 1) - 2,
|
||||
borderRadius, borderRadius
|
||||
)
|
||||
g?.color = borderColor
|
||||
g?.drawRoundRect(
|
||||
(width - 1) / 2, 0,
|
||||
(width - 1) / 2, (height - 1),
|
||||
borderRadius, borderRadius
|
||||
)
|
||||
// Draw the track with circular ends (rounded rectangle)
|
||||
val trackHeight = height - 2
|
||||
val trackWidth = width - 2
|
||||
val trackArc = trackHeight // Makes it fully rounded at the ends
|
||||
|
||||
g?.color = if (activated) activeSwitch else switchColor
|
||||
g?.fillRoundRect(1, 1, trackWidth, trackHeight, trackArc, trackArc)
|
||||
g?.color = borderColor
|
||||
g?.drawRoundRect(1, 1, trackWidth, trackHeight, trackArc, trackArc)
|
||||
|
||||
// Draw the thumb (circular button)
|
||||
val thumbDiameter = trackHeight - 4
|
||||
val thumbX = if (activated) {
|
||||
width - thumbDiameter - 3 // Right side when activated
|
||||
} else {
|
||||
g?.fillRoundRect(
|
||||
1, 1,
|
||||
(width - 1) / 2 - 2, (height - 1) - 2,
|
||||
borderRadius, borderRadius
|
||||
)
|
||||
g?.color = borderColor
|
||||
g?.drawRoundRect(
|
||||
0, 0,
|
||||
(width - 1) / 2, (height - 1),
|
||||
borderRadius, borderRadius
|
||||
)
|
||||
3 // Left side when not activated
|
||||
}
|
||||
val thumbY = (height - thumbDiameter) / 2
|
||||
|
||||
g?.color = buttonColor
|
||||
g?.fillOval(thumbX, thumbY, thumbDiameter, thumbDiameter)
|
||||
g?.color = borderColor
|
||||
g?.drawOval(thumbX, thumbY, thumbDiameter, thumbDiameter)
|
||||
|
||||
gr.drawImage(puffer, 0, 0, null)
|
||||
}
|
||||
|
|
@ -128,18 +124,4 @@ class ToggleSwitch : JPanel() {
|
|||
fun setActiveSwitch(activeSwitch: Color) {
|
||||
this.activeSwitch = activeSwitch
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the borderRadius
|
||||
*/
|
||||
fun getBorderRadius(): Int {
|
||||
return borderRadius
|
||||
}
|
||||
|
||||
/**
|
||||
* @param borderRadius the borderRadius to set
|
||||
*/
|
||||
fun setBorderRadius(borderRadius: Int) {
|
||||
this.borderRadius = borderRadius
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue