mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-15 19:10:22 -07:00
a
This commit is contained in:
parent
440b8d4de1
commit
6adc5135bc
4 changed files with 52 additions and 123 deletions
|
|
@ -1,7 +1,11 @@
|
||||||
package KondoKit
|
package KondoKit
|
||||||
|
|
||||||
import java.awt.Component
|
import java.awt.Component
|
||||||
|
import java.awt.Container
|
||||||
import java.awt.Dimension
|
import java.awt.Dimension
|
||||||
|
import java.awt.event.MouseAdapter
|
||||||
|
import java.awt.event.MouseEvent
|
||||||
|
import javax.swing.JPopupMenu
|
||||||
|
|
||||||
fun <T : Component> T.setFixedSize(width: Int, height: Int): T =
|
fun <T : Component> T.setFixedSize(width: Int, height: Int): T =
|
||||||
setFixedSize(Dimension(width, height))
|
setFixedSize(Dimension(width, height))
|
||||||
|
|
@ -12,3 +16,23 @@ fun <T : Component> T.setFixedSize(size: Dimension): T {
|
||||||
maximumSize = size
|
maximumSize = size
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Component.attachPopupMenu(popupMenu: JPopupMenu, includeChildren: Boolean = false) {
|
||||||
|
val listener = object : MouseAdapter() {
|
||||||
|
private fun maybeShow(e: MouseEvent) {
|
||||||
|
if (e.isPopupTrigger) {
|
||||||
|
popupMenu.show(e.component, e.x, e.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mousePressed(e: MouseEvent) = maybeShow(e)
|
||||||
|
|
||||||
|
override fun mouseReleased(e: MouseEvent) = maybeShow(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
addMouseListener(listener)
|
||||||
|
|
||||||
|
if (includeChildren && this is Container) {
|
||||||
|
Helpers.addMouseListenerToAll(this, listener)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
package KondoKit.views
|
package KondoKit.views
|
||||||
|
|
||||||
import KondoKit.Helpers
|
import KondoKit.Helpers
|
||||||
import KondoKit.Helpers.addMouseListenerToAll
|
|
||||||
import KondoKit.Helpers.formatHtmlLabelText
|
import KondoKit.Helpers.formatHtmlLabelText
|
||||||
import KondoKit.ImageCanvas
|
import KondoKit.ImageCanvas
|
||||||
import KondoKit.SpriteToBufferedImage.getBufferedImageFromSprite
|
import KondoKit.SpriteToBufferedImage.getBufferedImageFromSprite
|
||||||
import KondoKit.ViewConstants
|
import KondoKit.ViewConstants
|
||||||
import KondoKit.setFixedSize
|
import KondoKit.setFixedSize
|
||||||
|
import KondoKit.attachPopupMenu
|
||||||
import KondoKit.views.XPTrackerView.wrappedWidget
|
import KondoKit.views.XPTrackerView.wrappedWidget
|
||||||
import KondoKit.components.PopupMenuComponent
|
import KondoKit.components.PopupMenuComponent
|
||||||
import KondoKit.components.ProgressBar
|
import KondoKit.components.ProgressBar
|
||||||
|
|
@ -139,23 +139,7 @@ object LootTrackerView : View, OnPostClientTickCallback, OnKillingBlowNPCCallbac
|
||||||
|
|
||||||
val wrapped = wrappedWidget(totalTrackerWidget!!.container, padding = 0)
|
val wrapped = wrappedWidget(totalTrackerWidget!!.container, padding = 0)
|
||||||
val popupMenu = resetLootTrackerMenu()
|
val popupMenu = resetLootTrackerMenu()
|
||||||
|
wrapped.attachPopupMenu(popupMenu, includeChildren = true)
|
||||||
// Create a custom MouseListener
|
|
||||||
val rightClickListener = object : MouseAdapter() {
|
|
||||||
override fun mousePressed(e: MouseEvent) {
|
|
||||||
if (e.isPopupTrigger) {
|
|
||||||
popupMenu.show(e.component, e.x, e.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseReleased(e: MouseEvent) {
|
|
||||||
if (e.isPopupTrigger) {
|
|
||||||
popupMenu.show(e.component, e.x, e.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addMouseListenerToAll(wrapped,rightClickListener)
|
|
||||||
wrapped.addMouseListener(rightClickListener)
|
|
||||||
add(wrapped)
|
add(wrapped)
|
||||||
add(Box.createVerticalStrut(8))
|
add(Box.createVerticalStrut(8))
|
||||||
revalidate()
|
revalidate()
|
||||||
|
|
@ -504,23 +488,7 @@ object LootTrackerView : View, OnPostClientTickCallback, OnKillingBlowNPCCallbac
|
||||||
childFramePanel.add(lootPanel)
|
childFramePanel.add(lootPanel)
|
||||||
|
|
||||||
val popupMenu = removeLootFrameMenu(childFramePanel, npcName)
|
val popupMenu = removeLootFrameMenu(childFramePanel, npcName)
|
||||||
|
labelPanel.attachPopupMenu(popupMenu)
|
||||||
// Create a custom MouseListener
|
|
||||||
val rightClickListener = object : MouseAdapter() {
|
|
||||||
override fun mousePressed(e: MouseEvent) {
|
|
||||||
if (e.isPopupTrigger) {
|
|
||||||
popupMenu.show(e.component, e.x, e.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseReleased(e: MouseEvent) {
|
|
||||||
if (e.isPopupTrigger) {
|
|
||||||
popupMenu.show(e.component, e.x, e.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
labelPanel.addMouseListener(rightClickListener)
|
|
||||||
return childFramePanel
|
return childFramePanel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -570,23 +538,7 @@ object LootTrackerView : View, OnPostClientTickCallback, OnKillingBlowNPCCallbac
|
||||||
|
|
||||||
val wrapped = wrappedWidget(totalTrackerWidget!!.container, padding = 0)
|
val wrapped = wrappedWidget(totalTrackerWidget!!.container, padding = 0)
|
||||||
val _popupMenu = resetLootTrackerMenu()
|
val _popupMenu = resetLootTrackerMenu()
|
||||||
|
wrapped.attachPopupMenu(_popupMenu, includeChildren = true)
|
||||||
// Create a custom MouseListener
|
|
||||||
val rightClickListener = object : MouseAdapter() {
|
|
||||||
override fun mousePressed(e: MouseEvent) {
|
|
||||||
if (e.isPopupTrigger) {
|
|
||||||
_popupMenu.show(e.component, e.x, e.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseReleased(e: MouseEvent) {
|
|
||||||
if (e.isPopupTrigger) {
|
|
||||||
_popupMenu.show(e.component, e.x, e.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addMouseListenerToAll(wrapped,rightClickListener)
|
|
||||||
wrapped.addMouseListener(rightClickListener)
|
|
||||||
lootTrackerView?.add(Box.createVerticalStrut(5))
|
lootTrackerView?.add(Box.createVerticalStrut(5))
|
||||||
lootTrackerView?.add(wrapped)
|
lootTrackerView?.add(wrapped)
|
||||||
lootTrackerView?.add(Box.createVerticalStrut(8))
|
lootTrackerView?.add(Box.createVerticalStrut(8))
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import KondoKit.components.*
|
||||||
import KondoKit.ViewConstants
|
import KondoKit.ViewConstants
|
||||||
import KondoKit.views.ViewLayoutHelpers.createSearchFieldSection
|
import KondoKit.views.ViewLayoutHelpers.createSearchFieldSection
|
||||||
import KondoKit.setFixedSize
|
import KondoKit.setFixedSize
|
||||||
|
import KondoKit.attachPopupMenu
|
||||||
import KondoKit.ReflectiveEditorPlugin
|
import KondoKit.ReflectiveEditorPlugin
|
||||||
import KondoKit.pluginmanager.GitLabPlugin
|
import KondoKit.pluginmanager.GitLabPlugin
|
||||||
import KondoKit.pluginmanager.GitLabPluginFetcher
|
import KondoKit.pluginmanager.GitLabPluginFetcher
|
||||||
|
|
@ -22,8 +23,6 @@ import plugin.PluginInfo
|
||||||
import plugin.PluginRepository
|
import plugin.PluginRepository
|
||||||
import rt4.GlobalJsonConfig
|
import rt4.GlobalJsonConfig
|
||||||
import java.awt.*
|
import java.awt.*
|
||||||
import java.awt.event.MouseAdapter
|
|
||||||
import java.awt.event.MouseEvent
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.swing.*
|
import javax.swing.*
|
||||||
|
|
@ -274,15 +273,7 @@ object ReflectiveEditorView : View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createPluginItemPanel(pluginInfo: PluginInfo, plugin: Plugin): JPanel {
|
private fun createPluginItemPanel(pluginInfo: PluginInfo, plugin: Plugin): JPanel {
|
||||||
val panel = WidgetPanel(
|
val panel = createPluginWidgetPanel().apply {
|
||||||
widgetWidth = ViewConstants.PLUGIN_LIST_ITEM_SIZE.width,
|
|
||||||
widgetHeight = ViewConstants.PLUGIN_LIST_ITEM_SIZE.height,
|
|
||||||
paddingLeft = 10,
|
|
||||||
paddingRight = 10,
|
|
||||||
paddingTop = 10,
|
|
||||||
paddingBottom = 10,
|
|
||||||
addDefaultPadding = false
|
|
||||||
).apply {
|
|
||||||
layout = BorderLayout()
|
layout = BorderLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -336,22 +327,14 @@ object ReflectiveEditorView : View {
|
||||||
|
|
||||||
if (!isKondoKit(packageName)) {
|
if (!isKondoKit(packageName)) {
|
||||||
val popupMenu = createPluginContextMenu(plugin, pluginInfo, packageName, false)
|
val popupMenu = createPluginContextMenu(plugin, pluginInfo, packageName, false)
|
||||||
addContextMenuToPanel(panel, popupMenu)
|
panel.attachPopupMenu(popupMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
return panel
|
return panel
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createDisabledPluginItemPanel(pluginName: String): JPanel {
|
private fun createDisabledPluginItemPanel(pluginName: String): JPanel {
|
||||||
val panel = WidgetPanel(
|
val panel = createPluginWidgetPanel().apply {
|
||||||
widgetWidth = ViewConstants.PLUGIN_LIST_ITEM_SIZE.width,
|
|
||||||
widgetHeight = ViewConstants.PLUGIN_LIST_ITEM_SIZE.height,
|
|
||||||
paddingLeft = 10,
|
|
||||||
paddingRight = 10,
|
|
||||||
paddingTop = 10,
|
|
||||||
paddingBottom = 10,
|
|
||||||
addDefaultPadding = false
|
|
||||||
).apply {
|
|
||||||
layout = BorderLayout()
|
layout = BorderLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -388,22 +371,14 @@ object ReflectiveEditorView : View {
|
||||||
// Add right-click context menu (except for KondoKit itself)
|
// Add right-click context menu (except for KondoKit itself)
|
||||||
if (!isKondoKit(pluginName)) {
|
if (!isKondoKit(pluginName)) {
|
||||||
val popupMenu = createPluginContextMenu(null, null, pluginName, true)
|
val popupMenu = createPluginContextMenu(null, null, pluginName, true)
|
||||||
addContextMenuToPanel(panel, popupMenu)
|
panel.attachPopupMenu(popupMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
return panel
|
return panel
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createPluginStatusItemPanel(pluginStatus: PluginInfoWithStatus): JPanel {
|
private fun createPluginStatusItemPanel(pluginStatus: PluginInfoWithStatus): JPanel {
|
||||||
val panel = WidgetPanel(
|
val panel = createPluginWidgetPanel().apply {
|
||||||
widgetWidth = ViewConstants.PLUGIN_LIST_ITEM_SIZE.width,
|
|
||||||
widgetHeight = ViewConstants.PLUGIN_LIST_ITEM_SIZE.height,
|
|
||||||
paddingLeft = 10,
|
|
||||||
paddingRight = 10,
|
|
||||||
paddingTop = 10,
|
|
||||||
paddingBottom = 10,
|
|
||||||
addDefaultPadding = false
|
|
||||||
).apply {
|
|
||||||
layout = BorderLayout()
|
layout = BorderLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -557,12 +532,24 @@ object ReflectiveEditorView : View {
|
||||||
|
|
||||||
if (!isKondoKit(pluginStatus.name) && pluginStatus.isInstalled) {
|
if (!isKondoKit(pluginStatus.name) && pluginStatus.isInstalled) {
|
||||||
val popupMenu = createPluginContextMenu(null, null, pluginStatus.name, !pluginStatus.needsUpdate)
|
val popupMenu = createPluginContextMenu(null, null, pluginStatus.name, !pluginStatus.needsUpdate)
|
||||||
addContextMenuToPanel(panel, popupMenu)
|
panel.attachPopupMenu(popupMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
return panel
|
return panel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createPluginWidgetPanel(): WidgetPanel {
|
||||||
|
return WidgetPanel(
|
||||||
|
widgetWidth = ViewConstants.PLUGIN_LIST_ITEM_SIZE.width,
|
||||||
|
widgetHeight = ViewConstants.PLUGIN_LIST_ITEM_SIZE.height,
|
||||||
|
addDefaultPadding = false,
|
||||||
|
paddingTop = 10,
|
||||||
|
paddingLeft = 10,
|
||||||
|
paddingBottom = 10,
|
||||||
|
paddingRight = 10
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun buildInstallableTooltip(pluginStatus: PluginInfoWithStatus): String {
|
private fun buildInstallableTooltip(pluginStatus: PluginInfoWithStatus): String {
|
||||||
val lines = mutableListOf<String>()
|
val lines = mutableListOf<String>()
|
||||||
pluginStatus.remoteVersion?.takeIf { it.isNotBlank() }?.let {
|
pluginStatus.remoteVersion?.takeIf { it.isNotBlank() }?.let {
|
||||||
|
|
@ -801,24 +788,6 @@ object ReflectiveEditorView : View {
|
||||||
reflectiveEditorPlugin.startPluginDownload(pluginStatus, mainPanel ?: JPanel())
|
reflectiveEditorPlugin.startPluginDownload(pluginStatus, mainPanel ?: JPanel())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to add context menu to a panel
|
|
||||||
private fun addContextMenuToPanel(panel: JPanel, popupMenu: JPopupMenu) {
|
|
||||||
val rightClickListener = object : MouseAdapter() {
|
|
||||||
override fun mousePressed(e: MouseEvent) {
|
|
||||||
if (e.isPopupTrigger) {
|
|
||||||
popupMenu.show(e.component, e.x, e.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseReleased(e: MouseEvent) {
|
|
||||||
if (e.isPopupTrigger) {
|
|
||||||
popupMenu.show(e.component, e.x, e.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panel.addMouseListener(rightClickListener)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper method to create context menu for plugins
|
// Helper method to create context menu for plugins
|
||||||
private fun createPluginContextMenu(plugin: Plugin?, pluginInfo: PluginInfo?, pluginName: String, isDisabled: Boolean): JPopupMenu {
|
private fun createPluginContextMenu(plugin: Plugin?, pluginInfo: PluginInfo?, pluginName: String, isDisabled: Boolean): JPopupMenu {
|
||||||
val popupMenu = PopupMenuComponent()
|
val popupMenu = PopupMenuComponent()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package KondoKit.views
|
package KondoKit.views
|
||||||
|
|
||||||
import KondoKit.Helpers
|
import KondoKit.Helpers
|
||||||
import KondoKit.Helpers.addMouseListenerToAll
|
|
||||||
import KondoKit.Helpers.formatHtmlLabelText
|
import KondoKit.Helpers.formatHtmlLabelText
|
||||||
import KondoKit.Helpers.formatNumber
|
import KondoKit.Helpers.formatNumber
|
||||||
import KondoKit.Helpers.getProgressBarColor
|
import KondoKit.Helpers.getProgressBarColor
|
||||||
|
|
@ -9,6 +8,7 @@ import KondoKit.Helpers.getSpriteId
|
||||||
import KondoKit.SpriteToBufferedImage.getBufferedImageFromSprite
|
import KondoKit.SpriteToBufferedImage.getBufferedImageFromSprite
|
||||||
import KondoKit.ViewConstants
|
import KondoKit.ViewConstants
|
||||||
import KondoKit.setFixedSize
|
import KondoKit.setFixedSize
|
||||||
|
import KondoKit.attachPopupMenu
|
||||||
import KondoKit.XPTable
|
import KondoKit.XPTable
|
||||||
import KondoKit.components.PopupMenuComponent
|
import KondoKit.components.PopupMenuComponent
|
||||||
import KondoKit.components.ProgressBar
|
import KondoKit.components.ProgressBar
|
||||||
|
|
@ -26,8 +26,6 @@ import KondoKit.plugin.StateManager.focusedView
|
||||||
import plugin.api.API
|
import plugin.api.API
|
||||||
import java.awt.*
|
import java.awt.*
|
||||||
import java.awt.image.BufferedImage
|
import java.awt.image.BufferedImage
|
||||||
import java.awt.event.MouseAdapter
|
|
||||||
import java.awt.event.MouseEvent
|
|
||||||
import javax.swing.*
|
import javax.swing.*
|
||||||
import javax.swing.SwingConstants
|
import javax.swing.SwingConstants
|
||||||
|
|
||||||
|
|
@ -66,22 +64,6 @@ object XPTrackerView : View, OnUpdateCallback, OnXPUpdateCallback {
|
||||||
|
|
||||||
private val widgetFont = ViewConstants.FONT_RUNESCAPE_SMALL_16
|
private val widgetFont = ViewConstants.FONT_RUNESCAPE_SMALL_16
|
||||||
|
|
||||||
private fun createPopupListener(popupMenu: JPopupMenu) = object : MouseAdapter() {
|
|
||||||
override fun mousePressed(e: MouseEvent) {
|
|
||||||
if (e.isPopupTrigger) popupMenu.show(e.component, e.x, e.y)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseReleased(e: MouseEvent) {
|
|
||||||
if (e.isPopupTrigger) popupMenu.show(e.component, e.x, e.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun attachPopup(component: Container, popupMenu: JPopupMenu) {
|
|
||||||
val listener = createPopupListener(popupMenu)
|
|
||||||
addMouseListenerToAll(component, listener)
|
|
||||||
component.addMouseListener(listener)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun BufferedImage.ensureOpaque(): BufferedImage {
|
private fun BufferedImage.ensureOpaque(): BufferedImage {
|
||||||
for (y in 0 until height) {
|
for (y in 0 until height) {
|
||||||
for (x in 0 until width) {
|
for (x in 0 until width) {
|
||||||
|
|
@ -133,7 +115,9 @@ object XPTrackerView : View, OnUpdateCallback, OnXPUpdateCallback {
|
||||||
|
|
||||||
private fun createTotalWidgetContainer(popupMenu: JPopupMenu): Container {
|
private fun createTotalWidgetContainer(popupMenu: JPopupMenu): Container {
|
||||||
totalXPWidget = createTotalXPWidget()
|
totalXPWidget = createTotalXPWidget()
|
||||||
return wrappedWidget(totalXPWidget!!.container, padding = 0).also { attachPopup(it, popupMenu) }
|
return wrappedWidget(totalXPWidget!!.container, padding = 0).also {
|
||||||
|
it.attachPopupMenu(popupMenu, includeChildren = true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val panel: JPanel
|
override val panel: JPanel
|
||||||
|
|
@ -190,7 +174,7 @@ object XPTrackerView : View, OnUpdateCallback, OnXPUpdateCallback {
|
||||||
|
|
||||||
val wrapped = wrappedWidget(xpWidget.container)
|
val wrapped = wrappedWidget(xpWidget.container)
|
||||||
val popupMenu = removeXPWidgetMenu(wrapped, skillId)
|
val popupMenu = removeXPWidgetMenu(wrapped, skillId)
|
||||||
attachPopup(wrapped, popupMenu)
|
wrapped.attachPopupMenu(popupMenu, includeChildren = true)
|
||||||
|
|
||||||
xpTrackerView?.add(wrapped)
|
xpTrackerView?.add(wrapped)
|
||||||
xpTrackerView?.add(Box.createVerticalStrut(5))
|
xpTrackerView?.add(Box.createVerticalStrut(5))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue