Constant for FIXED_HEIGHT + transfercomponent helper

This commit is contained in:
downthecrop 2024-10-26 22:31:43 -07:00
parent 83fe4805ac
commit e7f46f1006

View file

@ -40,6 +40,7 @@ import rt4.GameShell.frame
import rt4.client.js5Archive8 import rt4.client.js5Archive8
import rt4.client.mainLoadState import rt4.client.mainLoadState
import java.awt.* import java.awt.*
import java.awt.Component
import java.awt.Font import java.awt.Font
import java.awt.event.* import java.awt.event.*
import java.awt.image.BufferedImage import java.awt.image.BufferedImage
@ -91,6 +92,7 @@ class plugin : Plugin() {
var uiOffset = 0 var uiOffset = 0
private const val FIXED_WIDTH = 765 private const val FIXED_WIDTH = 765
private const val FIXED_HEIGHT = 503
private const val NAVBAR_WIDTH = 30 private const val NAVBAR_WIDTH = 30
private const val MAIN_CONTENT_WIDTH = 242 private const val MAIN_CONTENT_WIDTH = 242
private const val WRENCH_ICON = 907 private const val WRENCH_ICON = 907
@ -111,6 +113,7 @@ class plugin : Plugin() {
private var lastUIOffset = 0 private var lastUIOffset = 0
private const val HIDDEN_VIEW = "HIDDEN" private const val HIDDEN_VIEW = "HIDDEN"
private val drawActions = mutableListOf<() -> Unit>() private val drawActions = mutableListOf<() -> Unit>()
private var hiddenFrame: JFrame? = null
fun registerDrawAction(action: () -> Unit) { fun registerDrawAction(action: () -> Unit) {
synchronized(drawActions) { synchronized(drawActions) {
@ -224,12 +227,12 @@ class plugin : Plugin() {
private fun validateGameImage() { private fun validateGameImage() {
val gc = GraphicsEnvironment.getLocalGraphicsEnvironment().defaultScreenDevice.defaultConfiguration val gc = GraphicsEnvironment.getLocalGraphicsEnvironment().defaultScreenDevice.defaultConfiguration
if (gameImage == null) { if (gameImage == null) {
gameImage = gc.createCompatibleVolatileImage(765, 503, Transparency.OPAQUE) gameImage = gc.createCompatibleVolatileImage(FIXED_WIDTH, FIXED_HEIGHT, Transparency.OPAQUE)
renderGameImage() renderGameImage()
} else { } else {
val status = gameImage!!.validate(gc) val status = gameImage!!.validate(gc)
if (status == VolatileImage.IMAGE_INCOMPATIBLE) { if (status == VolatileImage.IMAGE_INCOMPATIBLE) {
gameImage = gc.createCompatibleVolatileImage(765, 503, Transparency.OPAQUE) gameImage = gc.createCompatibleVolatileImage(FIXED_WIDTH, FIXED_HEIGHT, Transparency.OPAQUE)
renderGameImage() renderGameImage()
} else if (status == VolatileImage.IMAGE_RESTORED) { } else if (status == VolatileImage.IMAGE_RESTORED) {
renderGameImage() renderGameImage()
@ -261,13 +264,13 @@ class plugin : Plugin() {
do { do {
val gc = GraphicsEnvironment.getLocalGraphicsEnvironment().defaultScreenDevice.defaultConfiguration val gc = GraphicsEnvironment.getLocalGraphicsEnvironment().defaultScreenDevice.defaultConfiguration
if (gameImage == null) { if (gameImage == null) {
gameImage = gc.createCompatibleVolatileImage(765, 503, Transparency.OPAQUE) gameImage = gc.createCompatibleVolatileImage(FIXED_WIDTH, FIXED_HEIGHT, Transparency.OPAQUE)
renderGameImage() renderGameImage()
} else { } else {
val status = gameImage!!.validate(gc) val status = gameImage!!.validate(gc)
when (status) { when (status) {
VolatileImage.IMAGE_INCOMPATIBLE -> { VolatileImage.IMAGE_INCOMPATIBLE -> {
gameImage = gc.createCompatibleVolatileImage(765, 503, Transparency.OPAQUE) gameImage = gc.createCompatibleVolatileImage(FIXED_WIDTH, FIXED_HEIGHT, Transparency.OPAQUE)
renderGameImage() renderGameImage()
} }
VolatileImage.IMAGE_RESTORED -> renderGameImage() VolatileImage.IMAGE_RESTORED -> renderGameImage()
@ -370,7 +373,7 @@ class plugin : Plugin() {
fun createAltCanvas(): AltCanvas { fun createAltCanvas(): AltCanvas {
return AltCanvas().apply { return AltCanvas().apply {
preferredSize = Dimension(FIXED_WIDTH, 503) preferredSize = Dimension(FIXED_WIDTH, FIXED_HEIGHT)
} }
} }
@ -547,39 +550,51 @@ class plugin : Plugin() {
} }
} }
override fun LateDraw(timeDelta: Long){ override fun LateDraw(timeDelta: Long) {
if(!initialized) return if (!initialized) return
if (GetWindowMode() == WindowMode.FIXED) { if (GetWindowMode() == WindowMode.FIXED) {
if (canvas.parent !== hiddenFrame?.contentPane) { if (canvas.parent != hiddenFrame?.contentPane) {
if(altCanvas?.parent != frame) { if (altCanvas?.parent != frame) {
frame.add(altCanvas) frame.add(altCanvas)
} }
println("Moving canvas to hidden frame")
initializeHiddenFrame() initializeHiddenFrame()
frame.remove(canvas) // Remove from main frame if necessary hiddenFrame?.let { transferComponent(canvas, frame, it) }
hiddenFrame?.contentPane?.add(canvas)
hiddenFrame?.pack()
} }
} else { } else {
frame.remove(altCanvas) if (altCanvas?.parent == frame) {
frame.remove(altCanvas)
}
} }
altCanvas?.updateGameImage() // Update the game image as needed altCanvas?.updateGameImage() // Update the game image as needed
} }
private var hiddenFrame: JFrame? = null
fun initializeHiddenFrame() { fun transferComponent(component: Component, fromFrame: Frame, toFrame: Frame) {
println("Transferring component")
fromFrame.remove(component)
toFrame.add(component)
toFrame.pack()
fromFrame.revalidate()
toFrame.revalidate()
fromFrame.repaint()
toFrame.repaint()
}
fun initializeHiddenFrame(debugMode: Boolean = true) {
if (hiddenFrame == null) { if (hiddenFrame == null) {
hiddenFrame = JFrame().apply { hiddenFrame = JFrame().apply {
isUndecorated = true isUndecorated = !debugMode
isVisible = false // Keep it hidden isFocusable = false
setSize(1, 1) // Minimal size isVisible = debugMode // Show frame if debugMode is true
setSize(
if(debugMode) FIXED_WIDTH else 1,
if(debugMode) FIXED_HEIGHT else 1
)
defaultCloseOperation = JFrame.DO_NOTHING_ON_CLOSE defaultCloseOperation = JFrame.DO_NOTHING_ON_CLOSE
} }
} }
} }
private fun initKondoUI(){ private fun initKondoUI(){
DrawText(FontType.LARGE, fromColor(Color(16777215)), TextModifier.CENTER, "KondoKit Loading Sprites...", GameShell.canvasWidth/2, GameShell.canvasHeight/2) DrawText(FontType.LARGE, fromColor(Color(16777215)), TextModifier.CENTER, "KondoKit Loading Sprites...", GameShell.canvasWidth/2, GameShell.canvasHeight/2)
if(!allSpritesLoaded()) return; if(!allSpritesLoaded()) return;