diff --git a/plugin-playground/src/main/kotlin/KondoKit/.DS_Store b/plugin-playground/src/main/kotlin/KondoKit/.DS_Store index a55bac8..4caffea 100644 Binary files a/plugin-playground/src/main/kotlin/KondoKit/.DS_Store and b/plugin-playground/src/main/kotlin/KondoKit/.DS_Store differ diff --git a/plugin-playground/src/main/kotlin/KondoKit/plugin.kt b/plugin-playground/src/main/kotlin/KondoKit/plugin.kt index 08fec9f..b0b03b9 100644 --- a/plugin-playground/src/main/kotlin/KondoKit/plugin.kt +++ b/plugin-playground/src/main/kotlin/KondoKit/plugin.kt @@ -320,52 +320,77 @@ class plugin : Plugin() { } private fun updateDisplaySettings() { - val mode = GetWindowMode() - val currentScrollPaneWidth = if (mainContentPanel.isVisible) NAVBAR_WIDTH + MAIN_CONTENT_WIDTH else NAVBAR_WIDTH - lastUIOffset = uiOffset + val applyDisplaySettings = { + val mode = GetWindowMode() + val currentScrollPaneWidth = if (mainContentPanel.isVisible) NAVBAR_WIDTH + MAIN_CONTENT_WIDTH else NAVBAR_WIDTH + lastUIOffset = uiOffset - if(mode != WindowMode.FIXED) { - destroyAltCanvas() - } else if (useScaledFixed && altCanvas == null) { - initAltCanvas() - } else if (!useScaledFixed && altCanvas != null) { - // Was using scaled fixed but toggled the setting - // restore the original canvas - moveCanvasToFront() - destroyAltCanvas() - } - - when (mode) { - WindowMode.FIXED -> { - if (frame.width < FIXED_WIDTH + currentScrollPaneWidth + uiOffset) { - frame.setSize(FIXED_WIDTH + currentScrollPaneWidth + uiOffset, frame.height) - } - - val difference = frame.width - (uiOffset + currentScrollPaneWidth) - - if (useScaledFixed) { - GameShell.leftMargin = 0 - val canvasWidth = difference + uiOffset / 2 - val canvasHeight = frame.height - canvas.y // Restricting height to frame height - - altCanvas?.size = Dimension(canvasWidth, canvasHeight) - altCanvas?.setLocation(0, canvas.y) - canvas.setLocation(0, canvas.y) - } else { - val difference = frame.width - (FIXED_WIDTH + uiOffset + currentScrollPaneWidth) - GameShell.leftMargin = difference / 2 + // Ensure the scroll wrapper stays attached on the EAST edge even if the game resets the layout + rightPanelWrapper?.let { wrapper -> + val needsLayoutReset = frame.layout !is BorderLayout + val needsAttach = wrapper.parent != frame + if (needsLayoutReset || needsAttach) { + wrapper.parent?.remove(wrapper) + frame.layout = BorderLayout() + frame.add(wrapper, BorderLayout.EAST) + if (altCanvas != null) { + moveAltCanvasToFront() + } else { + moveCanvasToFront() + } } } - WindowMode.RESIZABLE -> { - GameShell.canvasWidth = frame.width - (currentScrollPaneWidth + uiOffset) + if(mode != WindowMode.FIXED) { + destroyAltCanvas() + } else if (useScaledFixed && altCanvas == null) { + initAltCanvas() + } else if (!useScaledFixed && altCanvas != null) { + // Was using scaled fixed but toggled the setting + // restore the original canvas + moveCanvasToFront() + destroyAltCanvas() } + + when (mode) { + WindowMode.FIXED -> { + if (frame.width < FIXED_WIDTH + currentScrollPaneWidth + uiOffset) { + frame.setSize(FIXED_WIDTH + currentScrollPaneWidth + uiOffset, frame.height) + } + + val difference = frame.width - (uiOffset + currentScrollPaneWidth) + + if (useScaledFixed) { + GameShell.leftMargin = 0 + val canvasWidth = difference + uiOffset / 2 + val canvasHeight = frame.height - canvas.y // Restricting height to frame height + + altCanvas?.size = Dimension(canvasWidth, canvasHeight) + altCanvas?.setLocation(0, canvas.y) + canvas.setLocation(0, canvas.y) + } else { + val difference = frame.width - (FIXED_WIDTH + uiOffset + currentScrollPaneWidth) + GameShell.leftMargin = difference / 2 + } + } + + WindowMode.RESIZABLE -> { + GameShell.canvasWidth = frame.width - (currentScrollPaneWidth + uiOffset) + } + } + + rightPanelWrapper?.preferredSize = Dimension(currentScrollPaneWidth, frame.height) + rightPanelWrapper?.isDoubleBuffered = true + rightPanelWrapper?.revalidate() + rightPanelWrapper?.repaint() + frame.validate() } - rightPanelWrapper?.preferredSize = Dimension(currentScrollPaneWidth, frame.height) - rightPanelWrapper?.isDoubleBuffered = true - rightPanelWrapper?.revalidate() - rightPanelWrapper?.repaint() + if (SwingUtilities.isEventDispatchThread()) { + applyDisplaySettings() + } else { + SwingUtilities.invokeLater { applyDisplaySettings() } + } } fun OnKondoValueUpdated(){