diff --git a/plugin-playground/src/main/kotlin/KondoKit/LootTrackerView.kt b/plugin-playground/src/main/kotlin/KondoKit/LootTrackerView.kt index 459b84f..e293408 100644 --- a/plugin-playground/src/main/kotlin/KondoKit/LootTrackerView.kt +++ b/plugin-playground/src/main/kotlin/KondoKit/LootTrackerView.kt @@ -538,39 +538,44 @@ object LootTrackerView { } popupMenu.add(menuItem1) menuItem1.addActionListener { - lootTrackerView?.removeAll() - npcKillCounts.clear() - lootItemPanels.clear() - totalTrackerWidget = createTotalLootWidget() - - val wrapped = wrappedWidget(totalTrackerWidget!!.container) - val _popupMenu = resetLootTrackerMenu() - - // 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) - } - } + plugin.registerDrawAction { + resetLootTracker() } - addMouseListenerToAll(wrapped,rightClickListener) - wrapped.addMouseListener(rightClickListener) - lootTrackerView?.add(Box.createVerticalStrut(5)) - lootTrackerView?.add(wrapped) - lootTrackerView?.add(Box.createVerticalStrut(10)) - lootTrackerView?.revalidate() - lootTrackerView?.repaint() } return popupMenu } + private fun resetLootTracker(){ + lootTrackerView?.removeAll() + npcKillCounts.clear() + lootItemPanels.clear() + totalTrackerWidget = createTotalLootWidget() + + val wrapped = wrappedWidget(totalTrackerWidget!!.container) + val _popupMenu = resetLootTrackerMenu() + + // 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(wrapped) + lootTrackerView?.add(Box.createVerticalStrut(10)) + lootTrackerView?.revalidate() + lootTrackerView?.repaint() + } class FixedSizePanel(private val fixedSize: Dimension) : JPanel() { override fun getPreferredSize(): Dimension { diff --git a/plugin-playground/src/main/kotlin/KondoKit/XPTrackerView.kt b/plugin-playground/src/main/kotlin/KondoKit/XPTrackerView.kt index ff41e11..a30030c 100644 --- a/plugin-playground/src/main/kotlin/KondoKit/XPTrackerView.kt +++ b/plugin-playground/src/main/kotlin/KondoKit/XPTrackerView.kt @@ -1,10 +1,10 @@ package KondoKit +import KondoKit.Helpers.addMouseListenerToAll import KondoKit.Helpers.formatHtmlLabelText import KondoKit.Helpers.formatNumber import KondoKit.Helpers.getProgressBarColor import KondoKit.Helpers.getSpriteId -import KondoKit.Helpers.addMouseListenerToAll import KondoKit.SpriteToBufferedImage.getBufferedImageFromSprite import KondoKit.plugin.Companion.IMAGE_SIZE import KondoKit.plugin.Companion.LVL_ICON @@ -295,14 +295,9 @@ object XPTrackerView { // Add menu items to the popup menu popupMenu.add(menuItem1) - //popupMenu.add(menuItem2) - //popupMenu.add(menuItem3) // Add action listeners to each menu item (optional) - menuItem1.addActionListener { resetXPTracker(xpTrackerView!!) } - //menuItem2.addActionListener { println("Option 2 selected") } - //menuItem3.addActionListener { println("Option 3 selected") } - + menuItem1.addActionListener { plugin.registerDrawAction { resetXPTracker(xpTrackerView!!) } } return popupMenu } diff --git a/plugin-playground/src/main/kotlin/KondoKit/plugin.kt b/plugin-playground/src/main/kotlin/KondoKit/plugin.kt index 368cc00..046c0fe 100644 --- a/plugin-playground/src/main/kotlin/KondoKit/plugin.kt +++ b/plugin-playground/src/main/kotlin/KondoKit/plugin.kt @@ -90,6 +90,13 @@ class plugin : Plugin() { private var initialized = false; private var lastClickTime = 0L private var lastUIOffset = 0 + private val drawActions = mutableListOf<() -> Unit>() + + fun registerDrawAction(action: () -> Unit) { + synchronized(drawActions) { + drawActions.add(action) + } + } } fun allSpritesLoaded() : Boolean { @@ -259,6 +266,17 @@ class plugin : Plugin() { accumulatedTime = 0L } + // Draw synced actions (that require to be done between glBegin and glEnd) + if (drawActions.isNotEmpty()) { + synchronized(drawActions) { + val actionsCopy = drawActions.toList() + drawActions.clear() + for (action in actionsCopy) { + action() + } + } + } + // Init in the draw call so we know we are between glBegin and glEnd for HD if(!initialized && mainLoadState >= loginScreen) { initKondoUI()